Java Code Examples for org.apache.flink.util.ExceptionUtils#rethrow()

The following examples show how to use org.apache.flink.util.ExceptionUtils#rethrow() . 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: TestingJobGraphStore.java    From flink with Apache License 2.0 6 votes vote down vote up
public TestingJobGraphStore build() {
	final TestingJobGraphStore jobGraphStore = new TestingJobGraphStore(
		startConsumer,
		stopRunnable,
		jobIdsFunction,
		recoverJobGraphFunction,
		putJobGraphConsumer,
		removeJobGraphConsumer,
		releaseJobGraphConsumer,
		initialJobGraphs);

	if (startJobGraphStore) {
		try {
			jobGraphStore.start(null);
		} catch (Exception e) {
			ExceptionUtils.rethrow(e);
		}
	}

	return jobGraphStore;
}
 
Example 2
Source File: NettyMessageClientDecoderDelegateTest.java    From flink with Apache License 2.0 6 votes vote down vote up
private List<ByteBuf> partitionBuffer(ByteBuf buffer, int partitionSize) {
	List<ByteBuf> result = new ArrayList<>();

	try {
		int bufferSize = buffer.readableBytes();
		for (int position = 0; position < bufferSize; position += partitionSize) {
			int endPosition = Math.min(position + partitionSize, bufferSize);
			ByteBuf partitionedBuffer = ALLOCATOR.buffer(endPosition - position);
			partitionedBuffer.writeBytes(buffer, position, endPosition - position);
			result.add(partitionedBuffer);
		}
	} catch (Throwable t) {
		releaseBuffers(result.toArray(new ByteBuf[0]));
		ExceptionUtils.rethrow(t);
	}

	return result;
}
 
Example 3
Source File: StreamTaskTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public void run() {
	signalRunLatch.trigger();
	continueRunLatch.countDown();

	try {
		// poor man's barrier because it can happen that the async operations thread gets
		// interrupted by the mail box thread. The CyclicBarrier would in this case fail
		// all participants of the barrier, leaving the future uncompleted
		continueRunLatch.await();
	} catch (InterruptedException e) {
		ExceptionUtils.rethrow(e);
	}

	future.complete(value);
}
 
Example 4
Source File: RemoteInputChannel.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Exclusive buffer is recycled to this input channel directly and it may trigger return extra
 * floating buffer and notify increased credit to the producer.
 *
 * @param segment The exclusive segment of this channel.
 */
@Override
public void recycle(MemorySegment segment) {
	int numAddedBuffers;

	synchronized (bufferQueue) {
		// Similar to notifyBufferAvailable(), make sure that we never add a buffer
		// after releaseAllResources() released all buffers (see below for details).
		if (isReleased.get()) {
			try {
				memorySegmentProvider.recycleMemorySegments(Collections.singletonList(segment));
				return;
			} catch (Throwable t) {
				ExceptionUtils.rethrow(t);
			}
		}
		numAddedBuffers = bufferQueue.addExclusiveBuffer(new NetworkBuffer(segment, this), numRequiredBuffers);
	}

	if (numAddedBuffers > 0 && unannouncedCredit.getAndAdd(numAddedBuffers) == 0) {
		notifyCreditAvailable();
	}
}
 
Example 5
Source File: FunctionUtils.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
/**
 * Convert at {@link FunctionWithException} into a {@link Function}.
 *
 * @param functionWithException function with exception to convert into a function
 * @param <A> input type
 * @param <B> output type
 * @return {@link Function} which throws all checked exception as an unchecked exception.
 */
public static <A, B> Function<A, B> uncheckedFunction(FunctionWithException<A, B, ?> functionWithException) {
	return (A value) -> {
		try {
			return functionWithException.apply(value);
		} catch (Throwable t) {
			ExceptionUtils.rethrow(t);
			// we need this to appease the compiler :-(
			return null;
		}
	};
}
 
Example 6
Source File: RestClient.java    From flink with Apache License 2.0 5 votes vote down vote up
public RestClient(RestClientConfiguration configuration, Executor executor) {
	Preconditions.checkNotNull(configuration);
	this.executor = Preconditions.checkNotNull(executor);
	this.terminationFuture = new CompletableFuture<>();

	final SSLHandlerFactory sslHandlerFactory = configuration.getSslHandlerFactory();
	ChannelInitializer<SocketChannel> initializer = new ChannelInitializer<SocketChannel>() {
		@Override
		protected void initChannel(SocketChannel socketChannel) {
			try {
				// SSL should be the first handler in the pipeline
				if (sslHandlerFactory != null) {
					socketChannel.pipeline().addLast("ssl", sslHandlerFactory.createNettySSLHandler(socketChannel.alloc()));
				}

				socketChannel.pipeline()
					.addLast(new HttpClientCodec())
					.addLast(new HttpObjectAggregator(configuration.getMaxContentLength()))
					.addLast(new ChunkedWriteHandler()) // required for multipart-requests
					.addLast(new IdleStateHandler(configuration.getIdlenessTimeout(), configuration.getIdlenessTimeout(), configuration.getIdlenessTimeout(), TimeUnit.MILLISECONDS))
					.addLast(new ClientHandler());
			} catch (Throwable t) {
				t.printStackTrace();
				ExceptionUtils.rethrow(t);
			}
		}
	};
	NioEventLoopGroup group = new NioEventLoopGroup(1, new ExecutorThreadFactory("flink-rest-client-netty"));

	bootstrap = new Bootstrap();
	bootstrap
		.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, Math.toIntExact(configuration.getConnectionTimeout()))
		.group(group)
		.channel(NioSocketChannel.class)
		.handler(initializer);

	LOG.info("Rest client endpoint started.");
}
 
