org.agrona.CloseHelper Java Examples
The following examples show how to use
org.agrona.CloseHelper.
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: NetworkPublication.java From aeron with Apache License 2.0 | 6 votes |
public void close() { CloseHelper.close(errorHandler, publisherPos); CloseHelper.close(errorHandler, publisherLimit); CloseHelper.close(errorHandler, senderPosition); CloseHelper.close(errorHandler, senderLimit); CloseHelper.close(errorHandler, senderBpe); CloseHelper.closeAll(errorHandler, spyPositions); for (int i = 0, size = untetheredSubscriptions.size(); i < size; i++) { final UntetheredSubscription untetheredSubscription = untetheredSubscriptions.get(i); if (UntetheredSubscription.State.RESTING == untetheredSubscription.state) { CloseHelper.close(errorHandler, untetheredSubscription.position); } } CloseHelper.close(errorHandler, rawLog); }
Example #2
Source File: ClusterNodeRestartTest.java From aeron with Apache License 2.0 | 6 votes |
private void connectClient() { while (true) { try { CloseHelper.close(aeronCluster); aeronCluster = AeronCluster.connect(); return; } catch (final TimeoutException ex) { System.out.println("warning: " + ex.getMessage()); } } }
Example #3
Source File: ClusterNodeTest.java From aeron with Apache License 2.0 | 6 votes |
@AfterEach public void after() { final ConsensusModule consensusModule = null == clusteredMediaDriver ? null : clusteredMediaDriver.consensusModule(); CloseHelper.closeAll(aeronCluster, consensusModule, container, clusteredMediaDriver); if (null != clusteredMediaDriver) { clusteredMediaDriver.consensusModule().context().deleteDirectory(); clusteredMediaDriver.archive().context().deleteDirectory(); clusteredMediaDriver.mediaDriver().context().deleteDirectory(); container.context().deleteDirectory(); } }
Example #4
Source File: ResetArchiveState.java From artio with Apache License 2.0 | 6 votes |
void resetState() { if (configuration.logAnyMessages()) { createArchiver(); try { truncateArchive(); backupState(); } finally { CloseHelper.close(archive); CloseHelper.close(aeron); } } }
Example #5
Source File: ParameterServerNode.java From nd4j with Apache License 2.0 | 6 votes |
/** * Stop the server * @throws Exception */ @Override public void close() throws Exception { if (subscriber != null) { for (int i = 0; i < subscriber.length; i++) { if (subscriber[i] != null) { subscriber[i].close(); } } } if (server != null) server.stop(); if (mediaDriver != null) CloseHelper.quietClose(mediaDriver); if (aeron != null) CloseHelper.quietClose(aeron); }
Example #6
Source File: ArchivingMediaDriver.java From aeron with Apache License 2.0 | 5 votes |
/** * Launch a new {@link ArchivingMediaDriver} with provided contexts. * * @param driverCtx for configuring the {@link MediaDriver}. * @param archiveCtx for configuring the {@link Archive}. * @return a new {@link ArchivingMediaDriver} with the provided contexts. */ public static ArchivingMediaDriver launch(final MediaDriver.Context driverCtx, final Archive.Context archiveCtx) { MediaDriver driver = null; Archive archive = null; try { driver = MediaDriver.launch(driverCtx); final int errorCounterId = SystemCounterDescriptor.ERRORS.id(); final AtomicCounter errorCounter = null == archiveCtx.errorCounter() ? new AtomicCounter(driverCtx.countersValuesBuffer(), errorCounterId) : archiveCtx.errorCounter(); final ErrorHandler errorHandler = null == archiveCtx.errorHandler() ? driverCtx.errorHandler() : archiveCtx.errorHandler(); archive = Archive.launch(archiveCtx .mediaDriverAgentInvoker(driver.sharedAgentInvoker()) .aeronDirectoryName(driverCtx.aeronDirectoryName()) .errorHandler(errorHandler) .errorCounter(errorCounter)); return new ArchivingMediaDriver(driver, archive); } catch (final Exception ex) { CloseHelper.quietCloseAll(archive, driver); throw ex; } }
Example #7
Source File: ArchiveMigration_1_2.java From aeron with Apache License 2.0 | 5 votes |
public void migrate( final PrintStream stream, final ArchiveMarkFile markFile, final Catalog catalog, final File archiveDir) { final FileChannel migrationTimestampFile = MigrationUtils.createMigrationTimestampFile( archiveDir, markFile.decoder().version(), minimumVersion()); catalog.forEach( (headerEncoder, headerDecoder, encoder, decoder) -> { final String version1Prefix = decoder.recordingId() + "-"; final String version1Suffix = ".rec"; String[] segmentFiles = archiveDir.list( (dir, filename) -> filename.startsWith(version1Prefix) && filename.endsWith(version1Suffix)); if (null == segmentFiles) { segmentFiles = ArrayUtil.EMPTY_STRING_ARRAY; } migrateRecording( stream, archiveDir, segmentFiles, version1Prefix, version1Suffix, headerEncoder, headerDecoder, encoder, decoder); }); markFile.encoder().version(minimumVersion()); catalog.updateVersion(minimumVersion()); CloseHelper.close(migrationTimestampFile); }
Example #8
Source File: DedicatedModeArchiveConductor.java From aeron with Apache License 2.0 | 5 votes |
protected void closeSessionWorkers() { CloseHelper.close(errorHandler, recorderAgentRunner); CloseHelper.close(errorHandler, replayerAgentRunner); while (processCloseQueue() > 0 || !closeQueue.isEmpty()) { Thread.yield(); if (Thread.currentThread().isInterrupted()) { break; } } }
Example #9
Source File: AeronArchive.java From aeron with Apache License 2.0 | 5 votes |
/** * Add a {@link Publication} and set it up to be recorded. If this is not the first, * i.e. {@link Publication#isOriginal()} is true, then an {@link ArchiveException} * will be thrown and the recording not initiated. * <p> * This is a sessionId specific recording. * * @param channel for the publication. * @param streamId for the publication. * @return the {@link Publication} ready for use. */ public Publication addRecordedPublication(final String channel, final int streamId) { Publication publication = null; lock.lock(); try { ensureOpen(); ensureNotReentrant(); publication = aeron.addPublication(channel, streamId); if (!publication.isOriginal()) { throw new ArchiveException( "publication already added for channel=" + channel + " streamId=" + streamId); } startRecording(ChannelUri.addSessionId(channel, publication.sessionId()), streamId, SourceLocation.LOCAL); } catch (final RuntimeException ex) { CloseHelper.quietClose(publication); throw ex; } finally { lock.unlock(); } return publication; }
Example #10
Source File: AeronArchive.java From aeron with Apache License 2.0 | 5 votes |
/** * Begin an attempt at creating a connection which can be completed by calling {@link AsyncConnect#poll()} until * it returns the client, before complete it will return null. * * @param ctx for the archive connection. * @return the {@link AsyncConnect} that can be polled for completion. */ public static AsyncConnect asyncConnect(final Context ctx) { Subscription subscription = null; Publication publication = null; try { ctx.conclude(); final Aeron aeron = ctx.aeron(); final long messageTimeoutNs = ctx.messageTimeoutNs(); final long deadlineNs = aeron.context().nanoClock().nanoTime() + messageTimeoutNs; subscription = aeron.addSubscription(ctx.controlResponseChannel(), ctx.controlResponseStreamId()); final ControlResponsePoller controlResponsePoller = new ControlResponsePoller(subscription); publication = aeron.addExclusivePublication(ctx.controlRequestChannel(), ctx.controlRequestStreamId()); final ArchiveProxy archiveProxy = new ArchiveProxy( publication, ctx.idleStrategy(), aeron.context().nanoClock(), messageTimeoutNs, DEFAULT_RETRY_ATTEMPTS, ctx.credentialsSupplier()); return new AsyncConnect(ctx, controlResponsePoller, archiveProxy, deadlineNs); } catch (final Exception ex) { if (!ctx.ownsAeronClient()) { CloseHelper.quietClose(subscription); CloseHelper.quietClose(publication); } ctx.close(); throw ex; } }
Example #11
Source File: UdpChannelTransport.java From aeron with Apache License 2.0 | 5 votes |
/** * Close transport, canceling any pending read operations and closing channel. */ public void close() { if (!isClosed) { isClosed = true; if (null != selectionKey) { selectionKey.cancel(); } if (null != transportPoller) { transportPoller.cancelRead(this); transportPoller.selectNowWithoutProcessing(); } CloseHelper.close(errorHandler, sendDatagramChannel); if (receiveDatagramChannel != sendDatagramChannel && null != receiveDatagramChannel) { CloseHelper.close(errorHandler, receiveDatagramChannel); } if (null != transportPoller) { transportPoller.selectNowWithoutProcessing(); } } }
Example #12
Source File: ClusterBackupAgent.java From aeron with Apache License 2.0 | 5 votes |
public void onClose() { if (!ctx.ownsAeronClient()) { CloseHelper.closeAll(consensusSubscription, consensusPublication); } if (NULL_VALUE != liveLogReplaySubscriptionId) { backupArchive.tryStopRecording(liveLogReplaySubscriptionId); } CloseHelper.closeAll(backupArchive, clusterArchiveAsyncConnect, clusterArchive, recordingLog); ctx.close(); }
Example #13
Source File: ArchiveConductor.java From aeron with Apache License 2.0 | 5 votes |
protected void postSessionsClose() { if (isAbort) { ctx.abortLatch().countDown(); } else { aeron.removeCloseHandler(aeronCloseHandler); if (!ctx.ownsAeronClient()) { aeron.removeUnavailableCounterHandler(this); for (final Subscription subscription : recordingSubscriptionMap.values()) { subscription.close(); } CloseHelper.close(localControlSubscription); CloseHelper.close(controlSubscription); CloseHelper.close(recordingEventsProxy); } } ctx.close(); }
Example #14
Source File: PubAndSubTest.java From aeron with Apache License 2.0 | 5 votes |
@AfterEach public void after() { CloseHelper.closeAll(publishingClient, subscribingClient, driver); if (null != driver) { driver.context().deleteDirectory(); } }
Example #15
Source File: TestCluster.java From aeron with Apache License 2.0 | 5 votes |
AeronCluster connectClient() { final String aeronDirName = CommonContext.getAeronDirectoryName(); if (null == clientMediaDriver) { dataCollector.add(Paths.get(aeronDirName)); clientMediaDriver = MediaDriver.launch( new MediaDriver.Context() .threadingMode(ThreadingMode.SHARED) .dirDeleteOnStart(true) .dirDeleteOnShutdown(false) .aeronDirectoryName(aeronDirName)); } CloseHelper.close(client); client = AeronCluster.connect( new AeronCluster.Context() .aeronDirectoryName(aeronDirName) .egressListener(egressMessageListener) .ingressChannel("aeron:udp?term-length=64k") .egressChannel(CLUSTER_EGRESS_CHANNEL) .ingressEndpoints(staticClusterMemberEndpoints)); return client; }
Example #16
Source File: HistogramLogWriter.java From artio with Apache License 2.0 | 5 votes |
public void close() { try { logFile.force(true); } catch (final IOException ex) { errorHandler.onError(ex); } CloseHelper.close(logFile); }
Example #17
Source File: BenchClient.java From rpc-bench with Apache License 2.0 | 5 votes |
public void shutdown() throws InterruptedException { CloseHelper.quietClose(subscription); CloseHelper.quietClose(publication); CloseHelper.quietClose(aeron); CloseHelper.quietClose(ctx); CloseHelper.quietClose(driver); }
Example #18
Source File: ClusterLoggingAgentTest.java From aeron with Apache License 2.0 | 5 votes |
@AfterEach public void after() { CloseHelper.closeAll(clusteredMediaDriver.consensusModule(), container, clusteredMediaDriver); AgentTests.afterAgent(); if (testDir != null && testDir.exists()) { IoUtil.delete(testDir, false); } }
Example #19
Source File: ReplicationSession.java From aeron with Apache License 2.0 | 5 votes |
private void stopRecording(final CountedErrorHandler countedErrorHandler) { if (null != recordingSubscription) { conductor.removeRecordingSubscription(recordingSubscription.registrationId()); CloseHelper.close(countedErrorHandler, recordingSubscription); recordingSubscription = null; } }
Example #20
Source File: ArchiveMigration_0_1.java From aeron with Apache License 2.0 | 5 votes |
public void migrate( final PrintStream stream, final ArchiveMarkFile markFile, final Catalog catalog, final File archiveDir) { final FileChannel migrationTimestampFile = MigrationUtils.createMigrationTimestampFile( archiveDir, markFile.decoder().version(), minimumVersion()); catalog.forEach( (headerEncoder, headerDecoder, encoder, decoder) -> { final String version0Prefix = decoder.recordingId() + "-"; final String version0Suffix = ".rec"; String[] segmentFiles = archiveDir.list( (dir, filename) -> filename.startsWith(version0Prefix) && filename.endsWith(version0Suffix)); if (null == segmentFiles) { segmentFiles = ArrayUtil.EMPTY_STRING_ARRAY; } migrateRecording( stream, archiveDir, segmentFiles, version0Prefix, version0Suffix, headerEncoder, headerDecoder, encoder, decoder); }); markFile.encoder().version(minimumVersion()); catalog.updateVersion(minimumVersion()); CloseHelper.close(migrationTimestampFile); }
Example #21
Source File: RecordingSessionTest.java From aeron with Apache License 2.0 | 5 votes |
@AfterEach public void after() { IoUtil.unmap(mockLogBufferMapped.byteBuffer()); CloseHelper.close(mockLogBufferChannel); IoUtil.delete(archiveDir, false); IoUtil.delete(termFile, false); }
Example #22
Source File: DynamicJoin.java From aeron with Apache License 2.0 | 5 votes |
public void close() { final CountedErrorHandler countedErrorHandler = ctx.countedErrorHandler(); CloseHelper.close(countedErrorHandler, consensusPublication); CloseHelper.close(countedErrorHandler, leaderArchive); CloseHelper.close(countedErrorHandler, leaderArchiveAsyncConnect); }
Example #23
Source File: BaseTransport.java From deeplearning4j with Apache License 2.0 | 5 votes |
protected void shutdownSilent() { log.info("Shutting down Aeron infrastructure..."); CloseHelper.quietClose(publicationForClients); CloseHelper.quietClose(publicationForShards); CloseHelper.quietClose(subscriptionForShards); CloseHelper.quietClose(subscriptionForClients); CloseHelper.quietClose(aeron); CloseHelper.quietClose(context); CloseHelper.quietClose(driver); }
Example #24
Source File: AuthenticationTest.java From aeron with Apache License 2.0 | 5 votes |
@AfterEach public void after() { final ConsensusModule consensusModule = null == clusteredMediaDriver ? null : clusteredMediaDriver.consensusModule(); CloseHelper.closeAll(aeronCluster, consensusModule, container, clusteredMediaDriver); if (null != clusteredMediaDriver) { clusteredMediaDriver.consensusModule().context().deleteDirectory(); clusteredMediaDriver.archive().context().deleteDirectory(); clusteredMediaDriver.mediaDriver().context().deleteDirectory(); } }
Example #25
Source File: ManageRecordingHistoryTest.java From aeron with Apache License 2.0 | 5 votes |
@AfterEach public void after() { CloseHelper.closeAll(aeronArchive, aeron, archive, archivingMediaDriver); archive.context().deleteDirectory(); archivingMediaDriver.context().deleteDirectory(); }
Example #26
Source File: ReplayMergeTest.java From aeron with Apache License 2.0 | 5 votes |
@AfterEach public void after() { if (received.get() != MIN_MESSAGES_PER_TERM * 6) { System.out.println( "received " + received.get() + ", sent " + messagesPublished + ", total " + (MIN_MESSAGES_PER_TERM * 6)); } CloseHelper.closeAll(aeronArchive, aeron, archive, mediaDriver); archive.context().deleteDirectory(); mediaDriver.context().deleteDirectory(); }
Example #27
Source File: ParameterServerSubscriber.java From deeplearning4j with Apache License 2.0 | 5 votes |
@Override public void close() { if (subscriber != null) CloseHelper.quietClose(subscriber); if (responder != null) CloseHelper.quietClose(responder); if (scheduledExecutorService != null) scheduledExecutorService.shutdown(); }
Example #28
Source File: DriverNameResolverTest.java From aeron with Apache License 2.0 | 5 votes |
@AfterEach public void after() { CloseHelper.closeAll(clients.values()); CloseHelper.closeAll(drivers.values()); for (final TestMediaDriver driver : drivers.values()) { driver.context().deleteDirectory(); } }
Example #29
Source File: ClusterNodeRestartTest.java From aeron with Apache License 2.0 | 5 votes |
@AfterEach public void after() { CloseHelper.closeAll(clusteredMediaDriver.consensusModule(), aeronCluster, container, clusteredMediaDriver); if (null != clusteredMediaDriver) { clusteredMediaDriver.consensusModule().context().deleteDirectory(); clusteredMediaDriver.archive().context().deleteDirectory(); clusteredMediaDriver.mediaDriver().context().deleteDirectory(); container.context().deleteDirectory(); } }
Example #30
Source File: TestNode.java From aeron with Apache License 2.0 | 5 votes |
public void close() { if (!isClosed) { isClosed = true; CloseHelper.closeAll(clusteredMediaDriver.consensusModule(), container, clusteredMediaDriver); } }