Search in sources :

Example 1 with ClusteredMediaDriver

use of io.aeron.cluster.ClusteredMediaDriver in project Aeron by real-logic.

the class EchoServiceNode method main.

/**
 * Main method for launching the process.
 *
 * @param args passed to the process.
 */
@SuppressWarnings("try")
public static void main(final String[] args) {
    final int nodeId = parseInt(System.getProperty("aeron.cluster.tutorial.nodeId"));
    final String hostnamesStr = System.getProperty("aeron.cluster.tutorial.hostnames", "localhost,localhost,localhost");
    final String internalHostnamesStr = System.getProperty("aeron.cluster.tutorial.hostnames.internal", hostnamesStr);
    final List<String> hostnames = Arrays.asList(hostnamesStr.split(","));
    final List<String> internalHostnames = Arrays.asList(internalHostnamesStr.split(","));
    final String baseDir = System.getProperty("aeron.cluster.tutorial.baseDir");
    final ShutdownSignalBarrier barrier = new ShutdownSignalBarrier();
    final ClusterConfig clusterConfig = ClusterConfig.create(nodeId, hostnames, internalHostnames, PORT_BASE, new EchoService());
    clusterConfig.mediaDriverContext().errorHandler(EchoServiceNode.errorHandler("Media Driver"));
    clusterConfig.archiveContext().errorHandler(EchoServiceNode.errorHandler("Archive"));
    clusterConfig.aeronArchiveContext().errorHandler(EchoServiceNode.errorHandler("Aeron Archive"));
    clusterConfig.consensusModuleContext().errorHandler(errorHandler("Consensus Module"));
    clusterConfig.clusteredServiceContext().errorHandler(errorHandler("Clustered Service"));
    try (ClusteredMediaDriver ignore = ClusteredMediaDriver.launch(clusterConfig.mediaDriverContext(), clusterConfig.archiveContext(), clusterConfig.consensusModuleContext());
        ClusteredServiceContainer ignore2 = ClusteredServiceContainer.launch(clusterConfig.clusteredServiceContext())) {
        System.out.println("[" + nodeId + "] Started Cluster Node on " + hostnames.get(nodeId) + "...");
        barrier.await();
        System.out.println("[" + nodeId + "] Exiting");
    }
}
Also used : ShutdownSignalBarrier(org.agrona.concurrent.ShutdownSignalBarrier) ClusteredMediaDriver(io.aeron.cluster.ClusteredMediaDriver) ClusteredServiceContainer(io.aeron.cluster.service.ClusteredServiceContainer)

Example 2 with ClusteredMediaDriver

use of io.aeron.cluster.ClusteredMediaDriver in project Aeron by real-logic.

the class BasicAuctionClusteredServiceNode method main.

/**
 * Main method for launching the process.
 *
 * @param args passed to the process.
 */
