org.apache.flink.util.function.ThrowingConsumer Java Examples
The following examples show how to use
org.apache.flink.util.function.ThrowingConsumer.
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: LambdaUtil.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
/** * This method supplies all elements from the input to the consumer. Exceptions that happen on elements are * suppressed until all elements are processed. If exceptions happened for one or more of the inputs, they are * reported in a combining suppressed exception. * * @param inputs iterator for all inputs to the throwingConsumer. * @param throwingConsumer this consumer will be called for all elements delivered by the input iterator. * @param <T> the type of input. * @throws Exception collected exceptions that happened during the invocation of the consumer on the input elements. */ public static <T> void applyToAllWhileSuppressingExceptions( Iterable<T> inputs, ThrowingConsumer<T, ? extends Exception> throwingConsumer) throws Exception { if (inputs != null && throwingConsumer != null) { Exception exception = null; for (T input : inputs) { if (input != null) { try { throwingConsumer.accept(input); } catch (Exception ex) { exception = ExceptionUtils.firstOrSuppressed(ex, exception); } } } if (exception != null) { throw exception; } } }
Example #2
Source File: LambdaUtil.java From flink with Apache License 2.0 | 6 votes |
/** * This method supplies all elements from the input to the consumer. Exceptions that happen on elements are * suppressed until all elements are processed. If exceptions happened for one or more of the inputs, they are * reported in a combining suppressed exception. * * @param inputs iterator for all inputs to the throwingConsumer. * @param throwingConsumer this consumer will be called for all elements delivered by the input iterator. * @param <T> the type of input. * @throws Exception collected exceptions that happened during the invocation of the consumer on the input elements. */ public static <T> void applyToAllWhileSuppressingExceptions( Iterable<T> inputs, ThrowingConsumer<T, ? extends Exception> throwingConsumer) throws Exception { if (inputs != null && throwingConsumer != null) { Exception exception = null; for (T input : inputs) { if (input != null) { try { throwingConsumer.accept(input); } catch (Exception ex) { exception = ExceptionUtils.firstOrSuppressed(ex, exception); } } } if (exception != null) { throw exception; } } }
Example #3
Source File: ConfigOptionsDocGenerator.java From flink with Apache License 2.0 | 6 votes |
@VisibleForTesting static void processConfigOptions(String rootDir, String module, String packageName, String pathPrefix, ThrowingConsumer<Class<?>, IOException> classConsumer) throws IOException, ClassNotFoundException { Path configDir = Paths.get(rootDir, module, pathPrefix, packageName.replaceAll("\\.", "/")); try (DirectoryStream<Path> stream = Files.newDirectoryStream(configDir)) { for (Path entry : stream) { String fileName = entry.getFileName().toString(); Matcher matcher = CLASS_NAME_PATTERN.matcher(fileName); if (matcher.matches()) { final String className = packageName + '.' + matcher.group(CLASS_NAME_GROUP); if (!EXCLUSIONS.contains(className)) { Class<?> optionsClass = Class.forName(className); classConsumer.accept(optionsClass); } } } } }
Example #4
Source File: AbstractTtlDecorator.java From flink with Apache License 2.0 | 6 votes |
<SE extends Throwable, CE extends Throwable, CLE extends Throwable, V> TtlValue<V> getWrappedWithTtlCheckAndUpdate( SupplierWithException<TtlValue<V>, SE> getter, ThrowingConsumer<TtlValue<V>, CE> updater, ThrowingRunnable<CLE> stateClear) throws SE, CE, CLE { TtlValue<V> ttlValue = getter.get(); if (ttlValue == null) { return null; } else if (expired(ttlValue)) { stateClear.run(); if (!returnExpired) { return null; } } else if (updateTsOnRead) { updater.accept(rewrapWithNewTs(ttlValue)); } return ttlValue; }
Example #5
Source File: AbstractTtlDecorator.java From flink with Apache License 2.0 | 6 votes |
<SE extends Throwable, CE extends Throwable, CLE extends Throwable, V> TtlValue<V> getWrappedWithTtlCheckAndUpdate( SupplierWithException<TtlValue<V>, SE> getter, ThrowingConsumer<TtlValue<V>, CE> updater, ThrowingRunnable<CLE> stateClear) throws SE, CE, CLE { TtlValue<V> ttlValue = getter.get(); if (ttlValue == null) { return null; } else if (expired(ttlValue)) { stateClear.run(); if (!returnExpired) { return null; } } else if (updateTsOnRead) { updater.accept(rewrapWithNewTs(ttlValue)); } return ttlValue; }
Example #6
Source File: SessionDispatcherLeaderProcessTest.java From flink with Apache License 2.0 | 6 votes |
private void runOnAddedJobGraphTest(TestingDispatcherGateway dispatcherGateway, ThrowingConsumer<TestingFatalErrorHandler, Exception> verificationLogic) throws Exception { jobGraphStore = TestingJobGraphStore.newBuilder() .setInitialJobGraphs(Collections.singleton(JOB_GRAPH)) .build(); dispatcherServiceFactory = TestingDispatcherServiceFactory.newBuilder() .setCreateFunction((dispatcherId, jobGraphs, jobGraphWriter) -> { assertThat(jobGraphs, containsInAnyOrder(JOB_GRAPH)); return TestingDispatcherGatewayService.newBuilder() .setDispatcherGateway(dispatcherGateway) .build(); }) .build(); try (final SessionDispatcherLeaderProcess dispatcherLeaderProcess = createDispatcherLeaderProcess()) { dispatcherLeaderProcess.start(); dispatcherLeaderProcess.getDispatcherGateway().get(); dispatcherLeaderProcess.onAddedJobGraph(JOB_GRAPH.getJobID()); verificationLogic.accept(fatalErrorHandler); } }
Example #7
Source File: LambdaUtil.java From flink with Apache License 2.0 | 6 votes |
/** * This method supplies all elements from the input to the consumer. Exceptions that happen on elements are * suppressed until all elements are processed. If exceptions happened for one or more of the inputs, they are * reported in a combining suppressed exception. * * @param inputs iterator for all inputs to the throwingConsumer. * @param throwingConsumer this consumer will be called for all elements delivered by the input iterator. * @param <T> the type of input. * @throws Exception collected exceptions that happened during the invocation of the consumer on the input elements. */ public static <T> void applyToAllWhileSuppressingExceptions( Iterable<T> inputs, ThrowingConsumer<T, ? extends Exception> throwingConsumer) throws Exception { if (inputs != null && throwingConsumer != null) { Exception exception = null; for (T input : inputs) { if (input != null) { try { throwingConsumer.accept(input); } catch (Exception ex) { exception = ExceptionUtils.firstOrSuppressed(ex, exception); } } } if (exception != null) { throw exception; } } }
Example #8
Source File: ConfigOptionsDocGenerator.java From flink with Apache License 2.0 | 6 votes |
static void processConfigOptions(String rootDir, String module, String packageName, String pathPrefix, ThrowingConsumer<Class<?>, IOException> classConsumer) throws IOException, ClassNotFoundException { Path configDir = Paths.get(rootDir, module, pathPrefix, packageName.replaceAll("\\.", "/")); try (DirectoryStream<Path> stream = Files.newDirectoryStream(configDir)) { for (Path entry : stream) { String fileName = entry.getFileName().toString(); Matcher matcher = CLASS_NAME_PATTERN.matcher(fileName); if (matcher.matches()) { final String className = packageName + '.' + matcher.group(CLASS_NAME_GROUP); if (!EXCLUSIONS.contains(className)) { Class<?> optionsClass = Class.forName(className); classConsumer.accept(optionsClass); } } } } }
Example #9
Source File: TestingJobGraphStore.java From flink with Apache License 2.0 | 6 votes |
private TestingJobGraphStore( ThrowingConsumer<JobGraphListener, ? extends Exception> startConsumer, ThrowingRunnable<? extends Exception> stopRunnable, FunctionWithException<Collection<JobID>, Collection<JobID>, ? extends Exception> jobIdsFunction, BiFunctionWithException<JobID, Map<JobID, JobGraph>, JobGraph, ? extends Exception> recoverJobGraphFunction, ThrowingConsumer<JobGraph, ? extends Exception> putJobGraphConsumer, ThrowingConsumer<JobID, ? extends Exception> removeJobGraphConsumer, ThrowingConsumer<JobID, ? extends Exception> releaseJobGraphConsumer, Collection<JobGraph> initialJobGraphs) { this.startConsumer = startConsumer; this.stopRunnable = stopRunnable; this.jobIdsFunction = jobIdsFunction; this.recoverJobGraphFunction = recoverJobGraphFunction; this.putJobGraphConsumer = putJobGraphConsumer; this.removeJobGraphConsumer = removeJobGraphConsumer; this.releaseJobGraphConsumer = releaseJobGraphConsumer; for (JobGraph initialJobGraph : initialJobGraphs) { storedJobs.put(initialJobGraph.getJobID(), initialJobGraph); } }
Example #10
Source File: AbstractTtlDecorator.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
<SE extends Throwable, CE extends Throwable, CLE extends Throwable, V> TtlValue<V> getWrappedWithTtlCheckAndUpdate( SupplierWithException<TtlValue<V>, SE> getter, ThrowingConsumer<TtlValue<V>, CE> updater, ThrowingRunnable<CLE> stateClear) throws SE, CE, CLE { TtlValue<V> ttlValue = getter.get(); if (ttlValue == null) { return null; } else if (expired(ttlValue)) { stateClear.run(); if (!returnExpired) { return null; } } else if (updateTsOnRead) { updater.accept(rewrapWithNewTs(ttlValue)); } return ttlValue; }
Example #11
Source File: ConfigOptionsDocGenerator.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
static void processConfigOptions(String rootDir, String module, String packageName, String pathPrefix, ThrowingConsumer<Class<?>, IOException> classConsumer) throws IOException, ClassNotFoundException { Path configDir = Paths.get(rootDir, module, pathPrefix, packageName.replaceAll("\\.", "/")); try (DirectoryStream<Path> stream = Files.newDirectoryStream(configDir)) { for (Path entry : stream) { String fileName = entry.getFileName().toString(); Matcher matcher = CLASS_NAME_PATTERN.matcher(fileName); if (matcher.matches()) { final String className = packageName + '.' + matcher.group(CLASS_NAME_GROUP); if (!EXCLUSIONS.contains(className)) { Class<?> optionsClass = Class.forName(className); classConsumer.accept(optionsClass); } } } } }
Example #12
Source File: ResourceManagerTest.java From flink with Apache License 2.0 | 5 votes |
private void runHeartbeatTimeoutTest( ThrowingConsumer<ResourceManagerGateway, Exception> registerComponentAtResourceManager, ThrowingConsumer<ResourceID, Exception> verifyHeartbeatTimeout) throws Exception { resourceManager = createAndStartResourceManager(fastHeartbeatServices); final ResourceManagerGateway resourceManagerGateway = resourceManager.getSelfGateway(ResourceManagerGateway.class); registerComponentAtResourceManager.accept(resourceManagerGateway); verifyHeartbeatTimeout.accept(resourceManagerResourceId); }
Example #13
Source File: ZooKeeperHaServicesTest.java From flink with Apache License 2.0 | 5 votes |
private void runCleanupTest( Configuration configuration, TestingBlobStoreService blobStoreService, ThrowingConsumer<ZooKeeperHaServices, Exception> zooKeeperHaServicesConsumer) throws Exception { try (ZooKeeperHaServices zooKeeperHaServices = new ZooKeeperHaServices( ZooKeeperUtils.startCuratorFramework(configuration), Executors.directExecutor(), configuration, blobStoreService)) { // create some Zk services to trigger the generation of paths final LeaderRetrievalService resourceManagerLeaderRetriever = zooKeeperHaServices.getResourceManagerLeaderRetriever(); final LeaderElectionService resourceManagerLeaderElectionService = zooKeeperHaServices.getResourceManagerLeaderElectionService(); final RunningJobsRegistry runningJobsRegistry = zooKeeperHaServices.getRunningJobsRegistry(); final TestingListener listener = new TestingListener(); resourceManagerLeaderRetriever.start(listener); resourceManagerLeaderElectionService.start(new TestingContender("foobar", resourceManagerLeaderElectionService)); final JobID jobId = new JobID(); runningJobsRegistry.setJobRunning(jobId); listener.waitForNewLeader(2000L); resourceManagerLeaderRetriever.stop(); resourceManagerLeaderElectionService.stop(); runningJobsRegistry.clearJob(jobId); zooKeeperHaServicesConsumer.accept(zooKeeperHaServices); } }
Example #14
Source File: AbstractTtlDecorator.java From flink with Apache License 2.0 | 5 votes |
<SE extends Throwable, CE extends Throwable, CLE extends Throwable, V> V getWithTtlCheckAndUpdate( SupplierWithException<TtlValue<V>, SE> getter, ThrowingConsumer<TtlValue<V>, CE> updater, ThrowingRunnable<CLE> stateClear) throws SE, CE, CLE { TtlValue<V> ttlValue = getWrappedWithTtlCheckAndUpdate(getter, updater, stateClear); return ttlValue == null ? null : ttlValue.getUserValue(); }
Example #15
Source File: ChannelStateWriteRequest.java From flink with Apache License 2.0 | 5 votes |
CheckpointInProgressRequest(String name, long checkpointId, ThrowingConsumer<ChannelStateCheckpointWriter, Exception> action, ThrowingConsumer<Throwable, Exception> discardAction, boolean ignoreMissingWriter) { this.checkpointId = checkpointId; this.action = checkNotNull(action); this.discardAction = checkNotNull(discardAction); this.name = checkNotNull(name); this.ignoreMissingWriter = ignoreMissingWriter; }
Example #16
Source File: StreamTwoInputProcessor.java From flink with Apache License 2.0 | 5 votes |
private StreamTaskNetworkOutput( TwoInputStreamOperator<IN1, IN2, ?> operator, ThrowingConsumer<StreamRecord<T>, Exception> recordConsumer, StreamStatusMaintainer streamStatusMaintainer, WatermarkGauge inputWatermarkGauge, int inputIndex) { super(streamStatusMaintainer); this.operator = checkNotNull(operator); this.recordConsumer = checkNotNull(recordConsumer); this.inputWatermarkGauge = checkNotNull(inputWatermarkGauge); this.inputIndex = inputIndex; }
Example #17
Source File: ChannelStateWriteRequest.java From flink with Apache License 2.0 | 5 votes |
static ThrowingConsumer<Throwable, Exception> recycle(Buffer[] flinkBuffers) { return unused -> { for (Buffer b : flinkBuffers) { b.recycleBuffer(); } }; }
Example #18
Source File: FileUtils.java From flink with Apache License 2.0 | 5 votes |
private static void guardIfMac(ThrowingConsumer<File, IOException> toRun, File file) throws IOException{ synchronized (DELETE_LOCK) { toRun.accept(file); // briefly wait and fall through the loop try { Thread.sleep(1); } catch (InterruptedException e) { // restore the interruption flag and error out of the method Thread.currentThread().interrupt(); throw new IOException("operation interrupted"); } } }
Example #19
Source File: FileUtils.java From flink with Apache License 2.0 | 5 votes |
private static void guardIfNotThreadSafe(ThrowingConsumer<File, IOException> toRun, File file) throws IOException { if (OperatingSystem.isWindows()) { guardIfWindows(toRun, file); return; } if (OperatingSystem.isMac()) { guardIfMac(toRun, file); return; } toRun.accept(file); }
Example #20
Source File: ZooKeeperHaServicesTest.java From flink with Apache License 2.0 | 5 votes |
private void runCleanupTest( Configuration configuration, TestingBlobStoreService blobStoreService, ThrowingConsumer<ZooKeeperHaServices, Exception> zooKeeperHaServicesConsumer) throws Exception { try (ZooKeeperHaServices zooKeeperHaServices = new ZooKeeperHaServices( ZooKeeperUtils.startCuratorFramework(configuration), Executors.directExecutor(), configuration, blobStoreService)) { // create some Zk services to trigger the generation of paths final LeaderRetrievalService resourceManagerLeaderRetriever = zooKeeperHaServices.getResourceManagerLeaderRetriever(); final LeaderElectionService resourceManagerLeaderElectionService = zooKeeperHaServices.getResourceManagerLeaderElectionService(); final RunningJobsRegistry runningJobsRegistry = zooKeeperHaServices.getRunningJobsRegistry(); final TestingListener listener = new TestingListener(); resourceManagerLeaderRetriever.start(listener); resourceManagerLeaderElectionService.start(new TestingContender("foobar", resourceManagerLeaderElectionService)); final JobID jobId = new JobID(); runningJobsRegistry.setJobRunning(jobId); listener.waitForNewLeader(2000L); resourceManagerLeaderRetriever.stop(); resourceManagerLeaderElectionService.stop(); runningJobsRegistry.clearJob(jobId); zooKeeperHaServicesConsumer.accept(zooKeeperHaServices); } }
Example #21
Source File: ResourceManagerTest.java From flink with Apache License 2.0 | 5 votes |
private void runHeartbeatTimeoutTest( ThrowingConsumer<ResourceManagerGateway, Exception> registerComponentAtResourceManager, ThrowingConsumer<ResourceID, Exception> verifyHeartbeatTimeout) throws Exception { resourceManager = createAndStartResourceManager(fastHeartbeatServices); final ResourceManagerGateway resourceManagerGateway = resourceManager.getSelfGateway(ResourceManagerGateway.class); registerComponentAtResourceManager.accept(resourceManagerGateway); verifyHeartbeatTimeout.accept(resourceManagerResourceId); }
Example #22
Source File: AbstractTtlDecorator.java From flink with Apache License 2.0 | 5 votes |
<SE extends Throwable, CE extends Throwable, CLE extends Throwable, V> V getWithTtlCheckAndUpdate( SupplierWithException<TtlValue<V>, SE> getter, ThrowingConsumer<TtlValue<V>, CE> updater, ThrowingRunnable<CLE> stateClear) throws SE, CE, CLE { TtlValue<V> ttlValue = getWrappedWithTtlCheckAndUpdate(getter, updater, stateClear); return ttlValue == null ? null : ttlValue.getUserValue(); }
Example #23
Source File: ZooKeeperHaServicesTest.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
private void runCleanupTest( Configuration configuration, TestingBlobStoreService blobStoreService, ThrowingConsumer<ZooKeeperHaServices, Exception> zooKeeperHaServicesConsumer) throws Exception { try (ZooKeeperHaServices zooKeeperHaServices = new ZooKeeperHaServices( ZooKeeperUtils.startCuratorFramework(configuration), Executors.directExecutor(), configuration, blobStoreService)) { // create some Zk services to trigger the generation of paths final LeaderRetrievalService resourceManagerLeaderRetriever = zooKeeperHaServices.getResourceManagerLeaderRetriever(); final LeaderElectionService resourceManagerLeaderElectionService = zooKeeperHaServices.getResourceManagerLeaderElectionService(); final RunningJobsRegistry runningJobsRegistry = zooKeeperHaServices.getRunningJobsRegistry(); final TestingListener listener = new TestingListener(); resourceManagerLeaderRetriever.start(listener); resourceManagerLeaderElectionService.start(new TestingContender("foobar", resourceManagerLeaderElectionService)); final JobID jobId = new JobID(); runningJobsRegistry.setJobRunning(jobId); listener.waitForNewLeader(2000L); resourceManagerLeaderRetriever.stop(); resourceManagerLeaderElectionService.stop(); runningJobsRegistry.clearJob(jobId); zooKeeperHaServicesConsumer.accept(zooKeeperHaServices); } }
Example #24
Source File: ResourceManagerTest.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
private void runHeartbeatTimeoutTest( ThrowingConsumer<ResourceManagerGateway, Exception> registerComponentAtResourceManager, ThrowingConsumer<ResourceID, Exception> verifyHeartbeatTimeout) throws Exception { resourceManager = createAndStartResourceManager(fastHeartbeatServices); final ResourceManagerGateway resourceManagerGateway = resourceManager.getSelfGateway(ResourceManagerGateway.class); registerComponentAtResourceManager.accept(resourceManagerGateway); verifyHeartbeatTimeout.accept(resourceManagerResourceId); }
Example #25
Source File: AbstractTtlDecorator.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
<SE extends Throwable, CE extends Throwable, CLE extends Throwable, V> V getWithTtlCheckAndUpdate( SupplierWithException<TtlValue<V>, SE> getter, ThrowingConsumer<TtlValue<V>, CE> updater, ThrowingRunnable<CLE> stateClear) throws SE, CE, CLE { TtlValue<V> ttlValue = getWrappedWithTtlCheckAndUpdate(getter, updater, stateClear); return ttlValue == null ? null : ttlValue.getUserValue(); }
Example #26
Source File: ChannelStateWriteRequest.java From flink with Apache License 2.0 | 4 votes |
CheckpointInProgressRequest(String name, long checkpointId, ThrowingConsumer<ChannelStateCheckpointWriter, Exception> action, boolean ignoreMissingWriter) { this(name, checkpointId, action, unused -> { }, ignoreMissingWriter); }
Example #27
Source File: AbstractTtlState.java From flink with Apache License 2.0 | 4 votes |
<SE extends Throwable, CE extends Throwable, T> T getWithTtlCheckAndUpdate( SupplierWithException<TtlValue<T>, SE> getter, ThrowingConsumer<TtlValue<T>, CE> updater) throws SE, CE { return getWithTtlCheckAndUpdate(getter, updater, original::clear); }
Example #28
Source File: AbstractTtlState.java From flink with Apache License 2.0 | 4 votes |
<SE extends Throwable, CE extends Throwable, T> T getWithTtlCheckAndUpdate( SupplierWithException<TtlValue<T>, SE> getter, ThrowingConsumer<TtlValue<T>, CE> updater) throws SE, CE { return getWithTtlCheckAndUpdate(getter, updater, original::clear); }
Example #29
Source File: AbstractTtlState.java From Flink-CEPplus with Apache License 2.0 | 4 votes |
<SE extends Throwable, CE extends Throwable, T> T getWithTtlCheckAndUpdate( SupplierWithException<TtlValue<T>, SE> getter, ThrowingConsumer<TtlValue<T>, CE> updater) throws SE, CE { return getWithTtlCheckAndUpdate(getter, updater, original::clear); }
Example #30
Source File: TestingJobGraphStore.java From flink with Apache License 2.0 | 4 votes |
public Builder setStartConsumer(ThrowingConsumer<JobGraphListener, ? extends Exception> startConsumer) { this.startConsumer = startConsumer; return this; }