@Test
  public void testConfigLifecycleListener() throws InterruptedException {
    ClientConfig config = new ClientConfig();
    final BlockingQueue<LifecycleEvent> q = new LinkedBlockingQueue<LifecycleEvent>();
    config.addListener(
        new LifecycleListener() {
          public void stateChanged(final LifecycleEvent event) {
            q.offer(event);
            System.out.println(event);
          }
        });
    Hazelcast.getDefaultInstance();
    HazelcastClient client = HazelcastClient.newHazelcastClient(config);

    Assert.assertEquals(new LifecycleEvent(LifecycleState.STARTING), q.poll(3, TimeUnit.SECONDS));
    Assert.assertEquals(
        new LifecycleEvent(LifecycleState.CLIENT_CONNECTION_OPENING), q.poll(3, TimeUnit.SECONDS));
    Assert.assertEquals(
        new LifecycleEvent(LifecycleState.CLIENT_CONNECTION_OPENED), q.poll(3, TimeUnit.SECONDS));
    Assert.assertEquals(new LifecycleEvent(LifecycleState.STARTED), q.poll(3, TimeUnit.SECONDS));
    client.shutdown();
    //        Assert.assertEquals(new LifecycleEvent(LifecycleState.CLIENT_CONNECTION_LOST),
    // q.poll(3, TimeUnit.SECONDS));
    Assert.assertEquals(
        new LifecycleEvent(LifecycleState.SHUTTING_DOWN), q.poll(3, TimeUnit.SECONDS));
    Assert.assertEquals(new LifecycleEvent(LifecycleState.SHUTDOWN), q.poll(3, TimeUnit.SECONDS));
  }
  private void start() throws IOException {

    if (logPath != null) {
      PropertyConfigurator.configure(logPath.getAbsolutePath());
    }

    if (!hazelcastFile.isFile()) {
      throw new RuntimeException("Could not find hazelcast configuration file : " + hazelcastFile);
    }

    /*
     * Start a lightweight http server, make sure it can only be accessed
     * from the machine it's running on (don't want to allow remote
     * shutdown).
     */
    server = HttpServer.create(new InetSocketAddress(host, port), port);
    server.createContext(baseContext + HazelcastServiceCommand.stop, new ShutdownHandler());
    server.createContext(baseContext + HazelcastServiceCommand.status, new StatusHandler());
    server.setExecutor(null);
    server.start();

    // Config config = new Config();
    // config.setConfigurationFile(hazelcastFile);
    // config.setConfigurationUrl(hazelcastFile.toURI().toURL());
    // hz = Hazelcast.newHazelcastInstance(config);

    /*
     * Creating a Config object (as commented out above) and setting the
     * file using setConfigurationFile doesn't seem to work at all. The
     * system property approach does.
     */
    String path = hazelcastFile.getAbsolutePath();
    logger.info("Setting configuration file " + path);
    System.setProperty("hazelcast.config", path);

    hz = Hazelcast.getDefaultInstance();

    logger.info(hz.getConfig().getConfigurationFile());
    logger.info(hz.getConfig().getGroupConfig().getName());

    monitor = new HazelcastMonitor();
    hz.addInstanceListener(monitor);

    if (testValues) {
      hz.getMap("tst").put("1", "1");
      hz.getMap("tst").put("2", "2");
      hz.getMap("tst").put("3", "3");

      logger.info(hz.getMap("tst").getId());
      logger.info(hz.getMap("tst").size());
    }

    System.out.println("-- HAZELCAST SERVICE WRAPPER READY --");
    System.out.println(
        String.format("To check status, request: '%s'.", url(HazelcastServiceCommand.status)));
    System.out.println(
        String.format("To shut it down, request: '%s'.", url(HazelcastServiceCommand.stop)));
  }