Initial commit from SVN.

This commit is contained in:
wcrisman
2014-05-30 10:31:51 -07:00
commit b45e56b890
1968 changed files with 370949 additions and 0 deletions

View File

@@ -0,0 +1,306 @@
/*
* Copyright (c) 2005,2009 Declarative Engineering LLC.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Declarative Engineering LLC
* verson 1 which accompanies this distribution, and is available at
* http://declarativeengineering.com/legal/DE_Developer_License_v1.txt
*/
package com.de22.orb.optional;
import com.common.event.ObjectHandler1;
import com.common.orb.IResultCallback;
import com.common.util.*;
import com.de22.orb.*;
public class CommonOrbWrapper implements com.common.orb.IOrbWrapper {
private Orb orb = null;
/**
* Listens for a proxy to become invalid and notifies the proper listener in the application.
*/
private static class ProxyInvalidListener implements IProxyInvalidListener {
com.common.orb.IInvalidProxyListener invalidProxyListener = null;
private ProxyInvalidListener(com.common.orb.IInvalidProxyListener invalidProxyListener) {
this.invalidProxyListener = invalidProxyListener;
}//ProxyInvalidListener()//
public void onProxyInvalid(Proxy proxy) {
invalidProxyListener.evaluate(proxy);
}//onProxyInvalid()//
public int hashCode() {
return invalidProxyListener.hashCode();
}//hashCode()//
public boolean equals(Object object) {
return (object instanceof ProxyInvalidListener) ? invalidProxyListener.equals(((ProxyInvalidListener) object).invalidProxyListener) : false;
}//equals()//
}//ProxyInvalidListener//
/**
* CommonOrbWrapper constructor.
* @param classLoader An optional class loader provided to the orb. This is most often an instance of <code>com.de22.orb.development.OrbClassLoader</code>
* @param instanceFactory An optional factory to allow the application control over how classes are instantiated.
* @param classTracker An optional object that allows the application notification of which classes are being used by the orb.
* @see com.de22.orb.development.OrbClassLoader
*/
public CommonOrbWrapper(ClassLoader classLoader, com.common.io.IInstanceFactory instanceFactory, com.common.io.IClassTracker classTracker) {
super();
orb = new Orb(classLoader, instanceFactory, classTracker, null, null, null);
}//CommonOrbWrapper()//
/**
* CommonOrbWrapper constructor.
* @param classLoader An optional class loader provided to the orb. This is most often an instance of <code>com.de22.orb.development.OrbClassLoader</code>
* @param instanceFactory An optional factory to allow the application control over how classes are instantiated.
* @param classTracker An optional object that allows the application notification of which classes are being used by the orb.
* @param nioEngine The optional NIO Engine instance to be used by all connections that are not otherwise provided an NIO Engine via their options. If this is null and the options don't provide an NIO Engine then a thread per socket will be used.
* @param proxyInterfaceLoader The optional object used to load proxy classes from the proxy'd interface or object.
* @see com.de22.orb.development.OrbClassLoader
*/
public CommonOrbWrapper(ClassLoader classLoader, com.common.io.IInstanceFactory instanceFactory, com.common.io.IClassTracker classTracker, NioEngine nioEngine, IProxyInterfaceLoader proxyInterfaceLoader) {
super();
orb = new Orb(classLoader, instanceFactory, classTracker, nioEngine, proxyInterfaceLoader, null);
}//CommonOrbWrapper()//
/**
* CommonOrbWrapper constructor.
* @param classLoader An optional class loader provided to the orb. This is most often an instance of <code>com.de22.orb.development.OrbClassLoader</code>
* @param instanceFactory An optional factory to allow the application control over how classes are instantiated.
* @param classTracker An optional object that allows the application notification of which classes are being used by the orb.
* @param nioEngine The optional NIO Engine instance to be used by all connections that are not otherwise provided an NIO Engine via their options. If this is null and the options don't provide an NIO Engine then a thread per socket will be used.
* @param proxyInterfaceLoader The optional object used to load proxy classes from the proxy'd interface or object.
* @param reconnectListener The optional listener called when a socket attempts to reconnect. The listener is given some feedback and control over the process.
* @see com.de22.orb.development.OrbClassLoader
*/
public CommonOrbWrapper(ClassLoader classLoader, com.common.io.IInstanceFactory instanceFactory, com.common.io.IClassTracker classTracker, NioEngine nioEngine, IProxyInterfaceLoader proxyInterfaceLoader, IReconnectListener reconnectListener) {
super();
orb = new Orb(classLoader, instanceFactory, classTracker, nioEngine, proxyInterfaceLoader, reconnectListener);
}//CommonOrbWrapper()//
/* (non-Javadoc)
* @see com.common.orb.IOrbWrapper#bind(java.lang.Object, java.lang.Object, com.common.util.LiteHashSet)
*/
public void bind(Object object, Object resource, LiteHashSet permissions) {
orb.bind(object, resource, permissions);
}//bind()//
/* (non-Javadoc)
* @see com.common.orb.IOrbWrapper#checkExactEquality(java.lang.Object, java.lang.Object)
*/
public boolean checkExactEquality(Object object1, Object object2) {
if(object1 instanceof com.common.comparison.IComparable) {
return ((com.common.comparison.IComparable) object1).equalsEquals(object2);
}//if//
else if(object2 instanceof com.common.comparison.IComparable) {
return ((com.common.comparison.IComparable) object2).equalsEquals(object1);
}//else if//
else if(isProxy(object1)) {
return ((Proxy) object1).equalsEquals(object2);
}//else if//
else if(isProxy(object2)) {
return ((Proxy) object2).equalsEquals(object1);
}//else if//
else {
return object1 == object2;
}//else//
}//checkExactEquality()//
/* (non-Javadoc)
* @see com.common.orb.IOrbWrapper#closeServerSocket(java.lang.Object)
*/
public void closeServerSocket(Object serverSocketIdentifier) throws java.io.IOException {
orb.closeServerSocket(serverSocketIdentifier);
}//closeServerSocket()//
/* (non-Javadoc)
* @see com.common.orb.IOrbWrapper#closeSocket(java.lang.Object)
*/
public void closeSocket(Object socketIdentifier) throws java.io.IOException {
orb.closeSocket(socketIdentifier);
}//closeSocket()//
/* (non-Javadoc)
* @see com.common.orb.IOrbWrapper#closeSocket(java.lang.Object, long)
*/
public void closeSocket(Object socketIdentifier, long delayTime) throws java.io.IOException {
orb.closeSocket(socketIdentifier, delayTime);
}//closeSocket()//
/* (non-Javadoc)
* @see com.common.orb.IOrbWrapper#closeSocket(java.lang.String)
*/
public void closeSocket(String socketName) throws java.io.IOException {
orb.closeSocket(socketName);
}//closeSocket()//
/* (non-Javadoc)
* @see com.common.orb.IOrbWrapper#closeSocket(java.lang.String, long)
*/
public void closeSocket(String socketName, long delayTime) throws java.io.IOException {
orb.closeSocket(socketName, delayTime);
}//closeSocket()//
/* (non-Javadoc)
* @see com.common.orb.IOrbWrapper#getConnectionIdentifier(java.lang.Object)
*/
public Object getConnectionIdentifier(Object proxy) throws IllegalArgumentException {
Object result = null;
if((isProxy(proxy)) && (!isLocal(proxy))) {
result = ((Proxy) proxy).getNetworkConnectionIdentifier__Proxy();
}//if//
return result;
}//getConnectionIdentifier()//
/* (non-Javadoc)
* @see com.common.orb.IOrbWrapper#getLocal(java.lang.Object)
*/
public Object getLocal(Object object) {
return object instanceof Proxy ? ((Proxy) object).getIsProxyLocal__Proxy() ? ((Proxy) object).getLocalObject__Proxy() : null : object;
}//getLocal()//
/* (non-Javadoc)
* @see com.common.orb.IOrbWrapper#getNonProxyClass(java.lang.Object)
*/
public Class getNonProxyClass(Object object) {
return object instanceof Proxy ? ((Proxy) object).getProxiedClass__Proxy() : object.getClass();
}//getNonProxyClass()//
/* (non-Javadoc)
* @see com.common.orb.IOrbWrapper#getNonProxyClassName(java.lang.Object)
*/
public String getNonProxyClassName(Object object) {
return object instanceof Proxy ? ((Proxy) object).getProxiedClassName__Proxy() : object.getClass().getName();
}//getNonProxyClassName()//
/**
* Gets the underlying orb reference.
* @return The orb that is being wrappered.
*/
public Orb getOrb() {
return orb;
}//getOrb()//
/* (non-Javadoc)
* @see com.common.orb.IOrbWrapper#getProxy(java.lang.Object, java.lang.Class)
*/
public Object getProxy(Object object, Class type) throws IllegalArgumentException {
//Convert default proxy into a generic proxy. I am assuming I will create a getDefaultProxy(Object) method if I want to allow default proxy interface detection. Currently this detection is not possible only because of the orb interface in the Common project.//
if(type == null) {
type = Proxy.class;
}//if//
return object == null ? null : orb.getProxy(object, type);
}//getProxy()//
/* (non-Javadoc)
* @see com.common.orb.IOrbWrapper#isInvalidProxyException(java.lang.Throwable)
*/
public boolean isInvalidProxyException(Throwable exception) {
return exception instanceof com.de22.orb.exception.InvalidProxyException;
}//isInvalidProxyException()//
/* (non-Javadoc)
* @see com.common.orb.IOrbWrapper#isLocal(java.lang.Object)
*/
public boolean isLocal(Object object) {
return object instanceof Proxy ? ((Proxy) object).getIsProxyLocal__Proxy() : true;
}//isLocal()//
/* (non-Javadoc)
* @see com.common.orb.IOrbWrapper#isProxy(java.lang.Object)
*/
public boolean isProxy(Object object) {
return object instanceof Proxy;
}//isProxy()//
/* (non-Javadoc)
* @see com.common.orb.IOrbWrapper#isProxyValid(java.lang.Object)
*/
public boolean isProxyValid(Object object) {
return (object != null) && (object instanceof Proxy) ? ((Proxy) object).getIsProxyValid__Proxy() : object != null;
}//isProxy()//
/* (non-Javadoc)
* @see com.common.orb.IOrbWrapper#isTimeoutException(java.lang.Throwable)
*/
public boolean isTimeoutException(Throwable exception) {
return exception instanceof com.de22.orb.exception.TimeoutException;
}//isTimeoutException()//
/* (non-Javadoc)
* @see com.common.orb.IOrbWrapper#lookup(java.lang.Object, java.lang.Object)
*/
public Object lookup(Object resource, Object socketId) {
return orb.lookup(resource, socketId);
}//lookup()//
/* (non-Javadoc)
* @see com.common.orb.IOrbWrapper#openServerSocket(java.lang.String, java.lang.Object)
*/
public Object openServerSocket(String socketName, Object serverSocketOptions) throws java.io.IOException {
if(!(serverSocketOptions instanceof IServerSocketOptions)) {
throw new IllegalArgumentException("Expecting an instance of: " + IServerSocketOptions.class.getName());
}//if//
return orb.openServerSocket(socketName, (IServerSocketOptions) serverSocketOptions);
}//openServerSocket()//
/* (non-Javadoc)
* @see com.common.orb.IOrbWrapper#openSocket(java.lang.String, java.lang.Object)
*/
public Object openSocket(String socketName, Object socketOptions) throws java.io.IOException {
if(!(socketOptions instanceof ISocketOptions)) {
throw new IllegalArgumentException("Expecting an instance of: " + ISocketOptions.class.getName());
}//if//
return orb.openSocket(socketName, (ISocketOptions) socketOptions);
}//openSocket()//
/* (non-Javadoc)
* @see com.common.orb.IOrbWrapper#registerInvalidProxyListener(java.lang.Object, com.common.orb.IInvalidProxyListener)
*/
public void registerInvalidProxyListener(Object proxy, com.common.orb.IInvalidProxyListener invalidProxyListener) {
if((proxy != null) && (proxy instanceof Proxy)) {
((Proxy) proxy).addProxyInvalidListener(new ProxyInvalidListener(invalidProxyListener));
}//if//
}//registerInvalidProxyListener()//
/* (non-Javadoc)
* @see com.common.orb.IOrbWrapper#sendAgent(java.lang.Object, java.lang.Object, boolean, long, com.common.orb.IResultCallback)
*/
public Object sendAgent(Object agent, Object connection, boolean isOneWay, long timeout, IResultCallback callback) {
return orb.sendAgent(agent, connection, isOneWay, timeout, callback == null ? null : new ResultCallbackWrapper(callback));
}//closeSocket()//
/* (non-Javadoc)
* @see com.common.orb.IOrbWrapper#setAutoProxy(java.lang.Object, java.lang.Class)
*/
public void setAutoProxy(Object object, Class interfaceType) {
if((object != null) && (object instanceof Proxy) && !((Proxy) object).getIsProxyLocal__Proxy()) {
((Proxy) object).setAutoProxy__Proxy(interfaceType);
}//if//
}//setAutoProxy()//
/* (non-Javadoc)
* @see com.common.orb.IOrbWrapper#setAutoMorph(java.lang.Object, java.lang.Class, com.common.event.ObjectHandler1)
*/
public void setAutoMorph(Object object, Class interfaceType, ObjectHandler1 handler) {
if((object != null) && (object instanceof Proxy) && !((Proxy) object).getIsProxyLocal__Proxy()) {
((Proxy) object).setAutoMorph__Proxy(interfaceType, handler);
}//if//
}//setAutoMorph()//
/* (non-Javadoc)
* @see com.common.orb.IOrbWrapper#setCallTimeout(java.lang.Object, long)
*/
public void setCallTimeout(Object object, long timeout) {
if((object != null) && (object instanceof Proxy)) {
((Proxy) object).setTimeout__Proxy(timeout);
}//if//
}//setCallTimeout()//
/* (non-Javadoc)
* @see com.common.orb.IOrbWrapper#setOneWayCall(java.lang.Object)
*/
public void setOneWayCall(Object object) {
if((object != null) && (object instanceof Proxy)) {
((Proxy) object).setIsOneWay__Proxy(true);
}//if//
}//setOneWayCall()//
/* (non-Javadoc)
* @see com.common.orb.IOrbWrapper#setResultCallback(java.lang.Object, com.common.orb.IResultCallback)
*/
public void setResultCallback(Object object, IResultCallback callback) {
if((object != null) && (object instanceof Proxy) && (callback != null)) {
((Proxy) object).setResultCallback__Proxy(new ResultCallbackWrapper(callback));
}//if//
}//setResultCallback()//
/* (non-Javadoc)
* @see com.common.orb.IOrbWrapper#unregisterInvalidProxyListener(java.lang.Object, com.common.orb.IInvalidProxyListener)
*/
public void unregisterInvalidProxyListener(Object proxy, com.common.orb.IInvalidProxyListener invalidProxyListener) {
if((proxy != null) && (proxy instanceof Proxy)) {
((Proxy) proxy).removeProxyInvalidListener(new ProxyInvalidListener(invalidProxyListener));
}//if//
}//unregisterInvalidProxyListener()//
/* (non-Javadoc)
* @see com.common.orb.IOrbWrapper#shutdown()
*/
public void shutdown() {
orb.shutdown();
}//shutdown()//
}//CommonOrbWrapper//

