jason.core
Class SocketService

java.lang.Object
  |
  +--jason.core.AbstractService
        |
        +--jason.core.ThreadableService
              |
              +--jason.core.TaskableService
                    |
                    +--jason.core.SocketService
All Implemented Interfaces:
java.io.Serializable, Service, ServiceDataListener
Direct Known Subclasses:
AdminService, ProcessableService

public abstract class SocketService
extends TaskableService

Created Sat Feb 16 18:50:38 2002

This service is for all socket service (like HTTP server). It simplify the socker server management by a thread pooling system.

User must implement the getTaskForSocket method

Author:
Alexandre Brillant (abrillant@wanadoo.fr)
See Also:
AbstractService, Serialized Form

Field Summary
protected  int port
           
protected  java.net.ServerSocket serverSocket
           
protected  boolean traceRequest
           
 
Fields inherited from class jason.core.ThreadableService
activeThread
 
Fields inherited from class jason.core.AbstractService
INITIALIZED, name, NOSTATE, serviceContext, STARTED, STOPPED
 
Fields inherited from interface jason.core.Service
ERROR_MESSAGE, INFORMATION_MESSAGE, VERBOSE_MESSAGE, WARNING_MESSAGE
 
Constructor Summary
SocketService()
          Run this service in a thread mode
 
Method Summary
protected  void beforeRun()
          This code is called in the current thread once before the run loop.
protected  void fireConflictDetected()
          A port conflict has been detected
protected  void fireSocketAccept(java.net.Socket host)
          Manage a connection on the port
 int getSocketTimeout()
           
protected abstract  Task getTaskForSocket(java.net.Socket host)
           
protected  void notifyBadPort()
          We find another service on the port, switch to the load Balancing mode
 void notifyData(java.lang.String key, java.lang.Object value)
          Test for the port value in the common service data space
protected  void notifyInitReady()
          Search for the port property
protected  void run()
          Start the service waiting for a user request or another service request for loadbalancing request
 void setBacklog(int backlog)
          Reset the queue size for the server socket object.
 void setSocketTimeout(int socketTimeout)
          This method will reset the timeout for socket.
 void setTraceRequest(boolean trace)
           
 void start()
          Start the service.
 
Methods inherited from class jason.core.TaskableService
notifyTask
 
Methods inherited from class jason.core.ThreadableService
actionForStart, enableServiceForThread, getThreadLoopDelay, isThreadLoopMode, isThreadStarted, isWaiting, notifyThreadRunning, runThread, setPriority, setThreadLoopDelay, setThreadLoopMode, threadNotify, threadWait
 
Methods inherited from class jason.core.AbstractService
canRestartOnError, checkForContext, fireCriticalErrorDetected, getAutoRestartCounter, getBooleanProperty, getInfo, getIntProperty, getName, getPropertiesName, getProperty, getServiceContext, getServiceState, getState, getStringProperty, getType, getVersion, hasServiceContext, init, isAutoStop, isEnabled, isInitialized, isOverride, isPersistent, isPrivate, isProcessable, isStarted, isStopped, isTest, isThreadable, isVerbose, manageRequest, manageRequestForType, notifyStartReady, notifyStopReady, postStop, restart, sendCustomMessage, sendErrorMessage, sendInformationMessage, sendInnerError, sendWarningMessage, setAutoRestartCounter, setAutoRestartOnError, setAutoStop, setEnabled, setName, setPersistent, setPrivate, setProperty, setServiceContext, setTest, setType, setVerbose, setVersion, stop
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

port

protected int port

traceRequest

protected boolean traceRequest

serverSocket

protected java.net.ServerSocket serverSocket
Constructor Detail

SocketService

public SocketService()
Run this service in a thread mode

Method Detail

setTraceRequest

public void setTraceRequest(boolean trace)

notifyInitReady

protected void notifyInitReady()
Search for the port property

Overrides:
notifyInitReady in class AbstractService

start

public void start()
Description copied from class: AbstractService
Start the service. By default this method will call the run method

Specified by:
start in interface Service
Overrides:
start in class AbstractService

setBacklog

public void setBacklog(int backlog)
Reset the queue size for the server socket object. By default this value is set to 100


beforeRun

protected void beforeRun()
This code is called in the current thread once before the run loop. This is necessary for code that interrompt the main thread. This method is the "invariant" part of the thread loop


setSocketTimeout

public void setSocketTimeout(int socketTimeout)
This method will reset the timeout for socket. By default the value is 20 s

Parameters:
socketTimeout - time out in ms

getSocketTimeout

public int getSocketTimeout()

run

protected void run()
Start the service waiting for a user request or another service request for loadbalancing request

Overrides:
run in class AbstractService

notifyBadPort

protected void notifyBadPort()
We find another service on the port, switch to the load Balancing mode


fireSocketAccept

protected void fireSocketAccept(java.net.Socket host)
Manage a connection on the port


getTaskForSocket

protected abstract Task getTaskForSocket(java.net.Socket host)
                                  throws ServiceException
Returns:
a task for a user socker
ServiceException

notifyData

public void notifyData(java.lang.String key,
                       java.lang.Object value)
Test for the port value in the common service data space

Specified by:
notifyData in interface ServiceDataListener
Overrides:
notifyData in class AbstractService

fireConflictDetected

protected void fireConflictDetected()
A port conflict has been detected