Example 7
Source File: FunctionUtils.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Converts a {@link ThrowingConsumer} into a {@link Consumer} which throws checked exceptions
 * as unchecked.
 *
 * @param throwingConsumer to convert into a {@link Consumer}
 * @param <A> input type
 * @return {@link Consumer} which throws all checked exceptions as unchecked
 */
public static <A> Consumer<A> uncheckedConsumer(ThrowingConsumer<A, ?> throwingConsumer) {
	return (A value) -> {
		try {
			throwingConsumer.accept(value);
		} catch (Throwable t) {
			ExceptionUtils.rethrow(t);
		}
	};
}
 
Example 8
Source File: BiFunctionWithException.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Convert at {@link BiFunctionWithException} into a {@link BiFunction}.
 *
 * @param biFunctionWithException function with exception to convert into a function
 * @param <A> input type
 * @param <B> output type
 * @return {@link BiFunction} which throws all checked exception as an unchecked exception.
 */
static <A, B, C> BiFunction<A, B, C> unchecked(BiFunctionWithException<A, B, C, ?> biFunctionWithException) {
	return (A a, B b) -> {
		try {
			return biFunctionWithException.apply(a, b);
		} catch (Throwable t) {
			ExceptionUtils.rethrow(t);
			// we need this to appease the compiler :-(
			return null;
		}
	};
}
 
Example 9
Source File: BiConsumerWithException.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Convert a {@link BiConsumerWithException} into a {@link BiConsumer}.
 *
 * @param biConsumerWithException BiConsumer with exception to convert into a {@link BiConsumer}.
 * @param <A> first input type
 * @param <B> second input type
 * @return {@link BiConsumer} which rethrows all checked exceptions as unchecked.
 */
static <A, B> BiConsumer<A, B> unchecked(BiConsumerWithException<A, B, ?> biConsumerWithException) {
	return (A a, B b) -> {
		try {
			biConsumerWithException.accept(a, b);
		} catch (Throwable t) {
			ExceptionUtils.rethrow(t);
		}
	};
}
 
Example 10
Source File: SessionDispatcherLeaderProcess.java    From flink with Apache License 2.0 5 votes vote down vote up
private void stopServices() {
	try {
		jobGraphStore.stop();
	} catch (Exception e) {
		ExceptionUtils.rethrow(e);
	}
}
 
Example 11
Source File: FunctionUtils.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Converts a {@link ThrowingConsumer} into a {@link Consumer} which throws checked exceptions
 * as unchecked.
 *
 * @param throwingConsumer to convert into a {@link Consumer}
 * @param <A> input type
 * @return {@link Consumer} which throws all checked exceptions as unchecked
 */
public static <A> Consumer<A> uncheckedConsumer(ThrowingConsumer<A, ?> throwingConsumer) {
	return (A value) -> {
		try {
			throwingConsumer.accept(value);
		} catch (Throwable t) {
			ExceptionUtils.rethrow(t);
		}
	};
}
 
Example 12
Source File: FunctionUtils.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Convert at {@link FunctionWithException} into a {@link Function}.
 *
 * @param functionWithException function with exception to convert into a function
 * @param <A> input type
 * @param <B> output type
 * @return {@link Function} which throws all checked exception as an unchecked exception.
 */
public static <A, B> Function<A, B> uncheckedFunction(FunctionWithException<A, B, ?> functionWithException) {
	return (A value) -> {
		try {
			return functionWithException.apply(value);
		} catch (Throwable t) {
			ExceptionUtils.rethrow(t);
			// we need this to appease the compiler :-(
			return null;
		}
	};
}
 
Example 13
Source File: FunctionUtils.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Convert at {@link FunctionWithException} into a {@link Function}.
 *
 * @param functionWithException function with exception to convert into a function
 * @param <A> input type
 * @param <B> output type
 * @return {@link Function} which throws all checked exception as an unchecked exception.
 */
