ibis.ipl
Interface WriteMessage


public interface WriteMessage

The Ibis abstraction for data to be written. A WriteMessage is obtained from a SendPort through the SendPort.newMessage method. At most one WriteMessage is alive at one time for a given SendPort. When a message is alive and a new message is requested, the requester is blocked until the live message is finished. For all write methods in this class, the invariant is that the reads must match the writes one by one. The only exception to this rule is that an array written with any of the writeArray methods can be read by ReadMessage.readObject. In particular, an array written with writeObject cannot be read with readArray, because writeObject does duplicate detection, and may have written only a handle.


Method Summary
 long finish()
          If needed, send, and then block until the entire message has been sent and clear the message.
 void finish(java.io.IOException e)
          This method can be used to inform Ibis that one of the WriteMessage methods has thrown an IOException.
 SendPort localPort()
          Returns the SendPort of this WriteMessage.
 void reset()
          Resets the state of any objects already written to the stream.
 int send()
          Starts sending the message to all ReceivePorts its SendPort is connected to.
 void sync(int ticket)
          Blocks until the data of the send which returned the ticket parameter may be used again.
 void writeArray(boolean[] val)
          Writes an array of booleans to the message.
 void writeArray(boolean[] val, int off, int len)
          Writes a slice of an array of booleans.
 void writeArray(byte[] val)
          Writes an array of bytes to the message.
 void writeArray(byte[] val, int off, int len)
          Write a slice of an array of bytes.
 void writeArray(char[] val)
          Writes an array of chars to the message.
 void writeArray(char[] val, int off, int len)
          Write a slice of an array of chars.
 void writeArray(double[] val)
          Writes an array of doubles to the message.
 void writeArray(double[] val, int off, int len)
          Write a slice of an array of doubles.
 void writeArray(float[] val)
          Writes an array of floats to the message.
 void writeArray(float[] val, int off, int len)
          Write a slice of an array of floats.
 void writeArray(int[] val)
          Writes an array of ints to the message.
 void writeArray(int[] val, int off, int len)
          Write a slice of an array of ints.
 void writeArray(long[] val)
          Writes an array of longs to the message.
 void writeArray(long[] val, int off, int len)
          Write a slice of an array of longs.
 void writeArray(java.lang.Object[] val)
          Writes an array of objects to the message.
 void writeArray(java.lang.Object[] val, int off, int len)
          Write a slice of an array of objects.
 void writeArray(short[] val)
          Writes an array of shorts to the message.
 void writeArray(short[] val, int off, int len)
          Write a slice of an array of shorts.
 void writeBoolean(boolean val)
          Writes a boolean value to the message.
 void writeByte(byte val)
          Writes a byte value to the message.
 void writeChar(char val)
          Writes a char value to the message.
 void writeDouble(double val)
          Writes a double value to the message.
 void writeFloat(float val)
          Writes a float value to the message.
 void writeInt(int val)
          Writes a int value to the message.
 void writeLong(long val)
          Writes a long value to the message.
 void writeObject(java.lang.Object val)
          Writes a Serializable object to the message.
 void writeShort(short val)
          Writes a short value to the message.
 void writeString(java.lang.String val)
          Writes a String to the message.
 

Method Detail

send

public int send()
         throws java.io.IOException
Starts sending the message to all ReceivePorts its SendPort is connected to. Data may be streamed, so the user is not allowed to change the data pushed into this message, as the send is NON-blocking. It is only safe to touch the data after it has actually been sent, which can be ensured by either calling finish() or reset(), or a sync(int) corresponding to this send. The send method returns a ticket, which can be used as a parameter to the sync(int) method, which will block until the data corresponding to this ticket can be used again.

Returns:
a ticket.
Throws:
java.io.IOException - an error occurred

sync

public void sync(int ticket)
          throws java.io.IOException
Blocks until the data of the send which returned the ticket parameter may be used again. It also synchronizes with respect to all sends before that. If ticket does not correspond to any send, it blocks until all outstanding sends have been processed.

Parameters:
ticket - the ticket number.
Throws:
java.io.IOException - an error occurred

reset

public void reset()
           throws java.io.IOException
Resets the state of any objects already written to the stream. It is reset to be the same as for a new WriteMessage.

Throws:
java.io.IOException - an error occurred

finish

public long finish()
            throws java.io.IOException
If needed, send, and then block until the entire message has been sent and clear the message.

Returns:
the number of bytes written in this message.
Throws:
java.io.IOException - an error occurred

finish

public void finish(java.io.IOException e)
This method can be used to inform Ibis that one of the WriteMessage methods has thrown an IOException. It implies a finish().

Parameters:
e - the exception that was thrown.

localPort

public SendPort localPort()
Returns the SendPort of this WriteMessage.

Returns:
the SendPort of this WriteMessage.

writeBoolean

public void writeBoolean(boolean val)
                  throws java.io.IOException
Writes a boolean value to the message.

Parameters:
val - the boolean value to write.
Throws:
java.io.IOException - an error occurred

writeByte

public void writeByte(byte val)
               throws java.io.IOException
Writes a byte value to the message.

Parameters:
val - the byte value to write.
Throws:
java.io.IOException - an error occurred

writeChar

public void writeChar(char val)
               throws java.io.IOException
Writes a char value to the message.

Parameters:
val - the char value to write.
Throws:
java.io.IOException - an error occurred

writeShort

public void writeShort(short val)
                throws java.io.IOException
Writes a short value to the message.

Parameters:
val - the short value to write.
Throws:
java.io.IOException - an error occurred

writeInt

public void writeInt(int val)
              throws java.io.IOException
Writes a int value to the message.

Parameters:
val - the int value to write.
Throws:
java.io.IOException - an error occurred

writeLong

public void writeLong(long val)
               throws java.io.IOException
Writes a long value to the message.

Parameters:
val - the long value to write.
Throws:
java.io.IOException - an error occurred

writeFloat

public void writeFloat(float val)
                throws java.io.IOException
Writes a float value to the message.

Parameters:
val - the float value to write.
Throws:
java.io.IOException - an error occurred

writeDouble

public void writeDouble(double val)
                 throws java.io.IOException
Writes a double value to the message.

Parameters:
val - the double value to write.
Throws:
java.io.IOException - an error occurred

writeString

public void writeString(java.lang.String val)
                 throws java.io.IOException
Writes a String to the message. A duplicate check for this String object is performed: if the object was already written to this message, a handle for this object is written instead of the object itself.

Parameters:
val - the string to write.
Throws:
java.io.IOException - an error occurred

writeObject

public void writeObject(java.lang.Object val)
                 throws java.io.IOException
Writes a Serializable object to the message. A duplicate check for this String object is performed: if the object was already written to this message, a handle for this object is written instead of the object itself.

Parameters:
val - the object value to write.
Throws:
java.io.IOException - an error occurred

writeArray

public void writeArray(boolean[] val)
                throws java.io.IOException
Writes an array of booleans to the message. No duplicate check is performed for this array! This method is just a shortcut for doing: writeArray(val, 0, val.length); (See writeArray(boolean[], int, int)).

Parameters:
val - the array to be written.
Throws:
java.io.IOException - an error occurred

writeArray

public void writeArray(byte[] val)
                throws java.io.IOException
Writes an array of bytes to the message. See writeArray(boolean[]) for a description.

Throws:
java.io.IOException

writeArray

public void writeArray(char[] val)
                throws java.io.IOException
Writes an array of chars to the message. See writeArray(boolean[]) for a description.

Throws:
java.io.IOException

writeArray

public void writeArray(short[] val)
                throws java.io.IOException
Writes an array of shorts to the message. See writeArray(boolean[]) for a description.

Throws:
java.io.IOException

writeArray

public void writeArray(int[] val)
                throws java.io.IOException
Writes an array of ints to the message. See writeArray(boolean[]) for a description.

Throws:
java.io.IOException

writeArray

public void writeArray(long[] val)
                throws java.io.IOException
Writes an array of longs to the message. See writeArray(boolean[]) for a description.

Throws:
java.io.IOException

writeArray

public void writeArray(float[] val)
                throws java.io.IOException
Writes an array of floats to the message. See writeArray(boolean[]) for a description.

Throws:
java.io.IOException

writeArray

public void writeArray(double[] val)
                throws java.io.IOException
Writes an array of doubles to the message. See writeArray(boolean[]) for a description.

Throws:
java.io.IOException

writeArray

public void writeArray(java.lang.Object[] val)
                throws java.io.IOException
Writes an array of objects to the message. See writeArray(boolean[]) for a description.

Throws:
java.io.IOException

writeArray

public void writeArray(boolean[] val,
                       int off,
                       int len)
                throws java.io.IOException
Writes a slice of an array of booleans. The slice starts at offset off No duplicate check is performed for this array!

Parameters:
val - the array to be written
off - offset in the array
len - the number of elements to be written
Throws:
java.io.IOException - an error occurred

writeArray

public void writeArray(byte[] val,
                       int off,
                       int len)
                throws java.io.IOException
Write a slice of an array of bytes. See writeArray(boolean[], int, int) for a description.

Throws:
java.io.IOException

writeArray

public void writeArray(char[] val,
                       int off,
                       int len)
                throws java.io.IOException
Write a slice of an array of chars. See writeArray(boolean[], int, int) for a description.

Throws:
java.io.IOException

writeArray

public void writeArray(short[] val,
                       int off,
                       int len)
                throws java.io.IOException
Write a slice of an array of shorts. See writeArray(boolean[], int, int) for a description.

Throws:
java.io.IOException

writeArray

public void writeArray(int[] val,
                       int off,
                       int len)
                throws java.io.IOException
Write a slice of an array of ints. See writeArray(boolean[], int, int) for a description.

Throws:
java.io.IOException

writeArray

public void writeArray(long[] val,
                       int off,
                       int len)
                throws java.io.IOException
Write a slice of an array of longs. See writeArray(boolean[], int, int) for a description.

Throws:
java.io.IOException

writeArray

public void writeArray(float[] val,
                       int off,
                       int len)
                throws java.io.IOException
Write a slice of an array of floats. See writeArray(boolean[], int, int) for a description.

Throws:
java.io.IOException

writeArray

public void writeArray(double[] val,
                       int off,
                       int len)
                throws java.io.IOException
Write a slice of an array of doubles. See writeArray(boolean[], int, int) for a description.

Throws:
java.io.IOException

writeArray

public void writeArray(java.lang.Object[] val,
                       int off,
                       int len)
                throws java.io.IOException
Write a slice of an array of objects. See writeArray(boolean[], int, int) for a description.

Throws:
java.io.IOException


The Ibis project