Class Mdf

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

public class Mdf extends Object
This class represents the connection object between the libmdf client and server
  • Constructor Details

    • Mdf

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

    • finalize

      protected void finalize() throws Throwable
      Overrides:
      finalize in class Object
      Throws:
      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:
    • 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:
    • getMessagesAndFields

      public 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:
    • connect

      public boolean connect(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:
    • 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:
    • 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

      public boolean setBindAddress(String address)
      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

      public String 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

      public String setCiphers(String ciphers)
      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

      public String 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

      public String getCipher()
      Returns the encryption cipher chosen by the server for the connection, only availably after connect returns
      Returns:
      the encryption cipher used for the connection.
    • setDigests

      public String setDigests(String digests)
      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

      public String 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

      public String getDigest()
      Returns the message digest chosen by the server for the connection, only availably after connect returns
      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

      public String getConnectedHostName()
      Returns the host name of the server we are connected to, only availably after connect returns
      Returns:
      the connected server name.
    • getConnectedHostIP

      public String getConnectedHostIP()
      Returns the ip of the server we are connected to, only availably after connect returns
      Returns:
      the connected server ip.
    • 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