us.ihmc.mockets
Class Mocket.Sender

java.lang.Object
  extended by us.ihmc.mockets.Mocket.Sender
Enclosing class:
Mocket

public class Mocket.Sender
extends java.lang.Object

The class used to send messages over Mockets. Obtained by calling getSender on an instance of Mocket. Note: messages may also be sent using the Mocket class directly, this class makes it more convenient by having default or configurable values for some of the parameters.


Constructor Summary
Mocket.Sender()
           
 
Method Summary
 int cancel(int tagId)
          Cancels (deletes) previously enqueued messages that have been tagged with the specified tag.
protected  void finalize()
          Removes mocket object.
 int gsend(byte[] buf1, byte[] buf2)
           
 int gsend(byte[] buf1, byte[] buf2, byte[] buf3)
           
 int gsend(byte[] buf1, byte[] buf2, byte[] buf3, byte[] buf4)
           
 int gsend(byte[] buf1, int offset1, int length1, byte[] buf2, int offset2, int length2)
           
 int gsend(byte[] buf1, int offset1, int length1, byte[] buf2, int offset2, int length2, byte[] buf3, int offset3, int length3)
           
 int gsend(byte[] buf1, int offset1, int length1, byte[] buf2, int offset2, int length2, byte[] buf3, int offset3, int length3, byte[] buf4, int offset4, int length4)
           
 int replace(byte[] buffer, int oldTag, int newTag)
          First cancels any previously enqueued messages that have been tagged with the specified OldTag value and then transmits the new message using the specified parameters.
 int replace(byte[] buffer, int offset, int length, int oldTag, int newTag)
          First cancels any previously enqueued messages that have been tagged with the specified OldTag value and then transmits the new message using the specified parameters.
 int replace(byte[] buffer, int offset, int length, int oldTag, int newTag, short priority, long enqueueTimeout, long retryTimeout)
          First cancels any previously enqueued messages that have been tagged with the specified OldTag value and then transmits the new message using the specified parameters.
 int replace(byte[] buffer, int offset, int length, int oldTag, Params params)
          First cancels any previously enqueued messages that have been tagged with the specified OldTag value and then transmits the new message using the specified parameters.
 int replace(byte[] buffer, int oldTag, int newTag, short priority, long enqueueTimeout, long retryTimeout)
          First cancels any previously enqueued messages that have been tagged with the specified OldTag value and then transmits the new message using the specified parameters.
 int replace(byte[] buffer, int oldTag, Params params)
          First cancels any previously enqueued messages that have been tagged with the specified OldTag value and then transmits the new message using the specified parameters.
 int send(byte[] buffer)
          Basic send function.
 int send(byte[] buffer, int offset, int length)
          Basic send function.
 int send(byte[] buffer, int offset, int length, int iTag, short sPriority)
          Enqueues data for transmission using the specified parameters.
 int send(byte[] buffer, int offset, int length, int iTag, short Priority, long EnqueueTimeout, long RetryTimeout)
          Enqueues data for transmission using the specified parameters.
 int send(byte[] buffer, int offset, int length, Params pParams)
          Enqueues data for transmission using the specified parameters.
 int send(byte[] buffer, int iTag, short sPriority)
          Enqueues data for transmission using the specified parameters.
 int send(byte[] buffer, int iTag, short sPriority, long lEnqueueTimeout, long lRetryTimeout)
          Enqueues data for transmission using the specified parameters.
 int send(byte[] buffer, Params pParams)
          Enqueues data for transmission using the specified parameters.
 void setDefaultEnqueueTimeout(long enqueueTimeout)
          Sets the default timeout for enqueuing data into the outgoing queue.
 void setDefaultRetryTimeout(long retryTimeout)
          Sets the default timeout for retransmission of reliable packets that have not been acknowledged.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Mocket.Sender

public Mocket.Sender()
Method Detail

send

public int send(byte[] buffer)
         throws java.io.IOException,
                java.lang.IllegalArgumentException
Basic send function. Given a byte array to be sent this function enqueues the data for transmission using the type of flow defined in the constructor of class Sender.

