Java Code Examples for org.apache.flink.runtime.io.network.api.TaskEventHandler

The following examples show how to use org.apache.flink.runtime.io.network.api.TaskEventHandler. These examples are extracted from open source projects. 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 Project: Flink-CEPplus   Author: ljygz   File: TaskEventDispatcher.java    License: 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 #2
Source Project: Flink-CEPplus   Author: ljygz   File: TaskEventDispatcher.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Publishes the event to the registered {@link EventListener} instances.
 *
 * <p>This method is either called directly from a {@link LocalInputChannel} or the network I/O
 * thread on behalf of a {@link RemoteInputChannel}.
 *
 * @return whether the event was published to a registered event handler (initiated via {@link
 * #registerPartition(ResultPartitionID)}) or not
 */
public boolean publish(ResultPartitionID partitionId, TaskEvent event) {
	checkNotNull(partitionId);
	checkNotNull(event);

	TaskEventHandler taskEventHandler;
	synchronized (registeredHandlers) {
		taskEventHandler = registeredHandlers.get(partitionId);
	}

	if (taskEventHandler != null) {
		taskEventHandler.publish(event);
		return true;
	}

	return false;
}
 
Example #3
Source Project: Flink-CEPplus   Author: ljygz   File: TaskEventHandlerTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Tests the publish/subscribe mechanisms implemented in the {@link TaskEventHandler}.
 */
@Test
public void testEventNotificationManager() {

	final TaskEventHandler evm = new TaskEventHandler();
	final TestEventListener listener = new TestEventListener();

	evm.subscribe(listener, StringTaskEvent.class);

	final StringTaskEvent stringTaskEvent1 = new StringTaskEvent("Test 1");

	evm.publish(stringTaskEvent1);
	evm.publish(new IntegerTaskEvent(5));

	assertNotNull(listener.getLastReceivedEvent());
	StringTaskEvent receivedStringEvent = (StringTaskEvent) listener.getLastReceivedEvent();
	assertEquals(stringTaskEvent1, receivedStringEvent);
}
 
Example #4
Source Project: flink   Author: flink-tpc-ds   File: TaskEventDispatcher.java    License: 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 #5
Source Project: flink   Author: flink-tpc-ds   File: TaskEventDispatcher.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Publishes the event to the registered {@link EventListener} instances.
 *
 * <p>This method is either called directly from a {@link LocalInputChannel} or the network I/O
 * thread on behalf of a {@link RemoteInputChannel}.
 *
 * @return whether the event was published to a registered event handler (initiated via {@link
 * #registerPartition(ResultPartitionID)}) or not
 */
@Override
public boolean publish(ResultPartitionID partitionId, TaskEvent event) {
	checkNotNull(partitionId);
	checkNotNull(event);

	TaskEventHandler taskEventHandler;
	synchronized (registeredHandlers) {
		taskEventHandler = registeredHandlers.get(partitionId);
	}

	if (taskEventHandler != null) {
		taskEventHandler.publish(event);
		return true;
	}

	return false;
}
 
Example #6
Source Project: flink   Author: flink-tpc-ds   File: TaskEventHandlerTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Tests the publish/subscribe mechanisms implemented in the {@link TaskEventHandler}.
 */
@Test
public void testEventNotificationManager() {

	final TaskEventHandler evm = new TaskEventHandler();
	final TestEventListener listener = new TestEventListener();

	evm.subscribe(listener, StringTaskEvent.class);

	final StringTaskEvent stringTaskEvent1 = new StringTaskEvent("Test 1");

	evm.publish(stringTaskEvent1);
	evm.publish(new IntegerTaskEvent(5));

	assertNotNull(listener.getLastReceivedEvent());
	StringTaskEvent receivedStringEvent = (StringTaskEvent) listener.getLastReceivedEvent();
	assertEquals(stringTaskEvent1, receivedStringEvent);
}
 
Example #7
Source Project: flink   Author: apache   File: TaskEventDispatcher.java    License: 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 #8
Source Project: flink   Author: apache   File: TaskEventDispatcher.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Publishes the event to the registered {@link EventListener} instances.
 *
 * <p>This method is either called directly from a {@link LocalInputChannel} or the network I/O
 * thread on behalf of a {@link RemoteInputChannel}.
 *
 * @return whether the event was published to a registered event handler (initiated via {@link
 * #registerPartition(ResultPartitionID)}) or not
 */
@Override
public boolean publish(ResultPartitionID partitionId, TaskEvent event) {
	checkNotNull(partitionId);
	checkNotNull(event);

	TaskEventHandler taskEventHandler;
	synchronized (registeredHandlers) {
		taskEventHandler = registeredHandlers.get(partitionId);
	}

	if (taskEventHandler != null) {
		taskEventHandler.publish(event);
		return true;
	}

	return false;
}
 
Example #9
Source Project: flink   Author: apache   File: TaskEventHandlerTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Tests the publish/subscribe mechanisms implemented in the {@link TaskEventHandler}.
 */
@Test
public void testEventNotificationManager() {

	final TaskEventHandler evm = new TaskEventHandler();
	final TestEventListener listener = new TestEventListener();

	evm.subscribe(listener, StringTaskEvent.class);

	final StringTaskEvent stringTaskEvent1 = new StringTaskEvent("Test 1");

	evm.publish(stringTaskEvent1);
	evm.publish(new IntegerTaskEvent(5));

	assertNotNull(listener.getLastReceivedEvent());
	StringTaskEvent receivedStringEvent = (StringTaskEvent) listener.getLastReceivedEvent();
	assertEquals(stringTaskEvent1, receivedStringEvent);
}
 
Example #10
Source Project: Flink-CEPplus   Author: ljygz   File: TaskEventDispatcher.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Registers the given partition for incoming task events allowing calls to {@link
 * #subscribeToEvent(ResultPartitionID, EventListener, Class)}.
 *
 * @param partitionId
 * 		the partition ID
 */
public void registerPartition(ResultPartitionID partitionId) {
	checkNotNull(partitionId);

	synchronized (registeredHandlers) {
		LOG.debug("registering {}", partitionId);
		if (registeredHandlers.put(partitionId, new TaskEventHandler()) != null) {
			throw new IllegalStateException(
				"Partition " + partitionId + " already registered at task event dispatcher.");
		}
	}
}
 
Example #11
Source Project: flink   Author: flink-tpc-ds   File: TaskEventDispatcher.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Registers the given partition for incoming task events allowing calls to {@link
 * #subscribeToEvent(ResultPartitionID, EventListener, Class)}.
 *
 * @param partitionId
 * 		the partition ID
 */
public void registerPartition(ResultPartitionID partitionId) {
	checkNotNull(partitionId);

	synchronized (registeredHandlers) {
		LOG.debug("registering {}", partitionId);
		if (registeredHandlers.put(partitionId, new TaskEventHandler()) != null) {
			throw new IllegalStateException(
				"Partition " + partitionId + " already registered at task event dispatcher.");
		}
	}
}
 
Example #12
Source Project: flink   Author: apache   File: TaskEventDispatcher.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Registers the given partition for incoming task events allowing calls to {@link
 * #subscribeToEvent(ResultPartitionID, EventListener, Class)}.
 *
 * @param partitionId
 * 		the partition ID
 */
public void registerPartition(ResultPartitionID partitionId) {
	checkNotNull(partitionId);

	synchronized (registeredHandlers) {
		LOG.debug("registering {}", partitionId);
		if (registeredHandlers.put(partitionId, new TaskEventHandler()) != null) {
			throw new IllegalStateException(
				"Partition " + partitionId + " already registered at task event dispatcher.");
		}
	}
}