Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## 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

The `CommunicatorServer` class defines generic behaviour for the server part of a connector or an adaptor. Most connectors or adaptors extend `CommunicatorServer` and inherit this behaviour. Connectors or adaptors that do not fit into this model do not extend `CommunicatorServer`.

An `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.

A `CommunicatorServer` may serve several clients concurrently. The number of concurrent clients can be limited using the property `maxActiveClientCount`. The default value of this property is defined by the subclasses.

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

See Also:
  Serialized Form

Field Summary
`protected java.lang.String` | `dbgTag`
`protected java.lang.String` | `host` The host name used by this CommunicatorServer.
`static int` | `HTML_TYPE` Indicates that it is a HTML connector type.
`static int` | `HTTP_TYPE` Indicates that it is a HTTP connector type.
`static int` | `HTTPS_TYPE` Indicates that it is a HTTPS connector type.
`protected int` | `infoType`
`protected int` | `maxActiveClientCount` The maximum number of clients that the CommunicatorServer can process concurrently.
`protected MBeanServer` | `mbs` The MBeanServer where this CommunicatorServer is to be registered with.
`protected ObjectName` | `objectName` The object name of the connector server.
`static int` | `OFFLINE` Represents an `OFFLINE` state.
`static int` | `ONLINE` Represents an `ONLINE` state.
`protected int` | `port` The port number used by this CommunicatorServer.
`static int` | `RMI_TYPE` Indicates that it is a RMI connector type.
`protected int` | `servedClientCount`
`static int` | `SNMP_TYPE` Indicates that it is a SNMP connector type.
`static int` | `STARTING` Represents a `STARTING` state.
`protected int` | `state` The state of the connector server.
`static int` | `STOPPING` Represents a `STOPPING` state.

Constructor Summary
`CommunicatorServer(int connectorType)` Instantiates a `CommunicatorServer`.

Method Summary
`protected void` | `changeState(int s)` For JDMK internal use only
`protected void` | `debug(java.lang.String func, java.lang.String info)`
`protected void` | `debug(java.lang.String clz, java.lang.String func, java.lang.String info)`
`protected void` | `debug(java.lang.String clz, java.lang.String func, java.lang.Throwable exception)`
`protected void` | `debug(java.lang.String func, java.lang.Throwable exception)`
`protected abstract void` | `doBind()`
`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.
`int` | `getActiveClientCount()` Gets the number of clients currently being processed by this `CommunicatorServer`.
`java.lang.String` | `getHost()` Gets the host name used by this `CommunicatorServer`.
`int` | `getMaxActiveClientCount()` Gets the maximum number of clients that this `CommunicatorServer` can process concurrently.
`protected MBeanServer` | `getMBeanServer()` For JDMK internal use only
`protected ObjectName` | `getObjectName()` For JDMK internal use only
`int` | `getPort()` Gets the port number used by this `CommunicatorServer`.
`abstract java.lang.String` | `getProtocol()` Gets the protocol being used by this `CommunicatorServer`.
`int` | `getServedClientCount()` Gets the number of clients that have been processed by this `CommunicatorServer` since its creation.
`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 if the `CommunicatorServer` is active.
`protected boolean` | `isDebugOn()`
`protected boolean` | `isTraceOn()`
`protected java.lang.String` | `makeDebugTag()` Returns the string used in debug traces.
`protected java.lang.String` | `makeThreadName()` Returns the string used to name the connector thread.
`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` | `setMaxActiveClientCount(int c)` Sets the maximum number of clients this `CommunicatorServer` can process concurrently.
`void` | `setPort(int p)` Sets the port number used by this `CommunicatorServer`.
`void` | `start()` Starts this `CommunicatorServer`.
`void` | `stop()` Stops this `CommunicatorServer`.
`protected void` | `trace(java.lang.String func, java.lang.String info)`
`protected void` | `trace(java.lang.String clz, java.lang.String func, java.lang.String info)`
`boolean` | `waitState(int s, 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.

### RMI_TYPE

    public static final int RMI_TYPE

  Indicates that it is a RMI connector type.

### HTTP_TYPE

    public static final int HTTP_TYPE

  Indicates that it is a HTTP connector type.

### HTML_TYPE

    public static final int HTML_TYPE

  Indicates that it is a HTML connector type.

### SNMP_TYPE

    public static final int SNMP_TYPE

  Indicates that it is a SNMP connector type.

### HTTPS_TYPE

    public static final int HTTPS_TYPE

  Indicates that it is a HTTPS connector type.

### state

    protected transient int state

  The state of the connector server.

### objectName

    protected ObjectName objectName

  The object name of the connector server.

### mbs

    protected MBeanServer mbs

  The MBeanServer where this CommunicatorServer is to be registered with.

### dbgTag

    protected transient java.lang.String dbgTag

### maxActiveClientCount

    protected int maxActiveClientCount

  The maximum number of clients that the CommunicatorServer can process concurrently.

### servedClientCount

    protected transient int servedClientCount

### host

    protected java.lang.String host

  The host name used by this CommunicatorServer.

### port

    protected int port

  The port number used by this CommunicatorServer.

### infoType

    protected int infoType

Constructor Detail

### CommunicatorServer

    public CommunicatorServer(int connectorType)
                       throws java.lang.IllegalArgumentException

  Instantiates a `CommunicatorServer`.
  Parameters:
    `connectorType` - Indicates the connector type. Possible values are: RMI_TYPE, HTTP_TYPE, HTML_TYPE, SNMP_TYPE and HTTPS_TYPE.
  Throws:
    java.lang.IllegalArgumentException - This connector type is not correct.

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 if the `CommunicatorServer` is active.
  Specified by:
    isActive in interface CommunicatorServerMBean
  Returns:
    True if connector is active; false otherwise.

### waitState

    public boolean waitState(int s,
                             long timeOut)

  Waits to be notified of a change in this object. It waits until either of the following two conditions has occurred:
  - Another thread notifies a new state that is the same as s argument.
  - The timeout period, specified by the timeout argument in milliseconds, has elapsed.

  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 s argument.

  Specified by:
    waitState in interface CommunicatorServerMBean
  Parameters:
    `s` - The state to wait.
    `timeOut` - The maximum time to wait in milliseconds.
  Returns:
    True if the state is the same as the s 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 p)
                 throws java.lang.IllegalStateException

  Sets the port number used by this `CommunicatorServer`.
  Specified by:
    setPort in interface CommunicatorServerMBean
  Parameters:
    `p` - 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.

