Package com.millistream.www
Class Mdf
java.lang.Object
com.millistream.www.Mdf
This class represents the connection object between the libmdf client and server
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanConnects to a server specified in the servers string.intconsume(int timeout) Consumes any bytes from the server (if any).voidDisconnects from the server.protected voidfinalize()Returns the current field in the message and proceed the internal position to the next field in the message.Returns the header of the current message in the stream.Gets the (by the user) set IPv4 or IPv6 address to bind to before connectingReturns the encryption cipher chosen by the server for the connection, only availably afterconnectreturnsReturns the encryption ciphers that the client will offer to the server upon connectReturns the ip of the server we are connected to, only availably afterconnectreturnsReturns the host name of the server we are connected to, only availably afterconnectreturnsReturns the message digest chosen by the server for the connection, only availably afterconnectreturnsReturns the message digests that the client will offer to the server upon connectintgetError()Gets the internal libmdf error codeintReturns if we have enabled delay-mode or not.intGets the Heartbeat Interval property.intGets Max Missed Heartbeats property.Callsget_next_message()+get_next_field()repeatedly and constructs anArrayListin order to minimize the amount of Java to native calls for performance critical and latency sensitive client applications.intGets the status of the Client to Server encryption.longGets the "Number of bytes received from the server" property.longGets the "Number of bytes sent to the server" propertyintGets the status of the TCP Nagle algorithm.intGets the Time Difference property.longGets the Time DifferenceNS property.intGets the Connection Timeout property.booleanSend the message chain to the server.booleansetBindAddress(String address) Sets the IPv4 or IPv6 address to bind to before connectingsetCiphers(String ciphers) Sets the encryption ciphers that the client will offer to the server upon connectbooleansetConsumeDataCallback(Callback callback) Registers a consumeData CallbacksetDigests(String digests) Sets the message digests that the client will offer to the server upon connectbooleansetHandleDelay(int value) Enables/Disables delay-mode.booleansetHeartbeatInterval(int value) Sets the Heartbeat Interval property.booleansetHeartbeatMaxMissed(int value) Sets the Max Missed Heartbeats property.booleansetNoEncryption(int value) Disable the Client to Server encryption.booleansetReceivedBytes(long value) Sets the "Number of bytes received from the server" property.booleansetSentBytes(long value) Sets the "Number of bytes sent to the server" propertybooleansetStatusChangeCallback(Callback callback) Registers a statusChange CallbackbooleansetTCPNoDelay(int value) Disable the TCP Nagle algorithm.booleansetTimeout(int value) Sets the Connection Timeout property,
-
Constructor Details
-
Mdf
public Mdf()Constructs a newMessageHeaderobject. The object is not thread-safe but different threads can access different objects simultaneously.
-
-
Method Details
-
finalize
-
get_next_message
Returns the header of the current message in the stream. Also proceeds the internal position to the next message in the stream. Performance critical and latency sensitive applications should use thegetMessagesAndFields()method instead.- Returns:
- a new MessageHeader object representing the current message in the stream or null if there is no more messages in the stream
- See Also:
-
get_next_field
Returns the current field in the message and proceed the internal position to the next field in the message. Performance critical and latency sensitive applications should use thegetMessagesAndFields()method instead.- Returns:
- a new MessageField object representing the current field in the message, or null if there is no more fields in the message
- See Also:
-
getMessagesAndFields
Callsget_next_message()+get_next_field()repeatedly and constructs anArrayListin order to minimize the amount of Java to native calls for performance critical and latency sensitive client applications. When this method is used thegetFields()method in theMessageHeaderclass can be called in order to get theArrayListof the fields.- Returns:
- a new ArrayList object representing all messages received by the
call to
consume()method. - See Also:
-
connect
Connects to a server specified in the servers string. The servers string can be a comma separated list of"server:port"where server can be a host name or a raw IP address (IPv6 must be enclosed in brackets "[address]", if the first server does not respond in time, the next will be tried and so on until there is no more servers in the list.- Parameters:
servers- a comma separated list in the form of "server:port"- Returns:
- true if a connection with a server was possible and false if connection failed with every server on the list
-
disconnect
public void disconnect()Disconnects from the server. Safe to call even if the connection is already down. -
consume
public int consume(int timeout) Consumes any bytes from the server (if any). If a complete transaction has been received, any defined consumeData callback function will be called.timeoutis the time in seconds to wait for data from the server, if zero the function will return immediately if there is no data to consume.- Parameters:
timeout- time in seconds to wait for data from the server- Returns:
- 1 if there are messages to decode and no callback function was defined, 0 if the function timeouts and -1 if there was an error
- See Also:
-
send
Send the message chain to the server.- Parameters:
message- the message to be sent to the server- Returns:
- true if the message is successfully sent, false if there is an error
- See Also:
-
setTimeout
public boolean setTimeout(int value) Sets the Connection Timeout property,- Parameters:
value- the number of seconds before determining that a connection attempt has timed out. Valid values are 1-60.- Returns:
- true if property successfully set, false if cannot be set
-
getTimeout
public int getTimeout()Gets the Connection Timeout property.- Returns:
- timeout in seconds
-
setHeartbeatInterval
public boolean setHeartbeatInterval(int value) Sets the Heartbeat Interval property.- Parameters:
value- the number of seconds the connection must be idle before the API sends a hearbeat request to the server. Valid values are 1-86400.- Returns:
- true if property successfully set, false if cannot be set
-
getHeartbeatInterval
public int getHeartbeatInterval()Gets the Heartbeat Interval property.- Returns:
- the number of seconds the connection must be idle before the API sends a heartbeat request to the server.
-
setHeartbeatMaxMissed
public boolean setHeartbeatMaxMissed(int value) Sets the Max Missed Heartbeats property.- Parameters:
value- how many outstanding heartbeat requests to allow before the connection is determined to be disconnected. Valid values are 1-100.- Returns:
- true if property successfully set, false if cannot be set
-
getHeartbeatMaxMissed
public int getHeartbeatMaxMissed()Gets Max Missed Heartbeats property.- Returns:
- how many outstanding heartbeat requests to allow before the connection is determined to be disconnected.
-
setTCPNoDelay
public boolean setTCPNoDelay(int value) Disable the TCP Nagle algorithm.- Parameters:
value- '1' will disable the Nagle algorithm, '0' will enable it (the default).- Returns:
- true if property successfully set, false if cannot be set
-
getTCPNoDelay
public int getTCPNoDelay()Gets the status of the TCP Nagle algorithm.- Returns:
- '1' if the TCP Nagle algorithm is disabled, '0' if it's enabled.
-
setNoEncryption
public boolean setNoEncryption(int value) Disable the Client to Server encryption.- Parameters:
value- '1' will disable client to server traffic encryption, '0' will enable it (the default). Once disabled it cannot be enabled again until the connection is closed.- Returns:
- true if property successfully set, false if cannot be set
-
getNoEncryption
public int getNoEncryption()Gets the status of the Client to Server encryption.- Returns:
- '1' if Client to Server encryption is disabled, '0' if it's enabled.
-
getTimeDifference
public int getTimeDifference()Gets the Time Difference property.- Returns:
- the time difference in number of seconds between the client and the server. The value should be added to the current time on the client in order to get the server time. Please note that the value can be negative if the client clock is ahead of the server clock.
-
getTimeDifferenceNS
public long getTimeDifferenceNS()Gets the Time DifferenceNS property.- Returns:
- the time difference in number of nano seconds between the client and the server. The value should be added to the current time on the client in order to get the server time. Please note that the value can be negative if the client clock is ahead of the server clock.
-
setReceivedBytes
public boolean setReceivedBytes(long value) Sets the "Number of bytes received from the server" property.- Parameters:
value- number of bytes, can NOT be negative- Returns:
- true if property successfully set, false if cannot be set
-
getReceivedBytes
public long getReceivedBytes()Gets the "Number of bytes received from the server" property.- Returns:
- the number of bytes received by the server
-
setSentBytes
public boolean setSentBytes(long value) Sets the "Number of bytes sent to the server" property- Parameters:
value- number of bytes, can NOT be negative- Returns:
- true if property successfully set, false if cannot be set
-
getSentBytes
public long getSentBytes()Gets the "Number of bytes sent to the server" property- Returns:
- the number of bytes sent to the server
-
getError
public int getError()Gets the internal libmdf error code- Returns:
- the internal libmdf error code (if any).
-
setBindAddress
Sets the IPv4 or IPv6 address to bind to before connecting- Parameters:
address- a numerical IPv4 or IPv6 address to bind to, can be null if the intention is to unset the bind address- Returns:
- true if property successfully set, false if cannot be set
-
getBindAddress
Gets the (by the user) set IPv4 or IPv6 address to bind to before connecting- Returns:
- the bind address set by the user.
-
setCiphers
Sets the encryption ciphers that the client will offer to the server upon connect- Parameters:
ciphers- a comma separated list of the encryption ciphers offered by the client to the server, can be null if the intention is to use the default list- Returns:
- true if property successfully set, false if cannot be set
-
getCiphers
Returns the encryption ciphers that the client will offer to the server upon connect- Returns:
- a comma separated list of the encryption ciphers offered by the client to the server.
-
getCipher
Returns the encryption cipher chosen by the server for the connection, only availably afterconnectreturns- Returns:
- the encryption cipher used for the connection.
-
setDigests
Sets the message digests that the client will offer to the server upon connect- Parameters:
digests- a comma separated list of the message digest offered by the client to the server, can be null if the intention is to use the default list- Returns:
- true if property successfully set, false if cannot be set
-
getDigests
Returns the message digests that the client will offer to the server upon connect- Returns:
- a comma separated list of the message digests offered by the client to the server.
-
getDigest
Returns the message digest chosen by the server for the connection, only availably afterconnectreturns- Returns:
- the message digest used for the connection.
-
setHandleDelay
public boolean setHandleDelay(int value) Enables/Disables delay-mode. Must be set prior to connect for the setting to take effect.- Parameters:
value- '1' will enable delay-mode, '0' will disable it (the default).- Returns:
- true if property successfully set, false if cannot be set
-
getHandleDelay
public int getHandleDelay()Returns if we have enabled delay-mode or not.- Returns:
- '1' if we have enabled delay-mode, '0' if it's disabled.
-
getConnectedHostName
Returns the host name of the server we are connected to, only availably afterconnectreturns- Returns:
- the connected server name.
-
getConnectedHostIP
Returns the ip of the server we are connected to, only availably afterconnectreturns- Returns:
- the connected server ip.
-
setConsumeDataCallback
Registers a consumeData Callback- Parameters:
callback- an implementation ofCallbackinterface, can be null if the intention is to unset the callback- Returns:
- true if successfully set, false if cannot be set
-
setStatusChangeCallback
Registers a statusChange Callback- Parameters:
callback- an implementation ofCallbackinterface, can be set to null if the intention is to unset the callback- Returns:
- true if successfully set, false if cannot be set
-