jrun.servlet.network
Class NetworkService

jrunx.kernel.ServiceAdapter
  |
  +--jrunx.scheduler.ThreadPoolService
        |
        +--jrun.servlet.network.NetworkService
All Implemented Interfaces:
NetworkServiceMBean, javax.naming.Referenceable, RunnableFactory, java.io.Serializable, Service, ServiceMBean, ThreadPoolServiceMBean
Direct Known Subclasses:
JRunProxyService, WebService

public abstract class NetworkService
extends ThreadPoolService
implements NetworkServiceMBean, RunnableFactory

The base class for developing network services. Network services are modules that, running within a server, make a particular application protocol such as FTP or DHCP available across a network. Services can typically interact with multiple clients concurrently, handling requests through one or more endpoints. The clients can be end-users using applications or applets, or other services.

This class takes care of most of the management for Tcp sockets. if other types of sockets are needed, a subclass can certianly override the necessary methods.

Author:
Paul Colton, Edwin Smith
See Also:
Serialized Form

Field Summary
static java.lang.String BYTES_IN
           
static java.lang.String BYTES_OUT
           
static java.lang.String HANDLED_MS
           
static java.lang.String HANDLED_RQ
           
protected  int metricsElapsedIndex
           
protected  int metricsIndexIn
           
protected  int metricsIndexOut
           
protected  int metricsServicedIndex
           
protected  javax.net.ServerSocketFactory serverSocketFactory
           
protected  java.net.ServerSocket ss
           
 
Fields inherited from class jrunx.scheduler.ThreadPoolService
metrics, threadPool
 
Fields inherited from class jrunx.kernel.ServiceAdapter
DEFAULT_DEACTIVATED, DEFAULT_DOMAIN, DOMAIN_NAME_SEPARATOR, DOMAIN_NAME_SUFFIX, domainName, jndiBindable, LOGGER_CACHE_TIME, SCHEDULER_SERVICE, SECURITY_MANAGER, server, status, TRANSACTION_MANAGER
 
Fields inherited from interface jrunx.kernel.Service
INITIALIZED, STARTED, STARTING, STOPPED, STOPPING, UNINITIALIZED
 
Fields inherited from interface jrunx.scheduler.RunnableFactory
BUSY, EXCEPTION, SHUTDOWN
 
Constructor Summary
NetworkService()
           
 
Method Summary
protected  java.net.Socket accept()
          Subclasses can override this to change the socket class or implement a different concurrency policy.
protected  void bindToSocket()
          Create and bind a protocol specific socket.
 Metrics createMetrics()
           
 int getAvailablePort(int startPort, int portCount)
          Gets first unused port
 int getBacklog()
          Gets the server socket backlog
 java.lang.String getBindAddress()
          Gets the bind address for the service
 int getInputMetricIndex()
           
 java.lang.String getInterface()
          Gets the accepted interface pattern
 Metrics getMetrics()
           
abstract  java.lang.String getMetricsPrefix()
          Gets the prefix to be used for metrics, such as "jcp" or "web".
 int getOutputMetricIndex()
           
 int getPort()
          Gets the port that this service will bind to
 RunnableFactory getRunnableFactory()
           
 int getServicedMetricIndex()
           
abstract  java.lang.String getServiceName()
          Gets the service name, such as JRun Web Server.
 java.lang.String getSocketFactoryName()
          Gets the socket factory class for this endpoint.
 int getTimeout()
          Gets the socket read timeout
protected  int getTimeoutMs()
           
 void init()
          Not every service needs to init, implement it out of convenience.
 void setBacklog(int backlog)
          Sets the server socket backlog.
 void setBindAddress(java.lang.String addr)
          Sets the bind address for the service.
 void setInterface(java.lang.String iface)
          Sets the accepted interface pattern.
 void setPort(int port)
          Sets the port that this service will bind to
 void setSocketFactoryName(java.lang.String className)
          Sets the socket factory class for this endpoint.
 void setTimeout(int seconds)
          Sets the socket read timeout
 void start()
          Every service other than mere data collections should start
 void stop()
          Every service other than mere data collections should stop
 void updateRequestMetrics()
          Updates the end of the request.
 
