com.kuka.common.events
Class EventProvider<ListenerType extends IEventListener>

java.lang.Object
  extended by com.kuka.common.events.EventProvider<ListenerType>
Type Parameters:
ListenerType - type of the listener.

public class EventProvider<ListenerType extends IEventListener>
extends Object

Helper class which provide the generic observer functionality.

Holds the list of event listeners. Supports calling the listener synchronously or asynchronously using ExecutorService worker.

This element is an undocumented internal feature. It is not intended to be used by applications as it might change or be removed in future versions.

Constructor Summary
EventProvider(ExecutorService worker)
          Creates an instance of the class using the specified executor.
EventProvider(String name)
          Creates an instance of the class using single thread executor created by Executors.newSingleThreadExecutor() method.
 
Method Summary
 void addListener(ListenerType listener)
          Adds the specified event listener.
 void callListenersAsync(IEventCaller<ListenerType> caller)
          Asynchronously calls for all registered listener the specified IEventCaller.callFor(IEventListener) method.
 void callListenersSync(IEventCaller<ListenerType> caller)
          Synchronously calls for all registered listener the specified IEventCaller.callFor(IEventListener) method.
 void clearListeners()
          Removes all listeners.
 void dispose()
          Shuts down the worker.
 boolean hasListeners()
          Indicates whether the event provider has still listeners that must be notified.
 void removeListener(ListenerType listener)
          Removes the specified listener.
 void setEventWorker(ExecutorService worker)
          Sets the executor which will be used to call asynchronous events.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EventProvider

public EventProvider(String name)
Creates an instance of the class using single thread executor created by Executors.newSingleThreadExecutor() method.

Parameters:
name - name of the event provider

EventProvider

public EventProvider(ExecutorService worker)
Creates an instance of the class using the specified executor.

Parameters:
worker - executor which will be used to call asynchronous events.

Can be null. In this case it will not be possible to call asynchronous events. Executor can be set later by using setEventWorker(ExecutorService) method.

Method Detail

dispose

public void dispose()
Shuts down the worker. Clears the listeners collection.


clearListeners

public void clearListeners()
Removes all listeners.


setEventWorker

public void setEventWorker(ExecutorService worker)
Sets the executor which will be used to call asynchronous events.

If there are events that are currently being executed, they will be executed and only then the new executor will be set.

Parameters:
worker - the executor which will be used to call asynchronous events.

Can be null. In this case it will not be possible to call asynchronous events.


addListener

public void addListener(ListenerType listener)
Adds the specified event listener.

Parameters:
listener - the listener for the events.
Throws:
IllegalArgumentException - if listener is null or the same listener is already registered

removeListener

public void removeListener(ListenerType listener)
Removes the specified listener.

Parameters:
listener - listener to remove

callListenersAsync

public void callListenersAsync(IEventCaller<ListenerType> caller)
Asynchronously calls for all registered listener the specified IEventCaller.callFor(IEventListener) method.

Parameters:
caller - reference to a class implementing IEventCaller interface.

callListenersSync

public void callListenersSync(IEventCaller<ListenerType> caller)
Synchronously calls for all registered listener the specified IEventCaller.callFor(IEventListener) method.

Parameters:
caller - reference to a class implementing IEventCaller interface.

hasListeners

public boolean hasListeners()
Indicates whether the event provider has still listeners that must be notified.

Returns:
true, if the event provider has listeners


Copyright © 2019. All rights reserved.