|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Object | +--jason.core.AbstractService
This class is the common class for services implementation.
Its role is to managed the service state (START/STOP). It
takes into consideration the XML service configuration file
by using the ServiceContext. So user can retreive
properties for handling correctly the service. The container
calls the init method and the start method
automatically. The start method will call by default the run method
that should contains the user core function.
The AbstractService doesn't behave excatly like a Thread.
For the Thread support, please look at the ThreadableService class
Developer can made its service persistent thanks to the setPersistent method.
This method must be changed before the start method. Then during the init
the setPersistent wish is delegated to the ServiceContext. User can change the behavior in
the notifyInit method. Then, if the service is set persistent, the container will call the
getServiceState method during the stop method for storing the service state. On the contrary,
when starting a service, the container will reload the old service state. A current implementation tried to get all
value for each get starting method name, writing the state is writing for all tied set method.
Service,
ThreadableService,
SocketService,
ServiceContext,
ServiceVersion,
Serialized Form| Field Summary | |
static int |
INITIALIZED
|
protected java.lang.String |
name
|
static int |
NOSTATE
|
protected ServiceContext |
serviceContext
|
static int |
STARTED
|
static int |
STOPPED
|
| Fields inherited from interface jason.core.Service |
ERROR_MESSAGE, INFORMATION_MESSAGE, VERBOSE_MESSAGE, WARNING_MESSAGE |
| Constructor Summary | |
AbstractService()
Default constructor, nothing to do |
|
| Method Summary | |
protected void |
actionForStart()
This method is called at the end of the start method.
|
boolean |
canRestartOnError()
|
protected void |
checkForContext()
Check that the context is not empty, else it throws a RuntimeException,
because this is an illegal access |
protected void |
fireCriticalErrorDetected(java.lang.Exception exc)
This method must be called for critical error, it will avoid the service to start |
long |
getAutoRestartCounter()
|
boolean |
getBooleanProperty(java.lang.String name)
|
ServiceInfo |
getInfo()
|
int |
getIntProperty(java.lang.String name)
|
java.lang.String |
getName()
This name should distinguish your service from another one. |
java.util.Enumeration |
getPropertiesName()
|
java.lang.Object |
getProperty(java.lang.String name)
|
ServiceContext |
getServiceContext()
|
ServiceState |
getServiceState()
|
int |
getState()
|
java.lang.String |
getStringProperty(java.lang.String name)
|
ServiceType |
getType()
This is an important function for cooperation, it says what it the role of a service such as a Web service. |
ServiceVersion |
getVersion()
|
boolean |
hasServiceContext()
|
void |
init(ServiceContext sc)
Initialize the current service. |
protected boolean |
isAutoStop()
|
boolean |
isEnabled()
This method is used only when starting the first time this service |
boolean |
isInitialized()
this method return true when the
service has a ServiceContext |
boolean |
isOverride()
By default it returns false |
boolean |
isPersistent()
|
boolean |
isPrivate()
Design the accessibility level for this service |
boolean |
isProcessable()
Check for a loadbalancing for each new process |
boolean |
isStarted()
|
boolean |
isStopped()
|
protected boolean |
isTest()
|
boolean |
isThreadable()
Check for the thread support from a thread pooling system |
boolean |
isVerbose()
This method will avoid to show the Information message type Look at the ServiceContect for more information |
ServiceResponse |
manageRequest(ServiceRequest request)
Manage a request |
protected ServiceResponse |
manageRequestForType(ServiceType type,
ServiceRequest request)
|
void |
notifyData(java.lang.String key,
java.lang.Object value)
|
protected void |
notifyInitReady()
This method is called when the init method is
runned |
protected void |
notifyStartReady()
This method is called at the end of the start method |
protected void |
notifyStopReady()
This method is called at the end of the stop method |
protected void |
postStop()
Action before stopping the service |
void |
restart()
restart the service |
protected void |
run()
User should override this method for running a task. |
void |
sendCustomMessage(int type,
java.lang.String message)
Send a custom message with a tied type |
void |
sendErrorMessage(java.lang.String message)
Send an error message |
void |
sendInformationMessage(java.lang.String message)
Send an information message, this message will not be taken into account if the verbose value is false |
void |
sendInnerError(java.lang.Exception exc)
Send an inner error exception |
void |
sendWarningMessage(java.lang.String message)
Send a warning message |
void |
setAutoRestartCounter(long counter)
Reset the counter for trying again to start the service on error reported. |
void |
setAutoRestartOnError(boolean restart)
Set a flag for restarting automatically the current service on runtime error. |
protected void |
setAutoStop(boolean autoStop)
Decide to stop the service automatically after the run invocakation, by default the value is false |
protected void |
setEnabled(boolean enabled)
Change the enabled mode. |
void |
setName(java.lang.String name)
Reset the name of the service |
void |
setPersistent(boolean persistent)
Make the current service persistent through the getServiceState |
protected void |
setPrivate(boolean privateState)
This method lets the user change the accessibility for service |
protected void |
setProperty(java.lang.String name,
java.lang.Object value)
Reset the starting property. it can be only called when the init method has been called. |
void |
setServiceContext(ServiceContext serviceContext)
|
protected void |
setTest(boolean test)
This method shows for the first run call a message that control your service is really running |
protected void |
setType(ServiceType type)
|
protected void |
setVerbose(boolean verbose)
Decide for the verbosity |
void |
setVersion(ServiceVersion version)
Reset the version of the service |
void |
start()
Start the service. |
void |
stop()
stop the service |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
public static final int NOSTATE
public static final int INITIALIZED
public static final int STOPPED
public static final int STARTED
protected transient ServiceContext serviceContext
protected java.lang.String name
| Constructor Detail |
public AbstractService()
| Method Detail |
public void init(ServiceContext sc)
init in interface Serviceprotected void setTest(boolean test)
protected boolean isTest()
true> is the test mode is supportedpublic java.util.Enumeration getPropertiesName()
protected void setProperty(java.lang.String name,
java.lang.Object value)
throws ServiceException
init method has been called. So, be careful and called it rather
in notifiyInitReadt called. If you invoke it before a RuntimeException will be
called
ServiceExceptionpublic java.lang.String getStringProperty(java.lang.String name)
getStringProperty in interface Servicepublic int getIntProperty(java.lang.String name)
getIntProperty in interface Servicepublic boolean getBooleanProperty(java.lang.String name)
getBooleanProperty in interface Servicepublic java.lang.Object getProperty(java.lang.String name)
getProperty in interface Serviceprotected void checkForContext()
RuntimeException,
because this is an illegal access
protected void notifyInitReady()
init method is
runned
protected void notifyStartReady()
start method
protected void notifyStopReady()
stop method
public void notifyData(java.lang.String key,
java.lang.Object value)
notifyData in interface ServiceDataListenerpublic void restart()
Service
restart in interface Servicepublic void stop()
Service
stop in interface Serviceprotected void setAutoStop(boolean autoStop)
false
protected boolean isAutoStop()
true if the service is automatically stop after the run methodpublic void setPersistent(boolean persistent)
getServiceState
public boolean isPersistent()
true if the service state can be storeprotected void postStop()
public ServiceState getServiceState()
getServiceState in interface Servicepublic void start()
run method
start in interface Serviceprotected void actionForStart()
start method.
By default it tries to call the run method
public void setAutoRestartOnError(boolean restart)
Setautorestartcounter
public boolean canRestartOnError()
true to restart the service if an unknown exception is
thrown. This is a secure way to maintain a running state for the service as
possiblepublic void setAutoRestartCounter(long counter)
public long getAutoRestartCounter()
public boolean isStarted()
public boolean isStopped()
public boolean isInitialized()
true when the
service has a ServiceContext
public int getState()
public void setVersion(ServiceVersion version)
public ServiceVersion getVersion()
getVersion in interface Servicepublic boolean isOverride()
false
isOverride in interface Servicepublic ServiceInfo getInfo()
getInfo in interface Servicepublic void setName(java.lang.String name)
public java.lang.String getName()
Service
getName in interface Serviceprotected void run()
setThreadLoopMode method
public void setServiceContext(ServiceContext serviceContext)
public ServiceContext getServiceContext()
public boolean hasServiceContext()
true if the serviceContext is availableprotected void setVerbose(boolean verbose)
public boolean isVerbose()
ServiceContect for more information
isVerbose in interface Servicepublic boolean isThreadable()
public boolean isProcessable()
public void sendErrorMessage(java.lang.String message)
public void sendInnerError(java.lang.Exception exc)
public void sendWarningMessage(java.lang.String message)
public void sendInformationMessage(java.lang.String message)
false
public void sendCustomMessage(int type,
java.lang.String message)
public boolean isPrivate()
isPrivate in interface Servicetrue if you don't want this service cooperate with other serviceprotected void setPrivate(boolean privateState)
public ServiceType getType()
Service
getType in interface Serviceprotected void fireCriticalErrorDetected(java.lang.Exception exc)
protected void setType(ServiceType type)
type - Reset the service type
public ServiceResponse manageRequest(ServiceRequest request)
throws ServiceException
manageRequest in interface Servicerequest - A request for the service
ServiceException - when the request is not managed
protected ServiceResponse manageRequestForType(ServiceType type,
ServiceRequest request)
throws ServiceException
ServiceExceptionpublic boolean isEnabled()
isEnabled in interface Servicetrue is the service can be runprotected void setEnabled(boolean enabled)
enabled - can start or not this service
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||