src/main/java/com/io7m/aeron_guide/take3/AeronMessagingServer.java
/**
     * Create a new server.
     *
     * @param clock A clock used for internal operations involving time
     * @param configuration The server configuration
     *
     * @return A new server
     *
     * @throws AeronMessagingServerException On any initialization error
     */
Create a new server.
@param clock A clock used for internal operations involving time
@param configuration The server configuration

@return A new server

@throws AeronMessagingServerException On any initialization error
Create a new server . @param clock A clock used for internal operations involving time @param configuration The server configuration @return A new server @throws AeronMessagingServerException On any initialization error
public static AeronMessagingServer create(
            final Clock clock,
            final AeronMessagingServerConfiguration configuration)
            throws AeronMessagingServerException {
        Objects.requireNonNull(clock, "clock");
        Objects.requireNonNull(configuration, "configuration");
        final String directory
                = configuration.baseDirectory().toAbsolutePath().toString();
        final MediaDriver.Context media_context
                = new MediaDriver.Context()
                        .dirDeleteOnStart(true)
                        .publicationReservedSessionIdLow(AeronMessagingServerSessions.RESERVED_SESSION_ID_LOW) 
                        .publicationReservedSessionIdHigh(AeronMessagingServerSessions.RESERVED_SESSION_ID_HIGH) 
                        .aeronDirectoryName(directory);
        final Aeron.Context aeron_context
                = new Aeron.Context()
                        .aeronDirectoryName(directory);
        AeronMessagingServerExecutorService executor = null;
        try {
            executor = AeronMessagingServerExecutor.create();
            MediaDriver media_driver = null;
            try {
                media_driver = MediaDriver.launch(media_context);
                Aeron aeron = null;
                try {
                    aeron = Aeron.connect(aeron_context);
                } catch (final Exception e) {
                    closeIfNotNull(aeron);
                    throw e;
                }
                return new AeronMessagingServer(clock, executor, media_driver, aeron, configuration);
            } catch (final Exception e) {
                closeIfNotNull(media_driver);
                throw e;
            }
        } catch (final Exception e) {
            try {
                closeIfNotNull(executor);
            } catch (final Exception c_ex) {
                e.addSuppressed(c_ex);
            }
            throw new AeronMessagingServerCreationException(e);
        }
    }
public static AeronMessagingServer create ( final Clock clock , final AeronMessagingServerConfiguration configuration ) throws AeronMessagingServerException { Objects . requireNonNull ( clock , "clock" ) ; Objects . requireNonNull ( configuration , "configuration" ) ; final String directory = configuration . baseDirectory ( ) . toAbsolutePath ( ) . toString ( ) ; final MediaDriver . Context media_context = new MediaDriver . Context ( ) . dirDeleteOnStart ( true ) . publicationReservedSessionIdLow ( AeronMessagingServerSessions . RESERVED_SESSION_ID_LOW ) . publicationReservedSessionIdHigh ( AeronMessagingServerSessions . RESERVED_SESSION_ID_HIGH ) . aeronDirectoryName ( directory ) ; final Aeron . Context aeron_context = new Aeron . Context ( ) . aeronDirectoryName ( directory ) ; AeronMessagingServerExecutorService executor = null ; try { executor = AeronMessagingServerExecutor . create ( ) ; MediaDriver media_driver = null ; try { media_driver = MediaDriver . launch ( media_context ) ; Aeron aeron = null ; try { aeron = Aeron . connect ( aeron_context ) ; } catch ( final Exception e ) { closeIfNotNull ( aeron ) ; throw e ; } return new AeronMessagingServer ( clock , executor , media_driver , aeron , configuration ) ; } catch ( final Exception e ) { closeIfNotNull ( media_driver ) ; throw e ; } } catch ( final Exception e ) { try { closeIfNotNull ( executor ) ; } catch ( final Exception c_ex ) { e . addSuppressed ( c_ex ) ; } throw new AeronMessagingServerCreationException ( e ) ; } }
Create a new server.
Create a new server .
// When the media driver automatically assigns session IDs, it must // use values outside of this range to avoid conflict with any that we assign ourselves.