/*******************************************************************************
 * This file is part of GECAMed.
 * 
 * GECAMed is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License (L-GPL) as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * GECAMed is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License (L-GPL)
 * along with GECAMed.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * GECAMed is Copyrighted by the Centre de Recherche Public Henri Tudor (http://www.tudor.lu)
 * (c) CRP Henri Tudor, Luxembourg, 2008
 *******************************************************************************/

// OBSOLENT


//package lu.tudor.santec.gecamed.core.gui;
//
//import java.io.IOException;
//import org.apache.log4j.Logger;
//
//import javax.swing.JFrame;
//import javax.swing.ProgressMonitor;
//
//import lu.tudor.santec.gecamed.core.utils.ManagerFactory;
//
//public class JBossStarter {
//
//	private String START_SCRIPT = "jboss/bin/run.sh";
//	private String STOP_SCRIPT = "jboss/bin/shutdown.sh -S";
//	private int 	CHECK_PERIOD = 2000;
//
//	private static Logger logger = Logger.getLogger(
//    "lu.tudor.santec.gecamed.core.gui.JBossStarter"); 
//	
//	public JBossStarter() {
//		if (System.getProperty("os.name").toLowerCase().startsWith("windows")) {
//			logger.info("creating JBossStarter on Windows");
//			START_SCRIPT = "jboss\\bin\\run.bat";
//			STOP_SCRIPT = "jboss\\bin\\shutdown.bat -S";
//		} else {
//			logger.info("creating JBossStarter on NON Windows");
//		}
//	}
//	
//	
//	public void addShutdownHook() {
//		logger.info("installing ShutdownHook for JBoss");
//			MainFrame.addShutdownHook(new Thread() {
//                public void run() {
//                    try {
//						stopJBoss();
//					} catch (IOException e) {
//						e.printStackTrace();
//					}
//                }
//            });;
//	}
//	
//	
//	public void startJBoss() throws IOException {
//		logger.info("starting  JBoss");
//		ProcessBuilder pb = new ProcessBuilder(START_SCRIPT).redirectErrorStream(true);
//		final Process p = pb.start();
//		new Thread() {
//	    	public void run() {
//	    		try {
//	    			        while ((p.getInputStream().read()) != -1) {
//	    			        }
//	    		    } catch (IOException e) {
//	    		    }
//	    	}
//	    }.start();
//	}
//	
//	@SuppressWarnings("deprecation")
//	public void stopJBoss() throws IOException {
//		logger.info("stopping  JBoss");
//		Process p = Runtime.getRuntime().exec(STOP_SCRIPT);
//		Thread thread = new Thread(new Runnable() {
//			public void run() {
//				ProgressMonitor pm = new ProgressMonitor(new JFrame(),
//						"Stopping JBoss...", "", 0, 100);
//				for (int i = 0; i <= 100; i++) {
//					pm.setProgress(i);
//					try {
//						Thread.sleep(100);
//					} catch (Exception ex) {
//					}
//				}
//			}
//		});
//		thread.start();
//	}
//	
//	public boolean checkJBoss() {
//		try {
//			ManagerFactory.getRemote(ManagerFactory.LOGINBEAN);
//			logger.info("	 JBoss is running");
//			return true;
//	    } catch (Exception e) {
//	    	logger.info("	 JBoss is NOT running !!!!!!!!!!");
//			return false;
//		}
//	}
//	
//	public boolean waitForJBoss(int timeoutSec) {
//		timeoutSec *= 1000;
//		while (timeoutSec > 0) {
//			logger.info("checking  JBoss for " + (timeoutSec/1000) + " sec.");
//			if (checkJBoss()) {
//				logger.info("running JBoss found");
//				return true;
//			}
//			try {
//				Thread.sleep(CHECK_PERIOD);
//			} catch (InterruptedException e) {
//				e.printStackTrace();
//				return false;
//			}
//			timeoutSec -= CHECK_PERIOD;
//		}
//		logger.warn("No running JBoss found !!!!!!!!!!!!!!!");
//		return false;
//	}
//
//}
