List of usage examples for java.net ServerSocket accept
public Socket accept() throws IOException
From source file:com.ls.zencat.ZenCat.java
public static void main(String[] args) throws Exception { try {/*ww w . ja va 2s . co m*/ if (args.length == 0) { System.out.println("first param should be config file"); System.exit(-1); } XMLConfiguration c = null; try { c = new XMLConfiguration(args[0]); } catch (ConfigurationException cex) { System.err.println("Configuration error, check config file"); cex.printStackTrace(); System.exit(1); } ZenCat bot = new ZenCat(c); // listen for stuff and send it to irc: ServerSocket serverSocket = null; InetAddress inet = null; try { if (bot.getCatIP() != null) inet = InetAddress.getByName(bot.getCatIP()); } catch (UnknownHostException ex) { System.out.println("Could not resolve config cat.ip, fix your config"); ex.printStackTrace(); System.exit(2); } try { serverSocket = new ServerSocket(bot.getCatPort(), 0, inet); } catch (IOException e) { System.err.println("Could not listen on port: " + bot.getCatPort()); System.exit(1); } System.out.println("Listening on " + bot.getCatIP() + " : " + bot.getCatPort()); while (true) { try { Socket clientSocket = serverSocket.accept(); // System.out.println("Connection on catport from: " // + clientSocket.getInetAddress().toString()); CatHandler handler = new CatHandler(clientSocket, bot); handler.start(); } catch (Exception e) { e.printStackTrace(); } } } catch (Exception e) { e.printStackTrace(); } }
From source file:com.app.server.Main.java
/** * This is the start of the all the services in web server * @param args//from w w w .j a v a 2s . co m * @throws IOException * @throws SAXException */ public static void main(String[] args) throws IOException, SAXException { long startTime = System.currentTimeMillis(); Hashtable urlClassLoaderMap = new Hashtable(); Hashtable executorServicesMap = new Hashtable(); Hashtable ataMap = new Hashtable<String, ATAConfig>(); Hashtable messagingClassMap = new Hashtable(); ConcurrentHashMap servletMapping = new ConcurrentHashMap(); Vector deployerList = new Vector(), serviceList = new Vector(); DigesterLoader serverdigesterLoader = DigesterLoader.newLoader(new FromXmlRulesModule() { protected void loadRules() { // TODO Auto-generated method stub try { loadXMLRules(new InputSource(new FileInputStream("./config/serverconfig-rules.xml"))); } catch (FileNotFoundException e) { log.error("Error in loading the xml rules ./config/serverconfig-rules.xml", e); // TODO Auto-generated catch block //e.printStackTrace(); } } }); Digester serverdigester = serverdigesterLoader.newDigester(); final ServerConfig serverconfig = (ServerConfig) serverdigester .parse(new InputSource(new FileInputStream("./config/serverconfig.xml"))); //log.info(messagingconfig); ////log.info(serverconfig.getDeploydirectory()); PropertyConfigurator.configure("log4j.properties"); /*MemcachedClient cache=new MemcachedClient( new InetSocketAddress("localhost", 1000));*/ // Store a value (async) for one hour //c.set("someKey", 36, new String("arun")); // Retrieve a value. System.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.naming.java.javaURLContextFactory"); System.setProperty(Context.URL_PKG_PREFIXES, "org.apache.naming"); ExecutorService executor = java.util.concurrent.Executors.newCachedThreadPool(); MBeanServer mbs = MBeanServerFactory.createMBeanServer("singham"); ObjectName name = null; try { mbs.registerMBean(serverconfig, new ObjectName("com.app.server:type=serverinfo")); } catch (Exception e1) { // TODO Auto-generated catch block e1.printStackTrace(); } /*try { name = new ObjectName("com.app.server:type=WarDeployer"); } catch (MalformedObjectNameException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } WarDeployer warDeployer=new WarDeployer(serverconfig.getDeploydirectory(),serverconfig.getFarmWarDir(),serverconfig.getClustergroup(),urlClassLoaderMap,executorServicesMap,messagingClassMap,servletMapping,messagingconfig,sessionObjects); warDeployer.setPriority(MIN_PRIORITY); try { mbs.registerMBean(warDeployer, name); } catch (InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } //warDeployer.start(); executor.execute(warDeployer);*/ final byte[] shutdownBt = new byte[50]; /*WebServerRequestProcessor webserverRequestProcessor=new WebServer().new WebServerRequestProcessor(servletMapping,urlClassLoaderMap,serverSocketChannel,serverconfig.getDeploydirectory(),Integer.parseInt(serverconfig.getShutdownport()),1); webserverRequestProcessor.setPriority(MIN_PRIORITY); try { name = new ObjectName("com.app.server:type=WebServerRequestProcessor"); } catch (MalformedObjectNameException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } try { mbs.registerMBean(webserverRequestProcessor, name); } catch (InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } //webserverRequestProcessor.start(); executor.execute(webserverRequestProcessor); for(int i=0;i<10;i++){ WebServerRequestProcessor webserverRequestProcessor1=new WebServer().new WebServerRequestProcessor(servletMapping,urlClassLoaderMap,serverSocketChannel,serverconfig.getDeploydirectory(),Integer.parseInt(serverconfig.getShutdownport()),2); webserverRequestProcessor1.setPriority(MIN_PRIORITY); try { name = new ObjectName("com.app.server:type=WebServerRequestProcessor"+(i+1)); } catch (MalformedObjectNameException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } try { mbs.registerMBean(webserverRequestProcessor1, name); } catch (InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } executor.execute(webserverRequestProcessor1); }*/ /*ExecutorServiceThread executorService=new ExecutorServiceThread(serverSocketChannelServices,executorServicesMap,Integer.parseInt(serverconfig.getShutdownport()),ataMap,urlClassLoaderMap,serverconfig.getDeploydirectory(),serverconfig.getServicesdirectory(),serverconfig.getEarservicesdirectory(),serverconfig.getNodesport()); try { name = new ObjectName("com.app.services:type=ExecutorServiceThread"); } catch (MalformedObjectNameException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } try { mbs.registerMBean(executorService, name); } catch (InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } //executorService.start(); executor.execute(executorService); for(int i=0;i<10;i++){ ExecutorServiceThread executorService1=new ExecutorServiceThread(serverSocketChannelServices,executorServicesMap,Integer.parseInt(serverconfig.getShutdownport()),ataMap,urlClassLoaderMap,serverconfig.getDeploydirectory(),serverconfig.getServicesdirectory(),serverconfig.getEarservicesdirectory(),serverconfig.getNodesport()); try { name = new ObjectName("com.app.services:type=ExecutorServiceThread"+(i+1)); } catch (MalformedObjectNameException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } try { mbs.registerMBean(executorService1, name); } catch (InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } executor.execute(executorService1); }*/ /*WebServerHttpsRequestProcessor webserverHttpsRequestProcessor=new WebServer().new WebServerHttpsRequestProcessor(servletMapping,urlClassLoaderMap,Integer.parseInt(serverconfig.getHttpsport()),serverconfig.getDeploydirectory(),Integer.parseInt(serverconfig.getShutdownport()),serverconfig.getHttpscertificatepath(),serverconfig.getHttpscertificatepasscode(),1); try { name = new ObjectName("com.app.server:type=WebServerHttpsRequestProcessor"); } catch (MalformedObjectNameException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } try { mbs.registerMBean(webserverHttpsRequestProcessor, name); } catch (InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } webserverHttpsRequestProcessor.setPriority(MAX_PRIORITY); //webserverRequestProcessor.start(); executor.execute(webserverHttpsRequestProcessor);*/ /* for(int i=0;i<2;i++){ webserverHttpsRequestProcessor=new WebServer().new WebServerHttpsRequestProcessor(urlClassLoaderMap,Integer.parseInt(serverconfig.getHttpsport())+(i+1),serverconfig.getDeploydirectory(),Integer.parseInt(serverconfig.getShutdownport()),serverconfig.getHttpscertificatepath(),serverconfig.getHttpscertificatepasscode(),1); try { name = new ObjectName("com.app.server:type=WebServerHttpsRequestProcessor"+(i+1)); } catch (MalformedObjectNameException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } try { mbs.registerMBean(webserverHttpsRequestProcessor, name); } catch (InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } executor.execute(webserverHttpsRequestProcessor); }*/ /*ATAServer ataServer=new ATAServer(serverconfig.getAtaaddress(),serverconfig.getAtaport(),ataMap); try { name = new ObjectName("com.app.services:type=ATAServer"); } catch (MalformedObjectNameException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } try { mbs.registerMBean(ataServer, name); } catch (InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } ataServer.start();*/ /*ATAConfigClient ataClient=new ATAConfigClient(serverconfig.getAtaaddress(),serverconfig.getAtaport(),serverconfig.getServicesport(),executorServicesMap); try { name = new ObjectName("com.app.services:type=ATAConfigClient"); } catch (MalformedObjectNameException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } try { mbs.registerMBean(ataClient, name); } catch (InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } ataClient.start();*/ /*MessagingServer messageServer=new MessagingServer(serverconfig.getMessageport(),messagingClassMap); try { name = new ObjectName("com.app.messaging:type=MessagingServer"); } catch (MalformedObjectNameException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } try { mbs.registerMBean(messageServer, name); } catch (InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } //messageServer.start(); executor.execute(messageServer);*/ /*RandomQueueMessagePicker randomqueuemessagepicker=new RandomQueueMessagePicker(messagingClassMap); try { name = new ObjectName("com.app.messaging:type=RandomQueueMessagePicker"); } catch (MalformedObjectNameException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } try { mbs.registerMBean(randomqueuemessagepicker, name); } catch (InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } //randomqueuemessagepicker.start(); executor.execute(randomqueuemessagepicker);*/ /*RoundRobinQueueMessagePicker roundrobinqueuemessagepicker=new RoundRobinQueueMessagePicker(messagingClassMap); try { name = new ObjectName("com.app.messaging:type=RoundRobinQueueMessagePicker"); } catch (MalformedObjectNameException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } try { mbs.registerMBean(roundrobinqueuemessagepicker, name); } catch (InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } //roundrobinqueuemessagepicker.start(); executor.execute(roundrobinqueuemessagepicker);*/ /*TopicMessagePicker topicpicker= new TopicMessagePicker(messagingClassMap); try { name = new ObjectName("com.app.messaging:type=TopicMessagePicker"); } catch (MalformedObjectNameException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } try { mbs.registerMBean(topicpicker, name); } catch (InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } //topicpicker.start(); executor.execute(topicpicker);*/ try { name = new ObjectName(SARDeployer.OBJECT_NAME); } catch (Exception e) { log.error("Error in creating the object name " + SARDeployer.OBJECT_NAME, e); // TODO Auto-generated catch block //e1.printStackTrace(); } log.info(System.getProperty("user.dir")); try { mbs.createMBean("com.app.server.SARDeployer", name); mbs.invoke(name, "init", new Object[] { deployerList }, new String[] { Vector.class.getName() }); mbs.invoke(name, "init", new Object[] { serviceList, serverconfig, mbs }, new String[] { Vector.class.getName(), ServerConfig.class.getName(), MBeanServer.class.getName() }); mbs.invoke(name, "start", null, null); mbs.invoke(name, "deploy", new Object[] { new URL("file:///" + new File("").getAbsolutePath() + "/config/mbean-service.xml") }, new String[] { URL.class.getName() }); /*name=new ObjectName("com.app.server:type=deployer,service=WARDeployer"); mbs.invoke(name, "deploy", new Object[]{new URL("file:///"+serverconfig.getDeploydirectory()+"/TestDollar2.war")}, new String[]{URL.class.getName()}); mbs.invoke(name, "deploy", new Object[]{new URL("file:///"+serverconfig.getDeploydirectory()+"/StrutsProj.war")}, new String[]{URL.class.getName()});*/ //mbs.registerMBean("", name); } catch (Exception ex) { log.error("Error in SAR DEPLOYER ", ex); // TODO Auto-generated catch block //e1.printStackTrace(); } //scanner.deployPackages(new File[]{new File(serverconfig.getDeploydirectory()+"/AppServer.war")}); try { new NodeResourceReceiver(mbs).start(); } catch (Exception ex) { log.error("Node Receiver start", ex); //e2.printStackTrace(); } long endTime = System.currentTimeMillis(); log.info("Server started in " + ((endTime - startTime) / 1000) + " seconds"); /*try { mbs.invoke(name, "startDeployer", null, null); } catch (InstanceNotFoundException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (ReflectionException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (MBeanException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } */ /*JarDeployer jarDeployer=new JarDeployer(registry,serverconfig.getServicesdirectory(), serverconfig.getServiceslibdirectory(),serverconfig.getCachedir(),executorServicesMap, urlClassLoaderMap); try { name = new ObjectName("com.app.server:type=JarDeployer"); } catch (MalformedObjectNameException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } try { mbs.registerMBean(jarDeployer, name); } catch (InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } //jarDeployer.start(); executor.execute(jarDeployer);*/ /*EARDeployer earDeployer=new EARDeployer(registry,serverconfig.getEarservicesdirectory(),serverconfig.getDeploydirectory(),executorServicesMap, urlClassLoaderMap,serverconfig.getCachedir(),warDeployer); try { name = new ObjectName("com.app.server:type=EARDeployer"); } catch (MalformedObjectNameException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } try { mbs.registerMBean(earDeployer, name); } catch (InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } //earDeployer.start(); executor.execute(earDeployer);*/ /*JVMConsole jvmConsole=new JVMConsole(Integer.parseInt(serverconfig.getJvmConsolePort())); try { name = new ObjectName("com.app.server:type=JVMConsole"); } catch (MalformedObjectNameException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } try { mbs.registerMBean(jvmConsole, name); } catch (InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } executor.execute(jvmConsole);*/ /*ScheduledExecutorService exec = Executors.newSingleThreadScheduledExecutor(); XMLDeploymentScanner xmlDeploymentScanner =new XMLDeploymentScanner(serverconfig.getDeploydirectory(),serverconfig.getServiceslibdirectory()); exec.scheduleAtFixedRate(xmlDeploymentScanner, 0, 1000, TimeUnit.MILLISECONDS);*/ /*EmbeddedJMS embeddedJMS=null; try { embeddedJMS=new EmbeddedJMS(); embeddedJMS.start(); } catch (Exception ex) { // TODO Auto-generated catch block ex.printStackTrace(); } EJBDeployer ejbDeployer=new EJBDeployer(serverconfig.getServicesdirectory(),registry,Integer.parseInt(serverconfig.getServicesregistryport()),embeddedJMS); try { name = new ObjectName("com.app.server:type=EJBDeployer"); } catch (MalformedObjectNameException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } try { mbs.registerMBean(ejbDeployer, name); } catch (InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } //jarDeployer.start(); executor.execute(ejbDeployer);*/ new Thread() { public void run() { try { ServerSocket serverSocket = new ServerSocket(Integer.parseInt(serverconfig.getShutdownport())); while (true) { Socket sock = serverSocket.accept(); InputStream istream = sock.getInputStream(); istream.read(shutdownBt); String shutdownStr = new String(shutdownBt); String[] shutdownToken = shutdownStr.split("\r\n\r\n"); //log.info(shutdownStr); if (shutdownToken[0].startsWith("shutdown WebServer")) { synchronized (shutDownObject) { shutDownObject.notifyAll(); } } } } catch (Exception e) { log.error("Shutdown error", e); // TODO Auto-generated catch block //e.printStackTrace(); } } }.start(); Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { public void run() { log.info("IN shutdown Hook"); synchronized (shutDownObject) { shutDownObject.notifyAll(); } } })); try { synchronized (shutDownObject) { shutDownObject.wait(); } //executor.shutdownNow(); //serverSocketChannelServices.close(); //embeddedJMS.stop(); } catch (Exception e) { log.error("Error in object wait ", e); // TODO Auto-generated catch block //e1.printStackTrace(); } try { mbs.invoke(name, "stop", null, null); mbs.invoke(name, "destroy", null, null); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } log.info("Halting JVM"); log.info("Exiting JVM"); /*try{ Thread.sleep(10000); } catch(Exception ex){ }*/ //webserverRequestProcessor.stop(); //webserverRequestProcessor1.stop(); /*warDeployer.stop(); executorService.stop(); //ataServer.stop(); //ataClient.stop(); messageServer.stop(); randomqueuemessagepicker.stop(); roundrobinqueuemessagepicker.stop(); topicpicker.stop();*/ /*try { mbs.invoke(new ObjectName("com.app.server:type=SARDeployer"), "destroyDeployer", null, null); } catch (InstanceNotFoundException | MalformedObjectNameException | ReflectionException | MBeanException e) { // TODO Auto-generated catch block e.printStackTrace(); }*/ //earDeployer.stop(); System.exit(0); }
From source file:simpleserver.SimpleServer.java
/** * @param args the command line arguments *///from w ww .ja va2s .co m public static void main(String[] args) throws IOException { /* * Use server Socket to listen on the portal for user data */ int i = 0; try { //ServerSocket SetupListener = new ServerSocket(DataSetupPort); ServerSocket SearchListener = new ServerSocket(SearchPort); Socket serverSetup, serverSearch; System.out.println("waiting to set up server data structure"); /* doComms conn_c; serverSetup = SearchListener.accept(); conn_c = new doComms(serverSetup); Thread setup = new Thread(conn_c); setup.start();*/ while (true) {//(i++ < maxConnections) || (maxConnections == 0)){ System.out.println("fcking up server"); counter++; /* Socket2 searchSocket; serverSearch = SearchListener.accept(); searchSocket = new Socket2(serverSearch); //start setup && search server. listen to port 4444 & 4400 Thread search = new Thread(searchSocket); search.start();*/ doComms conn_c; serverSetup = SearchListener.accept(); conn_c = new doComms(serverSetup); Thread setup = new Thread(conn_c); setup.start(); } } catch (IOException ioe) { System.out.println("IOException on socket listen: " + ioe); ioe.printStackTrace(); } }
From source file:Logi.GSeries.Service.LogiGSKService.java
/** * @param args the command line arguments *//* w w w . j a v a 2 s . co m*/ public static void main(String[] args) { SystemTray.DEBUG = false; Settings settings; if (IOOperations.currentSettingsExist()) { settings = IOOperations.loadCurrentSettingsObjectFromFile(); } else { settings = new Settings(); } LogiGSKService l = new LogiGSKService(); if (settings.getShowSystemTray()) { l.showSystemTray(); } else { l.hideSystemTray(); } l.begin(); try { String dataFolderPath = IOOperations.getLocalDataDirectoryPath(); File dataFolder = new File(dataFolderPath); if (!dataFolder.exists()) { dataFolder.mkdir(); } String logFolderPath = IOOperations.getLogDirectoryPath(); File logFolder = new File(logFolderPath); if (!logFolder.exists()) { logFolder.mkdir(); } FileHandler fileHandler = new FileHandler(logFolderPath + "LogiGSK.log", FILE_SIZE, 3); fileHandler.setLevel(Level.ALL); logger.setLevel(Level.ALL); logger.addHandler(fileHandler); } catch (IOException | SecurityException ex) { Logger.getLogger(LogiGSKService.class.getName()).log(Level.SEVERE, null, ex); } int clientNumber = 0; ServerSocket listener = null; PropertyConfigurator.configure(LogiGSKService.class.getResource("/Logi/GSeries/Service/log4j.properties")); reloading = true; boolean firstTime = true; while (reloading) { listener = null; if (reloading && !firstTime) { if (IOOperations.currentSettingsExist()) { settings = IOOperations.loadCurrentSettingsObjectFromFile(); } else { settings = new Settings(); } } firstTime = false; reloading = false; running = true; try { listener = new ServerSocket(settings.getPort(), 0, InetAddress.getByName(null)); while (running) { new Manager(listener.accept(), clientNumber++, logger).start(); } } catch (IOException ex) { Logger.getLogger(LogiGSKService.class.getName()).log(Level.SEVERE, null, ex); } finally { if (listener != null) { try { listener.close(); } catch (IOException ex) { Logger.getLogger(LogiGSKService.class.getName()).log(Level.SEVERE, null, ex); } } } } }
From source file:com.biggerbytes.scheduleupdates.Main.java
/** * /*from w w w. ja va2 s.c o m*/ * @param args * @throws IOException */ public static void main(String[] args) throws IOException { java.util.logging.Logger.getLogger("com.gargoylesoftware").setLevel(Level.OFF); // In order to remove all the log warnings, THANK GOD IT IS THAT SIMPLE final int PORT = 25565; ServerSocket serverSocket = null; // Logger initialization if (LOG) { fh = new FileHandler("serv_log.log", true); //It will create a new file everytime we start the server because the previous log is locked, I am not really sure where to close the handler. logger.addHandler(fh); SimpleFormatter formatter = new SimpleFormatter(); fh.setFormatter(formatter); } // /* Dummy Test */ // List<Byte> command = new ArrayList<>(); // command.add(CommandConstants.SCEHDULES_HEADER); // command.add(CommandConstants.ADD_SUB_DUMMY); // command.add((byte) 24); // command.addAll(Arrays.asList(ArrayUtils.toObject("05".getBytes()))); // command.addAll(Arrays.asList(ArrayUtils.toObject("20.03.2016".getBytes()))); // command.addAll(Arrays.asList(ArrayUtils.toObject(" ".getBytes()))); // System.out.println("Size is " + command.size()); // byte[] commandArr = new byte[command.size()]; // for (int i = 0; i < commandArr.length; ++i) // commandArr[i] = command.get(i); // CommandProcessor.executeCommand(commandArr); /* Dummy Test End - TESTED, IT WORKS*/ /* Dummy removal */ // byte[] remvCommand = new byte[3]; // remvCommand[0] = CommandConstants.SCEHDULES_HEADER; // remvCommand[1] = CommandConstants.REMOVE_ALL_DUMMIES_FROM_ID; // remvCommand[2] = (byte) 24; // // CommandProcessor.executeCommand(remvCommand); // /* Dummy removal end - TESTED, WORKS*/ try { serverSocket = new ServerSocket(PORT); initDataRefreshThread(); infoReadThread.start(); } catch (Exception e) { if (LOG) logger.info("Couldn't listen on port " + PORT); System.exit(-1); } new CreateClientThread().start(); //Setup thread for creating threads for clients while (true) { System.out.println("waiting"); if (LOG) logger.info("Waiting for a client."); //TODO wait for the server to finish loading data then start waiting for a client Socket clientSocket = serverSocket.accept(); clientsQ.add(clientSocket); } }
From source file:com.web.server.WebServer.java
/** * This is the start of the all the services in web server * @param args/*from w ww .ja v a 2 s . c o m*/ * @throws IOException * @throws SAXException */ public static void main(String[] args) throws IOException, SAXException { Hashtable urlClassLoaderMap = new Hashtable(); Hashtable executorServicesMap = new Hashtable(); Hashtable ataMap = new Hashtable<String, ATAConfig>(); Hashtable messagingClassMap = new Hashtable(); ConcurrentHashMap servletMapping = new ConcurrentHashMap(); DigesterLoader serverdigesterLoader = DigesterLoader.newLoader(new FromXmlRulesModule() { protected void loadRules() { // TODO Auto-generated method stub try { loadXMLRules(new InputSource(new FileInputStream("./config/serverconfig-rules.xml"))); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }); Digester serverdigester = serverdigesterLoader.newDigester(); final ServerConfig serverconfig = (ServerConfig) serverdigester .parse(new InputSource(new FileInputStream("./config/serverconfig.xml"))); DigesterLoader messagingdigesterLoader = DigesterLoader.newLoader(new FromXmlRulesModule() { protected void loadRules() { // TODO Auto-generated method stub try { loadXMLRules(new InputSource(new FileInputStream("./config/messagingconfig-rules.xml"))); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }); Digester messagingdigester = messagingdigesterLoader.newDigester(); MessagingElem messagingconfig = (MessagingElem) messagingdigester .parse(new InputSource(new FileInputStream("./config/messaging.xml"))); //System.out.println(messagingconfig); ////System.out.println(serverconfig.getDeploydirectory()); PropertyConfigurator.configure("log4j.properties"); /*MemcachedClient cache=new MemcachedClient( new InetSocketAddress("localhost", 1000));*/ // Store a value (async) for one hour //c.set("someKey", 36, new String("arun")); // Retrieve a value. System.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.naming.java.javaURLContextFactory"); System.setProperty(Context.URL_PKG_PREFIXES, "org.apache.naming"); ExecutorService executor = java.util.concurrent.Executors.newCachedThreadPool(); MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); ObjectName name = null; try { name = new ObjectName("com.web.server:type=WarDeployer"); } catch (MalformedObjectNameException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } WarDeployer warDeployer = new WarDeployer(serverconfig.getDeploydirectory(), serverconfig.getFarmWarDir(), serverconfig.getClustergroup(), urlClassLoaderMap, executorServicesMap, messagingClassMap, servletMapping, messagingconfig, sessionObjects); warDeployer.setPriority(MIN_PRIORITY); try { mbs.registerMBean(warDeployer, name); } catch (InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } //warDeployer.start(); executor.execute(warDeployer); ServerSocketChannel serverSocketChannel = ServerSocketChannel.open(); serverSocketChannel.bind(new InetSocketAddress("0.0.0.0", Integer.parseInt(serverconfig.getPort()))); serverSocketChannel.configureBlocking(false); final byte[] shutdownBt = new byte[50]; WebServerRequestProcessor webserverRequestProcessor = new WebServer().new WebServerRequestProcessor( servletMapping, urlClassLoaderMap, serverSocketChannel, serverconfig.getDeploydirectory(), Integer.parseInt(serverconfig.getShutdownport()), 1); webserverRequestProcessor.setPriority(MIN_PRIORITY); try { name = new ObjectName("com.web.server:type=WebServerRequestProcessor"); } catch (MalformedObjectNameException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } try { mbs.registerMBean(webserverRequestProcessor, name); } catch (InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } //webserverRequestProcessor.start(); executor.execute(webserverRequestProcessor); for (int i = 0; i < 10; i++) { WebServerRequestProcessor webserverRequestProcessor1 = new WebServer().new WebServerRequestProcessor( servletMapping, urlClassLoaderMap, serverSocketChannel, serverconfig.getDeploydirectory(), Integer.parseInt(serverconfig.getShutdownport()), 2); webserverRequestProcessor1.setPriority(MIN_PRIORITY); try { name = new ObjectName("com.web.server:type=WebServerRequestProcessor" + (i + 1)); } catch (MalformedObjectNameException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } try { mbs.registerMBean(webserverRequestProcessor1, name); } catch (InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } executor.execute(webserverRequestProcessor1); } ServerSocketChannel serverSocketChannelServices = ServerSocketChannel.open(); serverSocketChannelServices .bind(new InetSocketAddress("0.0.0.0", Integer.parseInt(serverconfig.getServicesport()))); serverSocketChannelServices.configureBlocking(false); ExecutorServiceThread executorService = new ExecutorServiceThread(serverSocketChannelServices, executorServicesMap, Integer.parseInt(serverconfig.getShutdownport()), ataMap, urlClassLoaderMap, serverconfig.getDeploydirectory(), serverconfig.getServicesdirectory(), serverconfig.getEarservicesdirectory(), serverconfig.getNodesport()); try { name = new ObjectName("com.web.services:type=ExecutorServiceThread"); } catch (MalformedObjectNameException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } try { mbs.registerMBean(executorService, name); } catch (InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } //executorService.start(); executor.execute(executorService); for (int i = 0; i < 10; i++) { ExecutorServiceThread executorService1 = new ExecutorServiceThread(serverSocketChannelServices, executorServicesMap, Integer.parseInt(serverconfig.getShutdownport()), ataMap, urlClassLoaderMap, serverconfig.getDeploydirectory(), serverconfig.getServicesdirectory(), serverconfig.getEarservicesdirectory(), serverconfig.getNodesport()); try { name = new ObjectName("com.web.services:type=ExecutorServiceThread" + (i + 1)); } catch (MalformedObjectNameException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } try { mbs.registerMBean(executorService1, name); } catch (InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } executor.execute(executorService1); } WebServerHttpsRequestProcessor webserverHttpsRequestProcessor = new WebServer().new WebServerHttpsRequestProcessor( servletMapping, urlClassLoaderMap, Integer.parseInt(serverconfig.getHttpsport()), serverconfig.getDeploydirectory(), Integer.parseInt(serverconfig.getShutdownport()), serverconfig.getHttpscertificatepath(), serverconfig.getHttpscertificatepasscode(), 1); try { name = new ObjectName("com.web.server:type=WebServerHttpsRequestProcessor"); } catch (MalformedObjectNameException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } try { mbs.registerMBean(webserverHttpsRequestProcessor, name); } catch (InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } webserverHttpsRequestProcessor.setPriority(MAX_PRIORITY); //webserverRequestProcessor.start(); executor.execute(webserverHttpsRequestProcessor); /* for(int i=0;i<2;i++){ webserverHttpsRequestProcessor=new WebServer().new WebServerHttpsRequestProcessor(urlClassLoaderMap,Integer.parseInt(serverconfig.getHttpsport())+(i+1),serverconfig.getDeploydirectory(),Integer.parseInt(serverconfig.getShutdownport()),serverconfig.getHttpscertificatepath(),serverconfig.getHttpscertificatepasscode(),1); try { name = new ObjectName("com.web.server:type=WebServerHttpsRequestProcessor"+(i+1)); } catch (MalformedObjectNameException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } try { mbs.registerMBean(webserverHttpsRequestProcessor, name); } catch (InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } executor.execute(webserverHttpsRequestProcessor); }*/ /*ATAServer ataServer=new ATAServer(serverconfig.getAtaaddress(),serverconfig.getAtaport(),ataMap); try { name = new ObjectName("com.web.services:type=ATAServer"); } catch (MalformedObjectNameException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } try { mbs.registerMBean(ataServer, name); } catch (InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } ataServer.start();*/ /*ATAConfigClient ataClient=new ATAConfigClient(serverconfig.getAtaaddress(),serverconfig.getAtaport(),serverconfig.getServicesport(),executorServicesMap); try { name = new ObjectName("com.web.services:type=ATAConfigClient"); } catch (MalformedObjectNameException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } try { mbs.registerMBean(ataClient, name); } catch (InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } ataClient.start();*/ MessagingServer messageServer = new MessagingServer(serverconfig.getMessageport(), messagingClassMap); try { name = new ObjectName("com.web.messaging:type=MessagingServer"); } catch (MalformedObjectNameException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } try { mbs.registerMBean(messageServer, name); } catch (InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } //messageServer.start(); executor.execute(messageServer); RandomQueueMessagePicker randomqueuemessagepicker = new RandomQueueMessagePicker(messagingClassMap); try { name = new ObjectName("com.web.messaging:type=RandomQueueMessagePicker"); } catch (MalformedObjectNameException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } try { mbs.registerMBean(randomqueuemessagepicker, name); } catch (InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } //randomqueuemessagepicker.start(); executor.execute(randomqueuemessagepicker); RoundRobinQueueMessagePicker roundrobinqueuemessagepicker = new RoundRobinQueueMessagePicker( messagingClassMap); try { name = new ObjectName("com.web.messaging:type=RoundRobinQueueMessagePicker"); } catch (MalformedObjectNameException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } try { mbs.registerMBean(roundrobinqueuemessagepicker, name); } catch (InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } //roundrobinqueuemessagepicker.start(); executor.execute(roundrobinqueuemessagepicker); TopicMessagePicker topicpicker = new TopicMessagePicker(messagingClassMap); try { name = new ObjectName("com.web.messaging:type=TopicMessagePicker"); } catch (MalformedObjectNameException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } try { mbs.registerMBean(topicpicker, name); } catch (InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } //topicpicker.start(); executor.execute(topicpicker); try { name = new ObjectName("com.web.server:type=SARDeployer"); } catch (MalformedObjectNameException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } SARDeployer sarDeployer = SARDeployer.newInstance(serverconfig.getDeploydirectory()); try { mbs.registerMBean(sarDeployer, name); } catch (InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } executor.execute(sarDeployer); /*try { mbs.invoke(name, "startDeployer", null, null); } catch (InstanceNotFoundException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (ReflectionException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (MBeanException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } */ System.setProperty(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.rmi.registry.RegistryContextFactory"); System.setProperty(Context.PROVIDER_URL, "rmi://localhost:" + serverconfig.getServicesregistryport()); ; Registry registry = LocateRegistry.createRegistry(Integer.parseInt(serverconfig.getServicesregistryport())); /*JarDeployer jarDeployer=new JarDeployer(registry,serverconfig.getServicesdirectory(), serverconfig.getServiceslibdirectory(),serverconfig.getCachedir(),executorServicesMap, urlClassLoaderMap); try { name = new ObjectName("com.web.server:type=JarDeployer"); } catch (MalformedObjectNameException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } try { mbs.registerMBean(jarDeployer, name); } catch (InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } //jarDeployer.start(); executor.execute(jarDeployer);*/ EARDeployer earDeployer = new EARDeployer(registry, serverconfig.getEarservicesdirectory(), serverconfig.getDeploydirectory(), executorServicesMap, urlClassLoaderMap, serverconfig.getCachedir(), warDeployer); try { name = new ObjectName("com.web.server:type=EARDeployer"); } catch (MalformedObjectNameException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } try { mbs.registerMBean(earDeployer, name); } catch (InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } //earDeployer.start(); executor.execute(earDeployer); JVMConsole jvmConsole = new JVMConsole(Integer.parseInt(serverconfig.getJvmConsolePort())); try { name = new ObjectName("com.web.server:type=JVMConsole"); } catch (MalformedObjectNameException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } try { mbs.registerMBean(jvmConsole, name); } catch (InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } executor.execute(jvmConsole); ScheduledExecutorService exec = Executors.newSingleThreadScheduledExecutor(); XMLDeploymentScanner xmlDeploymentScanner = new XMLDeploymentScanner(serverconfig.getDeploydirectory(), serverconfig.getServiceslibdirectory()); exec.scheduleAtFixedRate(xmlDeploymentScanner, 0, 1000, TimeUnit.MILLISECONDS); EmbeddedJMS embeddedJMS = null; try { embeddedJMS = new EmbeddedJMS(); embeddedJMS.start(); } catch (Exception ex) { // TODO Auto-generated catch block ex.printStackTrace(); } EJBDeployer ejbDeployer = new EJBDeployer(serverconfig.getServicesdirectory(), registry, Integer.parseInt(serverconfig.getServicesregistryport()), embeddedJMS); try { name = new ObjectName("com.web.server:type=EJBDeployer"); } catch (MalformedObjectNameException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } try { mbs.registerMBean(ejbDeployer, name); } catch (InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } //jarDeployer.start(); executor.execute(ejbDeployer); new Thread() { public void run() { try { ServerSocket serverSocket = new ServerSocket(Integer.parseInt(serverconfig.getShutdownport())); while (true) { Socket sock = serverSocket.accept(); InputStream istream = sock.getInputStream(); istream.read(shutdownBt); String shutdownStr = new String(shutdownBt); String[] shutdownToken = shutdownStr.split("\r\n\r\n"); //System.out.println(shutdownStr); if (shutdownToken[0].startsWith("shutdown WebServer")) { synchronized (shutDownObject) { shutDownObject.notifyAll(); } } } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }.start(); Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { public void run() { System.out.println("IN shutdown Hook"); synchronized (shutDownObject) { shutDownObject.notifyAll(); } } })); try { synchronized (shutDownObject) { shutDownObject.wait(); } executor.shutdownNow(); serverSocketChannel.close(); serverSocketChannelServices.close(); embeddedJMS.stop(); } catch (Exception e1) { // TODO Auto-generated catch block e1.printStackTrace(); } System.out.println("IN shutdown Hook1"); /*try{ Thread.sleep(10000); } catch(Exception ex){ }*/ //webserverRequestProcessor.stop(); //webserverRequestProcessor1.stop(); /*warDeployer.stop(); executorService.stop(); //ataServer.stop(); //ataClient.stop(); messageServer.stop(); randomqueuemessagepicker.stop(); roundrobinqueuemessagepicker.stop(); topicpicker.stop();*/ /*try { mbs.invoke(new ObjectName("com.web.server:type=SARDeployer"), "destroyDeployer", null, null); } catch (InstanceNotFoundException | MalformedObjectNameException | ReflectionException | MBeanException e) { // TODO Auto-generated catch block e.printStackTrace(); }*/ //earDeployer.stop(); System.exit(0); }
From source file:ca.uqac.info.monitor.BeepBeepMonitor.java
public static void main(String[] args) { int verbosity = 1, slowdown = 0, tcp_port = 0; boolean show_stats = false, to_stdout = false; String trace_filename = "", pipe_filename = "", event_name = "message"; final MonitorFactory mf = new MonitorFactory(); // In case we open a socket ServerSocket m_serverSocket = null; Socket m_connection = null;//from www. j a va 2s. c om // Parse command line arguments Options options = setupOptions(); CommandLine c_line = setupCommandLine(args, options); assert c_line != null; if (c_line.hasOption("verbosity")) { verbosity = Integer.parseInt(c_line.getOptionValue("verbosity")); } if (verbosity > 0) { showHeader(); } if (c_line.hasOption("version")) { System.err.println("(C) 2008-2013 Sylvain Hall et al., Universit du Qubec Chicoutimi"); System.err.println("This program comes with ABSOLUTELY NO WARRANTY."); System.err.println("This is a free software, and you are welcome to redistribute it"); System.err.println("under certain conditions. See the file COPYING for details.\n"); System.exit(ERR_OK); } if (c_line.hasOption("h")) { showUsage(options); System.exit(ERR_OK); } if (c_line.hasOption("version")) { System.exit(ERR_OK); } if (c_line.hasOption("slowdown")) { slowdown = Integer.parseInt(c_line.getOptionValue("slowdown")); if (verbosity > 0) System.err.println("Slowdown factor: " + slowdown + " ms"); } if (c_line.hasOption("stats")) { show_stats = true; } if (c_line.hasOption("csv")) { // Will output data in CSV format to stdout to_stdout = true; } if (c_line.hasOption("eventname")) { // Set event name event_name = c_line.getOptionValue("eventname"); } if (c_line.hasOption("t")) { // Read events from a trace trace_filename = c_line.getOptionValue("t"); } if (c_line.hasOption("p")) { // Read events from a pipe pipe_filename = c_line.getOptionValue("p"); } if (c_line.hasOption("k")) { // Read events from a TCP port tcp_port = Integer.parseInt(c_line.getOptionValue("k")); } if (!trace_filename.isEmpty() && !pipe_filename.isEmpty()) { System.err.println("ERROR: you must specify at most one of trace file or named pipe"); showUsage(options); System.exit(ERR_ARGUMENTS); } @SuppressWarnings("unchecked") List<String> remaining_args = c_line.getArgList(); if (remaining_args.isEmpty()) { System.err.println("ERROR: no input formula specified"); showUsage(options); System.exit(ERR_ARGUMENTS); } // Instantiate the event notifier boolean notify = (verbosity > 0); EventNotifier en = new EventNotifier(notify); en.m_slowdown = slowdown; en.m_csvToStdout = to_stdout; // Create one monitor for each input file and add it to the notifier for (String formula_filename : remaining_args) { try { String formula_contents = FileReadWrite.readFile(formula_filename); Operator op = Operator.parseFromString(formula_contents); op.accept(mf); Monitor mon = mf.getMonitor(); Map<String, String> metadata = getMetadata(formula_contents); metadata.put("Filename", formula_filename); en.addMonitor(mon, metadata); } catch (IOException e) { e.printStackTrace(); System.exit(ERR_IO); } catch (Operator.ParseException e) { System.err.println("Error parsing input formula"); System.exit(ERR_PARSE); } } // Read trace and iterate // Opens file PipeReader pr = null; try { if (!pipe_filename.isEmpty()) { // We tell the pipe reader we read a pipe File f = new File(pipe_filename); if (verbosity > 0) System.err.println("Reading from pipe named " + f.getName()); pr = new PipeReader(new FileInputStream(f), en, false); } else if (!trace_filename.isEmpty()) { // We tell the pipe reader we read a regular file File f = new File(trace_filename); if (verbosity > 0) System.err.println("Reading from file " + f.getName()); pr = new PipeReader(new FileInputStream(f), en, true); } else if (tcp_port > 0) { // We tell the pipe reader we read from a socket if (verbosity > 0) System.err.println("Reading from TCP port " + tcp_port); m_serverSocket = new ServerSocket(tcp_port); m_connection = m_serverSocket.accept(); pr = new PipeReader(m_connection.getInputStream(), en, false); } else { // We tell the pipe reader we read from standard input if (verbosity > 0) System.err.println("Reading from standard input"); pr = new PipeReader(System.in, en, false); } } catch (FileNotFoundException ex) { // We print both trace and pipe since one of them must be empty System.err.println("ERROR: file not found " + trace_filename + pipe_filename); System.exit(ERR_IO); } catch (IOException e) { // Caused by socket error e.printStackTrace(); System.exit(ERR_IO); } pr.setSeparator("<" + event_name + ">", "</" + event_name + ">"); // Check parameters for the event notifier if (c_line.hasOption("no-trigger")) { en.m_notifyOnVerdict = false; } else { en.m_notifyOnVerdict = true; } if (c_line.hasOption("mirror")) { en.m_mirrorEventsOnStdout = true; } // Start event notifier en.reset(); Thread th = new Thread(pr); long clock_start = System.nanoTime(); th.start(); try { th.join(); // Wait for thread to finish } catch (InterruptedException e1) { // Thread is finished } if (tcp_port > 0 && m_serverSocket != null) { // We opened a socket; now we close it try { m_serverSocket.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } long clock_end = System.nanoTime(); int ret_code = pr.getReturnCode(); switch (ret_code) { case PipeReader.ERR_EOF: if (verbosity > 0) System.err.println("\nEnd of file reached"); break; case PipeReader.ERR_EOT: if (verbosity > 0) System.err.println("\nEOT received on pipe: closing"); break; case PipeReader.ERR_OK: // Do nothing break; default: // An error System.err.println("Runtime error"); System.exit(ERR_RUNTIME); break; } if (show_stats) { if (verbosity > 0) { System.out.println("Messages: " + en.m_numEvents); System.out.println("Time: " + (int) (en.m_totalTime / 1000000f) + " ms"); System.out.println("Clock time: " + (int) ((clock_end - clock_start) / 1000000f) + " ms"); System.out.println("Max heap: " + (int) (en.heapSize / 1048576f) + " MB"); } else { // If stats are asked but verbosity = 0, only show time value // (both monitor and wall clock) System.out.print((int) (en.m_totalTime / 1000000f)); System.out.print(","); System.out.print((int) ((clock_end - clock_start) / 1000000f)); } } System.exit(ERR_OK); }
From source file:PoolServerBase.java
static public void startServer(int port) { ServerSocket ssock; Socket sock;//from w ww . j av a2s . c o m try { ssock = new ServerSocket(port); while (true) { Socket esock = null; try { esock = ssock.accept(); while (listEmpty()) yield(); assignThread(esock); } catch (Exception e) { try { esock.close(); } catch (Exception ec) { } } } } catch (IOException e) { } }
From source file:GossipP2PServer.java
/** * Setup current server as a concurrent server. * @param port Port that server is listening on. *//* w ww .j a v a2 s.c om*/ static void runConcurrentServer(int port) { Socket sock; try { ServerSocket serverSocket = new ServerSocket(port); DatagramSocket dgSocket = new DatagramSocket(port); for (;;) { new ConcurrentUDPServerThread(dgSocket).start(); sock = serverSocket.accept(); new ConcurrentTCPServerThread(sock).start(); } } catch (Exception e) { } }
From source file:de.hshannover.f4.trust.iron.mapserver.contentauth.RemotePDP.java
private static void runServer(int port, LocalSunXacml pdp, int threads) { Executor clientExec = Executors.newFixedThreadPool(threads); ServerSocketFactory sockFac = ServerSocketFactory.getDefault(); try {// w w w .j ava2s.c om ServerSocket sock = sockFac.createServerSocket(port); while (true) { Socket clientSock = sock.accept(); Runnable cmd = new HandleXacmlRequest(clientSock, pdp); System.out.println(nameDate() + "new client " + clientSock.getInetAddress()); clientExec.execute(cmd); } } catch (IOException e) { System.err.println(nameDate() + e.toString()); System.exit(1); } }