View File

@@ -0,0 +1,28 @@
/*
* Copyright (c) 2004,2009 Declarative Engineering LLC.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Declarative Engineering LLC
* verson 1 which accompanies this distribution, and is available at
* http://declarativeengineering.com/legal/DE_Developer_License_v1.txt
*/
package com.de22.orb.optional;
/*
* Simply wrappers the orb wrapper's callback interface with an object that implements this orb's callback interface.
*/
public class ResultCallbackWrapper implements com.de22.orb.IResultCallback {
private com.common.orb.IResultCallback callback = null;
/**
* ResultCallbackWrapper constructor.
*/
public ResultCallbackWrapper(com.common.orb.IResultCallback callback) {
super();
this.callback = callback;
}//ResultCallbackWrapper()//
/* (non-Javadoc)
* @see com.de22.orb.IResultCallback#run(java.lang.Object)
*/
public void run(Object result) {
callback.run(result);
}//run()//
}//ResultCallbackWrapper//

View File

@@ -0,0 +1,176 @@
/*
* Copyright (c) 1999,2009 Declarative Engineering LLC.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Declarative Engineering LLC
* verson 1 which accompanies this distribution, and is available at
* http://declarativeengineering.com/legal/DE_Developer_License_v1.txt
*/
package com.de22.orb.optional;
import com.de22.orb.*;
import com.de22.orb.security.AbstractSecurityProvider;
/**
* A basic implementation of the IServerSocketOptions interface. Most applications can use this implementation.
* <p>It should be noted that the sign(..) method should be overloaded for applications requiring authentication of the server.</p>
*/
public class ServerSocketOptions implements IServerSocketOptions {
public static final Integer DEFAULT_BACKLOG = new Integer(50);
public static final long DEFAULT_AUTO_RECONNECT_TIME_LIMIT = 180000; //3 minutes.//
public static final long DEFAULT_KEEP_ALIVE_INTERVAL = 60000; //1 minute.//
private Address address = null;
private Address externalAddress = null;
private Integer backlog = DEFAULT_BACKLOG;
private ISocketOptions socketOptions = null;
private long autoReconnectTimeLimit = DEFAULT_AUTO_RECONNECT_TIME_LIMIT;
private long keepAliveInterval = DEFAULT_KEEP_ALIVE_INTERVAL;
private AbstractSecurityProvider securityProvider = null;
/** The optional NIO Engine. If provided then the server socket will utilize the NIO Engine to handle all threading. */
private NioEngine nioEngine = null;
/** The download URI's passed to the client when is has the wrong version of either the orb protocol or the application protocol (not used for custom app version management). */
private String[] downloadUris = null;
/**
* ServerSocketOptions constructor.
* @param address The address the server socket will listen to.
* @param externalAddress If the external address is not the same as the one being bound to (for example when using NAT) then this would be the external address that the client might see.
* @param socketOptions The socket options that will define the accepted sockets.
* @deprecated
*/
public ServerSocketOptions(Address address, Address externalAddress, ISocketOptions socketOptions) {
this(address, externalAddress, socketOptions, null);
}//ServerSocketOptions()//
/**
* ServerSocketOptions constructor.
* @param address The address the server socket will listen to.
* @param externalAddress If the external address is not the same as the one being bound to (for example when using NAT) then this would be the external address that the client might see.
* @param socketOptions The socket options that will define the accepted sockets.
* @param nioEngine The optional NIO Engine. This must be provided if the server socket will use an NIO selector.
*/
public ServerSocketOptions(Address address, Address externalAddress, ISocketOptions socketOptions, NioEngine nioEngine) {
super();
if((address == null) || (address.getPort() == Address.INVALID_PORT)) {
throw new RuntimeException("Invalid address.");
}//if//
if(socketOptions == null) {
throw new RuntimeException("Invalid socket options.");
}//if//
this.address = address;
this.externalAddress = externalAddress;
//Note: We don't need to clone this since the options cannot be changed once created.//
this.socketOptions = socketOptions;
this.nioEngine = nioEngine;
}//ServerSocketOptions()//
/**
* ServerSocketOptions constructor.
* @param address The address the server socket will listen to.
* @param externalAddress If the external address is not the same as the one being bound to (for example when using NAT) then this would be the external address that the client might see.
* @param socketOptions The socket options that will define the accepted sockets.
* @param downloadUris The (optional if upgrading is irrelevant) download URI's passed to the client when is has the wrong version of either the orb protocol or the application protocol (not used for custom app version management).
* @param autoReconnectTimeLimit The number of milliseconds the server will wait for the client to reconnect a failed socket. A value less than 1000 will be equivalent to zero and a zero value (default) indicates the server does not allow the client to reconnect automatically.
* @param keepAliveInterval The number of milliseconds between keep alive messages. This should be roughly half the auto-reconnect time limit so that the client is notified of a socket error with enough time to reconnect even if the client is inactive. This number should not be less than 500 in which case the default value will be used, and not greater than 600,000 (the longest possible length of time without a message before a socket seems to get closed).
* @param securityProvider The security provider that will supply the security system instances for all incomming sockets.
* @deprecated
*/
public ServerSocketOptions(Address address, Address externalAddress, ISocketOptions socketOptions, String[] downloadUris, long autoReconnectTimeLimit, long keepAliveInterval, AbstractSecurityProvider securityProvider) {
this(address, externalAddress, socketOptions, null);
this.downloadUris = downloadUris;
this.autoReconnectTimeLimit = autoReconnectTimeLimit < 1000 ? 0 : autoReconnectTimeLimit;
this.securityProvider = securityProvider;
this.keepAliveInterval = keepAliveInterval < 500 ? DEFAULT_KEEP_ALIVE_INTERVAL : keepAliveInterval > 600000 ? 600000 : keepAliveInterval;
}//ServerSocketOptions()//
/**
* ServerSocketOptions constructor.
* @param address The address the server socket will listen to.
* @param externalAddress If the external address is not the same as the one being bound to (for example when using NAT) then this would be the external address that the client might see.
* @param socketOptions The socket options that will define the accepted sockets.
* @param nioEngine The optional NIO Engine. This must be provided if the server socket will use an NIO selector.
* @param downloadUris The (optional if upgrading is irrelevant) download URI's passed to the client when is has the wrong version of either the orb protocol or the application protocol (not used for custom app version management).
* @param autoReconnectTimeLimit The number of milliseconds the server will wait for the client to reconnect a failed socket. A value less than 1000 will be equivalent to zero and a zero value (default) indicates the server does not allow the client to reconnect automatically.
* @param keepAliveInterval The number of milliseconds between keep alive messages. This should be roughly half the auto-reconnect time limit so that the client is notified of a socket error with enough time to reconnect even if the client is inactive. This number should not be less than 500 in which case the default value will be used, and not greater than 600,000 (the longest possible length of time without a message before a socket seems to get closed).
* @param securityProvider The security provider that will supply the security system instances for all incomming sockets.
*/
public ServerSocketOptions(Address address, Address externalAddress, ISocketOptions socketOptions, NioEngine nioEngine, String[] downloadUris, long autoReconnectTimeLimit, long keepAliveInterval, AbstractSecurityProvider securityProvider) {
this(address, externalAddress, socketOptions, nioEngine);
this.downloadUris = downloadUris;
this.autoReconnectTimeLimit = autoReconnectTimeLimit < 1000 ? 0 : autoReconnectTimeLimit;
this.securityProvider = securityProvider;
this.keepAliveInterval = keepAliveInterval < 500 ? DEFAULT_KEEP_ALIVE_INTERVAL : keepAliveInterval > 600000 ? 600000 : keepAliveInterval;
}//ServerSocketOptions()//
/**
* Gets the address that the server socket will listen on.
* @return The address the orb will find or create a server socket for.
*/
public Address getAddress() {
return address;
}//getAddress()//
/**
* Gets the size of the backlog that the server socket will maintain.
* @return The server socket's backlog size, or null to use the default value for the server socket.
*/
public Integer getBacklog() {
return backlog;
}//getBacklog()//
/**
* Gets the externally visible address and optional port that clients may reconnect through.
* <p>This allows clients to reconnect to the exact same server when the actual server address may be internal (and visible only via NAT or some other networking layer).
* Often times a server farm may have multiple servers a client may connect to and the default address for a service will be redirected to one of the identical servers.
* This feature allows the client to connect to the exact same server as the last time it connected so that the session information may be reused which will increase overall performance.</p>
* @return The address the server socket is visible on externally such that clients can reconnect. This may be null if the address that the server socket opens on is externally visible to clients. The port number may be optionally specified if it differs from the port number the server socket listens on.
*/
public Address getExternalAddress() {
return externalAddress;
}//getExternalAddress()//
/**
* Gets the socket options that all accepted sockets will use.
* @return Socket options accepted sockets will adhere to.
*/
public ISocketOptions getSocketOptions() {
return socketOptions;
}//getSocketOptions()//
/* (non-Javadoc)
* @see com.de22.orb.IServerSocketOptions#getAutoReconnectTimeLimit()
*/
public long getAutoReconnectTimeLimit() {
return autoReconnectTimeLimit;
}//getAutoReconnectTimeLimit()//
/* (non-Javadoc)
* @see com.de22.orb.IServerSocketOptions#getKeepAliveInterval()
*/
public long getKeepAliveInterval() {
return keepAliveInterval;
}//getKeepAliveInterval()//
/* (non-Javadoc)
* @see com.de22.orb.IServerSocketOptions#getSecurityProvider()
*/
public AbstractSecurityProvider getSecurityProvider() {
return securityProvider;
}//getSecurityProvider()//
/* (non-Javadoc)
* @see com.de22.orb.IServerSocketOptions#getNioEngine()
*/
public NioEngine getNioEngine() {
return nioEngine;
}//getNioEngine()//
/* (non-Javadoc)
* @see com.de22.orb.IServerSocketOptions#getDownloadUris()
*/
public String[] getDownloadUris() {
return downloadUris;
}//getDownloadUris()//
/* (non-Javadoc)
* @see com.de22.orb.IServerSocketOptions#getSignatureSize(int)
*/
public int getSignatureSize(int applicationProtocolVersion) {
return 0;
}//getSignatureSize()//
/* (non-Javadoc)
* @see com.de22.orb.IServerSocketOptions#sign(int, byte[], byte[])
*/
public byte[] sign(int applicationProtocolVersion, byte[] unsignedBytes, byte[] responseBytes) {
return null;
}//sign()//
}//ServerSocketOptions//

