fulmine.demo
Class Subscriber

java.lang.Object
  extended by fulmine.demo.Subscriber
All Implemented Interfaces:
IEventListener

public class Subscriber
extends Object
implements IEventListener

A simple subscriber that opens a random TcpConnectionBroker port and subscribes to a IConnectionBroker identity "Publisher" for an IContainer called "time" and prints each event to the console. Pressing any key terminates the subscriber.

Author:
Ramon Servadei

Constructor Summary
Subscriber()
           
 
Method Summary
 void addedAsListenerFor(IEventSource source)
          The listener receives this when it has been added as a listener to an event source via IEventSource.addListener(IEventListener).
 void destroy()
           
 Class<? extends IEvent>[] getEventTypeFilter()
          Get the classes of IEvent instances this listener can process.
static void main(String[] args)
           
 void removedAsListenerFrom(IEventSource source)
          The listener receives this when it has been removed as a listener from an event source via IEventSource.removeListener(IEventListener).
 void update(IEvent event)
          An update has occurred that this listener is interested in.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Subscriber

public Subscriber()
Method Detail

main

public static void main(String[] args)
                 throws IOException,
                        InterruptedException
Parameters:
args -
Throws:
IOException
InterruptedException

addedAsListenerFor

public void addedAsListenerFor(IEventSource source)
Description copied from interface: IEventListener
The listener receives this when it has been added as a listener to an event source via IEventSource.addListener(IEventListener).

Specified by:
addedAsListenerFor in interface IEventListener
Parameters:
source - the source that this listener will receive events from.

removedAsListenerFrom

public void removedAsListenerFrom(IEventSource source)
Description copied from interface: IEventListener
The listener receives this when it has been removed as a listener from an event source via IEventSource.removeListener(IEventListener).

Specified by:
removedAsListenerFrom in interface IEventListener
Parameters:
source - the source that this listener will no longer receive events from.

update

public void update(IEvent event)
Description copied from interface: IEventListener
An update has occurred that this listener is interested in. IEventSource instances are bound to EventProcessor instances so the same thread will execute this method for events originating from the same event source. This does not mean that this method is thread safe; this method may be run by multiple EventProcessor instances and so should be thread aware as appropriate.

This method can throw any Exception and processing will not be interrupted. The EventProcessor will handle the exception.

Specified by:
update in interface IEventListener
Parameters:
event - the event encapsulating the update.

destroy

public void destroy()

getEventTypeFilter

public Class<? extends IEvent>[] getEventTypeFilter()
Description copied from interface: IEventListener
Get the classes of IEvent instances this listener can process. The IEventListener.update(IEvent) method will only be called with IEvent instances whose Class is assignment compatible with any contained in this array.

This is an event filtering mechanism. An IEventSource may generate many types of IEvent instances but a listener may only be interested in one type. By specifying the types of events the listener is interested in using this method, the listener effectively filters out unwanted events.

If the filter is dynamic then this method must be thread aware.

Specified by:
getEventTypeFilter in interface IEventListener
Returns:
an array of Class objects that determine the types of IEvent instances this listener can process


Copyright © 2007-2009. All Rights Reserved.