org.abstracthorizon.danube.service
Class Service

java.lang.Object
  extended by org.abstracthorizon.danube.service.Service
All Implemented Interfaces:
Runnable
Direct Known Subclasses:
ServerService, ServerSocketChannelService

public abstract class Service
extends Object
implements Runnable

This class represents a Service that can run independently under some framework.

Author:
Daniel Sendula

Field Summary
static int DESTROYED
           
static int INITIALIZED
           
protected  Set<ServiceNotificationListener> listeners
          Listeners
protected  org.slf4j.Logger logger
           
protected  String name
          Service name
static int NOT_INITIALIZED
           
static int RUNNING
           
static String[] SERVICE_STATE_NAMES
           
static int STARTED
           
static int STOPPED
           
static int STOPPING
           
protected  boolean stopService
          Flag to signal to service that it needs to stop
 
Constructor Summary
Service()
          Constructor
 
Method Summary
 void addListener(ServiceNotificationListener listener)
          Adds new listener
protected  void changeState(int newState)
          This method changes state.
 void create()
          This method is to be called for service to be set-up.
 void destroy()
          This method is to be called when service is to be removed from the system.
 String getName()
          Returns service name
 int getState()
          Returns current state
 String getStateName()
          Returns state as a string
 void removeListener(ServiceNotificationListener listener)
          Removes a listener
 void setName(String name)
          Sets service's name
 void start()
          This method is to be called for service to be started.
 void stop()
          This method is to be called for service to be stopped.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.lang.Runnable
run
 

Field Detail

NOT_INITIALIZED

public static final int NOT_INITIALIZED
See Also:
Constant Field Values

INITIALIZED

public static final int INITIALIZED
See Also:
Constant Field Values

STARTED

public static final int STARTED
See Also:
Constant Field Values

RUNNING

public static final int RUNNING
See Also:
Constant Field Values

STOPPING

public static final int STOPPING
See Also:
Constant Field Values

STOPPED

public static final int STOPPED
See Also:
Constant Field Values

DESTROYED

public static final int DESTROYED
See Also:
Constant Field Values

SERVICE_STATE_NAMES

public static final String[] SERVICE_STATE_NAMES

logger

protected final org.slf4j.Logger logger

stopService

protected boolean stopService
Flag to signal to service that it needs to stop


listeners

protected Set<ServiceNotificationListener> listeners
Listeners


name

protected String name
Service name

Constructor Detail

Service

public Service()
Constructor

Method Detail

setName

public void setName(String name)
Sets service's name

Parameters:
name - service's name

getName

public String getName()
Returns service name

Returns:
service name

changeState

protected void changeState(int newState)
This method changes state. It notifies all registered listeners about the change.

Parameters:
newState - new state

addListener

public void addListener(ServiceNotificationListener listener)
Adds new listener

Parameters:
listener - listener

removeListener

public void removeListener(ServiceNotificationListener listener)
Removes a listener

Parameters:
listener - listener

getState

public int getState()
Returns current state

Returns:
current state

getStateName

public String getStateName()
Returns state as a string

Returns:
state as a string

create

public void create()
            throws ServiceException
This method is to be called for service to be set-up. This implementation does nothing.

Throws:
ServiceException

destroy

public void destroy()
             throws ServiceException
This method is to be called when service is to be removed from the system. This implementation does nothing.

Throws:
Exception
ServiceException

start

public void start()
           throws ServiceException
This method is to be called for service to be started.

Throws:
Exception
ServiceException

stop

public void stop()
          throws ServiceException
This method is to be called for service to be stopped. Service won't stop immediately but only stopService flag is going to be set to true

Throws:
Exception
ServiceException


Copyright © 2005-2009 Abstract Horizon. All Rights Reserved.