org.ijsberg.iglu.util.io
Class BasicChannel

java.lang.Object
  extended by org.ijsberg.iglu.util.io.BasicChannel
All Implemented Interfaces:
Channel, Transmitter

public class BasicChannel
extends Object
implements Channel, Transmitter

Transmits messages to a number of Receivers.


Constructor Summary
BasicChannel(String name)
          Constructs a channel with a certain name.
BasicChannel(String name, boolean echo)
          Constructs a channel with a certain name and the ability to echo objects back to the transceiver.
BasicChannel(String name, int maxNrofReceivers)
          Constructs a channel with a certain name and a maximun nunber of receivers.
BasicChannel(String name, int maxNrofReceivers, boolean echo)
          Constructs a channel with a certain name, a maximun nunber of receivers and the ability to echo objects back to the transceiver.
 
Method Summary
 void close()
          Closes the channel and all receivers.
 ReceiverQueue createReceiver()
          Creates a receiver for this channel.
 ReceiverQueue createReceiver(int limit)
          Creates a receiver for this channel.
 String getName()
           
 int getNrofReceivers()
           
 boolean isClosed()
           
 Receiver registerReceiver(Receiver receiver)
          Adds a receiver so that it will receive transmitted messages.
 String toString()
          Returns a string representation of a channel object including all connected receivers and queue sizes.
 void transmit(Object o)
          Dispatches an object to all connected receivers.
 void transmit(Object o, ReceiverQueue t)
          Dispatches an object to all connected receivers.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BasicChannel

public BasicChannel(String name)
Constructs a channel with a certain name.

Parameters:
name - name

BasicChannel

public BasicChannel(String name,
                    int maxNrofReceivers)
Constructs a channel with a certain name and a maximun nunber of receivers.

Parameters:
name - name
maxNrofReceivers - maximum number of receivers

BasicChannel

public BasicChannel(String name,
                    boolean echo)
Constructs a channel with a certain name and the ability to echo objects back to the transceiver.

Parameters:
name - name
echo - echo back to transceiver

BasicChannel

public BasicChannel(String name,
                    int maxNrofReceivers,
                    boolean echo)
Constructs a channel with a certain name, a maximun nunber of receivers and the ability to echo objects back to the transceiver.

Parameters:
name - name
maxNrofReceivers - maximum number of receivers
echo - echo back to transceiver
Method Detail

transmit

public void transmit(Object o)
Dispatches an object to all connected receivers.

Specified by:
transmit in interface Transmitter
Parameters:
o - the object to dispatch

transmit

public void transmit(Object o,
                     ReceiverQueue t)
Dispatches an object to all connected receivers.

Parameters:
o - the object to dispatch
t - the transceiver sending the object

getNrofReceivers

public int getNrofReceivers()
Returns:
the number of listening receivers

createReceiver

public ReceiverQueue createReceiver()
Creates a receiver for this channel.

Returns:
a receiver

createReceiver

public ReceiverQueue createReceiver(int limit)
Creates a receiver for this channel.

Parameters:
limit - the maximum number of objects stored in the receiver queue
Returns:
a receiver

registerReceiver

public Receiver registerReceiver(Receiver receiver)
Adds a receiver so that it will receive transmitted messages.

Specified by:
registerReceiver in interface Channel
Parameters:
receiver -
Returns:
the registered receiver for convenience or null if the channel is closed or the maximum number of receivers is reached

close

public void close()
Closes the channel and all receivers.

Specified by:
close in interface Transmitter

isClosed

public boolean isClosed()
Specified by:
isClosed in interface Transmitter
Returns:
true if the channel is closed

getName

public String getName()
Returns:
the name of the channel

toString

public String toString()
Returns a string representation of a channel object including all connected receivers and queue sizes.

Overrides:
toString in class Object
Returns:
a string representation of a channel object


Copyright © 2011. All Rights Reserved.