Several communication parameter are not specified, the default value is going to be used for the following parameters: tag = 0, priority = 5, enqueue timeout = 0 or a value set using the method setDefaultEnqueueTimeout, retry timeout = 0 or a value set using the method setDefaultRetryTimeout.

Parameters:
buffer - the buffer to be sent. The buffer is going to be sent entirely.
Returns:
  • 0 if the message is successfully enqueued to be sent.
  • -1 if the connection is not in the state ESTABLISHED, it is not established yet or one of the peers called close;
  • -2 if adding the data chunk to a packet fails;
  • -3 if inserting into pendingPacketQueue fails;
  • -10 if MessageSender is not initialized, MessageSender is null;
  • -11 if the parameter buffer is invalid, buffer is null.
Throws:
java.io.IOException
java.lang.IllegalArgumentException
See Also:
Mocket.getSender(boolean, boolean)

send

public int send(byte[] buffer,
                int offset,
                int length)
         throws java.io.IOException,
                java.lang.IllegalArgumentException,
                java.lang.IndexOutOfBoundsException
Basic send function. Given a byte array this function extracts length bytes starting at offset and enqueues the data for transmission. The delivery will use the type of flow defined in the constructor of class Sender.

Several communication parameter are not specified, the default value is going to be used for the following parameters: tag = 0, priority = 5, enqueue timeout = 0 or a value set using the method setDefaultEnqueueTimeout, retry timeout = 0 or a value set using the method setDefaultRetryTimeout.

Parameters:
buffer - the buffer to be sent.
offset - the position in the buffer we start to send from. E.g. offset=10, we send buffer starting at the 10th byte in the array
length - the length for which we send. E.g. length=50 we send 50 bytes of the buffer, starting at offset. If offset=10, length=50 we send bytes from position 10 in the buffer through position 60.
Returns:
  • 0 if the message is successfully enqueued to be sent.
  • -1 if the connection is not in the state ESTABLISHED, it is not established yet or one of the peers called close;
  • -2 if adding the data chunk to a packet fails;
  • -3 if inserting into pendingPacketQueue fails;
  • -10 if MessageSender is not initialized, MessageSender is null;
  • -11 if the parameter buffer is invalid, buffer is null.
Throws:
java.io.IOException
java.lang.IllegalArgumentException
java.lang.IndexOutOfBoundsException - if the parameters offset or length are illegal for buffer.
See Also:
Mocket.getSender(boolean, boolean)

send

public int send(byte[] buffer,
                int iTag,
                short sPriority)
         throws java.io.IOException,
                java.lang.IllegalArgumentException
Enqueues data for transmission using the specified parameters. This send function enqueues the data for transmission and allows to specify a tag and a priority for the data to be sent. Data will be delivered using the type of flow defined in the constructor of class Sender.

Several communication parameter are not specified, the default value is going to be used for the following parameters: enqueue timeout = 0 or a value set using the method setDefaultEnqueueTimeout, retry timeout = 0 or a value set using the method setDefaultRetryTimeout.

Parameters:
buffer - the buffer to be sent. The buffer is going to be sent entirely.
iTag - integer value that can be used to mark a flow of messages belonging to the same type. The value has to be >0.
sPriority - used to assign a priority different than the default one (higher or lower). The value has to be >0. Note that the priority of a message will grow every time it is skipped in favor of a higher priority messages that gets sent first. This mechanism is implemented to avoid message starvation. The range of priority values is 0-255.
Returns:
  • 0 if the message is successfully enqueued to be sent;
  • -1 if the connection is not in the state ESTABLISHED, it is not established yet or one of the peers called close;
  • -2 if adding the data chunk to a packet fails;
  • -3 if inserting into pendingPacketQueue fails;
  • -10 if the parameters iTag or sPriority are illegal (less then zero);
  • -11 if MessageSender is not initialized, MessageSender is null;
  • -12 if the parameter buffer is invalid, buffer is null.
Throws:
java.io.IOException
java.lang.IllegalArgumentException
See Also:
"replace and cancel to take advantage of iTag.", Mocket.getSender(boolean, boolean)

send