Methods inherited from class jrunx.scheduler.ThreadPoolService
getActiveHandlerThreads, getMaxHandlerThreads, getMinHandlerThreads, getThreadWaitTimeout, setActiveHandlerThreads, setMaxHandlerThreads, setMinHandlerThreads, setThreadWaitTimeout
 
Methods inherited from class jrunx.kernel.ServiceAdapter
bind, destroy, findObjectInstance, findObjectInstance, findObjectInstance, getBindToJNDI, getDeactivated, getDomainName, getDomainSearchPath, getJRunService, getLogger, getName, getParentService, getReference, getResourceManager, getServerName, getServerProperties, getStatus, invokeMethod, isInPartition, isPartition, lookup, postDeregister, postRegister, preDeregister, preRegister, requestServer, scheduleRunnable, setBindToJNDI, setDeactivated, setDomainName, setName, setParentService, toString, unbind, unscheduleRunnable, updateStatus
 
Methods inherited from interface jrunx.scheduler.ThreadPoolServiceMBean
getActiveHandlerThreads, getMaxHandlerThreads, getMinHandlerThreads, getThreadWaitTimeout, setActiveHandlerThreads, setMaxHandlerThreads, setMinHandlerThreads, setThreadWaitTimeout
 
Methods inherited from interface jrunx.kernel.ServiceMBean
bind, getBindToJNDI, getDeactivated, getDomainName, getJRunService, getLogger, getName, getParentService, getServerName, requestServer, setBindToJNDI, setDeactivated, setDomainName, setName, setParentService, unbind
 
Methods inherited from interface jrunx.kernel.Service
destroy, getStatus, updateStatus
 
Methods inherited from interface jrunx.scheduler.RunnableFactory
createRunnable, destroyRunnable, invokeRunnable, swapRunnable
 

Field Detail

BYTES_IN

public static final java.lang.String BYTES_IN

BYTES_OUT

public static final java.lang.String BYTES_OUT

HANDLED_RQ

public static final java.lang.String HANDLED_RQ

HANDLED_MS

public static final java.lang.String HANDLED_MS

metricsIndexIn

protected int metricsIndexIn

metricsIndexOut

protected int metricsIndexOut

metricsServicedIndex

protected int metricsServicedIndex

metricsElapsedIndex

protected int metricsElapsedIndex

serverSocketFactory

protected javax.net.ServerSocketFactory serverSocketFactory

ss

protected java.net.ServerSocket ss
Constructor Detail

NetworkService

public NetworkService()
Method Detail

init

public void init()
          throws java.lang.Exception
Description copied from class: ServiceAdapter
Not every service needs to init, implement it out of convenience.
Specified by:
init in interface Service
Overrides:
init in class ThreadPoolService

setBindAddress

public void setBindAddress(java.lang.String addr)
Description copied from interface: NetworkServiceMBean
Sets the bind address for the service. The default is "*".
Specified by:
setBindAddress in interface NetworkServiceMBean
Following copied from interface: jrun.servlet.network.NetworkServiceMBean
Parameters:
addr - The bind address

getBindAddress

public java.lang.String getBindAddress()
Description copied from interface: NetworkServiceMBean
Gets the bind address for the service
Specified by:
getBindAddress in interface NetworkServiceMBean
Following copied from interface: jrun.servlet.network.NetworkServiceMBean
Returns:
The bind address

setPort

public void setPort(int port)
Description copied from interface: NetworkServiceMBean
Sets the port that this service will bind to
Specified by:
setPort in interface NetworkServiceMBean
Following copied from interface: jrun.servlet.network.NetworkServiceMBean
Parameters:
port - The port number

getPort

public int getPort()
Description copied from interface: NetworkServiceMBean
Gets the port that this service will bind to
Specified by:
getPort in interface NetworkServiceMBean
Following copied from interface: jrun.servlet.network.NetworkServiceMBean
Returns:
The port number

getAvailablePort

public int getAvailablePort(int startPort,
                            int portCount)
Gets first unused port
Specified by:
getAvailablePort in interface NetworkServiceMBean
Parameters:
startPort - The port number to start scan
portCount - The number of ports to check for availability

setBacklog

public void setBacklog(int backlog)
Description copied from interface: NetworkServiceMBean
Sets the server socket backlog. The default is 1000.
Specified by:
setBacklog in interface NetworkServiceMBean
Following copied from interface: jrun.servlet.network.NetworkServiceMBean
Parameters:
backlog - The backlog

