T
- type of the eventpublic class EventImpl<T>
extends java.lang.Object
// Class exposing some event.
class MyExposingClass
{
// Exposed to a user for subscribing.
public Event<TMyEvent> calculationCompleted()
{
// Returns event, so that the user can only subscribe or unsubscribe.
// Note: User of the event cannot raise the event.
return myCalculationCompletedEvent.getApi();
}
...
private void someMethod()
{
// Raise the event.
myCalculationCompletedEvent.raise(this, new TMyEvent(...));
}
// Declaring the event.
private EventImpl<TMyEvent> myCalculationCompletedEvent = new EventImpl<TMyEvent>();
}
...
// Class consuming the event.
class MyConsumingClass
{
// Subscribing for the event.
private void someMethod()
{
myExposingClass.subscribe(myOnCalculationCompleted);
}
// Method processing the event.
private void onCalculationCompleted(object sender, TMyEvent e)
{
...
}
// Declaring the event handler.
private EventHandler<TMyEvent> myOnCalculationCompleted = new EventHandler<TMyEvent>()
{
public void onEvent(Object x, TMyEvent y)
{
onCalculationCompleted(x, y);
}
}
}
Constructor and Description |
---|
EventImpl() |
Modifier and Type | Method and Description |
---|---|
Event<T> |
getApi()
Returns event for the user.
|
boolean |
isSubscribed()
REturns true if somebody is subscribe.
|
void |
raise(java.lang.Object sender,
T eventArgs)
Raises the event to all subscribers.
|
public void raise(java.lang.Object sender, T eventArgs) throws java.lang.Exception
sender
- reference to the sendereventArgs
- event parameterjava.lang.Exception
public Event<T> getApi()
public boolean isSubscribed()