org.sapia.ubik.mcast
Class EventChannel

java.lang.Object
  extended by org.sapia.ubik.mcast.EventChannel

public class EventChannel
extends java.lang.Object

An instance of this class represents a node in a given logical event channel. Instances of this class are logically grouped on a per-domain basis. Remote events are sent/dispatched to other instances of this class through the network.

A given EventChannel instance will only send/received events to/from other instances of the same domain.

Author:
Yanick Duchesne
Copyright:
Copyright © 2002-2003 Sapia Open Source Software. All Rights Reserved.
License:
Read the license.txt file of the jar or visit the license page at the Sapia OSS web site
See Also:
DomainName, RemoteEvent

Nested Class Summary
static class EventChannel.ChannelEventListener
           
 
Constructor Summary
EventChannel(java.lang.String domain, java.lang.String mcastHost, int mcastPort)
          Constructor for EventChannel.
EventChannel(java.lang.String domain, java.lang.String mcastHost, int mcastPort, int unicastPort)
          Constructor for EventChannel.
 
Method Summary
 void addDiscoveryListener(DiscoveryListener listener)
          Adds the given discovery listener to this instance.
 void close()
          Closes this instance.
 boolean containsAsyncListener(AsyncEventListener listener)
           
 boolean containsSyncListener(SyncEventListener listener)
           
 void dispatch(boolean alldomains, java.lang.String type, java.lang.Object data)
           
 void dispatch(ServerAddress addr, java.lang.String type, java.lang.Object data)
           
 void dispatch(java.lang.String type, java.lang.Object data)
          Dispatches the given data to all nodes in this instance's domain.
 DomainName getDomainName()
          Returns this instance's domain name.
 java.lang.String getMulticastHost()
          Returns this instance's multicast address.
 int getMulticastPort()
          Returns this instance's multicast port.
 java.lang.String getNode()
           
 View getView()
          Returns this instance's "view".
 boolean isClosed()
           
 boolean isStarted()
           
 void registerAsyncListener(java.lang.String type, AsyncEventListener listener)
          Registers a listener of asynchronous remote events of the given type.
 void registerSyncListener(java.lang.String type, SyncEventListener listener)
          Registers a listener of synchronous remote events of the given type.
 Response send(ServerAddress addr, java.lang.String type, java.lang.Object data)
          Synchronously sends a remote event to the node corresponding to the given ServerAddress, and returns the corresponding response.
 RespList send(java.lang.String type, java.lang.Object data)
          Synchronously sends a remote event to all the nodes corresponding to the given ServerAddress, and returns the corresponding responses.
 void setBufsize(int size)
           
 void start()
          Starts this instances.
 void unregisterListener(AsyncEventListener listener)
          Unregisters the given listener from this instance.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EventChannel

public EventChannel(java.lang.String domain,
                    java.lang.String mcastHost,
                    int mcastPort)
             throws java.io.IOException
Constructor for EventChannel. For point-to-point communication, this instance will open a UDP server on a random port.

Parameters:
domain - the domain name of this instance.
mcastHost - the multicast address that this instance will use to broadcast remote events.
mcastPort - the multicast port that this instance will use to broadcast remote events.
Throws:
java.io.IOException
See Also:
DomainName

EventChannel

public EventChannel(java.lang.String domain,
                    java.lang.String mcastHost,
                    int mcastPort,
                    int unicastPort)
             throws java.io.IOException
Constructor for EventChannel.

Parameters:
domain - the domain name of this instance.
mcastHost - the multicast address that this instance will use to broadcast remote events.
mcastPort - the multicast port that this instance will use to broadcast remote events.
unicastPort - the port of the UDP server that this instance encapsulates, and that is used for point-to-point communication.
Throws:
java.io.IOException
See Also:
DomainName
Method Detail

getDomainName

public DomainName getDomainName()
Returns this instance's domain name.

Returns:
a DomainName.

getMulticastHost

public java.lang.String getMulticastHost()
Returns this instance's multicast address.