getBacklog

public int getBacklog()
Description copied from interface: NetworkServiceMBean
Gets the server socket backlog
Specified by:
getBacklog in interface NetworkServiceMBean
Following copied from interface: jrun.servlet.network.NetworkServiceMBean
Returns:
The backlog

setInterface

public void setInterface(java.lang.String iface)
Description copied from interface: NetworkServiceMBean
Sets the accepted interface pattern. The default is 127.0.0.1
Specified by:
setInterface in interface NetworkServiceMBean
Following copied from interface: jrun.servlet.network.NetworkServiceMBean
Parameters:
iface - The interface

getInterface

public java.lang.String getInterface()
Description copied from interface: NetworkServiceMBean
Gets the accepted interface pattern
Specified by:
getInterface in interface NetworkServiceMBean
Following copied from interface: jrun.servlet.network.NetworkServiceMBean
Returns:
The interface

setSocketFactoryName

public void setSocketFactoryName(java.lang.String className)
Description copied from interface: NetworkServiceMBean
Sets the socket factory class for this endpoint.
Specified by:
setSocketFactoryName in interface NetworkServiceMBean
Following copied from interface: jrun.servlet.network.NetworkServiceMBean
Parameters:
className - The server socket factory class name

getSocketFactoryName

public java.lang.String getSocketFactoryName()
Description copied from interface: NetworkServiceMBean
Gets the socket factory class for this endpoint.
Specified by:
getSocketFactoryName in interface NetworkServiceMBean
Following copied from interface: jrun.servlet.network.NetworkServiceMBean
Returns:
The server socket factory class name

setTimeout

public void setTimeout(int seconds)
Description copied from interface: NetworkServiceMBean
Sets the socket read timeout
Specified by:
setTimeout in interface NetworkServiceMBean
Following copied from interface: jrun.servlet.network.NetworkServiceMBean
Parameters:
seconds - The read timeout in seconds

getTimeout

public int getTimeout()
Description copied from interface: NetworkServiceMBean
Gets the socket read timeout
Specified by:
getTimeout in interface NetworkServiceMBean
Following copied from interface: jrun.servlet.network.NetworkServiceMBean
Returns:
The read timeout in seconds

getTimeoutMs

protected int getTimeoutMs()

start

public void start()
           throws java.lang.Exception
Description copied from class: ServiceAdapter
Every service other than mere data collections should start
Specified by:
start in interface Service
Overrides:
start in class ThreadPoolService

getRunnableFactory

public RunnableFactory getRunnableFactory()
Overrides:
getRunnableFactory in class ThreadPoolService

createMetrics

public Metrics createMetrics()
Overrides:
createMetrics in class ThreadPoolService

stop

public void stop()
          throws java.lang.Exception
Description copied from class: ServiceAdapter
Every service other than mere data collections should stop
Specified by:
stop in interface Service
Overrides:
stop in class ServiceAdapter

getMetricsPrefix

public abstract java.lang.String getMetricsPrefix()
Gets the prefix to be used for metrics, such as "jcp" or "web". This must be implemented by any subclasses.
Overrides:
getMetricsPrefix in class ThreadPoolService

getServiceName

public abstract java.lang.String getServiceName()
Gets the service name, such as JRun Web Server. This must be implemented by any subclasses

bindToSocket

protected void bindToSocket()
                     throws java.io.IOException
Create and bind a protocol specific socket. Implement abstract method from the super class for TCP based server sockets.
Throws:
java.io.IOException - in case of address binding errors
ConfigException - if the configuration information is problematic

accept

protected java.net.Socket accept()
                          throws java.io.IOException,
                                 java.lang.InterruptedException
Subclasses can override this to change the socket class or implement a different concurrency policy.

getMetrics

public Metrics getMetrics()
Overrides:
getMetrics in class ThreadPoolService

getOutputMetricIndex

public int getOutputMetricIndex()

getInputMetricIndex

public int getInputMetricIndex()

getServicedMetricIndex

public int getServicedMetricIndex()

updateRequestMetrics

public final void updateRequestMetrics()
Updates the end of the request. Increments the handledRq metric and the handledMs metric


Copyright � 2002 Macromedia Corporation. All Rights Reserved.