Package org.hcjf.io.net.messages
Class MessagesServer<S extends NetSession>
- java.lang.Object
-
- org.hcjf.io.net.NetServiceConsumer<S,D>
-
- org.hcjf.io.net.NetServer<S,MessageBuffer>
-
- org.hcjf.io.net.messages.MessagesServer<S>
-
- All Implemented Interfaces:
ServiceConsumer
- Direct Known Subclasses:
CloudServer,ConsoleServer
public abstract class MessagesServer<S extends NetSession> extends NetServer<S,MessageBuffer>
This implementation provides the base to work with messages into the network. The messages are objects that are serialized in bson format to be transfer.- Author:
- javaito
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.hcjf.io.net.NetServiceConsumer
NetServiceConsumer.DecoupledAction
-
-
Constructor Summary
Constructors Constructor Description MessagesServer(java.lang.Integer port, NetService.TransportLayerProtocol protocol, boolean multiSession, boolean disconnectAndRemove)MessagesServer(java.lang.Integer port, NetService.TransportLayerProtocol protocol, boolean multiSession, boolean disconnectAndRemove, Cryptography cryptography)
-
Method Summary
Modifier and Type Method Description protected MessageBufferdecode(NetPackage netPackage)Decode the information from the network and append this into the internal message buffer.protected Messagedecrypt(EncryptedMessage encryptedMessage)This method must decrypt the encrypted message and returns the original message decrypted.voiddestroySession(NetSession session)This method destroy the buffer for the specific session.protected byte[]encode(MessageBuffer payLoad)Returns the byte array in order to transfer the message.protected EncryptedMessageencrypt(Message message)This method must encrypt the message and create an instance ofEncryptedMessagewrapping the original message.booleanisEncrypted()Returns true if the server use a encrypted protocol and false in the otherwiseprotected abstract voidonRead(S session, Message message)This method depends of each implementation.protected voidonRead(S session, MessageBuffer payLoad, NetPackage netPackage)This method is called when there are data for some session.voidsend(S session, Message message)Send message to the net using the buffer.-
Methods inherited from class org.hcjf.io.net.NetServer
createSession, isCreationTimeoutAvailable, isDisconnectAndRemove, isMultiSession, onStart, onStop, start, stop
-
Methods inherited from class org.hcjf.io.net.NetServiceConsumer
addDecoupledAction, checkSession, decoupleIoAction, disconnect, getName, getPort, getProtocol, getService, getShutdownFrame, getShutdownPackage, getSocketOptions, getSSLEngine, getWriteWaitForTimeout, isDecoupledIoAction, onCheckSessionError, onConnect, onConnect, onDisconnect, onDisconnect, onRead, onWrite, onWrite, setService, setWriteWaitForTimeout, write, write
-
-
-
-
Constructor Detail
-
MessagesServer
public MessagesServer(java.lang.Integer port, NetService.TransportLayerProtocol protocol, boolean multiSession, boolean disconnectAndRemove)
-
MessagesServer
public MessagesServer(java.lang.Integer port, NetService.TransportLayerProtocol protocol, boolean multiSession, boolean disconnectAndRemove, Cryptography cryptography)
-
-
Method Detail
-
isEncrypted
public final boolean isEncrypted()
Returns true if the server use a encrypted protocol and false in the otherwise- Returns:
- Is encrypted or no.
-
encode
protected final byte[] encode(MessageBuffer payLoad)
Returns the byte array in order to transfer the message.- Specified by:
encodein classNetServiceConsumer<S extends NetSession,MessageBuffer>- Parameters:
payLoad- Implementation data.- Returns:
- Byte array that represents the message.
-
decode
protected final MessageBuffer decode(NetPackage netPackage)
Decode the information from the network and append this into the internal message buffer.- Specified by:
decodein classNetServiceConsumer<S extends NetSession,MessageBuffer>- Parameters:
netPackage- Net package.- Returns:
- Returns the message buffer with all the information.
-
send
public final void send(S session, Message message) throws java.io.IOException
Send message to the net using the buffer.- Parameters:
session- Session that indicate the remote host.message- Message to transfer.- Throws:
java.io.IOException- Io Exception
-
destroySession
public void destroySession(NetSession session)
This method destroy the buffer for the specific session.- Specified by:
destroySessionin classNetServiceConsumer<S extends NetSession,MessageBuffer>- Parameters:
session- Net session to be destroyed
-
onRead
protected final void onRead(S session, MessageBuffer payLoad, NetPackage netPackage)
This method is called when there are data for some session.- Overrides:
onReadin classNetServiceConsumer<S extends NetSession,MessageBuffer>- Parameters:
session- Net session.payLoad- Net package decodednetPackage- Net package.
-
encrypt
protected EncryptedMessage encrypt(Message message)
This method must encrypt the message and create an instance ofEncryptedMessagewrapping the original message.- Parameters:
message- Original message.- Returns:
- Encrypted message.
-
decrypt
protected Message decrypt(EncryptedMessage encryptedMessage)
This method must decrypt the encrypted message and returns the original message decrypted.- Parameters:
encryptedMessage- Incoming encrypted message.- Returns:
- Original message decrypted.
-
-