@Test(timeout=5000) public void testConnect() { final WebSocketSession session = registrySessionContext.get(); if (registrySessionContext.isAvailable()) { WebSocketSessionContext.disconnect(session); Assert.assertFalse(session.isOpen()); } Assert.assertTrue(registrySessionContext.isAvailable()); registrySessionContext.connect(); Assert.assertTrue(registrySessionContext.isAvailable()); }
protected void connect() { if (_isConnecting.compareAndSet(false, true)) { try { if (rateLimiter.isRateLimited("connect")) { _logger.error("WebSocketSessionContext reconnect times exceed expected value for a period time"); return; } final AddressContext context = _addressManager.getContext(); if (!context.isAavailable()) { return; } ListenableFuture<WebSocketSession> future = _wsClient.doHandshake(_handler, context.getWebSocketEndPoint()); future.addCallback(new WebSocketSessionCallback(this, context)); try { WebSocketSession session = future.get(_connectTimeout.typedValue(), TimeUnit.MILLISECONDS); final WebSocketSession oldSession = _session.getAndSet(session); _lastUpdatedTime = System.currentTimeMillis(); _addressContext.set(context); disconnect(oldSession); WebSocketSessionContext.this.afterConnectionEstablished(session); _logger.info("WebSocketSessionContext connected to: " + context.getWebSocketEndPoint()); } catch (Throwable ex) { context.markUnavailable(); _logger.warn("get WebSocketSession failed within the time specified", ex); } } catch (final Throwable e) { _addressContext.get().markUnavailable(); _logger.warn("connect to websocket endpoint failed", e); } finally { _isConnecting.set(false); } } }
WebSocketSessionContext { protected void connect() { if (_isConnecting.compareAndSet(false, true)) { try { if (rateLimiter.isRateLimited("connect")) { _logger.error("WebSocketSessionContext reconnect times exceed expected value for a period time"); return; } final AddressContext context = _addressManager.getContext(); if (!context.isAavailable()) { return; } ListenableFuture<WebSocketSession> future = _wsClient.doHandshake(_handler, context.getWebSocketEndPoint()); future.addCallback(new WebSocketSessionCallback(this, context)); try { WebSocketSession session = future.get(_connectTimeout.typedValue(), TimeUnit.MILLISECONDS); final WebSocketSession oldSession = _session.getAndSet(session); _lastUpdatedTime = System.currentTimeMillis(); _addressContext.set(context); disconnect(oldSession); WebSocketSessionContext.this.afterConnectionEstablished(session); _logger.info("WebSocketSessionContext connected to: " + context.getWebSocketEndPoint()); } catch (Throwable ex) { context.markUnavailable(); _logger.warn("get WebSocketSession failed within the time specified", ex); } } catch (final Throwable e) { _addressContext.get().markUnavailable(); _logger.warn("connect to websocket endpoint failed", e); } finally { _isConnecting.set(false); } } } }
WebSocketSessionContext { protected void connect() { if (_isConnecting.compareAndSet(false, true)) { try { if (rateLimiter.isRateLimited("connect")) { _logger.error("WebSocketSessionContext reconnect times exceed expected value for a period time"); return; } final AddressContext context = _addressManager.getContext(); if (!context.isAavailable()) { return; } ListenableFuture<WebSocketSession> future = _wsClient.doHandshake(_handler, context.getWebSocketEndPoint()); future.addCallback(new WebSocketSessionCallback(this, context)); try { WebSocketSession session = future.get(_connectTimeout.typedValue(), TimeUnit.MILLISECONDS); final WebSocketSession oldSession = _session.getAndSet(session); _lastUpdatedTime = System.currentTimeMillis(); _addressContext.set(context); disconnect(oldSession); WebSocketSessionContext.this.afterConnectionEstablished(session); _logger.info("WebSocketSessionContext connected to: " + context.getWebSocketEndPoint()); } catch (Throwable ex) { context.markUnavailable(); _logger.warn("get WebSocketSession failed within the time specified", ex); } } catch (final Throwable e) { _addressContext.get().markUnavailable(); _logger.warn("connect to websocket endpoint failed", e); } finally { _isConnecting.set(false); } } } WebSocketSessionContext(final ArtemisClientConfig config); }
WebSocketSessionContext { protected void connect() { if (_isConnecting.compareAndSet(false, true)) { try { if (rateLimiter.isRateLimited("connect")) { _logger.error("WebSocketSessionContext reconnect times exceed expected value for a period time"); return; } final AddressContext context = _addressManager.getContext(); if (!context.isAavailable()) { return; } ListenableFuture<WebSocketSession> future = _wsClient.doHandshake(_handler, context.getWebSocketEndPoint()); future.addCallback(new WebSocketSessionCallback(this, context)); try { WebSocketSession session = future.get(_connectTimeout.typedValue(), TimeUnit.MILLISECONDS); final WebSocketSession oldSession = _session.getAndSet(session); _lastUpdatedTime = System.currentTimeMillis(); _addressContext.set(context); disconnect(oldSession); WebSocketSessionContext.this.afterConnectionEstablished(session); _logger.info("WebSocketSessionContext connected to: " + context.getWebSocketEndPoint()); } catch (Throwable ex) { context.markUnavailable(); _logger.warn("get WebSocketSession failed within the time specified", ex); } } catch (final Throwable e) { _addressContext.get().markUnavailable(); _logger.warn("connect to websocket endpoint failed", e); } finally { _isConnecting.set(false); } } } WebSocketSessionContext(final ArtemisClientConfig config); void start(); static void disconnect(final WebSocketSession session); WebSocketSession get(); void checkHealth(); void markdown(); void shutdown(); }
WebSocketSessionContext { protected void connect() { if (_isConnecting.compareAndSet(false, true)) { try { if (rateLimiter.isRateLimited("connect")) { _logger.error("WebSocketSessionContext reconnect times exceed expected value for a period time"); return; } final AddressContext context = _addressManager.getContext(); if (!context.isAavailable()) { return; } ListenableFuture<WebSocketSession> future = _wsClient.doHandshake(_handler, context.getWebSocketEndPoint()); future.addCallback(new WebSocketSessionCallback(this, context)); try { WebSocketSession session = future.get(_connectTimeout.typedValue(), TimeUnit.MILLISECONDS); final WebSocketSession oldSession = _session.getAndSet(session); _lastUpdatedTime = System.currentTimeMillis(); _addressContext.set(context); disconnect(oldSession); WebSocketSessionContext.this.afterConnectionEstablished(session); _logger.info("WebSocketSessionContext connected to: " + context.getWebSocketEndPoint()); } catch (Throwable ex) { context.markUnavailable(); _logger.warn("get WebSocketSession failed within the time specified", ex); } } catch (final Throwable e) { _addressContext.get().markUnavailable(); _logger.warn("connect to websocket endpoint failed", e); } finally { _isConnecting.set(false); } } } WebSocketSessionContext(final ArtemisClientConfig config); void start(); static void disconnect(final WebSocketSession session); WebSocketSession get(); void checkHealth(); void markdown(); void shutdown();  }