Returns:
a host address as a string.

getMulticastPort

public int getMulticastPort()
Returns this instance's multicast port.

Returns:
a port.

start

public void start()
           throws java.io.IOException
Starts this instances. This method should be called after instantiating this instance, prior to start receiving/sending remote events.

Throws:
java.io.IOException - if an IO problem occurs starting this instance.

isStarted

public boolean isStarted()
Returns:
true if the start() method was called on this instance.
See Also:
start()

close

public void close()
Closes this instance.


isClosed

public boolean isClosed()
Returns:
true if the close() method was called on this instance.
See Also:
close()

dispatch

public void dispatch(boolean alldomains,
                     java.lang.String type,
                     java.lang.Object data)
              throws java.io.IOException
Throws:
java.io.IOException
See Also:
BroadcastDispatcher.dispatch(boolean, String, Object)

dispatch

public void dispatch(ServerAddress addr,
                     java.lang.String type,
                     java.lang.Object data)
              throws java.io.IOException
Throws:
java.io.IOException
See Also:
UnicastDispatcher.dispatch(ServerAddress, String, Object)

dispatch

public void dispatch(java.lang.String type,
                     java.lang.Object data)
              throws java.io.IOException
Dispatches the given data to all nodes in this instance's domain.

Throws:
java.io.IOException
See Also:
BroadcastDispatcher.dispatch(String, String, Object)

addDiscoveryListener

public void addDiscoveryListener(DiscoveryListener listener)
Adds the given discovery listener to this instance.

Parameters:
listener - a DiscoveryListener.

send

public Response send(ServerAddress addr,
                     java.lang.String type,
                     java.lang.Object data)
              throws java.io.IOException,
                     TimeoutException
Synchronously sends a remote event to the node corresponding to the given ServerAddress, and returns the corresponding response.

Parameters:
addr - the ServerAddress of the node to which to send the remote event.
type - the "logical type" of the remote event.
data - the data to encapsulate in the remote event.
Returns:
the Response corresponding to this call.
Throws:
java.io.IOException
TimeoutException
See Also:
RemoteEvent

send

public RespList send(java.lang.String type,
                     java.lang.Object data)
              throws java.io.IOException
Synchronously sends a remote event to all the nodes corresponding to the given ServerAddress, and returns the corresponding responses.

Parameters:
type - the "logical type" of the remote event.
data - the data to encapsulate in the remote event.
Throws:
java.io.IOException
See Also:
RemoteEvent

registerAsyncListener

public void registerAsyncListener(java.lang.String type,
                                  AsyncEventListener listener)
Registers a listener of asynchronous remote events of the given type.

Parameters:
type - the logical type of the remotee events to listen for.
listener - an AsyncEventListener.

registerSyncListener

public void registerSyncListener(java.lang.String type,
                                 SyncEventListener listener)
                          throws ListenerAlreadyRegisteredException
Registers a listener of synchronous remote events of the given type.

Parameters:
type - the logical type of the remotee events to listen for.
listener - a SyncEventListener.
Throws:
ListenerAlreadyRegisteredException - if a listener has already been registered for the given event type.

unregisterListener

public void unregisterListener(AsyncEventListener listener)
Unregisters the given listener from this instance.

Parameters:
listener - a ASyncEventListener.

getView

public View getView()
Returns this instance's "view".

Returns:
a View.

containsAsyncListener

public boolean containsAsyncListener(AsyncEventListener listener)
See Also:
EventConsumer.containsAsyncListener(AsyncEventListener)

containsSyncListener

public boolean containsSyncListener(SyncEventListener listener)
See Also:
EventConsumer.containsSyncListener(SyncEventListener)

setBufsize

public void setBufsize(int size)
See Also:
BroadcastDispatcher.setBufsize(int), UnicastDispatcher.setBufsize(int)

getNode

public java.lang.String getNode()
See Also:
BroadcastDispatcher.getNode()


Copyright © 2010 Sapia OSS. All Rights Reserved.