package com.sibilantsolutions.grison;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.sibilantsolutions.grison.demo.ApiDemo;
import com.sibilantsolutions.grison.demo.Demo;

/**
 * Grisons, also known as South American wolverines, are mustelids native to Central and South America.
 *   -- Wikipedia
 */
public class Grison
{

    final static private Logger log = LoggerFactory.getLogger( Grison.class );

    static public void main( final String[] args )
    {
        log.info( "main() started." );

        int i = 0;
        final String host = args[i++];
        final int port = Integer.parseInt(args[i++]);
        final String username = args[i++];
        final String password = args[i++];

        if (i < args.length) {
            if (args[i].equals("ui")) {
                Demo.demo(host, port, username, password);
            } else {
                throw new IllegalArgumentException(args[i]);
            }
        } else {
            ApiDemo.go(host, port, username, password);
        }

        log.info("main() finished.");

    }

}

@@ -32,16 +32,78 @@
 rison;%0A%0A
+import java.io.IOException;%0Aimport java.net.SocketException;%0A%0A
 import o
@@ -119,16 +119,16 @@
 Logger;%0A
-
 import o
@@ -248,16 +248,114 @@
 mo.Demo;
+%0Aimport io.reactivex.exceptions.UndeliverableException;%0Aimport io.reactivex.plugins.RxJavaPlugins;
 %0A%0A/**%0A *
@@ -674,24 +674,43 @@
 arted.%22 );%0A%0A
+        rxInit();%0A%0A
         int 
@@ -1252,10 +1252,1448 @@
 %0A    %7D%0A%0A
+    private static void rxInit() %7B%0A        RxJavaPlugins.setErrorHandler(e -%3E %7B%0A            boolean isUndeliverableException = false;%0A            if (e instanceof UndeliverableException) %7B%0A                isUndeliverableException = true;%0A                e = e.getCause();%0A            %7D%0A            if ((e instanceof IOException) %7C%7C (e instanceof SocketException)) %7B%0A                // fine, irrelevant network problem or API that throws on cancellation%0A                return;%0A            %7D%0A            if (e instanceof InterruptedException) %7B%0A                // fine, some blocking code was interrupted by a dispose call%0A                return;%0A            %7D%0A            if ((e instanceof NullPointerException) %7C%7C (e instanceof IllegalArgumentException)) %7B%0A                // that's likely a bug in the application%0A                Thread.currentThread().getUncaughtExceptionHandler()%0A                        .uncaughtException(Thread.currentThread(), e);%0A                return;%0A            %7D%0A            if (e instanceof IllegalStateException) %7B%0A                // that's a bug in RxJava or in a custom operator%0A                Thread.currentThread().getUncaughtExceptionHandler()%0A                        .uncaughtException(Thread.currentThread(), e);%0A                return;%0A            %7D%0A            log.warn(%22Undeliverable exception received, not sure what to do (source was UE=%7B%7D)%22, isUndeliverableException, e);%0A        %7D);%0A    %7D%0A%0A
 %7D%0A

Install RxJava global error handler.