public static <A, B> Function<A, B> uncheckedFunction(FunctionWithException<A, B, ?> functionWithException) {
	return (A value) -> {
		try {
			return functionWithException.apply(value);
		} catch (Throwable t) {
			ExceptionUtils.rethrow(t);
			// we need this to appease the compiler :-(
			return null;
		}
	};
}
 
Example 14
Source File: SubtaskCheckpointCoordinatorTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void run() {
	signalRunLatch.trigger();
	countDownLatch.countDown();

	try {
		countDownLatch.await();
	} catch (InterruptedException e) {
		ExceptionUtils.rethrow(e);
	}

	future.complete(value);
}
 
Example 15
Source File: TriFunctionWithException.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Convert at {@link TriFunctionWithException} into a {@link TriFunction}.
 *
 * @param triFunctionWithException function with exception to convert into a function
 * @param <A> first input type
 * @param <B> second input type
 * @param <C> third input type
 * @param <D> output type
 * @return {@link BiFunction} which throws all checked exception as an unchecked exception.
 */
static <A, B, C, D> TriFunction<A, B, C, D> unchecked(TriFunctionWithException<A, B, C, D, ?> triFunctionWithException) {
	return (A a, B b, C c) -> {
		try {
			return triFunctionWithException.apply(a, b, c);
		} catch (Throwable t) {
			ExceptionUtils.rethrow(t);
			// we need this to appease the compiler :-(
			return null;
		}
	};
}
 
Example 16
Source File: RestClient.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
public RestClient(RestClientConfiguration configuration, Executor executor) {
	Preconditions.checkNotNull(configuration);
	this.executor = Preconditions.checkNotNull(executor);
	this.terminationFuture = new CompletableFuture<>();

	final SSLHandlerFactory sslHandlerFactory = configuration.getSslHandlerFactory();
	ChannelInitializer<SocketChannel> initializer = new ChannelInitializer<SocketChannel>() {
		@Override
		protected void initChannel(SocketChannel socketChannel) {
			try {
				// SSL should be the first handler in the pipeline
				if (sslHandlerFactory != null) {
					socketChannel.pipeline().addLast("ssl", sslHandlerFactory.createNettySSLHandler());
				}

				socketChannel.pipeline()
					.addLast(new HttpClientCodec())
					.addLast(new HttpObjectAggregator(configuration.getMaxContentLength()))
					.addLast(new ChunkedWriteHandler()) // required for multipart-requests
					.addLast(new IdleStateHandler(configuration.getIdlenessTimeout(), configuration.getIdlenessTimeout(), configuration.getIdlenessTimeout(), TimeUnit.MILLISECONDS))
					.addLast(new ClientHandler());
			} catch (Throwable t) {
				t.printStackTrace();
				ExceptionUtils.rethrow(t);
			}
		}
	};
	NioEventLoopGroup group = new NioEventLoopGroup(1, new ExecutorThreadFactory("flink-rest-client-netty"));

	bootstrap = new Bootstrap();
	bootstrap
		.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, Math.toIntExact(configuration.getConnectionTimeout()))
		.group(group)
		.channel(NioSocketChannel.class)
		.handler(initializer);

	LOG.info("Rest client endpoint started.");
}
 
Example 17
Source File: BiConsumerWithException.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
/**
 * Convert a {@link BiConsumerWithException} into a {@link BiConsumer}.
 *
 * @param biConsumerWithException BiConsumer with exception to convert into a {@link BiConsumer}.
 * @param <A> first input type
 * @param <B> second input type
 * @return {@link BiConsumer} which rethrows all checked exceptions as unchecked.
 */
static <A, B> BiConsumer<A, B> unchecked(BiConsumerWithException<A, B, ?> biConsumerWithException) {
	return (A a, B b) -> {
		try {
			biConsumerWithException.accept(a, b);
		} catch (Throwable t) {
			ExceptionUtils.rethrow(t);
		}
	};
}
 
Example 18
Source File: BiConsumerWithException.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Convert a {@link BiConsumerWithException} into a {@link BiConsumer}.
 *
 * @param biConsumerWithException BiConsumer with exception to convert into a {@link BiConsumer}.
 * @param <A> first input type
 * @param <B> second input type
 * @return {@link BiConsumer} which rethrows all checked exceptions as unchecked.
 */
static <A, B> BiConsumer<A, B> unchecked(BiConsumerWithException<A, B, ?> biConsumerWithException) {
	return (A a, B b) -> {
		try {
			biConsumerWithException.accept(a, b);
		} catch (Throwable t) {
			ExceptionUtils.rethrow(t);
		}
	};
}
 
Example 19
Source File: JobMasterTest.java    From flink with Apache License 2.0 5 votes vote down vote up
AllocationID takeAllocationId() {
	try {
		return allocationIds.take();
	} catch (InterruptedException e) {
		ExceptionUtils.rethrow(e);
		return null;
	}
}
 
Example 20
Source File: SavepointEnvironment.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public void failExternally(Throwable cause) {
	ExceptionUtils.rethrow(cause);
}