code polish/cleanup
This commit is contained in:
parent
ff38339f31
commit
c92974af61
@ -62,8 +62,6 @@ import java.net.InetSocketAddress;
|
|||||||
public
|
public
|
||||||
class Client extends EndPointClient implements Connection {
|
class Client extends EndPointClient implements Connection {
|
||||||
|
|
||||||
private final Configuration options;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Starts a LOCAL <b>only</b> client, with the default local channel name and serialization scheme
|
* Starts a LOCAL <b>only</b> client, with the default local channel name and serialization scheme
|
||||||
*/
|
*/
|
||||||
@ -87,7 +85,6 @@ class Client extends EndPointClient implements Connection {
|
|||||||
public
|
public
|
||||||
Client(final Configuration options) throws InitializationException, SecurityException, IOException {
|
Client(final Configuration options) throws InitializationException, SecurityException, IOException {
|
||||||
super(options);
|
super(options);
|
||||||
this.options = options;
|
|
||||||
|
|
||||||
String threadName = Client.class.getSimpleName();
|
String threadName = Client.class.getSimpleName();
|
||||||
|
|
||||||
@ -109,9 +106,6 @@ class Client extends EndPointClient implements Connection {
|
|||||||
options.udtPort = -1;
|
options.udtPort = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// tcpBootstrap.setOption(SO_SNDBUF, 1048576);
|
|
||||||
// tcpBootstrap.setOption(SO_RCVBUF, 1048576);
|
|
||||||
|
|
||||||
// setup the thread group to easily ID what the following threads belong to (and their spawned threads...)
|
// setup the thread group to easily ID what the following threads belong to (and their spawned threads...)
|
||||||
SecurityManager s = System.getSecurityManager();
|
SecurityManager s = System.getSecurityManager();
|
||||||
ThreadGroup nettyGroup = new ThreadGroup(s != null
|
ThreadGroup nettyGroup = new ThreadGroup(s != null
|
||||||
@ -136,6 +130,10 @@ class Client extends EndPointClient implements Connection {
|
|||||||
manageForShutdown(boss);
|
manageForShutdown(boss);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
if (options.host == null) {
|
||||||
|
throw new IllegalArgumentException("You must define what host you want to connect to.");
|
||||||
|
}
|
||||||
|
|
||||||
if (options.tcpPort > 0) {
|
if (options.tcpPort > 0) {
|
||||||
Bootstrap tcpBootstrap = new Bootstrap();
|
Bootstrap tcpBootstrap = new Bootstrap();
|
||||||
this.bootstraps.add(new BootstrapWrapper("TCP", options.tcpPort, tcpBootstrap));
|
this.bootstraps.add(new BootstrapWrapper("TCP", options.tcpPort, tcpBootstrap));
|
||||||
@ -356,6 +354,7 @@ class Client extends EndPointClient implements Connection {
|
|||||||
/**
|
/**
|
||||||
* Expose methods to send objects to a destination when the connection has become idle.
|
* Expose methods to send objects to a destination when the connection has become idle.
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public
|
public
|
||||||
IdleBridge sendOnIdle(IdleSender<?, ?> sender) {
|
IdleBridge sendOnIdle(IdleSender<?, ?> sender) {
|
||||||
return this.connectionManager.getConnection0()
|
return this.connectionManager.getConnection0()
|
||||||
@ -365,6 +364,7 @@ class Client extends EndPointClient implements Connection {
|
|||||||
/**
|
/**
|
||||||
* Expose methods to send objects to a destination when the connection has become idle.
|
* Expose methods to send objects to a destination when the connection has become idle.
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public
|
public
|
||||||
IdleBridge sendOnIdle(Object message) {
|
IdleBridge sendOnIdle(Object message) {
|
||||||
return this.connectionManager.getConnection0()
|
return this.connectionManager.getConnection0()
|
||||||
@ -383,14 +383,6 @@ class Client extends EndPointClient implements Connection {
|
|||||||
return this.connectionManager.getConnection0();
|
return this.connectionManager.getConnection0();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Fetches the host (server) name for this client.
|
|
||||||
*/
|
|
||||||
public
|
|
||||||
String getHost() {
|
|
||||||
return this.options.host;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Closes all connections ONLY (keeps the server/client running).
|
* Closes all connections ONLY (keeps the server/client running).
|
||||||
* <p/>
|
* <p/>
|
||||||
@ -427,6 +419,7 @@ class Client extends EndPointClient implements Connection {
|
|||||||
*
|
*
|
||||||
* @see RemoteObject
|
* @see RemoteObject
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public
|
public
|
||||||
<Iface, Impl extends Iface> Iface createRemoteObject(final Class<Impl> remoteImplementationClass) throws NetException {
|
<Iface, Impl extends Iface> Iface createRemoteObject(final Class<Impl> remoteImplementationClass) throws NetException {
|
||||||
return this.connectionManager.getConnection0().createRemoteObject(remoteImplementationClass);
|
return this.connectionManager.getConnection0().createRemoteObject(remoteImplementationClass);
|
||||||
@ -456,11 +449,9 @@ class Client extends EndPointClient implements Connection {
|
|||||||
*
|
*
|
||||||
* @see RemoteObject
|
* @see RemoteObject
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public
|
public
|
||||||
<Iface, Impl extends Iface> Iface getRemoteObject(final int objectId) throws NetException {
|
<Iface, Impl extends Iface> Iface getRemoteObject(final int objectId) throws NetException {
|
||||||
return this.connectionManager.getConnection0().getRemoteObject(objectId);
|
return this.connectionManager.getConnection0().getRemoteObject(objectId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,9 @@ import java.util.concurrent.Executor;
|
|||||||
|
|
||||||
public
|
public
|
||||||
class Configuration {
|
class Configuration {
|
||||||
|
/**
|
||||||
|
* On the server, if host is null, it will bind to the "any" address, otherwise you must specify the hostname/IP to bind to.
|
||||||
|
*/
|
||||||
public String host = null;
|
public String host = null;
|
||||||
public int tcpPort = -1;
|
public int tcpPort = -1;
|
||||||
|
|
||||||
|
@ -152,10 +152,6 @@ class Server extends EndPointServer {
|
|||||||
this.udtBootstrap = null;
|
this.udtBootstrap = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: do we need to set the snd/rcv buffer?
|
|
||||||
// tcpBootstrap.setOption(SO_SNDBUF, 1048576);
|
|
||||||
// tcpBootstrap.setOption(SO_RCVBUF, 1048576);
|
|
||||||
|
|
||||||
// setup the thread group to easily ID what the following threads belong to (and their spawned threads...)
|
// setup the thread group to easily ID what the following threads belong to (and their spawned threads...)
|
||||||
SecurityManager s = System.getSecurityManager();
|
SecurityManager s = System.getSecurityManager();
|
||||||
ThreadGroup nettyGroup = new ThreadGroup(s != null
|
ThreadGroup nettyGroup = new ThreadGroup(s != null
|
||||||
@ -230,6 +226,7 @@ class Server extends EndPointServer {
|
|||||||
this.tcpBootstrap.localAddress(this.tcpPort);
|
this.tcpBootstrap.localAddress(this.tcpPort);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// android screws up on this!!
|
// android screws up on this!!
|
||||||
this.tcpBootstrap.option(ChannelOption.TCP_NODELAY, !Sys.isAndroid);
|
this.tcpBootstrap.option(ChannelOption.TCP_NODELAY, !Sys.isAndroid);
|
||||||
this.tcpBootstrap.childOption(ChannelOption.TCP_NODELAY, !Sys.isAndroid);
|
this.tcpBootstrap.childOption(ChannelOption.TCP_NODELAY, !Sys.isAndroid);
|
||||||
|
@ -173,8 +173,11 @@ class EndPoint {
|
|||||||
|
|
||||||
this.logger = org.slf4j.LoggerFactory.getLogger(type);
|
this.logger = org.slf4j.LoggerFactory.getLogger(type);
|
||||||
|
|
||||||
|
// The registration wrapper permits the registration process to access protected/package fields/methods, that we don't want
|
||||||
|
// to expose to external code. "this" escaping can be ignored, because it is benign.
|
||||||
|
//noinspection ThisEscapedInObjectConstruction
|
||||||
this.registrationWrapper = new RegistrationWrapper(this,
|
this.registrationWrapper = new RegistrationWrapper(this,
|
||||||
this.logger); // TODO - get rid of the wrapper, since it just loops back on itself
|
this.logger);
|
||||||
|
|
||||||
// make sure that 'localhost' is REALLY our specific IP address
|
// make sure that 'localhost' is REALLY our specific IP address
|
||||||
if (options.host != null && (options.host.equals("localhost") || options.host.startsWith("127."))) {
|
if (options.host != null && (options.host.equals("localhost") || options.host.startsWith("127."))) {
|
||||||
@ -315,26 +318,6 @@ class EndPoint {
|
|||||||
return (T) this.propertyStore;
|
return (T) this.propertyStore;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* TODO maybe remove this? method call is used by jetty ssl
|
|
||||||
*
|
|
||||||
* @return the ECC public key in use by this endpoint
|
|
||||||
*/
|
|
||||||
public
|
|
||||||
ECPrivateKeyParameters getPrivateKey() {
|
|
||||||
return this.privateKey;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* TODO maybe remove this? method call is used by jetty ssl
|
|
||||||
*
|
|
||||||
* @return the ECC private key in use by this endpoint
|
|
||||||
*/
|
|
||||||
public
|
|
||||||
ECPublicKeyParameters getPublicKey() {
|
|
||||||
return this.publicKey;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Internal call by the pipeline to notify the client to continue registering the different session protocols.
|
* Internal call by the pipeline to notify the client to continue registering the different session protocols.
|
||||||
* The server does not use this.
|
* The server does not use this.
|
||||||
@ -411,7 +394,7 @@ class EndPoint {
|
|||||||
*
|
*
|
||||||
* @return a new network connection
|
* @return a new network connection
|
||||||
*/
|
*/
|
||||||
public
|
protected
|
||||||
ConnectionImpl newConnection(final Logger logger, final EndPoint endPoint, final RmiBridge rmiBridge) {
|
ConnectionImpl newConnection(final Logger logger, final EndPoint endPoint, final RmiBridge rmiBridge) {
|
||||||
return new ConnectionImpl(logger, endPoint, rmiBridge);
|
return new ConnectionImpl(logger, endPoint, rmiBridge);
|
||||||
}
|
}
|
||||||
@ -522,38 +505,12 @@ class EndPoint {
|
|||||||
* Registers a tool with the server, to be used by other services.
|
* Registers a tool with the server, to be used by other services.
|
||||||
*/
|
*/
|
||||||
public
|
public
|
||||||
void registerTool(EndPointTool toolClass) {
|
<T extends EndPointTool> void registerTool(T toolClass) {
|
||||||
if (toolClass == null) {
|
if (toolClass == null) {
|
||||||
throw new IllegalArgumentException("Tool must not be null! Unable to add tool");
|
throw new IllegalArgumentException("Tool must not be null! Unable to add tool");
|
||||||
}
|
}
|
||||||
|
|
||||||
Class<?>[] interfaces = toolClass.getClass()
|
EndPointTool put = this.toolMap.put(toolClass.getClass(), toolClass);
|
||||||
.getInterfaces();
|
|
||||||
int length = interfaces.length;
|
|
||||||
int index = -1;
|
|
||||||
|
|
||||||
if (length > 1) {
|
|
||||||
Class<?> clazz2;
|
|
||||||
Class<EndPointTool> cls = EndPointTool.class;
|
|
||||||
|
|
||||||
for (int i = 0; i < length; i++) {
|
|
||||||
clazz2 = interfaces[i];
|
|
||||||
if (cls.isAssignableFrom(clazz2)) {
|
|
||||||
index = i;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (index == -1) {
|
|
||||||
throw new IllegalArgumentException("Unable to discover tool interface! WHOOPS!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
index = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
Class<?> clazz = interfaces[index];
|
|
||||||
EndPointTool put = this.toolMap.put(clazz, toolClass);
|
|
||||||
if (put != null) {
|
if (put != null) {
|
||||||
throw new IllegalArgumentException("Tool must be unique! Unable to add tool");
|
throw new IllegalArgumentException("Tool must be unique! Unable to add tool");
|
||||||
}
|
}
|
||||||
@ -563,7 +520,7 @@ class EndPoint {
|
|||||||
* Only get the tools in the ModuleStart (ie: load) methods. If done in the constructor, the tool might not be available yet
|
* Only get the tools in the ModuleStart (ie: load) methods. If done in the constructor, the tool might not be available yet
|
||||||
*/
|
*/
|
||||||
public
|
public
|
||||||
<T extends EndPointTool> T getTool(Class<?> toolClass) {
|
<T extends EndPointTool> T getTool(Class<T> toolClass) {
|
||||||
if (toolClass == null) {
|
if (toolClass == null) {
|
||||||
throw new IllegalArgumentException("Tool must not be null! Unable to add tool");
|
throw new IllegalArgumentException("Tool must not be null! Unable to add tool");
|
||||||
}
|
}
|
||||||
|
@ -68,12 +68,10 @@ class RegistrationWrapper implements UdpServer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public
|
|
||||||
void setKryoTcpEncoder(KryoEncoder kryoTcpEncoder) {
|
void setKryoTcpEncoder(KryoEncoder kryoTcpEncoder) {
|
||||||
this.kryoTcpEncoder = kryoTcpEncoder;
|
this.kryoTcpEncoder = kryoTcpEncoder;
|
||||||
}
|
}
|
||||||
|
|
||||||
public
|
|
||||||
void setKryoTcpCryptoEncoder(KryoEncoderCrypto kryoTcpCryptoEncoder) {
|
void setKryoTcpCryptoEncoder(KryoEncoderCrypto kryoTcpCryptoEncoder) {
|
||||||
this.kryoTcpCryptoEncoder = kryoTcpCryptoEncoder;
|
this.kryoTcpCryptoEncoder = kryoTcpCryptoEncoder;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user