public int send(byte[] buffer,
                int offset,
                int length,
                int iTag,
                short sPriority)
         throws java.io.IOException,
                java.lang.IllegalArgumentException,
                java.lang.IndexOutOfBoundsException
Enqueues data for transmission using the specified parameters. Given a byte array this send function extracts length bytes starting at offset and enqueues the data for transmission. This send function allows to specify a tag and a priority for the data to be sent. Data will be delivered using the type of flow defined in the constructor of class Sender.

Several communication parameter are not specified, the default value is going to be used for the following parameters: enqueue timeout = 0 or a value set using the method setDefaultEnqueueTimeout, retry timeout = 0 or a value set using the method setDefaultRetryTimeout.

Parameters:
buffer - the buffer to be sent.
offset - the position in the buffer we start to send from. E.g. offset=10, we send buffer starting at the 10th byte in the array
length - the length for which we send. E.g. length=50 we send 50 bytes of the buffer, starting at offset. If offset=10, length=50 we send bytes from position 10 in the buffer through position 60.
iTag - integer value that can be used to mark a flow of messages belonging to the same type. The value has to be >0.
sPriority - used to assign a priority different than the default one (higher or lower). The value has to be >0. Note that the priority of a message will grow every time it is skipped in favor of a higher priority messages that gets sent first. This mechanism is implemented to avoid message starvation. The range of priority values is 0-255.
Returns:
  • 0 if the message is successfully enqueued to be sent;
  • -1 if the connection is not in the state ESTABLISHED, it is not established yet or one of the peers called close;
  • -2 if adding the data chunk to a packet fails;
  • -3 if inserting into pendingPacketQueue fails;
  • -10 if the parameters iTag or sPriority are illegal (less then zero);
  • -11 if MessageSender is not initialized, MessageSender is null;
  • -12 if the parameter buffer is invalid, buffer is null.
Throws:
java.io.IOException
java.lang.IllegalArgumentException
java.lang.IndexOutOfBoundsException - if the parameters offset or length are illegal for buffer.
See Also:
"replace and cancel to take advantage of iTag.", Mocket.getSender(boolean, boolean)

send

public int send(byte[] buffer,
                Params pParams)
         throws java.io.IOException,
                java.lang.IllegalArgumentException
Enqueues data for transmission using the specified parameters. This send function enqueues the byte array buffer for transmission, and allows to specify a parameter of type Param that will contain information about tag, priority, enqueueTimeout and retryTimeout.

Parameters:
buffer - the buffer to be sent. The buffer is going to be sent entirely.
pParams - an instance of class Param that contains: tag, priority, enqueueTimeout, retryTimeout.
Returns:
  • 0 if the message is successfully enqueued to be sent;
  • -1 if the connection is not in the state ESTABLISHED, it is not established yet or one of the peers called close;
  • -2 if add the data chunk to a packet failed;
  • -3 if insert into pendingPacketQueue failed;
  • -10 if MessageSender is not initialized, MessageSender is null;
  • -11 if the parameter buffer is invalid, buffer is null;
  • -12 if the parameter pParams is invalid, pParams is null.
Throws:
java.io.IOException
java.lang.IllegalArgumentException
See Also:
Params, Mocket.getSender(boolean, boolean)

send

public int send(byte[] buffer,
                int offset,
                int length,
                Params pParams)
         throws java.io.IOException,
                java.lang.IllegalArgumentException,
                java.lang.IndexOutOfBoundsException
Enqueues data for transmission using the specified parameters. Given a byte array this send function extracts length bytes starting at offset and enqueues the data for transmission. This send function allows to specify a parameter of type Param that will contain information about tag, priority, enqueueTimeout and retryTimeout.

Parameters:
buffer - the buffer to be sent.
offset - the position in the buffer we start to send from. E.g. offset=10, we send buffer starting at the 10th byte in the array
length - the length for which we send. E.g. length=50 we send 50 bytes of the buffer, starting at offset. If offset=10, length=50 we send bytes from position 10 in the buffer through position 60.
pParams - an instance of class Param that contains: tag, priority, enqueueTimeout, retryTimeout.
Returns:
  • 0 if the message is successfully enqueued to be sent;
  • -1 if the connection is not in the state ESTABLISHED, it is not established yet or one of the peers called close;
  • -2 if add the data chunk to a packet failed;
  • -3 if insert into pendingPacketQueue failed;
  • -10 if MessageSender is not initialized, MessageSender is null;
  • -11 if the parameter buffer is invalid, buffer is null;
  • -12 if the parameter pParams is invalid, pParams is null.
