org.gcube.common.core.utils.events
Class GCUBEProducer<TOPIC extends GCUBETopic,PAYLOAD>

java.lang.Object
  extended by org.gcube.common.core.utils.events.GCUBEProducer<TOPIC,PAYLOAD>
Type Parameters:
TOPIC - the type of the event topics.
PAYLOAD - the type of the event payload.

public class GCUBEProducer<TOPIC extends GCUBETopic,PAYLOAD>
extends Object

Base implementation for producers of event notifications. A producer notifies GCUBEConsumers which have previously subscribed with it of the occurrence of GCUBEEvents about given GCUBETopics and carrying given payloads.

Through type instantiation, producers may be constrained to handle only GCUBEEvents about given topics and/or carrying given payloads. For example:

a GCUBEProducer<MyTopic,Object> handles only events about MyTopics but carrying any payload.
a GCUBEProducer<GCUBETopic,MyPayload> handles events about any GCUBETopic as long as they carry MyPayloads.
a GCUBEProducer<MyTopic,MyPayload> handles only events about MyTopics which carry MyPayloads.

Type constraints may be specified when the producer is created, e.g.:

GCUBEProducer<MyTopic,MyPayload> myProducer = new GCUBEProducer<MyTopic,MyPayload>();

or else by subclassing, e.g.

public class MyProducer extends GCUBEProducer<MyTopic,MyPayload> {...}
...
MyProducer myProducer = new MyProducer();

Author:
Fabio Simeoni (University of Strathclyde)
See Also:
GCUBEEvent, GCUBETopic, GCUBEConsumer

Field Summary
protected static List<GCUBEProducer<?,?>> classExtent
          The class extent.
protected  Map<TOPIC,List<GCUBEConsumer<TOPIC,PAYLOAD>>> consumers
          Subscribed consumers, indexed by topic.
protected  Map<TOPIC,List<GCUBEEvent<? extends TOPIC,? extends PAYLOAD>>> events
          Notified events, indexed by topic.
protected  GCUBELog logger
          Object logger.
protected static org.gcube.common.core.utils.events.GCUBEProducer.EventSweeper sweeper
          The sweeper scheduler
 
Constructor Summary
GCUBEProducer()
          Creates a new instance.
 
Method Summary
protected  List<GCUBEConsumer<TOPIC,PAYLOAD>> getConsumers(TOPIC topic)
          Used internally to return all the consumers subscribed for a given topic.
protected  List<GCUBEEvent<? extends TOPIC,? extends PAYLOAD>> getEvents(TOPIC topic)
          Used internally to return all the events recorded for a given topic.
<T1 extends TOPIC,P1 extends PAYLOAD>
void
notify(T1 topic, GCUBEEvent<T1,P1>... events)
          Notifies consumers of the occurrence of one or more events about a topic for which they subscribed.
protected
<T1 extends TOPIC,P1 extends PAYLOAD>
void
notifyConsumer(GCUBEConsumer<TOPIC,PAYLOAD> consumer, GCUBEEvent<T1,P1>... events)
          Notifies asynchronously a given consumer of the occurrence of one or more events.
 void subscribe(GCUBEConsumer<TOPIC,PAYLOAD> consumer, TOPIC... topics)
          Subscribes a consumer to events about one or more topics.
 void unsubscribe(GCUBEConsumer<TOPIC,PAYLOAD> consumer, TOPIC... topics)
          Unsubscribes a consumer from events about one or more topics.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected GCUBELog logger
Object logger.


consumers

protected Map<TOPIC extends GCUBETopic,List<GCUBEConsumer<TOPIC extends GCUBETopic,PAYLOAD>>> consumers
Subscribed consumers, indexed by topic.


events

protected Map<TOPIC extends GCUBETopic,List<GCUBEEvent<? extends TOPIC extends GCUBETopic,? extends PAYLOAD>>> events
Notified events, indexed by topic.


classExtent

protected static List<GCUBEProducer<?,?>> classExtent
The class extent.


sweeper

protected static org.gcube.common.core.utils.events.GCUBEProducer.EventSweeper sweeper
The sweeper scheduler

Constructor Detail

GCUBEProducer

public GCUBEProducer()
Creates a new instance.

Method Detail

getConsumers

protected List<GCUBEConsumer<TOPIC,PAYLOAD>> getConsumers(TOPIC topic)
Used internally to return all the consumers subscribed for a given topic.

Parameters:
topic - the topic.
Returns:
the consumers.

getEvents

protected List<GCUBEEvent<? extends TOPIC,? extends PAYLOAD>> getEvents(TOPIC topic)
Used internally to return all the events recorded for a given topic.

Parameters:
topic - the topic.
Returns:
the events.

subscribe

public void subscribe(GCUBEConsumer<TOPIC,PAYLOAD> consumer,
                      TOPIC... topics)
               throws IllegalArgumentException
Subscribes a consumer to events about one or more topics.

Parameters:
TOPIC - the topic type.
PAYLOAD - the event payload type.
consumer - the consumer.
topics - the topics.
Throws:
IllegalArgumentException - if invoked with no topics.

unsubscribe

public void unsubscribe(GCUBEConsumer<TOPIC,PAYLOAD> consumer,
                        TOPIC... topics)
                 throws IllegalArgumentException
Unsubscribes a consumer from events about one or more topics.

Type Parameters:
TOPIC - the topic type.
PAYLOAD - the event payload type.
Parameters:
consumer - the consumer.
topics - the topics.
Throws:
IllegalArgumentException - if invoked with null or empty inputs.

notifyConsumer

protected <T1 extends TOPIC,P1 extends PAYLOAD> void notifyConsumer(GCUBEConsumer<TOPIC,PAYLOAD> consumer,
                                                                    GCUBEEvent<T1,P1>... events)
Notifies asynchronously a given consumer of the occurrence of one or more events.

Type Parameters:
TOPIC - the topic type.
PAYLOAD - the event payload type.
Parameters:
consumer - the consumer.
events - the events.

notify

public <T1 extends TOPIC,P1 extends PAYLOAD> void notify(T1 topic,
                                                         GCUBEEvent<T1,P1>... events)
            throws IllegalArgumentException
Notifies consumers of the occurrence of one or more events about a topic for which they subscribed.

Type Parameters:
T1 - the topic type.
P1 - the payload type.
Parameters:
topic - the topic.
events - the events.
Throws:
IllegalArgumentException - if invoked with null or empty inputs.


Copyright © 2012. All Rights Reserved.