@SuppressWarnings("try")
public static // tag::main[]
void main(final String[] args) {
    // <1>
    final int nodeId = parseInt(System.getProperty("aeron.cluster.tutorial.nodeId"));
    final String[] hostnames = System.getProperty("aeron.cluster.tutorial.hostnames", "localhost,localhost,localhost").split(// <2>
    ",");
    final String hostname = hostnames[nodeId];
    // <3>
    final File baseDir = new File(System.getProperty("user.dir"), "node" + nodeId);
    final String aeronDirName = CommonContext.getAeronDirectoryName() + "-" + nodeId + "-driver";
    // <4>
    final ShutdownSignalBarrier barrier = new ShutdownSignalBarrier();
    // end::main[]
    // tag::media_driver[]
    final MediaDriver.Context mediaDriverContext = new MediaDriver.Context().aeronDirectoryName(aeronDirName).threadingMode(ThreadingMode.SHARED).termBufferSparseFile(true).multicastFlowControlSupplier(new MinMulticastFlowControlSupplier()).terminationHook(barrier::signal).errorHandler(BasicAuctionClusteredServiceNode.errorHandler("Media Driver"));
    // end::media_driver[]
    final AeronArchive.Context replicationArchiveContext = new AeronArchive.Context().controlResponseChannel("aeron:udp?endpoint=" + hostname + ":0");
    // tag::archive[]
    final Archive.Context archiveContext = new Archive.Context().aeronDirectoryName(aeronDirName).archiveDir(new File(baseDir, "archive")).controlChannel(udpChannel(nodeId, hostname, ARCHIVE_CONTROL_PORT_OFFSET)).archiveClientContext(replicationArchiveContext).localControlChannel("aeron:ipc?term-length=64k").recordingEventsEnabled(false).threadingMode(ArchiveThreadingMode.SHARED);
    // end::archive[]
    // tag::archive_client[]
    final AeronArchive.Context aeronArchiveContext = new AeronArchive.Context().lock(NoOpLock.INSTANCE).controlRequestChannel(archiveContext.localControlChannel()).controlResponseChannel(archiveContext.localControlChannel()).aeronDirectoryName(aeronDirName);
    // end::archive_client[]
    // tag::consensus_module[]
    final ConsensusModule.Context consensusModuleContext = new ConsensusModule.Context().errorHandler(errorHandler("Consensus Module")).clusterMemberId(// <1>
    nodeId).clusterMembers(// <2>
    clusterMembers(Arrays.asList(hostnames))).clusterDir(// <3>
    new File(baseDir, "cluster")).ingressChannel(// <4>
    "aeron:udp?term-length=64k").logChannel(// <5>
    logControlChannel(nodeId, hostname, LOG_CONTROL_PORT_OFFSET)).replicationChannel(// <6>
    logReplicationChannel(hostname)).archiveContext(// <7>
    aeronArchiveContext.clone());
    // end::consensus_module[]
    // tag::clustered_service[]
    final ClusteredServiceContainer.Context clusteredServiceContext = new ClusteredServiceContainer.Context().aeronDirectoryName(// <1>
    aeronDirName).archiveContext(// <2>
    aeronArchiveContext.clone()).clusterDir(new File(baseDir, "cluster")).clusteredService(// <3>
    new BasicAuctionClusteredService()).errorHandler(errorHandler("Clustered Service"));
    // tag::running[]
    try (ClusteredMediaDriver clusteredMediaDriver = ClusteredMediaDriver.launch(mediaDriverContext, archiveContext, // <1>
    consensusModuleContext);
        ClusteredServiceContainer container = ClusteredServiceContainer.launch(// <2>
        clusteredServiceContext)) {
        System.out.println("[" + nodeId + "] Started Cluster Node on " + hostname + "...");
        // <3>
        barrier.await();
        System.out.println("[" + nodeId + "] Exiting");
    }
// end::running[]
}
Also used : CommonContext(io.aeron.CommonContext) ClusteredMediaDriver(io.aeron.cluster.ClusteredMediaDriver) Archive(io.aeron.archive.Archive) AeronArchive(io.aeron.archive.client.AeronArchive) MinMulticastFlowControlSupplier(io.aeron.driver.MinMulticastFlowControlSupplier) AeronArchive(io.aeron.archive.client.AeronArchive) ShutdownSignalBarrier(org.agrona.concurrent.ShutdownSignalBarrier) MediaDriver(io.aeron.driver.MediaDriver) ClusteredMediaDriver(io.aeron.cluster.ClusteredMediaDriver) ConsensusModule(io.aeron.cluster.ConsensusModule) File(java.io.File) ClusteredServiceContainer(io.aeron.cluster.service.ClusteredServiceContainer)

Example 3 with ClusteredMediaDriver

use of io.aeron.cluster.ClusteredMediaDriver in project aeron by real-logic.

the class EchoServiceNode method main.

/**
 * Main method for launching the process.
 *
 * @param args passed to the process.
 */
