org.apache.flink.runtime.util.event.EventListener Java Examples

The following examples show how to use org.apache.flink.runtime.util.event.EventListener. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractReaderTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
@SuppressWarnings("unchecked")
public void testTaskEvent() throws Exception {
	final AbstractReader reader = new MockReader(createInputGate(1));

	final EventListener<TaskEvent> listener1 = mock(EventListener.class);
	final EventListener<TaskEvent> listener2 = mock(EventListener.class);
	final EventListener<TaskEvent> listener3 = mock(EventListener.class);

	reader.registerTaskEventListener(listener1, TestTaskEvent1.class);
	reader.registerTaskEventListener(listener2, TestTaskEvent2.class);
	reader.registerTaskEventListener(listener3, TaskEvent.class);

	reader.handleEvent(new TestTaskEvent1()); // for listener1 only
	reader.handleEvent(new TestTaskEvent2()); // for listener2 only

	verify(listener1, times(1)).onEvent(Matchers.any(TaskEvent.class));
	verify(listener2, times(1)).onEvent(Matchers.any(TaskEvent.class));
	verify(listener3, times(0)).onEvent(Matchers.any(TaskEvent.class));
}
 
Example #2
Source File: TaskEventDispatcher.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Subscribes a listener to this dispatcher for events on a partition.
 *
 * @param partitionId
 * 		ID of the partition to subscribe for (must be registered via {@link
 * 		#registerPartition(ResultPartitionID)} first!)
 * @param eventListener
 * 		the event listener to subscribe
 * @param eventType
 * 		event type to subscribe to
 */
public void subscribeToEvent(
		ResultPartitionID partitionId,
		EventListener<TaskEvent> eventListener,
		Class<? extends TaskEvent> eventType) {
	checkNotNull(partitionId);
	checkNotNull(eventListener);
	checkNotNull(eventType);

	TaskEventHandler taskEventHandler;
	synchronized (registeredHandlers) {
		taskEventHandler = registeredHandlers.get(partitionId);
	}
	if (taskEventHandler == null) {
		throw new IllegalStateException(
			"Partition " + partitionId + " not registered at task event dispatcher.");
	}
	taskEventHandler.subscribe(eventListener, eventType);
}
 
Example #3
Source File: TaskEventDispatcher.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
/**
 * Subscribes a listener to this dispatcher for events on a partition.
 *
 * @param partitionId
 * 		ID of the partition to subscribe for (must be registered via {@link
 * 		#registerPartition(ResultPartitionID)} first!)
 * @param eventListener
 * 		the event listener to subscribe
 * @param eventType
 * 		event type to subscribe to
 */
public void subscribeToEvent(
		ResultPartitionID partitionId,
		EventListener<TaskEvent> eventListener,
		Class<? extends TaskEvent> eventType) {
	checkNotNull(partitionId);
	checkNotNull(eventListener);
	checkNotNull(eventType);

	TaskEventHandler taskEventHandler;
	synchronized (registeredHandlers) {
		taskEventHandler = registeredHandlers.get(partitionId);
	}
	if (taskEventHandler == null) {
		throw new IllegalStateException(
			"Partition " + partitionId + " not registered at task event dispatcher.");
	}
	taskEventHandler.subscribe(eventListener, eventType);
}
 
Example #4
Source File: AbstractReaderTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Test
@SuppressWarnings("unchecked")
public void testTaskEvent() throws Exception {
	final AbstractReader reader = new MockReader(createInputGate(1));

	final EventListener<TaskEvent> listener1 = mock(EventListener.class);
	final EventListener<TaskEvent> listener2 = mock(EventListener.class);
	final EventListener<TaskEvent> listener3 = mock(EventListener.class);

	reader.registerTaskEventListener(listener1, TestTaskEvent1.class);
	reader.registerTaskEventListener(listener2, TestTaskEvent2.class);
	reader.registerTaskEventListener(listener3, TaskEvent.class);

	reader.handleEvent(new TestTaskEvent1()); // for listener1 only
	reader.handleEvent(new TestTaskEvent2()); // for listener2 only

	verify(listener1, times(1)).onEvent(Matchers.any(TaskEvent.class));
	verify(listener2, times(1)).onEvent(Matchers.any(TaskEvent.class));
	verify(listener3, times(0)).onEvent(Matchers.any(TaskEvent.class));
}
 
Example #5
Source File: AbstractReaderTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
@SuppressWarnings("unchecked")
public void testTaskEvent() throws Exception {
	final AbstractReader reader = new MockReader(createInputGate(1));

	final EventListener<TaskEvent> listener1 = mock(EventListener.class);
	final EventListener<TaskEvent> listener2 = mock(EventListener.class);
	final EventListener<TaskEvent> listener3 = mock(EventListener.class);

	reader.registerTaskEventListener(listener1, TestTaskEvent1.class);
	reader.registerTaskEventListener(listener2, TestTaskEvent2.class);
	reader.registerTaskEventListener(listener3, TaskEvent.class);

	reader.handleEvent(new TestTaskEvent1()); // for listener1 only
	reader.handleEvent(new TestTaskEvent2()); // for listener2 only

	verify(listener1, times(1)).onEvent(Matchers.any(TaskEvent.class));
	verify(listener2, times(1)).onEvent(Matchers.any(TaskEvent.class));
	verify(listener3, times(0)).onEvent(Matchers.any(TaskEvent.class));
}
 
Example #6
Source File: TaskEventDispatcher.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Subscribes a listener to this dispatcher for events on a partition.
 *
 * @param partitionId
 * 		ID of the partition to subscribe for (must be registered via {@link
 * 		#registerPartition(ResultPartitionID)} first!)
 * @param eventListener
 * 		the event listener to subscribe
 * @param eventType
 * 		event type to subscribe to
 */
public void subscribeToEvent(
		ResultPartitionID partitionId,
		EventListener<TaskEvent> eventListener,
		Class<? extends TaskEvent> eventType) {
	checkNotNull(partitionId);
	checkNotNull(eventListener);
	checkNotNull(eventType);

	TaskEventHandler taskEventHandler;
	synchronized (registeredHandlers) {
		taskEventHandler = registeredHandlers.get(partitionId);
	}
	if (taskEventHandler == null) {
		throw new IllegalStateException(
			"Partition " + partitionId + " not registered at task event dispatcher.");
	}
	taskEventHandler.subscribe(eventListener, eventType);
}
 
Example #7
Source File: TaskEventHandler.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
/**
 * Publishes the task event to all subscribed event listeners.
 *
 * @param event The event to publish.
 */
public void publish(TaskEvent event) {
	synchronized (listeners) {
		for (EventListener<TaskEvent> listener : listeners.get(event.getClass())) {
			listener.onEvent(event);
		}
	}
}
 
Example #8
Source File: TaskEventHandler.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Publishes the task event to all subscribed event listeners.
 *
 * @param event The event to publish.
 */
public void publish(TaskEvent event) {
	synchronized (listeners) {
		for (EventListener<TaskEvent> listener : listeners.get(event.getClass())) {
			listener.onEvent(event);
		}
	}
}
 
Example #9
Source File: TaskEventHandler.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Publishes the task event to all subscribed event listeners.
 *
 * @param event The event to publish.
 */
public void publish(TaskEvent event) {
	synchronized (listeners) {
		for (EventListener<TaskEvent> listener : listeners.get(event.getClass())) {
			listener.onEvent(event);
		}
	}
}
 
Example #10
Source File: AbstractReader.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public void registerTaskEventListener(EventListener<TaskEvent> listener, Class<? extends TaskEvent> eventType) {
	taskEventHandler.subscribe(listener, eventType);
}
 
Example #11
Source File: TaskEventHandler.java    From flink with Apache License 2.0 4 votes vote down vote up
public void subscribe(EventListener<TaskEvent> listener, Class<? extends TaskEvent> eventType) {
	synchronized (listeners) {
		listeners.put(eventType, listener);
	}
}
 
Example #12
Source File: TaskEventHandler.java    From flink with Apache License 2.0 4 votes vote down vote up
public void subscribe(EventListener<TaskEvent> listener, Class<? extends TaskEvent> eventType) {
	synchronized (listeners) {
		listeners.put(eventType, listener);
	}
}
 
Example #13
Source File: AbstractReader.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public void registerTaskEventListener(EventListener<TaskEvent> listener, Class<? extends TaskEvent> eventType) {
	taskEventHandler.subscribe(listener, eventType);
}
 
Example #14
Source File: AbstractReader.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
public void registerTaskEventListener(EventListener<TaskEvent> listener, Class<? extends TaskEvent> eventType) {
	taskEventHandler.subscribe(listener, eventType);
}
 
Example #15
Source File: TaskEventHandler.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
public void subscribe(EventListener<TaskEvent> listener, Class<? extends TaskEvent> eventType) {
	synchronized (listeners) {
		listeners.put(eventType, listener);
	}
}
 
Example #16
Source File: ReaderBase.java    From flink with Apache License 2.0 votes vote down vote up
void registerTaskEventListener(EventListener<TaskEvent> listener, Class<? extends TaskEvent> eventType); 
Example #17
Source File: ReaderBase.java    From Flink-CEPplus with Apache License 2.0 votes vote down vote up
void registerTaskEventListener(EventListener<TaskEvent> listener, Class<? extends TaskEvent> eventType); 
Example #18
Source File: ReaderBase.java    From flink with Apache License 2.0 votes vote down vote up
void registerTaskEventListener(EventListener<TaskEvent> listener, Class<? extends TaskEvent> eventType);