public WebSocketServer(int port) { log.info("Starting Changes Plugin"); server = new Server("localhost", port, "/ws", null, WebSocketEndpoint.class); }
@Override public Void run() { try { // Tyrus tries to load the server code using reflection. In Elasticsearch 2.x Java // security manager is used which breaks the reflection code as it can't find the class. // This is a workaround for that Thread.currentThread().setContextClassLoader(getClass().getClassLoader()); server.start(); return null; } catch (DeploymentException e) { throw new RuntimeException("Failed to start server", e); } } });
public void end() { this.localWebSocketServer.stop(); this.localWebSocketServer = null; }
public static void main(String[] args) { if (args.length < 4) { System.out.println( "Please provide: (<hostname>, <port>, <websockets root path>, <;-sep fully qualfied classnames of" + " your bean>) in the command line"); System.out.println("e.g. localhost 8021 /websockets/myapp myapp.Bean1;myapp.Bean2"); System.exit(1); } Set<Class<?>> beanClasses = getClassesFromString(args[3]); int port = Integer.parseInt(args[1]); String hostname = args[0]; String wsroot = args[2]; Server server = new Server(hostname, port, wsroot, null, beanClasses); try { server.start(); System.out.println("Press any key to stop the WebSocket server..."); //noinspection ResultOfMethodCallIgnored System.in.read(); } catch (IOException ioe) { System.err.println("IOException during server run"); ioe.printStackTrace(); } catch (DeploymentException de) { de.printStackTrace(); } finally { server.stop(); } }
/** * Start embedded server unless "tyrus.test.host" system property is specified. * * @param endpointClasses websocket endpoints and configs to be deployed. * @return new {@link Server} instance or {@code null} if "tyrus.test.host" system property is set. * @throws DeploymentException when the server cannot be started. */ protected Server startServer(Class<?>... endpointClasses) throws DeploymentException { final String host = System.getProperty("tyrus.test.host"); if (host == null) { final Server server = new Server(defaultHost, getPort(), contextPath, serverProperties, endpointClasses); server.start(); return server; } else { return null; } }
/** * Starts a WebSocket server that has two endpoints, one that generates * String payloads and another that generates binary payloads. */ @Test public void startWebSocketServer() { Server server = new Server("localhost", 6543, "/sitewhere", null, WebSocketConfiguration.class); try { server.start(); BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); System.out.print("Please press a key to stop the server."); reader.readLine(); } catch (Exception e) { e.printStackTrace(); } finally { server.stop(); } } }
/** * Start the server. */ public void start() throws DeploymentException { try { if (server == null) { server = ServerContainerFactory.createServerContainer(properties); for (Class<?> clazz : configuration) { server.addEndpoint(clazz); } server.start(contextPath, port); if (server instanceof TyrusServerContainer) { this.port = ((TyrusServerContainer) server).getPort(); } LOGGER.info("WebSocket Registered apps: URLs all start with ws://" + this.hostName + ":" + getPort()); LOGGER.info("WebSocket server started."); } } catch (IOException e) { throw new DeploymentException(e.getMessage(), e); } }
public static void main(String[] args) { if (args.length < 4) { System.out.println( "Please provide: (<hostname>, <port>, <websockets root path>, <;-sep fully qualfied classnames of" + " your bean>) in the command line"); System.out.println("e.g. localhost 8021 /websockets/myapp myapp.Bean1;myapp.Bean2"); System.exit(1); } Set<Class<?>> beanClasses = getClassesFromString(args[3]); int port = Integer.parseInt(args[1]); String hostname = args[0]; String wsroot = args[2]; Server server = new Server(hostname, port, wsroot, null, beanClasses); try { server.start(); System.out.println("Press any key to stop the WebSocket server..."); //noinspection ResultOfMethodCallIgnored System.in.read(); } catch (IOException ioe) { System.err.println("IOException during server run"); ioe.printStackTrace(); } catch (DeploymentException de) { de.printStackTrace(); } finally { server.stop(); } }
/** * Start embedded server unless "tyrus.test.host" system property is specified. * * @param endpointClasses websocket endpoints and configs to be deployed. * @return new {@link Server} instance or {@code null} if "tyrus.test.host" system property is set. * @throws DeploymentException when the server cannot be started. */ protected Server startServer(Class<?>... endpointClasses) throws DeploymentException { final String host = System.getProperty("tyrus.test.host"); if (host == null) { final Server server = new Server(defaultHost, getPort(), contextPath, serverProperties, endpointClasses); server.start(); return server; } else { return null; } }
/** * Start the server. */ public void start() throws DeploymentException { try { if (server == null) { server = ServerContainerFactory.createServerContainer(properties); for (Class<?> clazz : configuration) { server.addEndpoint(clazz); } server.start(contextPath, port); if (server instanceof TyrusServerContainer) { this.port = ((TyrusServerContainer) server).getPort(); } LOGGER.info("WebSocket Registered apps: URLs all start with ws://" + this.hostName + ":" + getPort()); LOGGER.info("WebSocket server started."); } } catch (IOException e) { throw new DeploymentException(e.getMessage(), e); } }
public void run() { this.localWebSocketServer = new Server(ws_hostname, ws_port, "/", userProperties, RuntimeWebSocketServerService.class); ClassLoader classLoader = Thread.currentThread() .getContextClassLoader(); ClassLoader currentClassloader = this.getClass().getClassLoader(); if (classLoader != null) { this.droolsPlatformKnowledgeBase.setProjectClassLoader(classLoader); Thread.currentThread().setContextClassLoader(currentClassloader); } try { localWebSocketServer.start(); } catch (DeploymentException e) { LOG.error("WebSocketServer.run", e); } finally { if (classLoader != null) { Thread.currentThread().setContextClassLoader(classLoader); } } }
/** * Stop the server. * * @param server to be stopped. */ protected void stopServer(Server server) { if (server != null) { server.stop(); } }
/** * Stop the server. * * @param server to be stopped. */ protected void stopServer(Server server) { if (server != null) { server.stop(); } }
@Override public void close() { if (closed) return; synchronized (lock) { if (server != null) { closed = true; server.stop(); openSessions.closeAll(); openSessions = null; running = false; server = null; globalListener = null; } } }