Files
Brainstorm/Orb/src/com/de22/orb/optional/ServerSocketOptions.java

176 lines
10 KiB
Java
Raw Normal View History

2014-05-30 10:31:51 -07:00
/*
* 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//