org.apache.flink.util.LambdaUtil Java Examples

The following examples show how to use org.apache.flink.util.LambdaUtil. 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: MasterHooks.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public CompletableFuture<T> triggerCheckpoint(long checkpointId, long timestamp, final Executor executor) throws Exception {
	final Executor wrappedExecutor = new Executor() {
		@Override
		public void execute(Runnable command) {
			executor.execute(new WrappedCommand(userClassLoader, command));
		}
	};

	return LambdaUtil.withContextClassLoader(
			userClassLoader,
			() -> hook.triggerCheckpoint(checkpointId, timestamp, wrappedExecutor));
}
 
Example #2
Source File: MasterHooks.java    From flink with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public CompletableFuture<T> triggerCheckpoint(long checkpointId, long timestamp, final Executor executor) throws Exception {
	final Executor wrappedExecutor = command -> executor.execute(new WrappedCommand(userClassLoader, command));

	return LambdaUtil.withContextClassLoader(
			userClassLoader,
			() -> hook.triggerCheckpoint(checkpointId, timestamp, wrappedExecutor));
}
 
Example #3
Source File: SavepointOutputFormat.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void writeRecord(Savepoint savepoint) throws IOException {
	String path = LambdaUtil.withContextClassLoader(getRuntimeContext().getUserCodeClassLoader(), () -> {
			try (CheckpointMetadataOutputStream out = targetLocation.createMetadataOutputStream()) {
				Checkpoints.storeCheckpointMetadata(savepoint, out);
				CompletedCheckpointStorageLocation finalizedLocation = out.closeAndFinalizeCheckpoint();
				return finalizedLocation.getExternalPointer();
			}
	});

	LOG.info("Savepoint written to " + path);
}
 
Example #4
Source File: SavepointOutputFormat.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void writeRecord(CheckpointMetadata metadata) throws IOException {
	String path = LambdaUtil.withContextClassLoader(getRuntimeContext().getUserCodeClassLoader(), () -> {
			try (CheckpointMetadataOutputStream out = targetLocation.createMetadataOutputStream()) {
				Checkpoints.storeCheckpointMetadata(metadata, out);
				CompletedCheckpointStorageLocation finalizedLocation = out.closeAndFinalizeCheckpoint();
				return finalizedLocation.getExternalPointer();
			}
	});

	LOG.info("Savepoint written to " + path);
}
 
Example #5
Source File: MasterHooks.java    From flink with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public CompletableFuture<T> triggerCheckpoint(long checkpointId, long timestamp, final Executor executor) throws Exception {
	final Executor wrappedExecutor = new Executor() {
		@Override
		public void execute(Runnable command) {
			executor.execute(new WrappedCommand(userClassLoader, command));
		}
	};

	return LambdaUtil.withContextClassLoader(
			userClassLoader,
			() -> hook.triggerCheckpoint(checkpointId, timestamp, wrappedExecutor));
}
 
Example #6
Source File: MasterHooks.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
public void close() throws Exception {
	LambdaUtil.withContextClassLoader(userClassLoader, hook::close);
}
 
Example #7
Source File: MasterHooks.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public void run() {
	LambdaUtil.withContextClassLoader(userClassLoader, command::run);
}
 
Example #8
Source File: MasterHooks.java    From flink with Apache License 2.0 4 votes vote down vote up
@Nullable
@Override
public SimpleVersionedSerializer<T> createCheckpointDataSerializer() {
	return LambdaUtil.withContextClassLoader(userClassLoader, hook::createCheckpointDataSerializer);
}
 
Example #9
Source File: MasterHooks.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public void restoreCheckpoint(long checkpointId, @Nullable T checkpointData) throws Exception {
	LambdaUtil.withContextClassLoader(
			userClassLoader,
			() -> hook.restoreCheckpoint(checkpointId, checkpointData));
}
 
Example #10
Source File: MasterHooks.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public String getIdentifier() {
	return LambdaUtil.withContextClassLoader(userClassLoader, hook::getIdentifier);
}
 
Example #11
Source File: MasterHooks.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public void close() throws Exception {
	LambdaUtil.withContextClassLoader(userClassLoader, hook::close);
}
 
Example #12
Source File: MasterHooks.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public void reset() throws Exception {
	LambdaUtil.withContextClassLoader(userClassLoader, hook::reset);
}
 
Example #13
Source File: MasterHooks.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public void run() {
	LambdaUtil.withContextClassLoader(userClassLoader, command::run);
}
 