Throws:
java.io.IOException
java.lang.IllegalArgumentException
java.lang.IndexOutOfBoundsException - if the parameters offset or length are illegal for buffer.
See Also:
Params, Mocket.getSender(boolean, boolean)

send

public int send(byte[] buffer,
                int iTag,
                short sPriority,
                long lEnqueueTimeout,
                long lRetryTimeout)
         throws java.io.IOException,
                java.lang.IllegalArgumentException
Enqueues data for transmission using the specified parameters. This send function enqueues the byte array buffer for transmission allowing to specify a tag, a priority, the enqueue timeout and the retry timeout for the data to be sent. Given a byte array to be sent this function delivers the data using the type of flow defined in the constructor of class Sender.

Parameters:
buffer - the buffer to be sent. The buffer is going to be sent entirely.
iTag - integer value that can be used to mark a flow of messages belonging to the same type. The value has to be >0.
sPriority - used to assign a priority different than the default one (higher or lower). The value has to be >0. Note that the priority of a message will grow every time it is skipped in favor of a higher priority messages that gets sent first. This mechanism is implemented to avoid message starvation. The range of priority values is 0-255.
lEnqueueTimeout - indicates the length of time in milliseconds for which the method will wait if there is no room in the outgoing buffer. A zero value indicates wait forever.
lRetryTimeout - indicates the length of time for which the transmitter will retransmit the packet to ensure successful delivery. A zero value indicates retry with no time limit. Note that this parameter makes sense only if the flow is reliable, otherwise the behavior is to transmit and forget about the packet.
Returns:
  • 0 if the message is successfully enqueued to be sent;
  • -1 if the connection is not in the state ESTABLISHED, it is not established yet or one of the peers called close;
  • -2 if add the data chunk to a packet failed;
  • -3 if insert into pendingPacketQueue failed;
  • -10 if the parameters are illegal (less then zero);
  • -11 if MessageSender is not initialized, MessageSender is null;
  • -12 if the parameter buffer is invalid, buffer is null.
Throws:
java.io.IOException
java.lang.IllegalArgumentException
See Also:
setDefaultEnqueueTimeout(long), setDefaultRetryTimeout(long), "replace and cancel to take advantage of iTag.", Mocket.getSender(boolean, boolean)

send

public int send(byte[] buffer,
                int offset,
                int length,
                int iTag,
                short Priority,
                long EnqueueTimeout,
                long RetryTimeout)
         throws java.io.IOException,
                java.lang.IllegalArgumentException,
                java.lang.IndexOutOfBoundsException
Enqueues data for transmission using the specified parameters. Given a byte array this send function extracts length bytes starting at offset and enqueues the data for transmission. This send function also allows to specify a tag, a priority, the enqueue timeout and the retry timeout for the data to be sent. The data to be sent will be delivered using the type of flow defined in the constructor of class Sender.

Parameters:
buffer - the buffer to be sent.
offset - the position in the buffer we start to send from. E.g. offset=10, we send buffer starting at the 10th byte in the array
length - the length for which we send. E.g. length=50 we send 50 bytes of the buffer, starting at offset. If offset=10, length=50 we send bytes from position 10 in the buffer through position 60.
iTag - integer value that can be used to mark a flow of messages belonging to the same type. The value has to be >0.
Priority - used to assign a priority different than the default one (higher or lower). The value has to be >0. Note that the priority of a message will grow every time it is skipped in favor of a higher priority messages that gets sent first. This mechanism is implemented to avoid message starvation. The range of priority values is 0-255.
EnqueueTimeout - indicates the length of time in milliseconds for which the method will wait if there is no room in the outgoing buffer. A zero value indicates wait forever.
RetryTimeout - indicates the length of time for which the transmitter will retransmit the packet to ensure successful delivery. A zero value indicates retry with no time limit. Note that this parameter makes sense only if the flow is reliable, otherwise the behavior is to transmit and forget about the packet.
Returns:
  • 0 if the message is successfully enqueued to be sent;
  • -1 if the connection is not in the state ESTABLISHED, it is not established yet or one of the peers called close;
  • -2 if add the data chunk to a packet failed;
  • -3 if insert into pendingPacketQueue failed;
  • -10 if the parameters are illegal (less then zero);
  • -11 if MessageSender is not initialized, MessageSender is null;
  • -12 if the parameter buffer is invalid, buffer is null.
