1 45 package org.openejb.server; 46 47 import java.io.OutputStream ; 48 import java.net.Socket ; 49 50 54 public class Status { 55 56 public static void main(String [] args) { 57 new Status().status(); 59 } 60 61 public boolean status(){ 62 if (!connect()) { 63 System.out.println(":: server is stopped ::"); 64 return false; 65 } else { 66 System.out.println(":: server is started ::"); 67 return true; 68 } 69 } 70 71 private boolean connect() { 72 return connect( 1 ); 73 } 74 75 private boolean connect(int tries) { 76 try{ 77 Socket socket = new Socket ("localhost", 4201); 78 OutputStream out = socket.getOutputStream(); 79 } catch (Exception e){ 80 if ( tries < 2 ) { 81 return false; 82 } else { 83 try{ 84 Thread.sleep(2000); 85 } catch (Exception e2){ 86 e.printStackTrace(); 87 } 88 return connect(--tries); 89 } 90 } 91 92 return true; 93 } 94 } 95 | Popular Tags |