### getServedClientCount

    public int getServedClientCount()

  Gets the number of clients that have been processed by this `CommunicatorServer` since its creation.
  Returns:
    The number of clients handled by this `CommunicatorServer` since its creation. This counter is not reset by the `stop` method.

### getActiveClientCount

    public int getActiveClientCount()

  Gets the number of clients currently being processed by this `CommunicatorServer`.
  Returns:
    The number of clients currently being processed by this `CommunicatorServer`.

### getMaxActiveClientCount

    public int getMaxActiveClientCount()

  Gets the maximum number of clients that this `CommunicatorServer` can process concurrently.
  Returns:
    The maximum number of clients that this `CommunicatorServer` can process concurrently.

### setMaxActiveClientCount

    public void setMaxActiveClientCount(int c)
                                 throws java.lang.IllegalStateException

  Sets the maximum number of clients this `CommunicatorServer` can process concurrently.
  Parameters:
    `c` - The number of clients.
  Throws:
    java.lang.IllegalStateException - This method has been invoked while the communicator was ONLINE or STARTING.

### run

    public void run()

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

### 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()` ends up.

### 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()` ends up.

### 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.

### getObjectName

    protected ObjectName getObjectName()

  For JDMK internal use only

### getMBeanServer

    protected MBeanServer getMBeanServer()

  For JDMK internal use only

### changeState

    protected void changeState(int s)

  For JDMK internal use only

### makeDebugTag

    protected java.lang.String makeDebugTag()

  Returns the string used in debug traces.

### makeThreadName

    protected java.lang.String makeThreadName()

  Returns the string used to name the connector thread.

### 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 either 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

### isTraceOn

    protected boolean isTraceOn()

### trace

    protected void trace(java.lang.String clz,
                         java.lang.String func,
                         java.lang.String info)

### isDebugOn

    protected boolean isDebugOn()

### debug

    protected void debug(java.lang.String clz,
                         java.lang.String func,
                         java.lang.String info)

### debug

    protected void debug(java.lang.String clz,
                         java.lang.String func,
                         java.lang.Throwable exception)

### trace

    protected void trace(java.lang.String func,
                         java.lang.String info)

### debug

    protected void debug(java.lang.String func,
                         java.lang.String info)

### debug

    protected void debug(java.lang.String func,
                         java.lang.Throwable exception)

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD