org.miv.mbox.net
Class Sender

java.lang.Object
  extended by org.miv.mbox.net.Sender

public class Sender
extends Object

Sends messages to message boxes.

A sender is an object able to send data to another host on a given port. It is not necessary to create a distinct sender for each object we want to send data to (and it would be a loss of space), only for each host and port we need to send data to.

The SenderPool allows to remember a set of senders toward several hosts and ports. It can also create them.

Senders send data synchronously, that is, you wait while the data is sent, however you do not wait until the data is received.

Since:
20040624
Author:
Antoine Dutot
See Also:
SenderPool

Field Summary
protected  ByteArrayOutputStream byteArrayOut
          Byte output stream.
protected  boolean debug
          Echo debugging messages?.
protected  byte[] header
          Oh?!.
protected static String LIGHT_GREEN
           
protected  MBoxLocator locator
          Locator of the distant message box.
protected  ObjectOutputStream objectOut
          Object output stream.
protected  int reset
          Ah?!.
protected static String RESET
           
protected  SocketChannel socket
          Socket to the receiver.
 
Constructor Summary
Sender(MBoxLocator locator)
          New sender toward the given receiver.
Sender(MBoxLocator locator, boolean debug)
          New sender toward the given receiver.
 
Method Summary
protected  void debug(String message, Object... data)
           
 MBoxLocator getLocator()
          Locator of the distant receiver.
 void send(Packet packet)
          Send a data packet.
 void send(String from, String to, Object... messages)
          Send a message.
 void setDebugOn(boolean on)
          Enable or disable debugging.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

socket

protected SocketChannel socket
Socket to the receiver.


locator

protected MBoxLocator locator
Locator of the distant message box.


objectOut

protected ObjectOutputStream objectOut
Object output stream.


byteArrayOut

protected ByteArrayOutputStream byteArrayOut
Byte output stream.


debug

protected boolean debug
Echo debugging messages?.


reset

protected int reset
Ah?!.


header

protected byte[] header
Oh?!.


LIGHT_GREEN

protected static final String LIGHT_GREEN
See Also:
Constant Field Values

RESET

protected static final String RESET
See Also:
Constant Field Values
Constructor Detail

Sender

public Sender(MBoxLocator locator)
       throws IOException,
              UnknownHostException
New sender toward the given receiver. The given locator must only contain an hostname and a port.

Parameters:
locator - MBoxLocator of the receiver.
Throws:
IOException
UnknownHostException

Sender

public Sender(MBoxLocator locator,
              boolean debug)
       throws IOException,
              UnknownHostException
New sender toward the given receiver. The given locator must only contain an hostname and a port.

Parameters:
locator - MBoxLocator of the receiver.
debug - Enable or disable debugging outputs on the console.
Throws:
IOException
UnknownHostException
Method Detail

getLocator

public MBoxLocator getLocator()
Locator of the distant receiver.

Returns:
The locator of a receiver.

setDebugOn

public void setDebugOn(boolean on)
Enable or disable debugging.


send

public void send(String from,
                 String to,
                 Object... messages)
          throws IOException
Send a message. This method encodes the messages and the destination and sender names into a packet and send it.

Parameters:
from - Sender identifier.
to - Receiver identifier.
messages - Message parameters.
Throws:
IOException

send

public void send(Packet packet)
          throws IOException
Send a data packet. This method is a shortcut, assuming you are able to build your own packets to send them. The send(String, String, Object[]) method uses it.

Parameters:
packet - The already packed message to send.
Throws:
IOException

debug

protected void debug(String message,
                     Object... data)


Copyright © 2011. All Rights Reserved.