com.sun.jdmk.comm
Class CommunicatorServer

java.lang.Object
  |
  +--com.sun.jdmk.comm.CommunicatorServer
Direct Known Subclasses:
HtmlAdaptorServer

public abstract class CommunicatorServer
extends java.lang.Object
implements java.lang.Runnable, java.io.Serializable, MBeanRegistration, CommunicatorServerMBean

Defines generic behavior for the server part of a connector or an adaptor. Most connectors or adaptors extend CommunicatorServer and inherit this behavior. Connectors or adaptors that do not fit into this model do not extend CommunicatorServer.

A CommunicatorServer is an active object, it listens for client requests and processes them in its own thread. When necessary, a CommunicatorServer creates other threads to process multiple requests concurrently.

A CommunicatorServer object can be stopped by calling the stop method. When it is stopped, the CommunicatorServer no longer listens to client requests and no longer holds any thread or communication resources. It can be started again by calling the start method.

A CommunicatorServer has a state property which reflects its activity.

CommunicatorServer State
stopped OFFLINE
starting STARTING
running ONLINE
stopping STOPPING

The STARTING state marks the transition from OFFLINE to ONLINE.

The STOPPING state marks the transition from ONLINE to OFFLINE. This occurs when the CommunicatorServer is finishing or interrupting active requests.

When a CommunicatorServer is unregistered from the MBeanServer, it is stopped automatically.

See Also:
Serialized Form

Field Summary
static int OFFLINE
          Represents an OFFLINE state.
static int ONLINE
          Represents an ONLINE state.
static int STARTING
          Represents a STARTING state.
static int STOPPING
          Represents a STOPPING state.
 
Constructor Summary
CommunicatorServer()
          Instantiates a CommunicatorServer.
 
Method Summary
protected abstract  void doBind()
           
protected abstract  void doError(java.lang.Exception e)
           
protected abstract  void doProcess()
          doProcess() is called after doReceive(): it should process the requests of the incoming client.
protected abstract  void doReceive()
          doReceive() should block until a client is available.
protected abstract  void doUnbind()
          doUnbind() is called whenever the connector goes OFFLINE, except if doBind() has thrown an exception.
 java.lang.String getHost()
          Gets the host name used by this CommunicatorServer.
 int getPort()
          Gets the port number used by this CommunicatorServer.
abstract  java.lang.String getProtocol()
          Gets the protocol being used by this CommunicatorServer.
 int getState()
          Gets the state of this CommunicatorServer as an integer.
 java.lang.String getStateString()
          Gets the state of this CommunicatorServer as a string.
 boolean isActive()
          Tests whether the CommunicatorServer is active.
 void postDeregister()
          Do nothing.
 void postRegister(java.lang.Boolean registrationDone)
          Do nothing.
 void preDeregister()
          Stop the connector.
 ObjectName preRegister(MBeanServer server, ObjectName name)
          Preregister method of connector.
 void run()
          For Java DMK internal use only.
 void setPort(int port)
          Sets the port number used by this CommunicatorServer.
 void start()
          Starts this CommunicatorServer.
 void stop()
          Stops this CommunicatorServer.
 boolean waitState(int state, long timeOut)
          Waits to be notified of a change in this object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ONLINE

public static final int ONLINE
Represents an ONLINE state.

OFFLINE

public static final int OFFLINE
Represents an OFFLINE state.

STOPPING

public static final int STOPPING
Represents a STOPPING state.

STARTING

public static final int STARTING
Represents a STARTING state.
Constructor Detail

CommunicatorServer

public CommunicatorServer()
Instantiates a CommunicatorServer.
Method Detail

start

public void start()
Starts this CommunicatorServer.

Has no effect if this CommunicatorServer is ONLINE or STOPPING.

Specified by:
start in interface CommunicatorServerMBean

stop

public void stop()
Stops this CommunicatorServer.

Has no effect if this CommunicatorServer is OFFLINE or STOPPING.

Specified by:
stop in interface CommunicatorServerMBean

isActive

public boolean isActive()
Tests whether the CommunicatorServer is active.
Specified by:
isActive in interface CommunicatorServerMBean
Returns:
True if connector is active; false otherwise.

