|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object SK.gnome.dwarf.GenericService
Provides a generic Service
implementation.
This is the most basic implementation of the Service
interface.
All services of this framework extend this abstract class.
The following requirements related to the service lifecycle are imposed by this implementation, and must be fulfilled by the application code:
The following sample code illustrates a typical use of a service:
// instatiate a new service PizzaService ps = new PizzaService("Pizza Service"); // set the service attributes first ps.setGreeting("Hello, here's you pizza!"); // the greeting sentence ps.setType(ASAP); // the type of the delivery ps.setMultipleDelivery(true); // enable multiple deliveries // initialize the service ps.init(null); // null means that the service has no container // start the service ps.start(); // now the service is ready to serve ps.deliver(new Pizza(HAM_AND_CHEESE), "Mr. Spock", "2nd NW Hoyt, Portland, OR")); ps.deliver(new Pizza(NAPOLITANA), "Mr. Spock Jr.", "2nd NW Hoyt, Portland, OR")); // shut down the service ps.shutdown();
Thread-safety note:
The state transition methods are not synchronized, therefore they must be synchronized
manually, if required.
Field Summary | |
protected StringProperties |
initParameters
The initial service parameters. |
protected Server |
parent
The service container. |
Fields inherited from interface SK.gnome.dwarf.Service |
INITIALIZED, LOG_DEBUG, LOG_ERROR, LOG_FATAL, LOG_INFO, LOG_TRACE, LOG_WARN, LOG_XFER, SHUTDOWN, STARTED, STOPPED |
Constructor Summary | |
GenericService(java.lang.String name)
Constructs a new GenericService. |
Method Summary | |
protected Authenticator |
getAuthenticator()
Returns an authentication service for this object. |
protected java.lang.String |
getAuthFacility()
Returns the authentication facility. |
java.lang.String |
getFullName()
Returns the full service name. |
java.lang.String |
getInitParameter(java.lang.String name)
Returns the initial parameter by the name. |
java.util.Enumeration |
getInitParameterNames()
Returns the initial parameter names. |
protected java.lang.String |
getLogFacility()
Returns the logging facility. |
protected Logger |
getLogger()
Returns a logging service for this object. |
java.lang.String |
getName()
Returns the service name. |
Parameters |
getParameters()
Returns the service parameters. |
java.security.Principal |
getPrincipal()
Returns a principal representing the service. |
protected int |
getShutdownTimeout()
Returns the shutdown timeout. |
boolean |
getState(int state)
Returns the current service state. |
void |
init(Server parent)
Initializes the service. |
void |
log(LogLevel level,
java.lang.String message)
Logs the message with the given logging level. |
void |
log(LogLevel level,
java.lang.String message,
java.lang.Throwable error)
Logs the message and the error with the given logging level. |
AuthId |
login(javax.security.auth.Subject subject,
javax.security.auth.callback.CallbackHandler handler)
Authenticates the subject. |
void |
logout(AuthId id,
javax.security.auth.Subject subject)
Logouts the subject. |
void |
setAuthFacility(java.lang.String facility)
Sets the authentication facility. |
void |
setInitParameters(StringProperties parameters)
Sets the initial parameters. |
void |
setLogFacility(java.lang.String facility)
Sets the logging facility. |
void |
shutdown()
Shuts down the service. |
void |
start()
Starts the service. |
void |
stop()
Stops the service. |
java.lang.String |
toString()
Returns the string representation of the service. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
protected Server parent
Contains a reference to the parent server, i.e. the server which contains this service. A null value means that the service is not contained by any server.
The field value is assigned in the init(Server)
method during the initialization
procedure.
protected StringProperties initParameters
The initial parameters are intended to provide a set of initial read-only string parameters, probably with no prior knowledge of their type or syntax.
The purpose of the initial parameters is different than of those defined by the
Parameters
interface, which represents a set of parameters, dynamically shared
by a tree of server and service instances. The initial parameters, on the contrary,
represents a service-specific set of string arguments, accessible only to this service,
and not to the outside world. They may be used by a subclass instance to pass an arbitrary
initialization parameters to the service's initialization procedure, for example.
getInitParameter(String)
,
getInitParameterNames()
,
setInitParameters(StringProperties)
Constructor Detail |
public GenericService(java.lang.String name)
The string argument is trimmed before it is used for the service name. Since the slash "/" character is used as a separator in the full service names, it must not be included in the service name.
name
- the service name
java.lang.NullPointerException
- if the name is null
java.lang.IllegalArgumentException
- if either the name is empty string or it
contains the slash character '/'Method Detail |
public final java.lang.String getName()
Service
getName
in interface Service
public java.lang.String getFullName()
Service
The full name identifies the particular service instance in the whole service namespace. If there is a hierarchical tree of service instances, the full name must be a complete path from the top-level server down to the given nested service, like "Main Server/HTTP Server/Session Manager", for example.
The separation character used in the full name is always the slash "/".
getFullName
in interface Service
public final boolean getState(int state)
Service
If a service has been initialized, for example, the getState(INITIALIZED) call returns true, but the getState(STARTED) call returns false if it has not been started yet.
getState
in interface Service
state
- the queried state
Service.INITIALIZED
,
Service.STARTED
,
Service.STOPPED
,
Service.SHUTDOWN
public Parameters getParameters()
It returns the parent server's parameters as returned from its getParameters() method, or null if there is no parent server available.
getParameters
in interface Service
public void init(Server parent) throws ServiceException
Service
This method changes the service state to Service.INITIALIZED
.
If the parent argument is not null, it means that the service is becomig a part of the server which the parent argument points to.
After a successful initialization the service can be started by invoking the
Service.start()
method, or it can be shut down by invoking the Service.shutdown()
method.
init
in interface Service
parent
- the container of this service or null
ServiceException
- if an error occured during the initialization processpublic void start() throws ServiceException
Service
This method changes the service state to both the Service.INITIALIZED
and
Service.STARTED
.
In order to be started the service must be initialized first by calling its
Service.init(Server)
method.
After the successful start the service can be stopped by invoking the Service.stop()
method if it implements the Stoppable
interface, or it can be shut down by
invoking the Service.shutdown()
method on it.
start
in interface Service
ServiceException
- if an error occured during the starting processpublic void stop() throws ServiceException
Service
This method changes the service state to both the Service.INITIALIZED
and
Service.STOPPED
.
In order to allow this method to work properly, the service must implement the
Stoppable
interface.
After the service has been stopped, it must be able to start again by invoking the
Service.start()
method, or to shut down by invoking the Service.shutdown()
method on it.
stop
in interface Service
ServiceException
- if an error occured during the stopping processpublic void shutdown()
Service
This method changes the service state to both the Service.INITIALIZED
and
Service.SHUTDOWN
.
A service should be able to shut down if it has been initialized successfuly. If the shutdown process completes the service cannot be used more.
shutdown
in interface Service
public final void log(LogLevel level, java.lang.String message)
The message is logged via logging service returned from the getLogger()
method, or it is printed out to the standard system output, if that method returns
null.
The facility argument value passed into the Logger
is obtained via
the getLogFacility()
method.
log
in interface Service
level
- the logging levelmessage
- the messagepublic final void log(LogLevel level, java.lang.String message, java.lang.Throwable error)
The message is logged via logging service returned from the getLogger()
method, or it is printed out to the standard system output, if that method returns
null.
The facility argument value passed into the Logger
is obtained via
the getLogFacility()
method.
log
in interface Service
level
- the logging levelmessage
- the messageerror
- the errorpublic final AuthId login(javax.security.auth.Subject subject, javax.security.auth.callback.CallbackHandler handler) throws javax.security.auth.login.LoginException
The subject is authenticated via authentication service returned from the
getAuthenticator()
method. A LoginException is thrown if that method
returns null, i.e. there is no authentication service available.
After the successful login the principal returned by the getPrincipal()
method is added to the given subject to represent this service, thus enabling the
possibility to authenticate a single subject by more than one service.
The facility argument value passed into the Authenticator
is obtained
via the getAuthFacility()
method.
login
in interface Service
subject
- the subject to log inhandler
- the callback handler
javax.security.auth.login.LoginException
- if the login operation failspublic final void logout(AuthId id, javax.security.auth.Subject subject) throws javax.security.auth.login.LoginException
The subject is authenticated via authentication service returned from the
getAuthenticator()
method. A LoginException is thrown if that method
returns null, i.e. there is no authentication service available.
Before the logout the principal returned by the getPrincipal()
method
is removed from the given subject.
The facility argument value passed into the Authenticator
is obtained
via the getAuthFacility()
method.
logout
in interface Service
id
- the authentication identifiersubject
- the subject to log out
javax.security.auth.login.LoginException
- if the logout operation failspublic void setLogFacility(java.lang.String facility)
Sets the logging facility of this service.
getLogFacility()
public void setAuthFacility(java.lang.String facility)
Sets the authentication facility of this service.
getAuthFacility()
public void setInitParameters(StringProperties parameters)
It sets the value of the initParameters
field.
parameters
- the initial parameterspublic java.lang.String getInitParameter(java.lang.String name)
Returns the initial parameter corresponding to the given name or null if no such parameter exists.
name
- the parameter name
initParameters
public java.util.Enumeration getInitParameterNames()
Returns an enumeration of the parameter names or an empty enumeration if no parameters are available.
initParameters
public java.security.Principal getPrincipal()
Returns an instance of the ServicePrincipal
class with the name equal
to the service's full name.
getFullName()
protected java.lang.String getLogFacility()
Logging facility is a unique string, which identifies the log messages generated by this service.
This method returns either the logging facility set via the setLogFacility(String)
method, or the logging facility of the parent server. If there is no parent server available,
it returns null.
protected java.lang.String getAuthFacility()
Authentication facility is a unique string identifying the particular authentication mechanism (e.g. a login module configuration), which will be used to authenticate subjects in the context of this service.
This method returns either the authentication facility set via the
setAuthFacility(String)
method, or the authentication facility of the parent server.
If there is no parent server available, it returns null.
protected Logger getLogger()
It returns logging service of the parent server or null if there is no parent server available.
This service is used by the logging methods to actually handle the logging requests.
protected Authenticator getAuthenticator()
It returns authentication service of the parent server or null if there is no parent server available.
This service is used by the authentication methods to actually handle the authentication requests.
protected int getShutdownTimeout()
The shutdown timeout is a number of milliseconds the shutdown process should wait for
finishing the current service's operation before returning from its shutdown()
method.
This method returns a value of the Constants.DEFAULT_SHUTDOWN_TIMEOUT
constant.
public java.lang.String toString()
getName()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |