com.retrogui.dualrpc.server
Class DualRpcServer

java.lang.Object
  extended bycom.retrogui.dualrpc.server.DualRpcServer

public class DualRpcServer
extends java.lang.Object

DualRpcServer.


Constructor Summary
DualRpcServer(java.lang.String host, int port, java.lang.Object configurationObject)
          Instantiate a DualRpcServer.
 
Method Summary
 int currentConnectionCount()
          Report how many clients are currently connected to the server.
protected  java.util.ArrayList getListServerSideHandlerClassnames()
          Get the list of server handler classnames.
 int getMaxConnections()
          Get max connections number.
 MessageServer getMessageServer()
          Obtain a reference to the message server.
protected  IMethodAccessControl getMethodAccessControl()
           
protected  java.lang.String getNextMessageId()
           
protected  IRpcWorkerFactory getRpcWorkerFactory()
           
protected  java.lang.Object getServerHandlerConfigurationObject()
          Get the current configuration object.
 void listen()
          Start the server.
 void registerServerSideHandlerClassname(java.lang.String handlerClassname)
          Register a server handler by passing the handler class name.
 void setMaxConnections(int maxConnections)
          Set max number of client connections allowed.
 void setMessageEncoder(IMessageEncoder messageEncoder)
          Set an alternate message encoder.
 void setMessageSerializer(IMessageSerializer messageSerializer)
          Set an alternate message serializer for SOAP, XML-RPC, JSON, etc.
 void setMethodAccessControl(IMethodAccessControl methodAccessControl)
          Must be set before calling listen().
 void setRpcWorkerFactory(IRpcWorkerFactory rpcWorkerFactory)
          Must be set before calling listen().
 void setSendAndReceiveMessages(boolean isSendAndReceiveMessages)
          Control whether to allow sending and receiving of RPC messages.
 void setSocketFactory(javax.net.ServerSocketFactory factory)
          Specify an alternate (SSL) socket factory.
 void shutdown(int quietTimeInSeconds)
          Administrative method that demonstrates an orderly shutdown of a server.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DualRpcServer

public DualRpcServer(java.lang.String host,
                     int port,
                     java.lang.Object configurationObject)
Instantiate a DualRpcServer. Use a fully qualified DNS name to bind to a particular IP address on a machine. This is preferred. "localhost" will limit to local connections only. "0.0.0.0" to bind to all ip addresses on a machine.

Parameters:
configurationObject -
See Also:
Method Detail

listen

public void listen()
            throws java.io.IOException
Start the server. Set most of the optional environmental parameters such as max connections, etc BEFORE calling listen().

Throws:
java.io.IOException

registerServerSideHandlerClassname

public void registerServerSideHandlerClassname(java.lang.String handlerClassname)
                                        throws java.lang.ClassNotFoundException
Register a server handler by passing the handler class name.

Parameters:
handlerClassname -
Throws:
java.lang.ClassNotFoundException
See Also:

currentConnectionCount

public int currentConnectionCount()
Report how many clients are currently connected to the server.

Returns:

getListServerSideHandlerClassnames

protected java.util.ArrayList getListServerSideHandlerClassnames()
Get the list of server handler classnames. For internal use.

Returns:

getServerHandlerConfigurationObject

protected java.lang.Object getServerHandlerConfigurationObject()
Get the current configuration object. For internal use.

Returns:

setMaxConnections

public void setMaxConnections(int maxConnections)
Set max number of client connections allowed. Must be set before calling listen().

Parameters:
maxConnections -

getMaxConnections

public int getMaxConnections()
Get max connections number.

Returns:
- int

setSendAndReceiveMessages

public void setSendAndReceiveMessages(boolean isSendAndReceiveMessages)
                               throws ServerNotRunningException
Control whether to allow sending and receiving of RPC messages. Set to false to prevent messages from being sent or received. Usually done prior to a shutdown. This flag controls whether the Session sendMessage() and getMessage() function and the flag does not cause the queues to stop. If this flag is set to false for long enough then the queues may grow excessively large. DualRpcServer.listen() must have already been called before calling this method.

Parameters:
isSendAndReceiveMessages -
Throws:
ServerNotRunningException

shutdown

public void shutdown(int quietTimeInSeconds)
              throws ServerNotRunningException
Administrative method that demonstrates an orderly shutdown of a server. The quietTimeInSeconds parameter is the amount of time before shutting down while new inbound and outbound RPC calls are ignored and active RPC calls should have sufficient time to finish. I recommend setting a 10 second quietTimeInSeconds delay. Your server handler should implement some sort of authentication and authorization rules before allowing someone to shutdown the server. DualRpcServer.listen() must have already been called before calling this method.

Parameters:
quietTimeInSeconds - - amount of time that new connections and new RPC requests will be ignored before stopping the server - an int
Throws:
ServerNotRunningException

setSocketFactory

public void setSocketFactory(javax.net.ServerSocketFactory factory)
Specify an alternate (SSL) socket factory. The default socket factory is for normal TCP/IP sockets. Must be set before calling listen().

Parameters:
factory -

setMessageSerializer

public void setMessageSerializer(IMessageSerializer messageSerializer)
Set an alternate message serializer for SOAP, XML-RPC, JSON, etc. This is optional since the messageclient has a default java serializer. Must be set before calling listen(). This alternate serializer is set into the messageclient in the connect() method. For an example implementation of a message serializer, see the JavaSerializer class.

Parameters:
messageSerializer - The messageSerializer to set.

setMessageEncoder

public void setMessageEncoder(IMessageEncoder messageEncoder)
Set an alternate message encoder. This is optional since the messageclient has a default Base64 encoder. Must be set before calling listen(). A message encoder cannot use a newline character because it is reserved as the message delimiter. This alternate encoder is set into the messageclient in the connect() method. For an example implementation of a message encoder, see the Base64Encoder class.

Parameters:
messageEncoder - The messageEncoder to set.

getNextMessageId

protected java.lang.String getNextMessageId()
Returns:
get next message id string

setMethodAccessControl

public void setMethodAccessControl(IMethodAccessControl methodAccessControl)
Must be set before calling listen().

Parameters:
methodAccessControl - The methodAccessControl to set.

getMethodAccessControl

protected IMethodAccessControl getMethodAccessControl()
Returns:
Returns the methodAccessControl.

setRpcWorkerFactory

public void setRpcWorkerFactory(IRpcWorkerFactory rpcWorkerFactory)
Must be set before calling listen().

Parameters:
rpcWorkerFactory - The rpcWorkerFactory to set.

getRpcWorkerFactory

protected IRpcWorkerFactory getRpcWorkerFactory()
Returns:
Returns the rpcWorkerFactory.

getMessageServer

public MessageServer getMessageServer()
Obtain a reference to the message server. The message server has handles to all of the connected client's DualRpcServerDispatcher objects.

Returns:
Returns the messageServer.