Package com.iizix.server
Class AbstractEndPoint
- java.lang.Object
- com.iizix.server.AbstractEndPoint
- All Implemented Interfaces:
IServerWebSocketCommListener
,ITransactionCreator
,WebSocketCommListener
,IEndPoint
,IRootPropTransactionSender
- Direct Known Subclasses:
LoadBalancerEndPoint
,RemoteBuilderEndPoint
,ServerSession
,VirtualizedMonitorEndPoint
public abstract class AbstractEndPoint extends java.lang.Object implements IEndPoint, IServerWebSocketCommListener, IRootPropTransactionSender
An implementation of a common end point for an Editor, Server or Monitor.- Author:
- Christopher Mindus
Nested Class Summary
Nested classes/interfaces inherited from interface com.iizix.server.IEndPoint
IEndPoint.Type
Field Summary
Fields Modifier and Type Field Description protected boolean
DEBUG
Debug mode, very verbose output.protected PropMgr
endPointPropertyManager
The property endPointPropertyManager.protected IEndPoint.Type
endPointType
The end-point type.protected java.lang.String
name
The name of this end point.protected RootPropTransactionSender
propTransSender
Root property transaction sender.protected PropCnr
root
The root container property of the end point.protected ServerShell
server
The main server instance.protected long
serverSessionID
The server session ID.protected SessionInfo
sessionInfo
The SessionInfo.protected java.lang.ThreadGroup
threadGroup
The thread group for the end point.protected Worker
worker
The worker of the Editor.Fields inherited from interface com.iizix.server.IEndPoint
DEFAULT_HEARTBEAT_INTERVAL, STORAGE_NAME
Fields inherited from interface com.iizix.nio.WebSocketCommListener
CC_ABNORMAL_CLOSURE, CC_GOING_AWAY, CC_INTERNAL_ERROR, CC_INVALID_PAYLOAD_DATA, CC_MANDATORY_EXT, CC_MESSAGE_TOO_BIG, CC_NO_STATUS_RECEIVED, CC_NORMAL, CC_POLICY_VIOLATION, CC_PROTOCOL_ERROR, CC_SERVICE_RESTART, CC_TLS_HANDSHAKE, CC_TRY_AGAIN_LATER, CC_UNSUPPORTED_DATA
Constructor Summary
Constructors Constructor Description AbstractEndPoint(IEndPoint.Type endPointType, java.lang.String name, long sessionID, IWebSocketComm comm, ServerShell server, java.lang.ThreadGroup serverThreadGroup, java.util.HashMap<java.lang.String,java.lang.String> classNameMap, java.lang.ClassLoader contextClassLoader)
Creates a new EndPoint instance.
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description SendTransaction
createTransaction()
Creates a Transaction using a Write Cache.boolean
dispose()
Disposes of the end point.java.lang.String
getClientContextMenuReference(UIContextMenu contextMenu)
Gets the reference to use for a context menu.IEndPoint
getEndPoint()
Gets the end-point.java.lang.String
getEndPointName()
Gets the end point name.IEndPoint.Type
getEndPointType()
Gets the end point type.protected long
getHeartBeatInterval()
Gets the heart-beat interval time in milliseconds, called during start-up in the constructor.PropCnr
getProperties()
Gets the end point properties, i.e.PropMgr
getPropertyManager()
Gets the property manager of the end point.ServerShell
getServer()
Gets the server.long
getServerSessionID()
Gets the Server Session ID.SessionInfo
getSessionInfo()
Gets the SessionInfo for this end point.IServerWebSocketCommListener
getWebSocketCommListener(IWebSocketComm comm)
Gets the WebSocketCommListener for the end point.boolean
isConnected()
Checks if the communication link is connected.protected void
onClientPropsCreated(PropCnr root)
Called when the root is created from a transaction from the client.void
onCommClosed(IWebSocketComm comm, int code, java.lang.String reason)
Called when the communication link is closed.void
onCommClosing(IWebSocketComm comm)
Called when the communication link is closing.void
onCommConnected(IWebSocketComm comm)
Called when the communication link is connected.void
onCommData(IWebSocketComm comm, byte[] _data, int offset, int len)
Called when the communication link has received binary data.void
onCommData(IWebSocketComm comm, java.lang.String data)
Called when the communication link has received String data.void
onCommError(IWebSocketComm comm, java.lang.Throwable e)
Called when the communication link is closed.void
onCommHeartBeat(IWebSocketComm comm, long duration)
Called when a heart-beat frame is received.void
onCommOpen(IWebSocketComm comm)
Called when the communication link is opened.void
onCommTimeout(IWebSocketComm comm, boolean isReadTimeout)
Called when the communication link has timed out on a read or write operation.protected void
onSendHeartHeat()
Called to perform sending of a heart-beat.protected void
onSessionConnected()
Called upon connect to enable initialization of e.g.protected java.lang.String
paramString()
Formats the value as a string to add toparamString
.protected abstract boolean
processQueuedTransaction(int code, ReadTransaction trans)
This method must be implemented in all extending classes.void
sendTransaction(SendTransaction trans)
Sends a transaction to the end point.java.lang.String
toString()
Returns a string representation of this component and its values.
Field Detail
DEBUG
protected boolean DEBUG
Debug mode, very verbose output.
serverSessionID
protected final long serverSessionID
The server session ID.
name
protected final java.lang.String name
The name of this end point.
worker
protected final Worker worker
The worker of the Editor.
server
protected final ServerShell server
The main server instance.
sessionInfo
protected final SessionInfo sessionInfo
The SessionInfo.
threadGroup
protected final java.lang.ThreadGroup threadGroup
The thread group for the end point.
endPointType
protected final IEndPoint.Type endPointType
The end-point type.
endPointPropertyManager
protected final PropMgr endPointPropertyManager
The property endPointPropertyManager.
root
protected PropCnr root
The root container property of the end point.
propTransSender
protected RootPropTransactionSender propTransSender
Root property transaction sender.
Constructor Detail
AbstractEndPoint
public AbstractEndPoint(IEndPoint.Type endPointType, java.lang.String name, long sessionID, IWebSocketComm comm, ServerShell server, java.lang.ThreadGroup serverThreadGroup, java.util.HashMap<java.lang.String,java.lang.String> classNameMap, java.lang.ClassLoader contextClassLoader) throws java.io.IOException
Creates a new EndPoint instance.- Parameters:
endPointType
- End point type.name
- Name of end point.sessionID
- Session ID.comm
- Communications interface to web sockets.server
- The server instance.serverThreadGroup
- The thread group.classNameMap
- The class name map.contextClassLoader
- The context class loader.- Throws:
java.io.IOException
- For I/O errors.
Method Detail
getEndPoint
public final IEndPoint getEndPoint()
Gets the end-point.- Specified by:
getEndPoint
in interfaceIServerWebSocketCommListener
- Returns:
- An instance of com.iizix.server.IEndPoint.
getServerSessionID
public final long getServerSessionID()
Gets the Server Session ID.- Specified by:
getServerSessionID
in interfaceIEndPoint
- Returns:
- The session ID.
getServer
public final ServerShell getServer()
Gets the server.
getWebSocketCommListener
public IServerWebSocketCommListener getWebSocketCommListener(IWebSocketComm comm)
Gets the WebSocketCommListener for the end point.- Specified by:
getWebSocketCommListener
in interfaceIEndPoint
- Parameters:
comm
- The WebSocket communication instance.- Returns:
- The WebSocket listener.
getEndPointType
public final IEndPoint.Type getEndPointType()
Gets the end point type.- Specified by:
getEndPointType
in interfaceIEndPoint
- Returns:
- The endpoint type.
getEndPointName
public java.lang.String getEndPointName()
Gets the end point name.- Specified by:
getEndPointName
in interfaceIEndPoint
- Returns:
- A short descriptive end-point type name.
getHeartBeatInterval
protected long getHeartBeatInterval()
Gets the heart-beat interval time in milliseconds, called during start-up in the constructor.- Returns:
- Interval in milliseconds, zero for none (default is DEFAULT_HEARTBEAT_INTERVAL, i.e. 20 seconds).
onSendHeartHeat
protected void onSendHeartHeat()
Called to perform sending of a heart-beat. Override if required. This method is called at regular intervals as specified by thegetHeartBeatInterval()
return value.
onSessionConnected
protected void onSessionConnected()
Called upon connect to enable initialization of e.g. the root property. This method is overridden by subclasses and the base EndPoint implementation does nothing.
getPropertyManager
public final PropMgr getPropertyManager()
Gets the property manager of the end point. The property manager for an end point is always of SERVER type.- Returns:
- The singleton PropMgr instance.
getProperties
public final PropCnr getProperties()
Gets the end point properties, i.e. the root container.- Returns:
- The root container.
getSessionInfo
public final SessionInfo getSessionInfo()
Gets the SessionInfo for this end point.- Specified by:
getSessionInfo
in interfaceIEndPoint
- Returns:
- The SessionInfo instance.
dispose
public boolean dispose()
Disposes of the end point.
onCommOpen
public void onCommOpen(IWebSocketComm comm)
Called when the communication link is opened.- Specified by:
onCommOpen
in interfaceWebSocketCommListener
- Parameters:
comm
- The WebSocket communication instance.
onCommConnected
public void onCommConnected(IWebSocketComm comm)
Called when the communication link is connected. The endpoint starts by sending a CREATE transaction of the endpoint root property container.- Specified by:
onCommConnected
in interfaceWebSocketCommListener
- Parameters:
comm
- The WebSocket communication instance.
onCommData
public void onCommData(IWebSocketComm comm, byte[] _data, int offset, int len)
Called when the communication link has received binary data.- Specified by:
onCommData
in interfaceWebSocketCommListener
- Parameters:
comm
- The WebSocket communication instance._data
- The data byte array.offset
- Offset in buffer.len
- Length of data.
onCommData
public void onCommData(IWebSocketComm comm, java.lang.String data)
Called when the communication link has received String data.- Specified by:
onCommData
in interfaceWebSocketCommListener
- Parameters:
comm
- The WebSocket communication instance.data
- The String data.
onCommHeartBeat
public void onCommHeartBeat(IWebSocketComm comm, long duration)
Called when a heart-beat frame is received.- Specified by:
onCommHeartBeat
in interfaceWebSocketCommListener
- Parameters:
duration
- Duration of the PING-PONG message exchange in milliseconds.comm
- The WebSocket communication instance.
onCommTimeout
public void onCommTimeout(IWebSocketComm comm, boolean isReadTimeout)
Called when the communication link has timed out on a read or write operation.- Specified by:
onCommTimeout
in interfaceWebSocketCommListener
- Parameters:
comm
- The WebSocket communication instance.isReadTimeout
- Flag indicating read timeout when true, false indicates write timeout.
onCommError
public void onCommError(IWebSocketComm comm, java.lang.Throwable e)
Called when the communication link is closed.- Specified by:
onCommError
in interfaceWebSocketCommListener
- Parameters:
comm
- The WebSocket communication instance.e
- The exception.
onCommClosing
public void onCommClosing(IWebSocketComm comm)
Called when the communication link is closing.- Specified by:
onCommClosing
in interfaceWebSocketCommListener
- Parameters:
comm
- The WebSocket communication instance.
onCommClosed
public void onCommClosed(IWebSocketComm comm, int code, java.lang.String reason)
Called when the communication link is closed.- Specified by:
onCommClosed
in interfaceWebSocketCommListener
- Parameters:
comm
- The WebSocket communication instance.code
- The reason code for closure.reason
- The reason string explanation for closure.
onClientPropsCreated
protected void onClientPropsCreated(PropCnr root)
Called when the root is created from a transaction from the client. Override to perform some additional processing such as adding server environment, etc.
processQueuedTransaction
protected abstract boolean processQueuedTransaction(int code, ReadTransaction trans)
This method must be implemented in all extending classes.- Parameters:
code
- The transaction code.trans
- The transaction.- Returns:
- true if the transaction has been processed, false otherwise.
isConnected
public final boolean isConnected()
Checks if the communication link is connected.- Specified by:
isConnected
in interfaceIRootPropTransactionSender
- Returns:
- true if the connection has been established, false if closed or if in progress of closing.
createTransaction
public final SendTransaction createTransaction()
Creates a Transaction using a Write Cache. This transaction is then used to write data into it. Be careful only to do it from a single thread as the Write Cache is not thread-safe!- Specified by:
createTransaction
in interfaceITransactionCreator
- Returns:
- The transaction with the WriteCache with parameters specified in the properties.
sendTransaction
public final void sendTransaction(SendTransaction trans)
Sends a transaction to the end point.- Specified by:
sendTransaction
in interfaceIRootPropTransactionSender
- Parameters:
trans
- The transaction to send.
paramString
protected java.lang.String paramString()
Formats the value as a string to add toparamString
.- Returns:
- String format of the parameters.
toString
public java.lang.String toString()
Returns a string representation of this component and its values.- Overrides:
toString
in classjava.lang.Object
- Returns:
- a string representation of this property.
getClientContextMenuReference
public java.lang.String getClientContextMenuReference(UIContextMenu contextMenu)
Gets the reference to use for a context menu. Override to process.- Specified by:
getClientContextMenuReference
in interfaceIRootPropTransactionSender
- Parameters:
contextMenu
- The context menu.- Returns:
- The reference to use, empty string for none (never null).