/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
 * You can obtain one at http://mozilla.org/MPL/2.0/. */

package pt.webdetails.cdc.hazelcast;

import com.hazelcast.core.Hazelcast;

public class StartServer extends com.hazelcast.examples.StartServer {
  
  
  public static void main(String[] args) 
  {
      try{
        Hazelcast.getConfig().setCheckCompatibility(false);
        Hazelcast.getCluster();
      }
      catch(Exception e){
        System.out.println("LAUNCH EXIT:" + e);
        Runtime.getRuntime().exit(3);
      }
    Hazelcast.addInstanceListener(new ExitingInstanceListener(3));
    new Thread(null, new Runnable(){

      @Override
      public void run() {
        boolean exit = false;
        while(!exit){
          try {
            Thread.sleep(5000);
            try{
              if(!Hazelcast.getLifecycleService().isRunning()){
                System.exit(5);
              }
//              Hazelcast.getMap("cdaCache");
            }
            catch(IllegalStateException e){
              System.out.println("ILLEGAL STATE EXCEPTION EXIT");
              System.exit(5);
            }
            catch(Exception e){
              System.out.println("EXCEPTION EXIT");
              System.exit(7);
            }
          } catch (InterruptedException e) {
            System.out.println("Interrupted!");
            System.exit(0);
          }
        }
      }
      
    }, "check hazelcast death" ).start();
  }

  
  
}

@@ -273,16 +273,61 @@
 zelcast;
+%0Aimport com.hazelcast.core.HazelcastInstance;
 %0A%0Apublic
@@ -390,21 +390,128 @@
 erver %7B%0A
+%0A
   
-%0A  
+public static int ERR_INI = 1;%0A  public static int ERR_ILLEGAL_STATE = 2;%0A  public static int ERR_OTHER = 3;%0A
 %0A  publi
@@ -553,29 +553,28 @@
   %7B%0A    
-  
 try
+ 
 %7B%0A      
   Hazelc
@@ -561,27 +561,95 @@
 try %7B%0A      
-  H
+HazelcastInstance hazelcast = Hazelcast.newHazelcastInstance();%0A      h
 azelcast.get
@@ -689,27 +689,25 @@
 lse);%0A      
-  H
+h
 azelcast.get
@@ -719,28 +719,187 @@
 er();%0A      
+hazelcast.addInstanceListener(new ExitingInstanceListener(3));%0A      %0A      new Thread(null, new PulseChecker(hazelcast), %22check hazelcast death%22 ).start();%0A    
 %7D%0A
-  
     catch(Ex
@@ -912,26 +912,24 @@
 n e)%7B%0A      
- 
- 
 System.out.p
@@ -962,18 +962,16 @@
 ;%0A      
-  
 Runtime.
@@ -992,22 +992,26 @@
 xit(
-3
+ERR_INI
 );%0A
-  
     %7D%0A  
   Ha
@@ -1010,129 +1010,175 @@
 %7D%0A  
-  Hazelcast.addInstanceListener(new ExitingInstanceListener(3));%0A    new Thread(null, new Runnable()%7B%0A%0A      @Override%0A  
+%7D%0A%0A  static class PulseChecker implements Runnable %7B%0A    HazelcastInstance hazelcast;%0A    public PulseChecker(HazelcastInstance hz) %7B%0A      this.hazelcast = hz;%0A    %7D%0A
     
@@ -1203,18 +1203,16 @@
 %7B%0A      
-  
 boolean 
@@ -1225,18 +1225,16 @@
  false;%0A
-  
       wh
@@ -1253,18 +1253,16 @@
         
-  
 try %7B%0A  
@@ -1269,18 +1269,16 @@
         
- 
- 
 Thread.s
@@ -1299,18 +1299,16 @@
         
-  
 try%7B%0A   
@@ -1320,15 +1320,13 @@
     
-  
 if(!
-H
+h
 azel
@@ -1372,34 +1372,32 @@
 %7B%0A              
-  
 System.exit(5);%0A
@@ -1412,60 +1412,10 @@
     
-  %7D%0A//              Hazelcast.getMap(%22cdaCache%22);%0A  
+%7D%0A
     
@@ -1414,34 +1414,32 @@
   %7D%0A          %7D%0A
-  
           catch(
@@ -1468,34 +1468,32 @@
 e)%7B%0A            
-  
 System.out.print
@@ -1499,43 +1499,34 @@
 tln(
-%22ILLEGAL STATE EXCEPTION EXIT%22
+e.getLocalizedMessage()
 );%0A
-  
     
@@ -1537,33 +1537,49 @@
     System.exit(
-5
+ERR_ILLEGAL_STATE
 );%0A            %7D
@@ -1567,38 +1567,34 @@
 ATE);%0A          
-  %7D%0A  
+%7D%0A
           catch(
@@ -1623,50 +1623,29 @@
     
-  System.out.println(%22EXCEPTION EXIT%22
+e.printStackTrace(
 );%0A
-  
     
@@ -1668,9 +1668,17 @@
 xit(
-7
+ERR_OTHER
 );%0A 
@@ -1678,38 +1678,34 @@
 HER);%0A          
-  %7D%0A  
+%7D%0A
         %7D catch 
@@ -1735,58 +1735,8 @@
 ) %7B%0A
-            System.out.println(%22Interrupted!%22);%0A  
     
@@ -1761,30 +1761,26 @@
 0);%0A        
- 
- 
 %7D%0A
-  
       %7D%0A    
@@ -1783,68 +1783,13 @@
     
+%7D%0A
   %7D
-%0A      %0A    %7D, %22check hazelcast death%22 ).start();%0A  %7D%0A%0A  
 %0A  %0A

remove deprecated