package it.lottomatica.utis.terminalservices.telecaricamento.controller; import it.lottomatica.utis.terminalservices.telecaricamento.adapter.DownloadSeverAdapter; import it.lottomatica.utis.terminalservices.telecaricamento.configuration.ConfigurationManager; import it.lottomatica.utis.terminalservices.telecaricamento.configuration.phases.interfaces.IWebServerConfigurationBean; import java.io.IOException; import org.apache.log4j.Logger; import com.sun.grizzly.http.embed.MyGrizzlyWebServer; import com.sun.grizzly.tcp.http11.GrizzlyAdapter; /** * * @author p.desalvo * */ public class ServiceController { private static Logger log = Logger.getLogger(ServiceController.class); private MyGrizzlyWebServer ws = null; private MyGrizzlyWebServer getWs() { return ws; } public void startServer() { log.info("startServer()"); IWebServerConfigurationBean conf = ConfigurationManager .getWebServerConf(); // jboss domain name if(log.isDebugEnabled()){ try { String jbossDomainName = System.getProperty("jboss.server.name", ""); log.info("L'applicativo e' avviato sul dominio di JBOSS \""+jbossDomainName+"\""); } catch (Exception e) { log.debug("Errore nel recuperare il nome del dominio jboss. Il problema e' segnalato ma non e' bloccante e l'applicazione sara' avviata normalmente.", e ); } } // port if(log.isDebugEnabled()){ log.debug("porta: " + conf.getPort()); } if(conf.isListenOnJbossBindAddress()){ String bindAddress = System.getProperty("jboss.bind.address", ""); if(log.isDebugEnabled()){ log.debug("jboss.bind.address=" + bindAddress); } log.debug("MaxThreads: " +conf.getMaxThreads()); log.debug("CoreThreads: " +conf.getCoreThreads()); log.debug("AsyncWrite: "+conf.isAsyncWrite()); log.debug("KeepAliveTimeoutInSeconds: "+conf.getKeepAliveTimeoutInSeconds()); this.ws = new MyGrizzlyWebServer(bindAddress, conf.getPort(), conf.getMaxThreads(),conf.getCoreThreads(),conf.isAsyncWrite(),conf.getKeepAliveTimeoutInSeconds()); log.info(new String("Il web server restera' in ascolto su "+bindAddress+":"+conf.getPort())); }else{ this.ws = new MyGrizzlyWebServer(conf.getPort(),conf.getMaxThreads(),conf.getCoreThreads(),conf.isAsyncWrite(),conf.getKeepAliveTimeoutInSeconds()); log.info(new String("Il web server restera' in ascolto su 0.0.0.0:"+conf.getPort())); } // Aggiunta degli adapter GrizzlyAdapter anAdapter = null; // DownloadServerAdapter log.info("adding DownloadServerAdapter..."); anAdapter = new DownloadSeverAdapter(); ws.addGrizzlyAdapter(anAdapter, new String[] { "/" }); log.info("DownloadServerAdapter added..."); // // WebServerAdapter // log.info("adding WebServerAdapter..."); // anAdapter = new WebServerAdapter(); // log.info("getResourcesContextPath()="+anAdapter.getResourcesContextPath()); // log.info("getRootFolder()="+anAdapter.getRootFolder()); // // ws.addGrizzlyAdapter(anAdapter, new String[] { "/www" }); // log.debug("WebServerAdapter added..."); // Start del webserver try { log.info("WebServer Start..."); ws.start(); log.info("WebServer Started!"); } catch (IOException ex) { log.error("Errore nell'avvio del server", ex); } } public void stopServer(){ getWs().stop(); } }