@SuppressWarnings("try")
public static void main(final String[] args) {
    final int nodeId = parseInt(System.getProperty("aeron.cluster.tutorial.nodeId"));
    final String hostnamesStr = System.getProperty("aeron.cluster.tutorial.hostnames", "localhost,localhost,localhost");
    final String internalHostnamesStr = System.getProperty("aeron.cluster.tutorial.hostnames.internal", hostnamesStr);
    final List<String> hostnames = Arrays.asList(hostnamesStr.split(","));
    final List<String> internalHostnames = Arrays.asList(internalHostnamesStr.split(","));
    final String baseDir = System.getProperty("aeron.cluster.tutorial.baseDir");
    final ShutdownSignalBarrier barrier = new ShutdownSignalBarrier();
    final ClusterConfig clusterConfig = ClusterConfig.create(nodeId, hostnames, internalHostnames, PORT_BASE, new EchoService());
    clusterConfig.mediaDriverContext().errorHandler(EchoServiceNode.errorHandler("Media Driver"));
    clusterConfig.archiveContext().errorHandler(EchoServiceNode.errorHandler("Archive"));
    clusterConfig.aeronArchiveContext().errorHandler(EchoServiceNode.errorHandler("Aeron Archive"));
    clusterConfig.consensusModuleContext().errorHandler(errorHandler("Consensus Module"));
    clusterConfig.clusteredServiceContext().errorHandler(errorHandler("Clustered Service"));
    try (ClusteredMediaDriver ignore = ClusteredMediaDriver.launch(clusterConfig.mediaDriverContext(), clusterConfig.archiveContext(), clusterConfig.consensusModuleContext());
        ClusteredServiceContainer ignore2 = ClusteredServiceContainer.launch(clusterConfig.clusteredServiceContext())) {
        System.out.println("[" + nodeId + "] Started Cluster Node on " + hostnames.get(nodeId) + "...");
        barrier.await();
        System.out.println("[" + nodeId + "] Exiting");
    }
}
Also used : ShutdownSignalBarrier(org.agrona.concurrent.ShutdownSignalBarrier) ClusteredMediaDriver(io.aeron.cluster.ClusteredMediaDriver) ClusteredServiceContainer(io.aeron.cluster.service.ClusteredServiceContainer)

Example 4 with ClusteredMediaDriver

use of io.aeron.cluster.ClusteredMediaDriver in project aeron by real-logic.

the class BasicAuctionClusteredServiceNode method main.

/**
 * Main method for launching the process.
 *
 * @param args passed to the process.
 */
