Parsing Engine

danbikel.switchboard
Class AbstractServer

java.lang.Object
  extended by java.rmi.server.RemoteObject
      extended by java.rmi.server.RemoteServer
          extended by danbikel.switchboard.AbstractSwitchboardUser
              extended by danbikel.switchboard.AbstractServer
All Implemented Interfaces:
Server, SwitchboardUser, Serializable, Remote
Direct Known Subclasses:
DecoderServer

public abstract class AbstractServer
extends AbstractSwitchboardUser
implements Server

Provides a convenient default implementation of the Server interface, allowing subclasses to focus solely on the services they will provide to clients.

N.B.: Subclasses should take care to properly call the AbstractSwitchboardUser.unexportWhenDead method.

A note on fault tolerance: In order to ensure the fault-tolerance of clients, subclasses should ensure that they use socket factories that set the SO_TIMEOUT values of their TCP/IP sockets to some integer greater than 0, by calling the constructors of this class with non-zero timeout arguments, or by providing custom socket factories that provide at least the functionality of TimeoutSocketFactory. Subclasses that use sockets other than TCP/IP sockets should have similar non-infinite timeouts.

See Also:
AbstractSwitchboardUser.unexportWhenDead(), Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class danbikel.switchboard.AbstractSwitchboardUser
AbstractSwitchboardUser.Alive, AbstractSwitchboardUser.SBUserRetry
 
Field Summary
protected  boolean acceptClientsOnlyByRequest
          Indicates whether this server will only accept clients that specifically request it.
protected  int maxClients
          The maximum number of clients this server is willing to accept.
 
Fields inherited from class danbikel.switchboard.AbstractSwitchboardUser
aliveSynch, aliveTimeout, className, defaultMaxSwitchboardTries, defaultTimeout, dieSynch, id, infiniteTries, maxSwitchboardTries, registered, switchboard, switchboardName, timeout, timeToDie
 
Fields inherited from class java.rmi.server.RemoteObject
ref
 
Fields inherited from interface danbikel.switchboard.Server
acceptUnlimitedClients
 
Constructor Summary
protected AbstractServer()
          Constructs a non-exported AbstractServer object.
protected AbstractServer(int timeout)
          Constructs a new server with the specified timeout value for its RMI sockets, to receive RMI calls on an anonymous port.
protected AbstractServer(int maxClients, boolean acceptClientsOnlyByRequest, int timeout, int port)
          Constructs a new server that will accept no more than the specified number of clients, will optionally accept clients only by request, that will use the specified timeout for its RMI sockets and will accept RMI calls on the specified port.
protected AbstractServer(int maxClients, boolean acceptClientsOnlyByRequest, int port, RMIClientSocketFactory csf, RMIServerSocketFactory ssf)
          Constructs a new server that will accept no more than the specified number of clients, will optionally accept clients only by request, will accept RMI calls on the specified port and will use the specified socket factories to create its RMI sockets.
protected AbstractServer(int timeout, int port)
          Constructs a new server with the specified timeout value for its RMI sockets, to receive RMI calls on the specified port.
protected AbstractServer(int port, RMIClientSocketFactory csf, RMIServerSocketFactory ssf)
          Constructs a new server that will accept RMI calls on the specified port, using the specified socket factories to create RMI sockets.
 
Method Summary
 boolean acceptClientsOnlyByRequest()
          Returns whether this server will only accept clients that specifically request it.
static void disableHttp(Properties props)
           
 int maxClients()
          Returns the maximum number of clients this server is willing to accept.
protected  void register(String switchboardName)
          Registers this server with the specified switchboard.
protected  void reRegister()
          Re-registers this server with the switchboard.
static void setPolicyFile(Class cl, Properties props)
          Calls AbstractSwitchboardUser.setPolicyFile(Class,String) with the specified class and the value of the SwitchboardRemote.serverPolicyFile property obtained from the specified Properties object.
protected static void setPolicyFile(Properties props)
          Calls AbstractSwitchboardUser.setPolicyFile(String) with the value of the SwitchboardRemote.serverPolicyFile property obtained from the specified Properties object.
 
Methods inherited from class danbikel.switchboard.AbstractSwitchboardUser
alive, cleanup, die, disableHttp, getAliveTimeout, getSwitchboard, getSwitchboard, getSwitchboard, getSwitchboard, getSwitchboard, getSwitchboard, host, id, nonZeroTimeout, setPolicyFile, setPolicyFile, startAliveThread, unexportWhenDead
 
Methods inherited from class java.rmi.server.RemoteServer
getClientHost, getLog, setLog
 
Methods inherited from class java.rmi.server.RemoteObject
equals, getRef, hashCode, toString, toStub
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface danbikel.switchboard.Server
id
 
Methods inherited from interface danbikel.switchboard.SwitchboardUser
alive, die, host
 

Field Detail

maxClients

protected int maxClients
The maximum number of clients this server is willing to accept.


acceptClientsOnlyByRequest

protected boolean acceptClientsOnlyByRequest
Indicates whether this server will only accept clients that specifically request it.

Constructor Detail

AbstractServer

protected AbstractServer()
Constructs a non-exported AbstractServer object.


AbstractServer

protected AbstractServer(int timeout)
                  throws RemoteException