View File

@@ -0,0 +1,348 @@
/*
* Copyright (c) 1999,2009 Declarative Engineering LLC.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Declarative Engineering LLC
* verson 1 which accompanies this distribution, and is available at
* http://declarativeengineering.com/legal/DE_Developer_License_v1.txt
*/
package com.de22.orb.optional;
import com.common.comparison.Comparator;
import com.common.security.IHashAlgorithm;
import com.common.security.ISignatureAlgorithm;
import com.de22.orb.*;
/**
* A simple implementation of the ISocketOptions interface, useable by most ORB users.
* <p>The user may wish to override the implementation of the isValidSignature(..) method.</p>
*/
public class SocketOptions implements ISocketOptions {
/** The application's protocol version, used to ensure that an older incompatible version of a client/server don't mix. The value should never be zero. */
private int applicationProtocolVersion = 1;
/** The address's that the socket is connecting on (only one will be selected). (Client Sockets Only) */
private Address[] addresses = null;
/** The permissions object used to identify the bound objects the remote process can access. (Client Sockets Only) */
private Object permissions = null;
/** The handler activated if the connected server is incompatible with this process. (Client Sockets Only) */
private IVersionChangeHandler versionChangeHandler = null;
private IStreamInjector streamInjector = null;
private IStreamClassNameManipulator streamClassNameManipulator = null;
/** The optional NIO Engine. If provided then the socket will utilize the NIO Engine to handle all threading. */
private NioEngine nioEngine = null;
/** The optional signature algorithm used to validate the server when a socket connects. */
private ISignatureAlgorithm signatureAlgorithm = null;
/** The hashAlgorithm used to hash a message for signing. */
private IHashAlgorithm hashAlgorithm = null;
/** The number of milliseconds to wait before timing out when connecting to the server. */
private int socketConnectionTimeout = 8000;
/**
* SocketOptions constructor.
* <p>This constructor should only be used to create socket options for a server socket options object.</p>
* @deprecated Call SocketOptions(int) instead.
*/
public SocketOptions() {
super();
}//SocketOptions()//
/**
* SocketOptions constructor.
* <p>This constructor should only be used to create socket options for a server socket options object.</p>
* @param applicationProtocolVersion The application's protocol version, used to ensure that an older incompatible version of a client/server don't mix. The value should never be zero.
*/
public SocketOptions(int applicationProtocolVersion) {
super();
this.applicationProtocolVersion = applicationProtocolVersion;
}//SocketOptions()//
/**
* SocketOptions constructor.
* <p>This constructor should only be used to create socket options for a server socket options object.</p>
* @param applicationProtocolVersion The application's protocol version, used to ensure that an older incompatible version of a client/server don't mix. The value should never be zero.
* @param permissions The application defined permissions object that can be assigned to the server socket. This can be used to restrict access to named objects (and possibly for other security features in the future).
* @param streamInjector The optional injector to use by the application to place application defined streams in the stream stack used by the socket.
* @param streamClassNameManipulator The optional manipulator that can change a class name being sent or received over the socket.
*/
public SocketOptions(int applicationProtocolVersion, Object permissions, IStreamInjector streamInjector, IStreamClassNameManipulator streamClassNameManipulator) {
super();
this.applicationProtocolVersion = applicationProtocolVersion;
this.permissions = permissions;
this.streamInjector = streamInjector;
this.streamClassNameManipulator = streamClassNameManipulator;
}//SocketOptions()//
/**
* SocketOptions constructor.
* @param primaryAddress The primary address that the socket should bind to.
* @param secondaryAddress The secondary (backup) address that the socket should bind to if the primary address fails.
* @param permissions The application defined permissions object that can be assigned to the server socket. This can be used to restrict access to named objects (and possibly for other security features in the future).
* @deprecated
*/
public SocketOptions(Address primaryAddress, Address secondaryAddress, Object permissions) {
super();
//Note: The primary address can be null if the socket options are part of the server socket options.//
if((primaryAddress != null) && ((primaryAddress.getName() == null) || (primaryAddress.getPort() == Address.INVALID_PORT))) {
throw new RuntimeException("Invalid primary address.");
}//if//
if((secondaryAddress != null) && ((secondaryAddress.getName() == null) || (secondaryAddress.getPort() == Address.INVALID_PORT))) {
throw new RuntimeException("Invalid secondary address.");
}//if//
try {
this.addresses = new Address[secondaryAddress == null ? primaryAddress == null ? 0 : 1 : 2];
if(primaryAddress != null) {
this.addresses[0] = (Address) primaryAddress.clone();
if(secondaryAddress != null) {
this.addresses[1] = (Address) secondaryAddress.clone();
}//if//
}//if//
}//try//
catch(CloneNotSupportedException e) {
//Ignored.//
}//catch//
this.permissions = permissions;
}//SocketOptions()//
/**
* SocketOptions constructor.
* @param primaryAddress The primary address that the socket should bind to.
* @param secondaryAddress The secondary (backup) address that the socket should bind to if the primary address fails.
* @param permissions The application defined permissions object that can be assigned to the server socket. This can be used to restrict access to named objects (and possibly for other security features in the future).
* @param streamInjector The optional injector to use by the application to place application defined streams in the stream stack used by the socket.
* @param streamClassNameManipulator The optional manipulator that can change a class name being sent or received over the socket.
* @deprecated
*/
public SocketOptions(Address primaryAddress, Address secondaryAddress, Object permissions, IStreamInjector streamInjector, IStreamClassNameManipulator streamClassNameManipulator) {
this(primaryAddress, secondaryAddress, permissions);
this.streamInjector = streamInjector;
this.streamClassNameManipulator = streamClassNameManipulator;
}//SocketOptions()//
/**
* SocketOptions constructor.
* @param primaryAddress The primary address that the socket should bind to.
* @param secondaryAddress The secondary (backup) address that the socket should bind to if the primary address fails.
* @param permissions The application defined permissions object that can be assigned to the server socket. This can be used to restrict access to named objects (and possibly for other security features in the future).
* @param streamInjector The optional injector to use by the application to place application defined streams in the stream stack used by the socket.
* @param streamClassNameManipulator The optional manipulator that can change a class name being sent or received over the socket.
* @param versionChangeHandler The optional handler called when the server reports a newer version of the application. This should not be specified via server sockets.
* @deprecated
*/
public SocketOptions(Address primaryAddress, Address secondaryAddress, Object permissions, IStreamInjector streamInjector, IStreamClassNameManipulator streamClassNameManipulator, IVersionChangeHandler versionChangeHandler) {
this(primaryAddress, secondaryAddress, permissions, streamInjector, streamClassNameManipulator);
this.versionChangeHandler = versionChangeHandler;
}//SocketOptions()//
/**
* SocketOptions constructor.
* @deprecated
* @param addresses The addresses that the socket should try to bind to. An existing socket will be looked for on each address prior to attempting a new connection.
* @param permissions The application defined permissions object that can be assigned to the server socket. This can be used to restrict access to named objects (and possibly for other security features in the future).
*/
public SocketOptions(Address[] addresses, Object permissions) {
this(1, addresses, permissions);
}//SocketOptions()//
/**
* SocketOptions constructor.
* @deprecated
* @param addresses The addresses that the socket should try to bind to. An existing socket will be looked for on each address prior to attempting a new connection.
* @param permissions The application defined permissions object that can be assigned to the server socket. This can be used to restrict access to named objects (and possibly for other security features in the future).
* @param streamInjector The optional injector to use by the application to place application defined streams in the stream stack used by the socket.
* @param streamClassNameManipulator The optional manipulator that can change a class name being sent or received over the socket.
*/
public SocketOptions(Address[] addresses, Object permissions, IStreamInjector streamInjector, IStreamClassNameManipulator streamClassNameManipulator) {
this(1, addresses, permissions);
this.streamInjector = streamInjector;
this.streamClassNameManipulator = streamClassNameManipulator;
}//SocketOptions()//
/**
* SocketOptions constructor.
* @deprecated
* @param addresses The addresses that the socket should try to bind to. An existing socket will be looked for on each address prior to attempting a new connection.
* @param permissions The application defined permissions object that can be assigned to the server socket. This can be used to restrict access to named objects (and possibly for other security features in the future).
* @param streamInjector The optional injector to use by the application to place application defined streams in the stream stack used by the socket.
* @param streamClassNameManipulator The optional manipulator that can change a class name being sent or received over the socket.
* @param versionChangeHandler The optional handler called when the server reports a newer version of the application. This should not be specified via server sockets.
*/
public SocketOptions(Address[] addresses, Object permissions, IStreamInjector streamInjector, IStreamClassNameManipulator streamClassNameManipulator, IVersionChangeHandler versionChangeHandler) {
this(1, addresses, permissions, streamInjector, streamClassNameManipulator);
this.versionChangeHandler = versionChangeHandler;
}//SocketOptions()//
/**
* SocketOptions constructor.
* <p>This constructor should only be used to create socket options for a client side socket.</p>
* @param applicationProtocolVersion The application's protocol version, used to ensure that an older incompatible version of a client/server don't mix. The value should never be zero.
* @param addresses The addresses that the socket should try to bind to. An existing socket will be looked for on each address prior to attempting a new connection.
* @param permissions The application defined permissions object that can be assigned to the server socket. This can be used to restrict access to named objects (and possibly for other security features in the future).
*/
public SocketOptions(int applicationProtocolVersion, Address[] addresses, Object permissions) {
super();
//Note: The addresses can be null or empty if the options are part of a server socket.//
if(addresses != null) {
for(int index = 0; index < addresses.length; index++) {
if(addresses[index] == null || addresses[index].getName() == null || addresses[index].getPort() == Address.INVALID_PORT) {
throw new RuntimeException("Invalid address found in the address set at index: " + index + ".");
}//if//
}//for//
//Clone the collection of addresses.//
try {
this.addresses = new Address[addresses.length];
for(int index = 0; index < addresses.length; index++) {
this.addresses[index] = (Address) addresses[index].clone();
}//for//
}//try//
catch(CloneNotSupportedException e) {
}//catch//
}//if//
this.applicationProtocolVersion = applicationProtocolVersion;
this.permissions = permissions;
}//SocketOptions()//
/**
* SocketOptions constructor.
* <p>This constructor should only be used to create socket options for a client side socket.</p>
* @param applicationProtocolVersion The application's protocol version, used to ensure that an older incompatible version of a client/server don't mix. The value should never be zero.
* @param addresses The addresses that the socket should try to bind to. An existing socket will be looked for on each address prior to attempting a new connection.
* @param permissions The application defined permissions object that can be assigned to the server socket. This can be used to restrict access to named objects (and possibly for other security features in the future).
* @param streamInjector The optional injector to use by the application to place application defined streams in the stream stack used by the socket.
* @param streamClassNameManipulator The optional manipulator that can change a class name being sent or received over the socket.
*/
public SocketOptions(int applicationProtocolVersion, Address[] addresses, Object permissions, IStreamInjector streamInjector, IStreamClassNameManipulator streamClassNameManipulator) {
this(applicationProtocolVersion, addresses, permissions);
this.streamInjector = streamInjector;
this.streamClassNameManipulator = streamClassNameManipulator;
}//SocketOptions()//
/**
* SocketOptions constructor.
* <p>This constructor should only be used to create socket options for a client side socket.</p>
* @param applicationProtocolVersion The application's protocol version, used to ensure that an older incompatible version of a client/server don't mix. The value should never be zero.
* @param addresses The addresses that the socket should try to bind to. An existing socket will be looked for on each address prior to attempting a new connection.
* @param permissions The application defined permissions object that can be assigned to the server socket. This can be used to restrict access to named objects (and possibly for other security features in the future).
* @param streamInjector The optional injector to use by the application to place application defined streams in the stream stack used by the socket.
* @param streamClassNameManipulator The optional manipulator that can change a class name being sent or received over the socket.
* @param versionChangeHandler The optional handler called when the server reports a newer version of the application. This should not be specified via server sockets.
* @param nioEngine The optional NIO Engine. This must be provided if the server socket will use an NIO selector.
*/
public SocketOptions(int applicationProtocolVersion, Address[] addresses, Object permissions, IStreamInjector streamInjector, IStreamClassNameManipulator streamClassNameManipulator, IVersionChangeHandler versionChangeHandler, NioEngine nioEngine) {
this(applicationProtocolVersion, addresses, permissions, streamInjector, streamClassNameManipulator);
this.versionChangeHandler = versionChangeHandler;
this.nioEngine = nioEngine;
}//SocketOptions()//
/**
* SocketOptions constructor.
* <p>This constructor should only be used to create socket options for a client side socket.</p>
* @param applicationProtocolVersion The application's protocol version, used to ensure that an older incompatible version of a client/server don't mix. The value should never be zero.
* @param addresses The addresses that the socket should try to bind to. An existing socket will be looked for on each address prior to attempting a new connection.
* @param permissions The application defined permissions object that can be assigned to the server socket. This can be used to restrict access to named objects (and possibly for other security features in the future).
* @param streamInjector The optional injector to use by the application to place application defined streams in the stream stack used by the socket.
* @param streamClassNameManipulator The optional manipulator that can change a class name being sent or received over the socket.
* @param versionChangeHandler The optional handler called when the server reports a newer version of the application. This should not be specified via server sockets.
* @param nioEngine The optional NIO Engine. This must be provided if the server socket will use an NIO selector.
* @param socketConnectionTimeout The number of milliseconds to wait before timing out when connecting to the server. The default value is 8000 (8 seconds), and the value should not be less than 500 otherwise the orb will set it to 500.
*/
public SocketOptions(int applicationProtocolVersion, Address[] addresses, Object permissions, IStreamInjector streamInjector, IStreamClassNameManipulator streamClassNameManipulator, IVersionChangeHandler versionChangeHandler, NioEngine nioEngine, int socketConnectionTimeout) {
this(applicationProtocolVersion, addresses, permissions, streamInjector, streamClassNameManipulator, versionChangeHandler, nioEngine);
this.socketConnectionTimeout = socketConnectionTimeout;
}//SocketOptions()//
/* (non-Javadoc)
* @see com.de22.orb.ISocketOptions#getSocketConnectionTimeout()
*/
public int getSocketConnectionTimeout() {
return socketConnectionTimeout;
}//getSocketConnectionTimeout()//
/* (non-Javadoc)
* @see com.de22.orb.ISocketOptions#getPermissions()
*/
public Object getPermissions() {
return permissions;
}//getPermissions()//
/* (non-Javadoc)
* @see com.de22.orb.ISocketOptions#getAddresses()
*/
public Address[] getAddresses() {
return addresses;
}//getAddresses()//
/* (non-Javadoc)
* @see com.de22.orb.ISocketOptions#useTcpNoDelay()
*/
public boolean useTcpNoDelay() {
return false;
}//useTcpNoDelay()//
/* (non-Javadoc)
* @see com.de22.orb.ISocketOptions#getVersionChangeHandler()
*/
public IVersionChangeHandler getVersionChangeHandler() {
return versionChangeHandler;
}//getVersionChangeHandler()//
/* (non-Javadoc)
* @see com.de22.orb.ISocketOptions#getStreamInjector()
*/
public IStreamInjector getStreamInjector() {
return streamInjector;
}//getStreamInjector()//
/* (non-Javadoc)
* @see com.de22.orb.ISocketOptions#getStreamClassNameManipulator()
*/
public IStreamClassNameManipulator getStreamClassNameManipulator() {
return streamClassNameManipulator;
}//getStreamClassNameManipulator()//
/* (non-Javadoc)
* @see com.de22.orb.ISocketOptions#getApplicationProtocolVersion()
*/
public int getApplicationProtocolVersion() {
return applicationProtocolVersion;
}//getApplicationProtocolVersion()//
/* (non-Javadoc)
* @see com.de22.orb.ISocketOptions#getNioEngine()
*/
public NioEngine getNioEngine() {
return nioEngine;
}//getNioEngine()//
/**
* Initializes the server authentication routines.
* @param hashAlgorithm The algorithm used to hash messages received from the server to authenticate them.
* @param signatureAlgorithm The signature algorithm (initialized with public key only) used to verify the signature sent by the server.
*/
public void initializeServerAuthentication(IHashAlgorithm hashAlgorithm, ISignatureAlgorithm signatureAlgorithm) {
this.hashAlgorithm = hashAlgorithm;
this.signatureAlgorithm = signatureAlgorithm;
}//initializeServerAuthentication()//
/* (non-Javadoc)
* @see com.de22.orb.ISocketOptions#getSignatureSize()
*/
public int getSignatureSize() {
return signatureAlgorithm != null && hashAlgorithm != null ? signatureAlgorithm.getSignedSize(hashAlgorithm.getHashSize()) : 0;
}//getSignatureSize()//
/* (non-Javadoc)
* @see com.de22.orb.ISocketOptions#getHashAlgorithm()
*/
public IHashAlgorithm getHashAlgorithm() {
return hashAlgorithm;
}//getHashAlgorithm()//
/**
* Determines whether the server's signature is valid, authenticating that the server is who it says it is.
* This method assumes that the client is valid and has a valid public key.
* The default implementation performs no validation.
* @param data The data sent to the server.
* @param signedData The signed data.
* @return Whether the signed data matches the data.
*/
public boolean isValidSignature(byte[] data, byte[] signedData) {
boolean result = true;
if(signatureAlgorithm != null && hashAlgorithm != null) {
byte[] unsignedData = signatureAlgorithm.verify(signedData);
result = unsignedData.length == data.length;
for(int index = 0; result && index < data.length; index++) {
if(data[index] != unsignedData[index]) {
result = false;
}//if//
}//for//
}//if//
return result;
}//isValidSignature()//
}//SocketOptions//