com.cycling74.net
Class MultiReceiver

java.lang.Object
  extended by com.cycling74.net.MultiReceiver
All Implemented Interfaces:
java.lang.Runnable

public class MultiReceiver
extends java.lang.Object
implements java.lang.Runnable

Connect to and receive from multicast groups. An internal Callback is maintained from a specified method name and object. The specified method must take an array of Atoms as its only argument. When data is received, it is translated to an array of Atoms and passed to the specified method. When a MultiReceiver is no longer needed its close() method should be called. created on 18-May-2004


Constructor Summary
MultiReceiver()
          Creates a new MultiReceiver.
MultiReceiver(int port)
          Creates a new MultiReceiver connected to a specified port.
MultiReceiver(java.lang.String groupName, int port)
          Creates a new MultiReceiver connected to a specified group and port.
MultiReceiver(java.lang.String groupName, int port, java.lang.Object toCallIn, java.lang.String methodName)
          Creates a new MultiReceiver connected to a specified group and port, and creates an internal callback to a given method.
 
Method Summary
 void close()
          Close down the MultiReceiver.
 java.lang.String[] getGroups()
           
 int getPort()
           
 void join(java.lang.String name)
          Join a multicast group.
 void leave(java.lang.String name)
          Leave one group.
 void leaveAllGroups()
          Leave all groups.
 void run()
           
 void setActive(boolean b)
          Turn the MultiReceiver on or off.
 void setCallback(java.lang.Object toCallIn, java.lang.String methodName)
          Creates and maintains a Callback for the MultiReceiver.
 void setDebugString(java.lang.String name)
          Sets the debug string to be used for purposes of error reporting.
 void setPort(int port)
          Sets the port to listen to.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MultiReceiver

public MultiReceiver()
Creates a new MultiReceiver. To make anything happen the user will have to connect to a port, group, and set a Callback.


MultiReceiver

public MultiReceiver(java.lang.String groupName,
                     int port,
                     java.lang.Object toCallIn,
                     java.lang.String methodName)
Creates a new MultiReceiver connected to a specified group and port, and creates an internal callback to a given method.

Parameters:
groupName - the group to join
port - port to communicate over
toCallIn - object that contains the method to call
methodName - method to call

MultiReceiver

public MultiReceiver(java.lang.String groupName,
                     int port)
Creates a new MultiReceiver connected to a specified group and port. A callback must be set with setCallback before this new MultiReceiver will do anything.

Parameters:
groupName - the group to join
port - port to communicate over

MultiReceiver

public MultiReceiver(int port)
Creates a new MultiReceiver connected to a specified port. A callback must be set with setCallback and a group joined with join before this new MultiReceiver will do anything.

Parameters:
port - port to communicate over
Method Detail

setPort

public void setPort(int port)
Sets the port to listen to. This requires closing the old socket and creating a new one. This method operates asynchronously.

Parameters:
port - the new port

getPort

public int getPort()
Returns:
the current port

setCallback

public void setCallback(java.lang.Object toCallIn,
                        java.lang.String methodName)
Creates and maintains a Callback for the MultiReceiver. This Callback is what is called when data is received. The method must take an array of Atoms as its only argument.

Parameters:
toCallIn - object that contains the method
methodName - method to call

setActive

public void setActive(boolean b)
Turn the MultiReceiver on or off.

Parameters:
b - true to turn it on

getGroups

public java.lang.String[] getGroups()
Returns:
an array of Strings representing the groups joined, one for each group

join

public void join(java.lang.String name)
Join a multicast group.

Parameters:
name - the name of the group to join. eg 224.74.74.74 (the maxhole group)

run

public void run()
Specified by:
run in interface java.lang.Runnable

close

public void close()
Close down the MultiReceiver. Should be called in your notifyDeleted method.


leaveAllGroups

public void leaveAllGroups()
Leave all groups.


leave

public void leave(java.lang.String name)
Leave one group.

Parameters:
name - the group to leave

setDebugString

public void setDebugString(java.lang.String name)
Sets the debug string to be used for purposes of error reporting.

Parameters:
name - the debug string to use when error reporting