src/main/java/com/io7m/aeron_guide/take4/aeron_messaging/client/AeronMessagingClient.java
/**
     * Run the client, returning when the client is finished.
     *
     * @throws ClientException On any error
     */
Run the client, returning when the client is finished.
@throws ClientException On any error
Run the client returning when the client is finished . @throws ClientException On any error
@Override
    public void run() {
        /**
         * Generate a one-time pad.
         */
        this.duologue_key = this.random.nextInt();
        final UnsafeBuffer buffer
                = new UnsafeBuffer(BufferUtil.allocateDirectAligned(1024, 16));
        final String session_name;
        Subscription all_client_subscription = null;
        Publication all_client_publication = null;
        try {
            all_client_subscription = this.setupAllClientsSubscription();
            all_client_publication = this.setupAllClientsPublication();
            /**
             * Send a one-time pad to the server.
             */
            MessagesHelper.send_message(
                    all_client_publication,
                    buffer,
                    "HELLO " + Integer.toUnsignedString(this.duologue_key, 16).toUpperCase());
            session_name = Integer.toString(all_client_publication.sessionId());
            this.waitForConnectResponse(all_client_subscription, session_name);
        } catch (final ClientException | IOException e) {
            this.got_exception = e;
            LOG.error("got_exception: " + e);
            return; 
        }
        /**
         * Connect to the publication and subscription that the server has sent
         * back to this client.
         */
        try (final Subscription private_subscription = this.setupConnectSubscription()) {
            try (final Publication private_publication = this.setupConnectPublication()) {
                this.runMainMessageProcessingLoop(
                        buffer,
                        session_name,
                        private_subscription,
                        private_publication,
                        all_client_subscription,
                        all_client_publication
                );
            } catch (final IOException e) {
                this.got_exception = e;
                LOG.error("got_exception: " + e);
            }
        } catch (final Exception e) {
            this.got_exception = e;
            LOG.error("got_exception: " + e);
        }
    }
@ Override public void run ( ) { /**
         * Generate a one-time pad.
         */ this . duologue_key = this . random . nextInt ( ) ; final UnsafeBuffer buffer = new UnsafeBuffer ( BufferUtil . allocateDirectAligned ( 1024 , 16 ) ) ; final String session_name ; Subscription all_client_subscription = null ; Publication all_client_publication = null ; try { all_client_subscription = this . setupAllClientsSubscription ( ) ; all_client_publication = this . setupAllClientsPublication ( ) ; /**
             * Send a one-time pad to the server.
             */ MessagesHelper . send_message ( all_client_publication , buffer , "HELLO " + Integer . toUnsignedString ( this . duologue_key , 16 ) . toUpperCase ( ) ) ; session_name = Integer . toString ( all_client_publication . sessionId ( ) ) ; this . waitForConnectResponse ( all_client_subscription , session_name ) ; } catch ( final ClientException | IOException e ) { this . got_exception = e ; LOG . error ( "got_exception: " + e ) ; return ; } /**
         * Connect to the publication and subscription that the server has sent
         * back to this client.
         */ try ( final Subscription private_subscription = this . setupConnectSubscription ( ) ) { try ( final Publication private_publication = this . setupConnectPublication ( ) ) { this . runMainMessageProcessingLoop ( buffer , session_name , private_subscription , private_publication , all_client_subscription , all_client_publication ) ; } catch ( final IOException e ) { this . got_exception = e ; LOG . error ( "got_exception: " + e ) ; } } catch ( final Exception e ) { this . got_exception = e ; LOG . error ( "got_exception: " + e ) ; } }
Run the client, returning when the client is finished.
Run the client returning when the client is finished .
// Commented out "try-with-resources" approach since this imply the "resource" to be closed after try block finishes, // but we want to maintain "all_client" sub and pub! //        try (all_client_subscription = this.setupAllClientsSubscription()) { //            try (all_client_publication = this.setupAllClientsPublication()) { // Since now we're in Runnable and in own thread, let's catch & preserve the exceptino we got and simply return. // There are some ways to throw an exception from runnable, but I didn't like them: https://stackoverflow.com/questions/11584159/is-there-a-way-to-make-runnables-run-throw-an-exception // this closes the AeronMessagingClient thread (end of run()) // Since now we're in Runnable and in own thread, let's catch & preserve the exceptino we got and simply return. // There are some ways to throw an exception from runnable, but I didn't like them: https://stackoverflow.com/questions/11584159/is-there-a-way-to-make-runnables-run-throw-an-exception // Since now we're in Runnable and in own thread, let's catch & preserve the exceptino we got and simply return. // There are some ways to throw an exception from runnable, but I didn't like them: https://stackoverflow.com/questions/11584159/is-there-a-way-to-make-runnables-run-throw-an-exception