Example #14
Source File: MasterHooks.java    From flink with Apache License 2.0 4 votes vote down vote up
@Nullable
@Override
public SimpleVersionedSerializer<T> createCheckpointDataSerializer() {
	return LambdaUtil.withContextClassLoader(userClassLoader, hook::createCheckpointDataSerializer);
}
 
Example #15
Source File: MasterHooks.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public void restoreCheckpoint(long checkpointId, @Nullable T checkpointData) throws Exception {
	LambdaUtil.withContextClassLoader(
			userClassLoader,
			() -> hook.restoreCheckpoint(checkpointId, checkpointData));
}
 
Example #16
Source File: MasterHooks.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public String getIdentifier() {
	return LambdaUtil.withContextClassLoader(userClassLoader, hook::getIdentifier);
}
 
Example #17
Source File: MasterHooks.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public void close() throws Exception {
	LambdaUtil.withContextClassLoader(userClassLoader, hook::close);
}
 
Example #18
Source File: MasterHooks.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public void reset() throws Exception {
	LambdaUtil.withContextClassLoader(userClassLoader, hook::reset);
}
 
Example #19
Source File: MasterHooks.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
public void run() {
	LambdaUtil.withContextClassLoader(userClassLoader, command::run);
}
 
Example #20
Source File: MasterHooks.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Nullable
@Override
public SimpleVersionedSerializer<T> createCheckpointDataSerializer() {
	return LambdaUtil.withContextClassLoader(userClassLoader, hook::createCheckpointDataSerializer);
}
 
Example #21
Source File: MasterHooks.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
public void restoreCheckpoint(long checkpointId, @Nullable T checkpointData) throws Exception {
	LambdaUtil.withContextClassLoader(
			userClassLoader,
			() -> hook.restoreCheckpoint(checkpointId, checkpointData));
}
 
Example #22
Source File: MasterHooks.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
public String getIdentifier() {
	return LambdaUtil.withContextClassLoader(userClassLoader, hook::getIdentifier);
}
 
Example #23
Source File: MasterHooks.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
public void reset() throws Exception {
	LambdaUtil.withContextClassLoader(userClassLoader, hook::reset);
}
 
Example #24
Source File: StateUtil.java    From flink with Apache License 2.0 2 votes vote down vote up
/**
 * Iterates through the passed state handles and calls discardState() on each handle that is not null. All
 * occurring exceptions are suppressed and collected until the iteration is over and emitted as a single exception.
 *
 * @param handlesToDiscard State handles to discard. Passed iterable is allowed to deliver null values.
 * @throws Exception exception that is a collection of all suppressed exceptions that were caught during iteration
 */
public static void bestEffortDiscardAllStateObjects(
	Iterable<? extends StateObject> handlesToDiscard) throws Exception {
	LambdaUtil.applyToAllWhileSuppressingExceptions(handlesToDiscard, StateObject::discardState);
}
 
Example #25
Source File: StateUtil.java    From Flink-CEPplus with Apache License 2.0 2 votes vote down vote up
/**
 * Iterates through the passed state handles and calls discardState() on each handle that is not null. All
 * occurring exceptions are suppressed and collected until the iteration is over and emitted as a single exception.
 *
 * @param handlesToDiscard State handles to discard. Passed iterable is allowed to deliver null values.
 * @throws Exception exception that is a collection of all suppressed exceptions that were caught during iteration
 */
public static void bestEffortDiscardAllStateObjects(
	Iterable<? extends StateObject> handlesToDiscard) throws Exception {
	LambdaUtil.applyToAllWhileSuppressingExceptions(handlesToDiscard, StateObject::discardState);
}
 
Example #26
Source File: StateUtil.java    From flink with Apache License 2.0 2 votes vote down vote up
/**
 * Iterates through the passed state handles and calls discardState() on each handle that is not null. All
 * occurring exceptions are suppressed and collected until the iteration is over and emitted as a single exception.
 *
 * @param handlesToDiscard State handles to discard. Passed iterable is allowed to deliver null values.
 * @throws Exception exception that is a collection of all suppressed exceptions that were caught during iteration
 */
public static void bestEffortDiscardAllStateObjects(
	Iterable<? extends StateObject> handlesToDiscard) throws Exception {
	LambdaUtil.applyToAllWhileSuppressingExceptions(handlesToDiscard, StateObject::discardState);
}