waitState

public boolean waitState(int state,
                         long timeOut)
Waits to be notified of a change in this object. It waits until either of the following two conditions has occurred:

The method returns immediately is the timeOut argument is negative. And if timeOut argument equals 0 (zero), it waits only until another thread notifies a new state that is the same as state argument.

Specified by:
waitState in interface CommunicatorServerMBean
Parameters:
state - The state to wait.
timeOut - The maximum time to wait in milliseconds.
Returns:
True if the state is the same as the state argument; false otherwise.

getState

public int getState()
Gets the state of this CommunicatorServer as an integer.
Specified by:
getState in interface CommunicatorServerMBean
Returns:
ONLINE, OFFLINE, STARTING or STOPPING.

getStateString

public java.lang.String getStateString()
Gets the state of this CommunicatorServer as a string.
Specified by:
getStateString in interface CommunicatorServerMBean
Returns:
One of the strings "ONLINE", "OFFLINE", "STARTING" or "STOPPING".

getHost

public java.lang.String getHost()
Gets the host name used by this CommunicatorServer.
Specified by:
getHost in interface CommunicatorServerMBean
Returns:
The host name used by this CommunicatorServer.

getPort

public int getPort()
Gets the port number used by this CommunicatorServer.
Specified by:
getPort in interface CommunicatorServerMBean
Returns:
The port number used by this CommunicatorServer.

setPort

public void setPort(int port)
             throws java.lang.IllegalStateException
Sets the port number used by this CommunicatorServer.
Specified by:
setPort in interface CommunicatorServerMBean
Parameters:
port - The port number used by this CommunicatorServer.
Throws:
java.lang.IllegalStateException - This method has been invoked while the communicator was ONLINE or STARTING.

getProtocol

public abstract java.lang.String getProtocol()
Gets the protocol being used by this CommunicatorServer.
Specified by:
getProtocol in interface CommunicatorServerMBean
Returns:
The protocol as a string.

run

public void run()
For Java DMK internal use only.
Specified by:
run in interface java.lang.Runnable

doError

protected abstract void doError(java.lang.Exception e)
                         throws CommunicationException

doBind

protected abstract void doBind()
                        throws CommunicationException,
                               java.lang.InterruptedException

doReceive

protected abstract void doReceive()
                           throws CommunicationException,
                                  java.lang.InterruptedException
doReceive() should block until a client is available. If this method throws an exception, doProcess() is not called but doUnbind() is called then run() stops.

doProcess

protected abstract void doProcess()
                           throws CommunicationException,
                                  java.lang.InterruptedException
doProcess() is called after doReceive(): it should process the requests of the incoming client. If it throws an exception, doUnbind() is called and run() stops.

doUnbind

protected abstract void doUnbind()
                          throws CommunicationException,
                                 java.lang.InterruptedException
doUnbind() is called whenever the connector goes OFFLINE, except if doBind() has thrown an exception.

preRegister

public ObjectName preRegister(MBeanServer server,
                              ObjectName name)
                       throws java.lang.Exception
Preregister method of connector.
Specified by:
preRegister in interface MBeanRegistration
Parameters:
server - The MBeanServer in which the MBean will be registered.
name - The object name of the MBean.
Returns:
The name of the MBean registered.
Throws:
java.langException - This exception should be caught by the MBeanServer and re-thrown as an MBeanRegistrationException.

postRegister

public void postRegister(java.lang.Boolean registrationDone)
Do nothing.
Specified by:
postRegister in interface MBeanRegistration
Parameters:
registrationDone - Indicates whether or not the MBean has been successfully registered in the MBeanServer. The value false means that the registration phase has failed.

preDeregister

public void preDeregister()
                   throws java.lang.Exception
Stop the connector.
Specified by:
preDeregister in interface MBeanRegistration
Throws:
java.langException - This exception should be caught by the MBeanServer and re-thrown as an MBeanRegistrationException.

postDeregister

public void postDeregister()
Do nothing.
Specified by:
postDeregister in interface MBeanRegistration