/** * Default constructor that calls * {@code ContainerProvider.getWebSocketContainer()} to obtain a (new) * {@link WebSocketContainer} instance. */ public StandardWebSocketClient() { this(ContainerProvider.getWebSocketContainer()); }
private static WebSocketContainer getWebSocketContainerImpl() { WebSocketContainer wsc = null; for (ContainerProvider impl : ServiceLoader.load(ContainerProvider.class)) { wsc = impl.getContainer(); if (wsc != null) { return wsc; } } if (wsc == null) { throw new RuntimeException("Could not find an implementation class."); } else { throw new RuntimeException("Could not find an implementation class with a non-null WebSocketContainer."); } }
/** * Obtain a new instance of a WebSocketContainer. The method looks for the * ContainerProvider implementation class in the order listed in the META-INF/services/javax.websocket.ContainerProvider * file, returning the WebSocketContainer implementation from the ContainerProvider implementation * that is not {@code null}. * @return an implementation provided instance of type WebSocketContainer */ public static WebSocketContainer getWebSocketContainer() { if(System.getSecurityManager() == null) { return getWebSocketContainerImpl(); } else { return AccessController.doPrivileged(new PrivilegedAction<WebSocketContainer>() { @Override public WebSocketContainer run() { return getWebSocketContainerImpl(); } }); } }
private static WebSocketContainer getWebSocketContainerImpl() { WebSocketContainer wsc = null; for (ContainerProvider impl : ServiceLoader.load(ContainerProvider.class)) { wsc = impl.getContainer(); if (wsc != null) { return wsc; } } if (wsc == null) { throw new RuntimeException("Could not find an implementation class."); } else { throw new RuntimeException("Could not find an implementation class with a non-null WebSocketContainer."); } }
/** * Obtain a new instance of a WebSocketContainer. The method looks for the * ContainerProvider implementation class in the order listed in the META-INF/services/javax.websocket.ContainerProvider * file, returning the WebSocketContainer implementation from the ContainerProvider implementation * that is not {@code null}. * @return an implementation provided instance of type WebSocketContainer */ public static WebSocketContainer getWebSocketContainer() { if(System.getSecurityManager() == null) { return getWebSocketContainerImpl(); } else { return AccessController.doPrivileged(new PrivilegedAction<WebSocketContainer>() { @Override public WebSocketContainer run() { return getWebSocketContainerImpl(); } }); } }
/** * Default constructor that calls {@code ContainerProvider.getWebSocketContainer()} * to obtain a (new) {@link WebSocketContainer} instance. Also see constructor * accepting existing {@code WebSocketContainer} instance. */ public StandardWebSocketClient() { this.webSocketContainer = ContainerProvider.getWebSocketContainer(); }
/** * Obtain a new instance of a WebSocketContainer. The method looks for the * ContainerProvider implementation class in the order listed in the META-INF/services/javax.websocket.ContainerProvider * file, returning the WebSocketContainer implementation from the ContainerProvider implementation * that is not {@code null}. * @return an implementation provided instance of type WebSocketContainer */ public static WebSocketContainer getWebSocketContainer() { WebSocketContainer wsc = null; for (ContainerProvider impl : ServiceLoader.load(ContainerProvider.class)) { wsc = impl.getContainer(); if (wsc != null) { return wsc; } } if (wsc == null) { throw new RuntimeException("Could not find an implementation class."); } else { throw new RuntimeException("Could not find an implementation class with a non-null WebSocketContainer."); } }
public DaemonMessagesClientEndpoint( String host, String port, boolean ssl, MessageEventService messageEventService ) throws KettleException { try { setAuthProperties(); String url = String.format( URL_TEMPLATE, ( ssl ? PRFX_WS_SSL : PRFX_WS ), host, port ); URI uri = new URI( url ); this.messageEventService = messageEventService; WebSocketContainer container = ContainerProvider.getWebSocketContainer(); container.connectToServer( this, ClientEndpointConfig.Builder.create() .encoders( Collections.singletonList( MessageEncoder.class ) ) .decoders( Collections.singletonList( MessageDecoder.class ) ) .configurator( new SessionConfigurator( uri, keytab, principal ) ) .build(), uri ); } catch ( Exception e ) { throw new KettleException( e ); } }
/** * Obtain a new instance of a WebSocketContainer. The method looks for the * ContainerProvider implementation class in the order listed in the META-INF/services/javax.websocket.ContainerProvider * file, returning the WebSocketContainer implementation from the ContainerProvider implementation * that is not {@code null}. * @return an implementation provided instance of type WebSocketContainer */ public static WebSocketContainer getWebSocketContainer() { WebSocketContainer wsc = null; for (ContainerProvider impl : ServiceLoader.load(ContainerProvider.class)) { wsc = impl.getContainer(); if (wsc != null) { return wsc; } } if (wsc == null) { throw new RuntimeException("Could not find an implementation class."); } else { throw new RuntimeException("Could not find an implementation class with a non-null WebSocketContainer."); } }
/** * Default constructor that calls * {@code ContainerProvider.getWebSocketContainer()} to obtain a (new) * {@link WebSocketContainer} instance. */ public StandardWebSocketClient() { this(ContainerProvider.getWebSocketContainer()); }
/** * Obtain a new instance of a WebSocketContainer. The method looks for the * ContainerProvider implementation class in the order listed in the META-INF/services/javax.websocket.ContainerProvider * file, returning the WebSocketContainer implementation from the ContainerProvider implementation * that is not {@code null}. * @return an implementation provided instance of type WebSocketContainer */ public static WebSocketContainer getWebSocketContainer() { WebSocketContainer wsc = null; for (ContainerProvider impl : ServiceLoader.load(ContainerProvider.class)) { wsc = impl.getContainer(); if (wsc != null) { return wsc; } } if (wsc == null) { throw new RuntimeException("Could not find an implementation class."); } else { throw new RuntimeException("Could not find an implementation class with a non-null WebSocketContainer."); } }
/** * Default constructor that calls {@code ContainerProvider.getWebSocketContainer()} * to obtain a (new) {@link WebSocketContainer} instance. Also see constructor * accepting existing {@code WebSocketContainer} instance. */ public StandardWebSocketClient() { this.webSocketContainer = ContainerProvider.getWebSocketContainer(); }
/** * Obtain a new instance of a WebSocketContainer. The method looks for the ContainerProvider implementation class in * the order listed in the "META-INF/services/javax.websocket.ContainerProvider" file, returning the first * WebSocketContainer implementation from the ContainerProvider implementation that is not {@code null}. * * @return an implementation provided instance of type WebSocketContainer */ public static WebSocketContainer getWebSocketContainer() { Iterator<ContainerProvider> providers = ServiceLoader.load(ContainerProvider.class).iterator(); if (providers.hasNext()) { do { ContainerProvider impl = providers.next(); WebSocketContainer wsc = impl.getContainer(); if (wsc != null) { return wsc; } } while (providers.hasNext()); throw new RuntimeException("Could not find an implementation class with a non-null WebSocketContainer."); } else { throw new RuntimeException("Could not find an implementation class."); } }
/** * Default constructor that calls {@code ContainerProvider.getWebSocketContainer()} * to obtain a (new) {@link WebSocketContainer} instance. Also see constructor * accepting existing {@code WebSocketContainer} instance. */ public StandardWebSocketClient() { this.webSocketContainer = ContainerProvider.getWebSocketContainer(); }
/** * Create a new container used to create outgoing WebSocket connections. */ public static WebSocketContainer getWebSocketContainer() { WebSocketContainer result = null; ServiceLoader<ContainerProvider> serviceLoader = ServiceLoader.load(ContainerProvider.class); Iterator<ContainerProvider> iter = serviceLoader.iterator(); while (result == null && iter.hasNext()) { result = iter.next().getContainer(); } // Fall-back. Also used by unit tests if (result == null) { try { @SuppressWarnings("unchecked") Class<WebSocketContainer> clazz = (Class<WebSocketContainer>) Class.forName( DEFAULT_PROVIDER_CLASS_NAME); result = clazz.newInstance(); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) { // No options left. Just return null. } } return result; }
WebSocketContainer getContainer() { WebSocketContainer wc = container.get(); if(wc==null) { wc = ContainerProvider.getWebSocketContainer(); if(!container.compareAndSet(null, wc)) { wc = container.get(); } } return wc; }
/** * Create a new container used to create outgoing WebSocket connections. * * @return A newly created container. */ public static WebSocketContainer getWebSocketContainer() { WebSocketContainer result = null; ServiceLoader<ContainerProvider> serviceLoader = ServiceLoader.load(ContainerProvider.class); Iterator<ContainerProvider> iter = serviceLoader.iterator(); while (result == null && iter.hasNext()) { result = iter.next().getContainer(); } // Fall-back. Also used by unit tests if (result == null) { try { @SuppressWarnings("unchecked") Class<WebSocketContainer> clazz = (Class<WebSocketContainer>) Class.forName( DEFAULT_PROVIDER_CLASS_NAME); result = clazz.getConstructor().newInstance(); } catch (ReflectiveOperationException | IllegalArgumentException | SecurityException e) { // No options left. Just return null. } } return result; }
public WebSocketClient(final int retries, final String uri, final String authorization, final String marker) { this.counterUri = URI.create(uri + "/wsirona/counter"); this.gaugeUri = URI.create(uri + "/wsirona/gauge"); this.validationUri = URI.create(uri + "/wsirona/validation"); this.maxSendTries = 1 + Math.max(0, retries); this.authorization = authorization; this.marker = marker; this.container = ContainerProvider.getWebSocketContainer(); }
/** * Create a new container used to create outgoing WebSocket connections. */ public static WebSocketContainer getWebSocketContainer() { WebSocketContainer result = null; ServiceLoader<ContainerProvider> serviceLoader = ServiceLoader.load(ContainerProvider.class); Iterator<ContainerProvider> iter = serviceLoader.iterator(); while (result == null && iter.hasNext()) { result = iter.next().getContainer(); } // Fall-back. Also used by unit tests if (result == null) { try { @SuppressWarnings("unchecked") Class<WebSocketContainer> clazz = (Class<WebSocketContainer>) Class.forName( DEFAULT_PROVIDER_CLASS_NAME); result = clazz.newInstance(); } catch (ClassNotFoundException e) { // No options left. Just return null. } catch (InstantiationException e) { // No options left. Just return null. } catch (IllegalAccessException e) { // No options left. Just return null. } } return result; }
public WSClientEndpoint(URI endpointURI, ObjectSink sink) { try { WebSocketContainer container = ContainerProvider.getWebSocketContainer(); container.connectToServer(this, endpointURI); this.sink = sink; } catch (Exception e) { throw new RuntimeException(e); } }