Package org.hcjf.io.net.messages
Class MessagesNode<S extends NetSession>
- java.lang.Object
-
- org.hcjf.io.net.NetServiceConsumer<S,D>
-
- org.hcjf.io.net.NetClient<S,MessageBuffer>
-
- org.hcjf.io.net.messages.MessagesNode<S>
-
- All Implemented Interfaces:
ServiceConsumer
- Direct Known Subclasses:
CloudClient
public abstract class MessagesNode<S extends NetSession> extends NetClient<S,MessageBuffer>
This class provides the base to implements a message node.- Author:
- javaito
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.hcjf.io.net.NetServiceConsumer
NetServiceConsumer.DecoupledAction
-
-
Constructor Summary
Constructors Constructor Description MessagesNode(java.lang.String host, java.lang.Integer port)MessagesNode(java.lang.String host, java.lang.Integer port, Cryptography cryptography)
-
Method Summary
Modifier and Type Method Description protected MessageBufferdecode(NetPackage netPackage)Decode the bytes into the net package and append this into the internal buffer.protected Messagedecrypt(EncryptedMessage encryptedMessage)This method must decrypt the encrypted message and returns the original message decrypted.protected byte[]encode(MessageBuffer payLoad)Encode buffer information to transfer the messages.protected EncryptedMessageencrypt(Message message)This method must encrypt the message and create an instance ofEncryptedMessagewrapping the original message.booleanisConnected()This method return the connected status of the node.booleanisEncrypted()Returns true if the server use a encrypted protocol and false in the otherwiseprotected voidonConnect(S session, MessageBuffer payLoad, NetPackage netPackage)This method is called when the node is connected.protected voidonConnectFail()This method is called when the node connection fail.protected voidonDisconnect(S session, NetPackage netPackage)Method must be implemented by the custom implementation to known when a session is disconnectedprotected abstract voidonRead(S session, Message incomingMessage)This method is called when there are a complete message into the buffer.protected voidonRead(S session, MessageBuffer payLoad, NetPackage netPackage)This method is called when the node read information from the net.voidsend(Message message)Send a message to the server.booleanwaitForConnect()Wait until the node is connected with the server.-
Methods inherited from class org.hcjf.io.net.NetClient
connect, getHost, getSession
-
Methods inherited from class org.hcjf.io.net.NetServiceConsumer
addDecoupledAction, checkSession, decoupleIoAction, destroySession, disconnect, getName, getPort, getProtocol, getService, getShutdownFrame, getShutdownPackage, getSocketOptions, getSSLEngine, getWriteWaitForTimeout, isDecoupledIoAction, onCheckSessionError, onConnect, onDisconnect, onRead, onWrite, onWrite, setService, setWriteWaitForTimeout, write, write
-
-
-
-
Constructor Detail
-
MessagesNode
public MessagesNode(java.lang.String host, java.lang.Integer port)
-
MessagesNode
public MessagesNode(java.lang.String host, java.lang.Integer port, Cryptography cryptography)
-
-
Method Detail
-
isEncrypted
public 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)
Encode buffer information to transfer the messages.- Specified by:
encodein classNetServiceConsumer<S extends NetSession,MessageBuffer>- Parameters:
payLoad- Implementation data.- Returns:
- Byte array.
-
decode
protected final MessageBuffer decode(NetPackage netPackage)
Decode the bytes into the net package and append this into the internal buffer.- Specified by:
decodein classNetServiceConsumer<S extends NetSession,MessageBuffer>- Parameters:
netPackage- Net package.- Returns:
- Returns the instance of message buffer.
-
send
public final void send(Message message) throws java.io.IOException
Send a message to the server.- Parameters:
message- Message instance.- Throws:
java.io.IOException- Io Exception
-
waitForConnect
public final boolean waitForConnect()
Wait until the node is connected with the server.- Returns:
- Connection status, if the result is true then the node connection was successful but if the response is false the something is not work.
-
onConnect
protected final void onConnect(S session, MessageBuffer payLoad, NetPackage netPackage)
This method is called when the node is connected.- Overrides:
onConnectin classNetServiceConsumer<S extends NetSession,MessageBuffer>- Parameters:
session- Connected session.payLoad- Decoded package payload.netPackage- Original package.
-
onConnectFail
protected final void onConnectFail()
This method is called when the node connection fail.- Overrides:
onConnectFailin classNetClient<S extends NetSession,MessageBuffer>
-
isConnected
public final boolean isConnected()
This method return the connected status of the node.- Returns:
- Returns true if the node is connected and false in the otherwise
-
onDisconnect
protected void onDisconnect(S session, NetPackage netPackage)
Description copied from class:NetServiceConsumerMethod must be implemented by the custom implementation to known when a session is disconnected- Overrides:
onDisconnectin classNetServiceConsumer<S extends NetSession,MessageBuffer>- Parameters:
session- Disconnected session.netPackage- Original package.
-
onRead
protected final void onRead(S session, MessageBuffer payLoad, NetPackage netPackage)
This method is called when the node read information from the net.- 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.
-
-