public abstract class AbstractServer extends java.lang.Object implements Server, StateChangeListener<ServerStatus>
Modifier and Type | Field and Description |
---|---|
protected java.lang.Throwable |
exception
Latest exception.
|
protected java.util.ArrayList<ServerListener> |
listeners
server listeners.
|
protected org.slf4j.Logger |
logger |
protected java.lang.String |
name
Server name for track.
|
protected StateMachine<ServerStatus> |
state
server status.
|
STATUS_CHANGED
Constructor and Description |
---|
AbstractServer() |
Modifier and Type | Method and Description |
---|---|
void |
addServerListener(ServerListener listener)
Add a listener for server event.
|
protected void |
changeStatus(ServerStatus status)
Change status to
status . |
void |
clearException()
Clear exception.
|
protected void |
fireEvent(ServerEvent event)
Fire
ServerEvent e to listeners. |
ServerStatus |
getStatus()
Return server status.
|
protected void |
handleError(java.lang.Throwable th)
Exception handling part in process.
|
protected void |
initialize()
Initialization part.
|
boolean |
isStatus(ServerStatus... status)
Check if current status is one of
status . |
protected void |
process()
Process part.
|
void |
removeServerListener(ServerListener listener)
Remove listener to be registered.
|
void |
stateChanged(ServerStatus old,
ServerStatus state,
java.lang.Object... args) |
protected void |
terminate()
Post process part.
|
void |
waitStatus(ServerStatus... status)
Wait for server status to be one of
status . |
protected final org.slf4j.Logger logger
protected StateMachine<ServerStatus> state
protected java.util.ArrayList<ServerListener> listeners
protected java.lang.Throwable exception
protected java.lang.String name
public ServerStatus getStatus()
Server
public boolean isStatus(ServerStatus... status)
Server
status
.public void waitStatus(ServerStatus... status)
Server
status
.waitStatus
in interface Server
status
- status values to wait forprotected void changeStatus(ServerStatus status)
status
.status
- status to setpublic void stateChanged(ServerStatus old, ServerStatus state, java.lang.Object... args)
stateChanged
in interface StateChangeListener<ServerStatus>
public void clearException()
public void addServerListener(ServerListener listener)
Server
addServerListener
in interface Server
listener
- listener to addpublic void removeServerListener(ServerListener listener)
Server
removeServerListener
in interface Server
listener
- listener to removeprotected void fireEvent(ServerEvent event)
ServerEvent
e
to listeners.event
- ServerEvent
to fireprotected void initialize() throws java.lang.Exception
java.lang.Exception
- Fail to initialize the serverprotected void process() throws java.lang.Exception
java.lang.Exception
- Fail to process the server taskprotected void handleError(java.lang.Throwable th)
th
- exception to be occurredprotected void terminate()
No exception occurred Just one called though exception occurred