Java Code Examples for org.apache.flink.runtime.concurrent.ScheduledExecutor#schedule()

The following examples show how to use org.apache.flink.runtime.concurrent.ScheduledExecutor#schedule() . 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: HeartbeatManagerSenderImpl.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
HeartbeatManagerSenderImpl(
		long heartbeatPeriod,
		long heartbeatTimeout,
		ResourceID ownResourceID,
		HeartbeatListener<I, O> heartbeatListener,
		ScheduledExecutor mainThreadExecutor,
		Logger log) {
	super(
		heartbeatTimeout,
		ownResourceID,
		heartbeatListener,
		mainThreadExecutor,
		log);

	this.heartbeatPeriod = heartbeatPeriod;
	mainThreadExecutor.schedule(this, 0L, TimeUnit.MILLISECONDS);
}
 
Example 2
Source File: AkkaRpcServiceTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
/**
 * Tests a simple scheduled runnable being executed by the RPC services scheduled executor
 * service.
 */
@Test(timeout = 60000)
public void testScheduledExecutorServiceSimpleSchedule() throws Exception {
	ScheduledExecutor scheduledExecutor = akkaRpcService.getScheduledExecutor();

	final OneShotLatch latch = new OneShotLatch();

	ScheduledFuture<?> future = scheduledExecutor.schedule(
		latch::trigger,
		10L,
		TimeUnit.MILLISECONDS);

	future.get();

	// once the future is completed, then the latch should have been triggered
	assertTrue(latch.isTriggered());
}
 
Example 3
Source File: HeartbeatManagerSenderImpl.java    From flink with Apache License 2.0 6 votes vote down vote up
HeartbeatManagerSenderImpl(
		long heartbeatPeriod,
		long heartbeatTimeout,
		ResourceID ownResourceID,
		HeartbeatListener<I, O> heartbeatListener,
		ScheduledExecutor mainThreadExecutor,
		Logger log) {
	super(
		heartbeatTimeout,
		ownResourceID,
		heartbeatListener,
		mainThreadExecutor,
		log);

	this.heartbeatPeriod = heartbeatPeriod;
	mainThreadExecutor.schedule(this, 0L, TimeUnit.MILLISECONDS);
}
 
Example 4
Source File: AkkaRpcServiceTest.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Tests a simple scheduled runnable being executed by the RPC services scheduled executor
 * service.
 */
@Test(timeout = 60000)
public void testScheduledExecutorServiceSimpleSchedule() throws Exception {
	ScheduledExecutor scheduledExecutor = akkaRpcService.getScheduledExecutor();

	final OneShotLatch latch = new OneShotLatch();

	ScheduledFuture<?> future = scheduledExecutor.schedule(
		latch::trigger,
		10L,
		TimeUnit.MILLISECONDS);

	future.get();

	// once the future is completed, then the latch should have been triggered
	assertTrue(latch.isTriggered());
}
 
Example 5
Source File: HeartbeatManagerSenderImpl.java    From flink with Apache License 2.0 6 votes vote down vote up
HeartbeatManagerSenderImpl(
		long heartbeatPeriod,
		long heartbeatTimeout,
		ResourceID ownResourceID,
		HeartbeatListener<I, O> heartbeatListener,
		ScheduledExecutor mainThreadExecutor,
		Logger log,
		HeartbeatMonitor.Factory<O> heartbeatMonitorFactory) {
	super(
		heartbeatTimeout,
		ownResourceID,
		heartbeatListener,
		mainThreadExecutor,
		log,
		heartbeatMonitorFactory);

	this.heartbeatPeriod = heartbeatPeriod;
	mainThreadExecutor.schedule(this, 0L, TimeUnit.MILLISECONDS);
}
 
Example 6
Source File: AkkaRpcServiceTest.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Tests a simple scheduled runnable being executed by the RPC services scheduled executor
 * service.
 */
@Test(timeout = 60000)
public void testScheduledExecutorServiceSimpleSchedule() throws Exception {
	ScheduledExecutor scheduledExecutor = akkaRpcService.getScheduledExecutor();

	final OneShotLatch latch = new OneShotLatch();

	ScheduledFuture<?> future = scheduledExecutor.schedule(
		latch::trigger,
		10L,
		TimeUnit.MILLISECONDS);

	future.get();

	// once the future is completed, then the latch should have been triggered
	assertTrue(latch.isTriggered());
}
 
Example 7
Source File: ApplicationDispatcherBootstrap.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Runs the user program entrypoint by scheduling a task on the given {@code scheduledExecutor}.
 * The returned {@link CompletableFuture} completes when all jobs of the user application
 * succeeded. if any of them fails, or if job submission fails.
 */
private CompletableFuture<Void> runApplicationAsync(
		final DispatcherGateway dispatcher,
		final ScheduledExecutor scheduledExecutor,
		final boolean enforceSingleJobExecution) {
	final CompletableFuture<List<JobID>> applicationExecutionFuture = new CompletableFuture<>();

	// we need to hand in a future as return value because we need to get those JobIs out
	// from the scheduled task that executes the user program
	applicationExecutionTask = scheduledExecutor.schedule(
			() -> runApplicationEntryPoint(
					applicationExecutionFuture,
					dispatcher,
					scheduledExecutor,
					enforceSingleJobExecution),
			0L,
			TimeUnit.MILLISECONDS);

	return applicationExecutionFuture.thenCompose(
			jobIds -> getApplicationResult(dispatcher, jobIds, scheduledExecutor));
}
 
Example 8
Source File: FailureRateRestartStrategy.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public void restart(final RestartCallback restarter, ScheduledExecutor executor) {
	if (isRestartTimestampsQueueFull()) {
		restartTimestampsDeque.remove();
	}
	restartTimestampsDeque.add(System.currentTimeMillis());

	executor.schedule(new Runnable() {
		@Override
		public void run() {
			restarter.triggerFullRecovery();
		}
	}, delayInterval.getSize(), delayInterval.getUnit());
}
 
Example 9
Source File: FixedDelayRestartStrategy.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
public void restart(final RestartCallback restarter, ScheduledExecutor executor) {
	currentRestartAttempt++;
	executor.schedule(restarter::triggerFullRecovery, delayBetweenRestartAttempts, TimeUnit.MILLISECONDS);
}