Java Code Examples for org.apache.flink.util.function.ThrowingConsumer#accept()
The following examples show how to use
org.apache.flink.util.function.ThrowingConsumer#accept() .
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: 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 3
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 4
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 5
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 6
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 7
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 8
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 9
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 10
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 11
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 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: 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 14
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 15
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 16
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 17
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 18
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); }