Throws:
java.io.IOException
java.lang.IllegalArgumentException
java.lang.IndexOutOfBoundsException - if the parameters offset or length are illegal for buffer.
See Also:
setDefaultEnqueueTimeout(long), setDefaultRetryTimeout(long), "replace and cancel to take advantage of iTag.", Mocket.getSender(boolean, boolean)

gsend

public int gsend(byte[] buf1,
                 byte[] buf2)
          throws java.io.IOException,
                 java.lang.IllegalArgumentException
Throws:
java.io.IOException
java.lang.IllegalArgumentException

gsend

public int gsend(byte[] buf1,
                 int offset1,
                 int length1,
                 byte[] buf2,
                 int offset2,
                 int length2)
          throws java.io.IOException,
                 java.lang.IllegalArgumentException,
                 java.lang.IndexOutOfBoundsException
Throws:
java.io.IOException
java.lang.IllegalArgumentException
java.lang.IndexOutOfBoundsException

gsend

public int gsend(byte[] buf1,
                 byte[] buf2,
                 byte[] buf3)
          throws java.io.IOException,
                 java.lang.IllegalArgumentException
Throws:
java.io.IOException
java.lang.IllegalArgumentException

gsend

public int gsend(byte[] buf1,
                 int offset1,
                 int length1,
                 byte[] buf2,
                 int offset2,
                 int length2,
                 byte[] buf3,
                 int offset3,
                 int length3)
          throws java.io.IOException,
                 java.lang.IllegalArgumentException,
                 java.lang.IndexOutOfBoundsException
Throws:
java.io.IOException
java.lang.IllegalArgumentException
java.lang.IndexOutOfBoundsException

gsend

public int gsend(byte[] buf1,
                 byte[] buf2,
                 byte[] buf3,
                 byte[] buf4)
          throws java.io.IOException,
                 java.lang.IllegalArgumentException
Throws:
java.io.IOException
java.lang.IllegalArgumentException

gsend

public int gsend(byte[] buf1,
                 int offset1,
                 int length1,
                 byte[] buf2,
                 int offset2,
                 int length2,
                 byte[] buf3,
                 int offset3,
                 int length3,
                 byte[] buf4,
                 int offset4,
                 int length4)
          throws java.io.IOException,
                 java.lang.IllegalArgumentException,
                 java.lang.IndexOutOfBoundsException
Throws:
java.io.IOException
java.lang.IllegalArgumentException
java.lang.IndexOutOfBoundsException

replace

public int replace(byte[] buffer,
                   int oldTag,
                   int newTag)
            throws java.io.IOException,
                   java.lang.IllegalArgumentException
First cancels any previously enqueued messages that have been tagged with the specified OldTag value and then transmits the new message using the specified parameters. Note that there may be no old messages to cancel, in which case this call behaves just like a send.

Several communication parameter are not specified, the default value is going to be used for the following parameters: priority = 5, enqueue timeout = 0 or a value set using the method setDefaultEnqueueTimeout, retry timeout = 0 or a value set using the method setDefaultRetryTimeout.

Parameters:
buffer - the buffer to be sent. The buffer is going to be sent entirely.
oldTag - the tag of the messages to be replaced.
newTag - tag of the new message to be enqueued. The values has to be >0.
Returns:
  • 0 if the message is successfully enqueued to be sent and any messages tagged with oldTag is successfully removed from the queues.
  • -1 if the retrieve of the instance of Transmitter did not work, the value is null.
  • -2 if the cancellation of messages marked with oldTag did not work.
  • -3 if the send operation on the new message did not work.
  • -10 if the parameters are illegal (less then zero);
  • -11 if MessageSender is not initialized, MessageSender is null;
  • -12 if the parameter buffer is invalid, buffer is null.