@SuppressWarnings("try")
public static // tag::main[]
void main(final String[] args) {
    // <1>
    final int nodeId = parseInt(System.getProperty("aeron.cluster.tutorial.nodeId"));
    final String[] hostnames = System.getProperty("aeron.cluster.tutorial.hostnames", "localhost,localhost,localhost").split(// <2>
    ",");
    final String hostname = hostnames[nodeId];
    // <3>
    final File baseDir = new File(System.getProperty("user.dir"), "node" + nodeId);
    final String aeronDirName = CommonContext.getAeronDirectoryName() + "-" + nodeId + "-driver";
    // <4>
    final ShutdownSignalBarrier barrier = new ShutdownSignalBarrier();
    // end::main[]
    // tag::media_driver[]
    final MediaDriver.Context mediaDriverContext = new MediaDriver.Context().aeronDirectoryName(aeronDirName).threadingMode(ThreadingMode.SHARED).termBufferSparseFile(true).multicastFlowControlSupplier(new MinMulticastFlowControlSupplier()).terminationHook(barrier::signal).errorHandler(BasicAuctionClusteredServiceNode.errorHandler("Media Driver"));
    // end::media_driver[]
    final AeronArchive.Context replicationArchiveContext = new AeronArchive.Context().controlResponseChannel("aeron:udp?endpoint=" + hostname + ":0");
    // tag::archive[]
    final Archive.Context archiveContext = new Archive.Context().aeronDirectoryName(aeronDirName).archiveDir(new File(baseDir, "archive")).controlChannel(udpChannel(nodeId, hostname, ARCHIVE_CONTROL_PORT_OFFSET)).archiveClientContext(replicationArchiveContext).localControlChannel("aeron:ipc?term-length=64k").recordingEventsEnabled(false).threadingMode(ArchiveThreadingMode.SHARED);
    // end::archive[]
    // tag::archive_client[]
    final AeronArchive.Context aeronArchiveContext = new AeronArchive.Context().lock(NoOpLock.INSTANCE).controlRequestChannel(archiveContext.localControlChannel()).controlResponseChannel(archiveContext.localControlChannel()).aeronDirectoryName(aeronDirName);
    // end::archive_client[]
    // tag::consensus_module[]
    final ConsensusModule.Context consensusModuleContext = new ConsensusModule.Context().errorHandler(errorHandler("Consensus Module")).clusterMemberId(// <1>
    nodeId).clusterMembers(// <2>
    clusterMembers(Arrays.asList(hostnames))).clusterDir(// <3>
    new File(baseDir, "cluster")).ingressChannel(// <4>
    "aeron:udp?term-length=64k").logChannel(// <5>
    logControlChannel(nodeId, hostname, LOG_CONTROL_PORT_OFFSET)).replicationChannel(// <6>
    logReplicationChannel(hostname)).archiveContext(// <7>
    aeronArchiveContext.clone());
    // end::consensus_module[]
    // tag::clustered_service[]
    final ClusteredServiceContainer.Context clusteredServiceContext = new ClusteredServiceContainer.Context().aeronDirectoryName(// <1>
    aeronDirName).archiveContext(// <2>
    aeronArchiveContext.clone()).clusterDir(new File(baseDir, "cluster")).clusteredService(// <3>
    new BasicAuctionClusteredService()).errorHandler(errorHandler("Clustered Service"));
    // tag::running[]
    try (ClusteredMediaDriver clusteredMediaDriver = ClusteredMediaDriver.launch(mediaDriverContext, archiveContext, // <1>
    consensusModuleContext);
        ClusteredServiceContainer container = ClusteredServiceContainer.launch(// <2>
        clusteredServiceContext)) {
        System.out.println("[" + nodeId + "] Started Cluster Node on " + hostname + "...");
        // <3>
        barrier.await();
        System.out.println("[" + nodeId + "] Exiting");
    }
// end::running[]
}
Also used : CommonContext(io.aeron.CommonContext) ClusteredMediaDriver(io.aeron.cluster.ClusteredMediaDriver) Archive(io.aeron.archive.Archive) AeronArchive(io.aeron.archive.client.AeronArchive) MinMulticastFlowControlSupplier(io.aeron.driver.MinMulticastFlowControlSupplier) AeronArchive(io.aeron.archive.client.AeronArchive) ShutdownSignalBarrier(org.agrona.concurrent.ShutdownSignalBarrier) MediaDriver(io.aeron.driver.MediaDriver) ClusteredMediaDriver(io.aeron.cluster.ClusteredMediaDriver) ConsensusModule(io.aeron.cluster.ConsensusModule) File(java.io.File) ClusteredServiceContainer(io.aeron.cluster.service.ClusteredServiceContainer)

Aggregations

ClusteredMediaDriver (io.aeron.cluster.ClusteredMediaDriver)4 ClusteredServiceContainer (io.aeron.cluster.service.ClusteredServiceContainer)4 ShutdownSignalBarrier (org.agrona.concurrent.ShutdownSignalBarrier)4 CommonContext (io.aeron.CommonContext)2 Archive (io.aeron.archive.Archive)2 AeronArchive (io.aeron.archive.client.AeronArchive)2 ConsensusModule (io.aeron.cluster.ConsensusModule)2 MediaDriver (io.aeron.driver.MediaDriver)2 MinMulticastFlowControlSupplier (io.aeron.driver.MinMulticastFlowControlSupplier)2 File (java.io.File)2