com.croftsoft.core.util.pubsub
Class ArrayPublisher

java.lang.Object
  extended by com.croftsoft.core.util.pubsub.ArrayPublisher
All Implemented Interfaces:
Publisher, Subscriber

public final class ArrayPublisher
extends Object
implements Publisher

A synchronous Publisher implementation backed by a Subscriber array.

In this simple Publisher implementation, message propagation is synchronous; all of the methods are synchronized and the publish() method does not return until all Subscribers have been contacted one-at-a-time and in array order.

Java 1.1 compatible.

Since:
2001-04-04
Version:
2002-01-29
See Also:
Publisher, Subscriber
Author:
David Wallace Croft

Constructor Summary
ArrayPublisher()
          this ( null, new Subscriber [ ] { } );
ArrayPublisher(ExceptionHandler exceptionHandler, Subscriber[] subscribers)
           
 
Method Summary
 boolean addSubscriber(Subscriber subscriber)
           
 void publish(Object message)
           
 void receive(Object message)
          Simply calls method publish(message).
 boolean removeSubscriber(Subscriber subscriber)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ArrayPublisher

public ArrayPublisher(ExceptionHandler exceptionHandler,
                      Subscriber[] subscribers)
Parameters:
exceptionHandler - Handles any Exceptions thrown by Subscriber.receive(). If null, exception.printStackTrace() will be used by default.

ArrayPublisher

public ArrayPublisher()
this ( null, new Subscriber [ ] { } );

Method Detail

addSubscriber

public boolean addSubscriber(Subscriber subscriber)
Specified by:
addSubscriber in interface Publisher
Returns:
False if the Subscriber was already in the array.

removeSubscriber

public boolean removeSubscriber(Subscriber subscriber)
Specified by:
removeSubscriber in interface Publisher
Returns:
False if the Subscriber was not in the array to be removed.

publish

public void publish(Object message)
Specified by:
publish in interface Publisher

receive

public void receive(Object message)
Description copied from interface: Publisher
Simply calls method publish(message).

This interface extends interface Subscriber so that it can be used as a one-to-many relay; received messages are published.

Specified by:
receive in interface Publisher
Specified by:
receive in interface Subscriber

CroftSoft Javadoc

CroftSoft Core Javadoc (2008-09-28 20:58:02)