Constructs a new server with the specified timeout value for its RMI sockets, to receive RMI calls on an anonymous port.

Warning: Using a value of 0 for the timeout argument will cause the distributed system implemented by this package to be non-fault-tolerant. Use a timeout value greater than 0 to ensure the fault-tolerance of the distributed computing system.

Parameters:
timeout - the time in milliseconds before client-side (switchboard-side) sockets used for this remote object time out; a value of 0 specifies infinite timeout, which is dangerous
Throws:
RemoteException

AbstractServer

protected AbstractServer(int timeout,
                         int port)
                  throws RemoteException
Constructs a new server with the specified timeout value for its RMI sockets, to receive RMI calls on the specified port.

Warning: Using a value of 0 for the timeout argument will cause the distributed system implemented by this package to be non-fault-tolerant. Use a timeout value greater than 0 to ensure the fault-tolerance of the distributed computing system.

Parameters:
timeout - the time in milliseconds before client-side (switchboard-side) sockets used for this remote object time out; a value of 0 specifies infinite timeout, which is dangerous
port - the port on which to receive RMI calls
Throws:
RemoteException

AbstractServer

protected AbstractServer(int maxClients,
                         boolean acceptClientsOnlyByRequest,
                         int timeout,
                         int port)
                  throws RemoteException
Constructs a new server that will accept no more than the specified number of clients, will optionally accept clients only by request, that will use the specified timeout for its RMI sockets and will accept RMI calls on the specified port.

Parameters:
maxClients - the maximum number of clients this server is willing to accept
acceptClientsOnlyByRequest - if true, then this server will only accept clients that request it specifically
timeout - the timeout value, in milliseconds, to be used for the client-side (switchboard-side) RMI sockets of this object
port - the port on which to receive RMI calls
Throws:
RemoteException

AbstractServer

protected AbstractServer(int port,
                         RMIClientSocketFactory csf,
                         RMIServerSocketFactory ssf)
                  throws RemoteException
Constructs a new server that will accept RMI calls on the specified port, using the specified socket factories to create RMI sockets.

Warning: Custom socket factories should ensure that their sockets have some sort of timeout mechanism (such as implemented for TCP/IP sockets by TimeoutSocketFactory). If sockets do not time out, then the distributed system implemented by this package will not be fault-tolerant.

Parameters:
port - the port on which to receive RMI calls
csf - the factory from which to create client-side RMI sockets
ssf - the factory from which to create server-side RMI sockets
Throws:
RemoteException

AbstractServer

protected AbstractServer(int maxClients,
                         boolean acceptClientsOnlyByRequest,
                         int port,
                         RMIClientSocketFactory csf,
                         RMIServerSocketFactory ssf)
                  throws RemoteException
Constructs a new server that will accept no more than the specified number of clients, will optionally accept clients only by request, will accept RMI calls on the specified port and will use the specified socket factories to create its RMI sockets.

Warning: Custom socket factories should ensure that their sockets have some sort of timeout mechanism (such as implemented for TCP/IP sockets by TimeoutSocketFactory). If sockets do not time out, then the distributed system implemented by this package will not be fault-tolerant.

Parameters:
maxClients - the maximum number of clients this server is willing to accept
acceptClientsOnlyByRequest - if true, then this server will only accept clients that request it specifically
port - the port on which to receive RMI calls
csf - the factory from which to create client-side RMI sockets
ssf - the factory from which to create server-side RMI sockets
Throws:
RemoteException
Method Detail

setPolicyFile

protected static void setPolicyFile(Properties props)
Calls AbstractSwitchboardUser.setPolicyFile(String) with the value of the SwitchboardRemote.serverPolicyFile property obtained from the specified Properties object.

Parameters:
props - the Properties object from which to obtain the value of the SwitchboardRemote.serverPolicyFile property

setPolicyFile

public static void setPolicyFile(Class cl,
                                 Properties props)
Calls AbstractSwitchboardUser.setPolicyFile(Class,String) with the specified class and the value of the SwitchboardRemote.serverPolicyFile property obtained from the specified Properties object.

Parameters:
props - the Properties object from which to obtain the value of the SwitchboardRemote.serverPolicyFile property

disableHttp

public static void disableHttp(Properties props)

reRegister

protected void reRegister()
                   throws RemoteException
Re-registers this server with the switchboard. This method should only be called in the event of a switchboard failure.

Specified by:
reRegister in class AbstractSwitchboardUser
Throws:
RemoteException

register

protected void register(String switchboardName)
                 throws RemoteException,
                        MalformedURLException
Registers this server with the specified switchboard.

Throws:
RemoteException
MalformedURLException

maxClients

public int maxClients()
               throws RemoteException
Returns the maximum number of clients this server is willing to accept.

Specified by:
maxClients in interface Server
Throws:
RemoteException
See Also:
SwitchboardRemote.register(Server)

acceptClientsOnlyByRequest

public boolean acceptClientsOnlyByRequest()
Returns whether this server will only accept clients that specifically request it.

Specified by:
acceptClientsOnlyByRequest in interface Server
See Also:
SwitchboardRemote.register(Server), SwitchboardRemote.getServer(int,int)

Parsing Engine

Author: Dan Bikel.