class RCLJava {

    public static void rclJavaInit(final String... args) {
        synchronized (RCLJava.class) {
            if (!RCLJava.initialized) {
                if (args != null) {
                    RCLJava.arguments = args;

                    for (final String arg : RCLJava.arguments) {
                        if (arg.contains("=")) {
                            final String[] keyVal = arg.split("=");
                            RCLJava.logger.debug("Args : " + keyVal[0] + "\t : " + keyVal[1]);
                        } else {
                            RCLJava.logger.debug("Args : " + arg);
                        }
                    }
                }

                // Auto-detect RMW implementation.
                if (RCLJava.rmwImplementation == null) {
                    RCLJava.displayContext();
                    RCLJava.autoLoadRmw();
                }

                // No RMW implementation founded !
                if (RCLJava.rmwImplementation == null) {
                    RCLJava.logger.error("No RMW implementation found...");
                    System.exit(1);
                } else

                // RMW implementation founded.
                {
                    RCLJava.logger.debug("Initialize rclJava with " + RCLJava.rmwImplementation);
                    RCLJava.nativeRCLJavaInit(RCLJava.arguments);
                    RCLJava.initialized = true;
                }
            } else {
                final NotInitializedException ex = new NotInitializedException("Cannot intialized twice !");
                logger.error(ex.getMessage());
                throw ex;
            }
        }
    }

}

class RCLJavaTest  {

    private static final Logger logger;
    public static final String TEST_TOPIC;
    public static final String ERROR_RUNTIME;

    @Test
    public final void testInitShutdownSequence() {

        logger.debug(new Object(){}.getClass().getEnclosingMethod().getName());

        boolean test = true;

        this.initRCLjava();
        this.releaseRCLjava();

        try {
            RCLJava.rclJavaInit();
            this.releaseRCLjava();
        } catch (Exception e) {
            test = false;
        }

        Assert.assertTrue("failed to initialize rclJava after shutdown", test);
    }

}