com.millistream.www
Class Mdf

java.lang.Object
  extended by com.millistream.www.Mdf

public class Mdf
extends java.lang.Object

This class represents the connection object between the libmdf client and server


Constructor Summary
Mdf()
          Constructs a new MessageHeader object.
 
Method Summary
 boolean connect(java.lang.String servers)
          Connects to a server specified in the servers string.
 int consume(int timeout)
          Consumes any bytes from the server (if any).
 void disconnect()
          Disconnects from the server.
protected  void finalize()
           
 MessageField get_next_field()
          Returns the current field in the message and proceed the internal position to the next field in the message.
 MessageHeader get_next_message()
          Returns the header of the current message in the stream.
 int getError()
          Gets the internal libmdf error code
 int getHeartbeatInterval()
          Gets the Heartbeat Interval property.
 int getHeartbeatMaxMissed()
          Gets Max Missed Heartbeats property.
 java.util.ArrayList<MessageHeader> getMessagesAndFields()
          Calls get_next_message() + get_next_field() repeatedly and constructs an ArrayList in order to minimize the amount of Java to native calls for performance critical and latency sensitive client applications.
 int getNoEncryption()
          Gets the status of the Client to Server encryption.
 long getReceivedBytes()
          Gets the "Number of bytes received from the server" property.
 long getSentBytes()
          Gets the "Number of bytes sent to the server" property
 int getTCPNoDelay()
          Gets the status of the TCP Nagle algorithm.
 int getTimeDifference()
          Gets the Time Difference property.
 int getTimeout()
          Gets the Connection Timeout property.
 boolean send(Message message)
          Send the message chain to the server.
 boolean setConsumeDataCallback(Callback callback)
          Registers a consumeData Callback
 boolean setHeartbeatInterval(int value)
          Sets the Heartbeat Interval property.
 boolean setHeartbeatMaxMissed(int value)
          Sets the Max Missed Heartbeats property.
 boolean setNoEncryption(int value)
          Disable the Client to Server encryption.
 boolean setReceivedBytes(long value)
          Sets the "Number of bytes received from the server" property.
 boolean setSentBytes(long value)
          Sets the "Number of bytes sent to the server" property
 boolean setStatusChangeCallback(Callback callback)
          Registers a statusChange Callback
 boolean setTCPNoDelay(int value)
          Disable the TCP Nagle algorithm.
 boolean setTimeout(int value)
          Sets the Connection Timeout property,
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Mdf

public Mdf()
Constructs a new MessageHeader object. The object is not thread-safe but different threads can access different objects simultaneously.

Method Detail

finalize

protected void finalize()
                 throws java.lang.Throwable
Overrides:
finalize in class java.lang.Object
Throws:
java.lang.Throwable

get_next_message

public MessageHeader 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 the getMessagesAndFields() 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:
MessageHeader

get_next_field

public MessageField 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 the getMessagesAndFields() 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:
MessageField

getMessagesAndFields

public java.util.ArrayList<MessageHeader> getMessagesAndFields()
Calls get_next_message() + get_next_field() repeatedly and constructs an ArrayList in order to minimize the amount of Java to native calls for performance critical and latency sensitive client applications. When this method is used the getFields() method in the MessageHeader class can be called in order to get the ArrayList of the fields.

Returns:
a new ArrayList object representing all messages received by the call to consume() method.
See Also:
MessageHeader

connect

public boolean connect(java.lang.String servers)
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. timeout is 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:
Callback

send

public boolean send(Message message)
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:
Message

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.

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).

setConsumeDataCallback

public boolean setConsumeDataCallback(Callback callback)
Registers a consumeData Callback

Parameters:
callback - an implementation of Callback interface, can be null if the intention is to unset the callback
Returns:
true if successfully set, false if cannot be set

setStatusChangeCallback

public boolean setStatusChangeCallback(Callback callback)
Registers a statusChange Callback

Parameters:
callback - an implementation of Callback interface, can be set to null if the intention is to unset the callback
Returns:
true if successfully set, false if cannot be set