Throws:
java.io.IOException
java.lang.IllegalArgumentException
See Also:
Mocket.cancel(boolean, boolean, int), Mocket.send(boolean, boolean, byte[], int, int, int, short, long, long), Mocket.getSender(boolean, boolean)

replace

public int replace(byte[] buffer,
                   int offset,
                   int length,
                   int oldTag,
                   int newTag)
            throws java.io.IOException,
                   java.lang.IllegalArgumentException,
                   java.lang.IndexOutOfBoundsException
First cancels any previously enqueued messages that have been tagged with the specified OldTag value and then transmits the new message using the specified parameters. Note that there may be no old messages to cancel, in which case this call behaves just like a send.

Several communication parameter are not specified, the default value is going to be used for the following parameters: priority = 5, enqueue timeout = 0 or a value set using the method setDefaultEnqueueTimeout, retry timeout = 0 or a value set using the method setDefaultRetryTimeout.

Parameters:
buffer - the buffer to be sent.
offset - the position in the buffer we start to send from. E.g. offset=10, we send buffer starting at the 10th byte in the array
length - the length for which we send. E.g. length=50 we send 50 bytes of the buffer, starting at offset. If offset=10, length=50 we send bytes from position 10 in the buffer through position 60.
oldTag - tag of the messages to replace. Messages tagged with oldTag will be canceled.
newTag - tag of the new message to be enqueued. The value has to be >0.
Returns:
  • 0 if the message is successfully enqueued to be sent and any messages tagged with oldTag is successfully removed from the queues;
  • -1 if the retrieve of the instance of Transmitter did not work, the value is null;
  • -2 if the cancellation of messages marked with oldTag did not work;
  • -3 if the send operation on the new message did not work;
  • -10 if the parameters are illegal (less then zero);
  • -11 if MessageSender is not initialized, MessageSender is null;
  • -12 if the parameter buffer is invalid, buffer is null.
Throws:
java.io.IOException
java.lang.IllegalArgumentException
java.lang.IndexOutOfBoundsException - if the parameters offset or length are illegal for buffer.
See Also:
Mocket.cancel(boolean, boolean, int), Mocket.send(boolean, boolean, byte[], int, int, int, short, long, long), Mocket.getSender(boolean, boolean)

replace

public int replace(byte[] buffer,
                   int oldTag,
                   Params params)
            throws java.io.IOException,
                   java.lang.IllegalArgumentException
First cancels any previously enqueued messages that have been tagged with the specified OldTag value and then transmits the new message using the specified parameters. Note that there may be no old messages to cancel, in which case this call behaves just like a send.

Parameters:
buffer - the buffer to be sent. The buffer is going to be sent entirely.
oldTag - the tag of the messages to be replaced.
params - an instance of class Param that contains: tag, priority, enqueueTimeout, retryTimeout.
Returns:
  • 0 if the message is successfully enqueued to be sent and any messages tagged with oldTag is successfully removed from the queues;
  • -1 if the retrieve of the instance of Transmitter did not work, the value is null;
  • -2 if the cancellation of messages marked with oldTag did not work;
  • -3 if the send operation on the new message did not work;
  • -10 if the parameter oldTag is illegal (less then zero);
  • -11 if MessageSender is not initialized, MessageSender is null;
  • -12 if the parameter buffer is invalid, buffer is null;
  • -13 if the parameter params is invalid, params is null.
Throws:
java.io.IOException
java.lang.IllegalArgumentException
See Also:
Mocket.cancel(boolean, boolean, int), Mocket.send(boolean, boolean, byte[], int, int, int, short, long, long), Mocket.getSender(boolean, boolean)

replace

public int replace(byte[] buffer,
                   int offset,
                   int length,
                   int oldTag,
                   Params params)
            throws java.io.IOException,
                   java.lang.IllegalArgumentException,
                   java.lang.IndexOutOfBoundsException
