net.sourceforge.hiveevents
Class SyncChannelImpl<T>

java.lang.Object
  extended by net.sourceforge.hiveevents.ChannelImpl<T>
      extended by net.sourceforge.hiveevents.SyncChannelImpl<T>
All Implemented Interfaces:
Channel<T>, Consumer<T>

public class SyncChannelImpl<T>
extends ChannelImpl<T>

Thread-safe implementation of an Event Channel.

Author:
Jean-Francois Poilpret

Nested Class Summary
 
Nested classes/interfaces inherited from class net.sourceforge.hiveevents.ChannelImpl
ChannelImpl.AbstractConsumerInfo<T>, ChannelImpl.ConsumerInfo<T>
 
Constructor Summary
SyncChannelImpl(java.lang.String name, int pullConsumerPriority, java.lang.Class<T> clazz, boolean logEvents)
           
 
Method Summary
 void block()
          Temporarily block the Channel, ie any supplied event will be stored inside the Channel but not dispatched to consumers until the Channel is unblocked.
protected  ChannelImpl.ConsumerInfo<T> getConsumer(int idConsumer)
           
 void push(T event)
          Called by an event supplier to trigger this Channel to notify all consumers about a new event.
 int registerPullConsumer(Filter<T> filter)
          Registers a pull-consumer to this Channel.
 int registerPushConsumer(int priority, Filter<T> filter, Consumer<T> consumer)
          Registers a push-consumer to this Channel.
 void unblock()
          Unblocks a Channel that was blocked ie any event that was received during the blocking time is dispatched to all consumers and any new event received will be normally dispatched as well.
 void unregisterAllConsumers()
          Unregister all consumers from this Channel.
 void unregisterConsumer(int idConsumer)
          Unregister the identified consumer from this Channel.
 
Methods inherited from class net.sourceforge.hiveevents.ChannelImpl
getName, logEvent, pull, pull, purgeConsumers, registerConsumer, registerPullConsumer, registerPushConsumer, unblockPullConsumer
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SyncChannelImpl

public SyncChannelImpl(java.lang.String name,
                       int pullConsumerPriority,
                       java.lang.Class<T> clazz,
                       boolean logEvents)
Method Detail

block

public void block()
Description copied from interface: Channel
Temporarily block the Channel, ie any supplied event will be stored inside the Channel but not dispatched to consumers until the Channel is unblocked.

If called n times, unblock() must also be called n times to unblock the Channel.

Specified by:
block in interface Channel<T>
Overrides:
block in class ChannelImpl<T>

unblock

public void unblock()
Description copied from interface: Channel
Unblocks a Channel that was blocked ie any event that was received during the blocking time is dispatched to all consumers and any new event received will be normally dispatched as well.

This method has no effect if the Channel is not currently blocked. It has no effect either if it has been called less times than block().

Specified by:
unblock in interface Channel<T>
Overrides:
unblock in class ChannelImpl<T>

unregisterConsumer

public void unregisterConsumer(int idConsumer)
Description copied from interface: Channel
Unregister the identified consumer from this Channel. That consumer will not be notified of any event any longer.

Specified by:
unregisterConsumer in interface Channel<T>
Overrides:
unregisterConsumer in class ChannelImpl<T>
Parameters:
idConsumer - the unique id of the consumer to unregister. If this id does not exist, then the method does nothing.

unregisterAllConsumers

public void unregisterAllConsumers()
Description copied from interface: Channel
Unregister all consumers from this Channel.

Specified by:
unregisterAllConsumers in interface Channel<T>
Overrides:
unregisterAllConsumers in class ChannelImpl<T>

registerPushConsumer

public int registerPushConsumer(int priority,
                                Filter<T> filter,
                                Consumer<T> consumer)
Description copied from interface: Channel
Registers a push-consumer to this Channel. From now on, this consumer will be notified of all events (if they are validated by the supplied Filter) supplied to the Channel.

Specified by:
registerPushConsumer in interface Channel<T>
Overrides:
registerPushConsumer in class ChannelImpl<T>
Parameters:
priority - the priority (order) with which the new consumer should be notified of new events, the lower the sooner.
filter - a filter instance that will be called for each event received by the Channel in order to decide whether the new consumer must be notified of this event or not
consumer - the actual instance that will be notified (push()) when events are supplied to the Channel
Returns:
the unique id of the new consumer for this Channel

registerPullConsumer

public int registerPullConsumer(Filter<T> filter)
Description copied from interface: Channel
Registers a pull-consumer to this Channel. From now on, this consumer will be notified of all events (if they are validated by the supplied Filter) supplied to the Channel (provided that a thread periodically calls pull() on this Channel on behalf of that consumer).

Specified by:
registerPullConsumer in interface Channel<T>
Overrides:
registerPullConsumer in class ChannelImpl<T>
Parameters:
filter - a filter instance that will be called for each event received by the Channel in order to decide whether the new consumer must be notified of this event or not
Returns:
the unique id of the new consumer for this Channel (to be used in the invocation of pull())

push

public void push(T event)
Description copied from interface: Channel
Called by an event supplier to trigger this Channel to notify all consumers about a new event.

Specified by:
push in interface Channel<T>
Specified by:
push in interface Consumer<T>
Overrides:
push in class ChannelImpl<T>
Parameters:
event - the event notified (can be anything)

getConsumer

protected ChannelImpl.ConsumerInfo<T> getConsumer(int idConsumer)
Overrides:
getConsumer in class ChannelImpl<T>