org.gcube.common.core.utils.events
Interface GCUBEConsumer<TOPIC extends GCUBETopic,PAYLOAD>

Type Parameters:
TOPIC - the type of the topics associated with the events managed by the producer.
PAYLOAD - the type of the payload of the events managed by the producer.
All Known Implementing Classes:
Consumer, CredentialConsumer, CredentialRequestConsumer, GCUBEPluginManager.PluginConsumer, GCUBEPortTypeContext.PTConsumer, GCUBEResource.ResourceConsumer, GCUBERIPersistenceManager.StateChangeConsumer, GCUBEServiceContext.Stager, GCUBEServiceSecurityManager.LifetimeConsumer, GHNConsumer, ISLocalPublisher.LocalProfileConsumer, ISNotifier.BaseNotificationConsumer, Monitor

public interface GCUBEConsumer<TOPIC extends GCUBETopic,PAYLOAD>

Interface for consumers of notification of GCUBEEvents about GCUBETopic A consumer receives notifications from a GCUBEProducers with which it has previously subscribed. Through type instantiation, consumers may be constrained to handle only GCUBEEvents about given topics and/or carrying given payloads. For example:

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

Type constraints may be specified when the consumer interface is implemented, either explicitly:

public class MyConsumer implements GCUBEConsumer<MyTopic,MyPayload> {...}
...
MyConsumer myConsumer = new MyConsumer();

or else implicitly, using anonymous inner classes, e.g.

GCUBEConsumer<MyTopic,MyPayload> myConsumer = new GCUBEConsumer<MyTopic,MyPayload>(){...};

A consumer which consumes events associated with different topics and/or payloads performs a type-based analysis on the events in input to onEvent(GCUBEEvent[]). For example, a consumer MyConsumer which implements the GCUBEConsumer<MyTopic,MyPayload> interface would implement onEvent(GCUBEEvent[]) along the following lines:

public void onEvent(GCUBEEvent ... event) {
  for (GCUBEEvent event : events) {
    if (event instanceof MyEvent) {...}
    else if (event instanceof MyOtherEvent) {...}
    ...
  }
}

For convenience, the type-based analysis of MyConsumer may dispatch to event-specific methods, e.g.:

public void onEvent(GCUBEEvent ... event) {
  for (GCUBEEvent event : events) {
    if (event instanceof MyEvent) {this.onEvent((MyEvent) event);}
    else if (event instanceof MyOtherEvent) {this.onEvent((MyOtherEvent) event);}
    ...

public void onEvent(MyEvent event){...}
public void onEvent(MyOtherEvent event){...}
  }
}

This approach suits complex type-based analyses, or else circumstances in which a concrete implementations of the consumers is best delegated to subclasses. In the latter case, the event-specific methods (and thus MyProducer) may be declared as abstract method.

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

Method Summary
<T1 extends TOPIC,P1 extends PAYLOAD>
void
onEvent(GCUBEEvent<T1,P1>... event)
          Notifies the consumer of one of more events about topics for which the consumer has previously subscribed with a GCUBEProducer
 

Method Detail

onEvent

<T1 extends TOPIC,P1 extends PAYLOAD> void onEvent(GCUBEEvent<T1,P1>... event)
Notifies the consumer of one of more events about topics for which the consumer has previously subscribed with a GCUBEProducer

Type Parameters:
T1 - the topic type.
P1 - the payload type.
Parameters:
event - the events.


Copyright © 2012. All Rights Reserved.