First cancels any previously enqueued messages that have been tagged with the specified OldTag value and then transmits the new message using the specified parameters. Note that there may be no old messages to cancel, in which case this call behaves just like a send.

Parameters:
buffer - the buffer to be sent.
offset - the position in the buffer we start to send from. E.g. offset=10, we send buffer starting at the 10th byte in the array.
length - the length for which we send. E.g. length=50 we send 50 bytes of the buffer, starting at offset. If offset=10, length=50 we send bytes from position 10 in the buffer through position 60.
oldTag - the tag of the messages to be replaced.
params - an instance of class Param that contains: tag, priority, enqueueTimeout, retryTimeout.
Returns:
  • 0 if the message is successfully enqueued to be sent and any messages tagged with oldTag is successfully removed from the queues;
  • -1 if the retrieve of the instance of Transmitter did not work, the value is null;
  • -2 if the cancellation of messages marked with oldTag did not work;
  • -3 if the send operation on the new message did not work;
  • -10 if the parameter oldTag is illegal (less then zero);
  • -11 if MessageSender is not initialized, MessageSender is null;
  • -12 if the parameter buffer is invalid, buffer is null;
  • -13 if the parameter params is invalid, params is null.
Throws:
java.io.IOException
java.lang.IllegalArgumentException
java.lang.IndexOutOfBoundsException - if the parameters offset or length are illegal for buffer.
See Also:
Mocket.cancel(boolean, boolean, int), Mocket.send(boolean, boolean, byte[], int, int, int, short, long, long), Mocket.getSender(boolean, boolean)

replace

public int replace(byte[] buffer,
                   int oldTag,
                   int newTag,
                   short priority,
                   long enqueueTimeout,
                   long retryTimeout)
            throws java.io.IOException,
                   java.lang.IllegalArgumentException
First cancels any previously enqueued messages that have been tagged with the specified OldTag value and then transmits the new message using the specified parameters. Note that there may be no old messages to cancel, in which case this call behaves just like a send.

Parameters:
buffer - the buffer to be sent. The buffer is going to be sent entirely.
oldTag - the tag of the messages to be replaced.
newTag - tag of the new message to be enqueued. The value has to be >0.
priority - used to assign a priority different than the default one (higher or lower). The value has to be >0. Note that the priority of a message will grow every time it is skipped in favor of a higher priority messages that gets sent first. This mechanism is implemented to avoid message starvation. The range of priority values is 0-255.
enqueueTimeout - indicates the length of time in milliseconds for which the method will wait if there is no room in the outgoing buffer. A zero value indicates wait forever.
retryTimeout - indicates the length of time for which the transmitter will retransmit the packet to ensure successful delivery. A zero value indicates retry with no time limit. Note that this parameter makes sense only if the flow is reliable, otherwise the behavior is to transmit and forget about the packet.
Returns:
  • 0 if the message is successfully enqueued to be sent and any messages tagged with oldTag is successfully removed from the queues;
  • -1 if the retrieve of the instance of Transmitter did not work, the value is null;
  • -2 if the cancellation of messages marked with oldTag did not work;
  • -3 if the send operation on the new message did not work;
  • -10 if the parameters are illegal (less then zero);
  • -11 if MessageSender is not initialized, MessageSender is null;
  • -12 if the parameter buffer is invalid, buffer is null.
Throws:
java.io.IOException
java.lang.IllegalArgumentException
See Also:
Mocket.cancel(boolean, boolean, int), Mocket.send(boolean, boolean, byte[], int, int, int, short, long, long), setDefaultEnqueueTimeout(long), setDefaultRetryTimeout(long), Mocket.getSender(boolean, boolean)

replace

public int replace(byte[] buffer,
                   int offset,
                   int length,
                   int oldTag,
                   int newTag,
                   short priority,
                   long enqueueTimeout,
                   long retryTimeout)
            throws java.io.IOException,
                   java.lang.IllegalArgumentException,
                   java.lang.IndexOutOfBoundsException
First cancels any previously enqueued messages that have been tagged with the specified OldTag value and then transmits the new message using the specified parameters. Note that there may be no old messages to cancel, in which case this call behaves just like a send.

Parameters:
buffer - the buffer to be sent.
offset - the position in the buffer we start to send from. E.g. offset=10, we send buffer starting at the 10th byte in the array.
length - the length for which we send. E.g. length=50 we send 50 bytes of the buffer, starting at offset. If offset=10, length=50 we send bytes from position 10 in the buffer through position 60.
oldTag - the tag of the messages to be replaced.
newTag - tag of the new message to be enqueued. The value has to be >0.
priority - used to assign a priority different than the default one (higher or lower). The value has to be >0. Note that the priority of a message will grow every time it is skipped in favor of a higher priority messages that gets sent first. This mechanism is implemented to avoid message starvation. The range of priority values is 0-255.
enqueueTimeout - indicates the length of time in milliseconds for which the method will wait if there is no room in the outgoing buffer. A zero value indicates wait forever.
retryTimeout - indicates the length of time for which the transmitter will retransmit the packet to ensure successful delivery. A zero value indicates retry with no time limit. Note that this parameter makes sense only if the flow is reliable, otherwise the behavior is to transmit and forget about the packet.
Returns:
  • 0 if the message is successfully enqueued to be sent and any messages tagged with oldTag is successfully removed from the queues;
  • -1 if the retrieve of the instance of Transmitter did not work, the value is null;
  • -2 if the cancellation of messages marked with oldTag did not work;
  • -3 if the send operation on the new message did not work;
  • -10 if the parameters are illegal (less then zero);
  • -11 if MessageSender is not initialized, MessageSender is null;
  • -12 if the parameter buffer is invalid, buffer is null.
Throws:
java.io.IOException
java.lang.IllegalArgumentException
java.lang.IndexOutOfBoundsException
See Also:
Mocket.cancel(boolean, boolean, int), Mocket.send(boolean, boolean, byte[], int, int, int, short, long, long), setDefaultEnqueueTimeout(long), setDefaultRetryTimeout(long), Mocket.getSender(boolean, boolean)

cancel

public int cancel(int tagId)
           throws java.io.IOException,
                  java.lang.IllegalArgumentException
Cancels (deletes) previously enqueued messages that have been tagged with the specified tag. Note that the messages may be pending transmission (which applies to all flows) or may have already been transmitted but not yet acknowledged (which only applies to reliable flows)

Parameters:
tagId - the tag of the messages to be removed.
Returns:
  • number of messages removed form the queues;
  • -1 if cancel on pending packet queue (queue of messages waiting to be sent) fails;
  • -2 if cancel on unacknowledged packet queue fails (only for reliable flow);
  • -10 if the parameter tagId is illegal (less then zero);
  • -11 if MessageSender is not initialized, MessageSender is null.
Throws:
java.io.IOException
java.lang.IllegalArgumentException
See Also:
Mocket.getSender(boolean, boolean)

setDefaultEnqueueTimeout

public void setDefaultEnqueueTimeout(long enqueueTimeout)
                              throws java.io.IOException,
                                     java.lang.IllegalArgumentException
Sets the default timeout for enqueuing data into the outgoing queue. If the outgoing buffer is full, a call to send will block until the timeout expires. 0 is the default value. Specifying a timeout value of 0 disables the timeout, wait indefinitely.

Parameters:
enqueueTimeout - time in milliseconds the message will wait in the outgoing queue.
Throws:
java.io.IOException
java.lang.IllegalArgumentException
See Also:
Mocket.getSender(boolean, boolean)

setDefaultRetryTimeout

public void setDefaultRetryTimeout(long retryTimeout)
                            throws java.io.IOException,
                                   java.lang.IllegalArgumentException
Sets the default timeout for retransmission of reliable packets that have not been acknowledged. Specifying a timeout value of 0 disables the timeout. NOTE: Setting a timeout would imply that packets may not be reliable!

Parameters:
retryTimeout - time in milliseconds the message will wait in the unacknowledged packet queue.
Throws:
java.io.IOException
java.lang.IllegalArgumentException
See Also:
Mocket.getSender(boolean, boolean)

finalize

protected void finalize()
Removes mocket object.

Overrides:
finalize in class java.lang.Object