public synchronized void poll(final Channel channel, final TransportMessage message) throws TransportException { throw new TransportException("Not implemented"); }
@Override public String toString() { return super.toString() + " (code=" + status + ")"; } }
protected void onError(Channel channel, Throwable throwable) { log.error(throwable, "Websocket connection error"); channel.onError(connectMessage, new RuntimeException("Websocket connection error", throwable)); getStatusHandler().handleException(new TransportException("Websocket connection error: " + throwable.getMessage())); } }
@Override public String toString() { return super.toString() + " (code=" + status + ")"; } }
protected void onError(Channel channel, Throwable throwable) { log.error(throwable, "Websocket connection error"); channel.onError(connectMessage, new RuntimeException("Websocket connection error", throwable)); getStatusHandler().handleException(new TransportException("Websocket connection error: " + throwable.getMessage())); } }
@Override public String toString() { return super.toString() + " (code=" + status + ")"; } }
@Override public synchronized boolean start() { if (isStarted()) return true; log.info("Starting Jetty WebSocketClient transport..."); try { webSocketClientFactory = new WebSocketClientFactory(); webSocketClientFactory.setBufferSize(4096); webSocketClientFactory.start(); final long timeout = System.currentTimeMillis() + 10000L; // 10sec. while (!webSocketClientFactory.isStarted()) { if (System.currentTimeMillis() > timeout) throw new TimeoutException("Jetty WebSocketFactory start process too long"); Thread.sleep(100); } log.info("Jetty WebSocketClient transport started."); return true; } catch (Exception e) { webSocketClientFactory = null; getStatusHandler().handleException(new TransportException("Could not start Jetty WebSocketFactory", e)); log.error(e, "Jetty WebSocketClient transport failed to start."); return false; } }
@Override public synchronized boolean start() { if (isStarted()) return true; log.info("Starting Jetty WebSocketClient transport..."); try { webSocketClientFactory.setBufferSize(4096); webSocketClientFactory.start(); final long timeout = System.currentTimeMillis() + 10000L; // 10sec. while (!webSocketClientFactory.isStarted()) { if (System.currentTimeMillis() > timeout) throw new TimeoutException("Jetty WebSocketFactory start process too long"); Thread.sleep(100); } log.info("Jetty WebSocketClient transport started."); return true; } catch (Exception e) { webSocketClientFactory = null; getStatusHandler().handleException(new TransportException("Could not start Jetty WebSocketFactory", e)); log.error(e, "Jetty WebSocketClient transport failed to start."); return false; } }
@Override public synchronized boolean start() { if (isStarted()) return true; log.info("Starting Jetty WebSocketClient transport..."); try { webSocketClientFactory.setBufferSize(4096); webSocketClientFactory.start(); final long timeout = System.currentTimeMillis() + 10000L; // 10sec. while (!webSocketClientFactory.isStarted()) { if (System.currentTimeMillis() > timeout) throw new TimeoutException("Jetty WebSocketFactory start process too long"); Thread.sleep(100); } log.info("Jetty WebSocketClient transport started."); return true; } catch (Exception e) { webSocketClientFactory = null; getStatusHandler().handleException(new TransportException("Could not start Jetty WebSocketFactory", e)); log.error(e, "Jetty WebSocketClient transport failed to start."); return false; } }
getStatusHandler().handleException(new TransportException("Transport could not connect code: " + closeCode + " " + message)); return; getStatusHandler().handleException(new TransportException("Transport disconnected")); return;
@Override public MessagingChannel newMessagingChannel(String channelType, String id, URI uri) { Transport transport = getMessagingTransport(channelType); if (transport == null) throw new RuntimeException("No transport defined for channel type " + channelType + ", start the ChannelFactory first"); if (!transport.isStarted() && !transport.start()) throw new TransportException("Could not start messaging transport: " + transport); MessagingCodec<Message[]> codec = newMessagingCodec(Message[].class); for (ChannelBuilder builder : ServiceLoader.load(ChannelBuilder.class)) { MessagingChannel channel = builder.buildMessagingChannel(channelType, id, uri, transport, codec); if (channel != null) { if (defaultTimeToLive != null) channel.setDefaultTimeToLive(defaultTimeToLive); return channel; } } MessagingChannel channel = defaultChannelBuilder.buildMessagingChannel(channelType, id, uri, transport, codec); if (channel == null) throw new RuntimeException("Could not build channel for type " + channelType + " and uri " + uri); if (defaultTimeToLive != null) channel.setDefaultTimeToLive(defaultTimeToLive); return channel; }
@Override public MessagingChannel newMessagingChannel(String channelType, String id, URI uri) { Transport transport = getMessagingTransport(channelType); if (transport == null) throw new RuntimeException("No transport defined for channel type " + channelType + ", start the ChannelFactory first"); if (!transport.isStarted() && !transport.start()) throw new TransportException("Could not start messaging transport: " + transport); MessagingCodec<Message[]> codec = newMessagingCodec(Message[].class); for (ChannelBuilder builder : ServiceLoader.load(ChannelBuilder.class)) { MessagingChannel channel = builder.buildMessagingChannel(channelType, id, uri, transport, codec); if (channel != null) { if (defaultTimeToLive != null) channel.setDefaultTimeToLive(defaultTimeToLive); return channel; } } MessagingChannel channel = defaultChannelBuilder.buildMessagingChannel(channelType, id, uri, transport, codec); if (channel == null) throw new RuntimeException("Could not build channel for type " + channelType + " and uri " + uri); if (defaultTimeToLive != null) channel.setDefaultTimeToLive(defaultTimeToLive); return channel; }
@Override public RemotingChannel newRemotingChannel(String id, URI uri, int maxConcurrentRequests) { if (getRemotingTransport() == null) throw new RuntimeException("Remoting transport not defined, start the ChannelFactory first"); if (!getRemotingTransport().isStarted() && !getRemotingTransport().start()) throw new TransportException("Could not start remoting transport: " + getRemotingTransport()); RemotingChannel channel = defaultChannelBuilder.buildRemotingChannel(getRemotingChannelClass(), id, uri, maxConcurrentRequests, getRemotingTransport(), newMessagingCodec(AMF0Message.class)); if (defaultTimeToLive != null) channel.setDefaultTimeToLive(defaultTimeToLive); return channel; }
@Override public RemotingChannel newRemotingChannel(String id, ServerApp serverApp, int maxConcurrentRequests) { if (getRemotingTransport() == null) throw new RuntimeException("Remoting transport not defined, start the ChannelFactory first"); if (!getRemotingTransport().isStarted() && !getRemotingTransport().start()) throw new TransportException("Could not start remoting transport: " + getRemotingTransport()); RemotingChannel channel = defaultChannelBuilder.buildRemotingChannel(getRemotingChannelClass(), id, serverApp, maxConcurrentRequests, getRemotingTransport(), newMessagingCodec(AMF0Message.class)); if (defaultTimeToLive != null) channel.setDefaultTimeToLive(defaultTimeToLive); return channel; }
@Override public MessagingChannel newMessagingChannel(String channelType, String id, ServerApp serverApp) { Transport transport = getMessagingTransport(channelType); if (transport == null) throw new RuntimeException("No transport defined for channel type " + channelType + ", start the ChannelFactory first"); if (!transport.isStarted() && !transport.start()) throw new TransportException("Could not start messaging transport: " + transport); MessagingCodec<Message[]> codec = newMessagingCodec(Message[].class); for (ChannelBuilder builder : ServiceLoader.load(ChannelBuilder.class)) { MessagingChannel channel = builder.buildMessagingChannel(channelType, id, serverApp, transport, codec); if (channel != null) { if (defaultTimeToLive != null) channel.setDefaultTimeToLive(defaultTimeToLive); return channel; } } MessagingChannel channel = defaultChannelBuilder.buildMessagingChannel(channelType, id, serverApp, transport, codec); if (channel == null) throw new RuntimeException("Could not build channel for type " + channelType + " and server " + serverApp.getServerName()); if (defaultTimeToLive != null) channel.setDefaultTimeToLive(defaultTimeToLive); return channel; }
@Override public MessagingChannel newMessagingChannel(String channelType, String id, ServerApp serverApp) { Transport transport = getMessagingTransport(channelType); if (transport == null) throw new RuntimeException("No transport defined for channel type " + channelType + ", start the ChannelFactory first"); if (!transport.isStarted() && !transport.start()) throw new TransportException("Could not start messaging transport: " + transport); MessagingCodec<Message[]> codec = newMessagingCodec(Message[].class); for (ChannelBuilder builder : ServiceLoader.load(ChannelBuilder.class)) { MessagingChannel channel = builder.buildMessagingChannel(channelType, id, serverApp, transport, codec); if (channel != null) { if (defaultTimeToLive != null) channel.setDefaultTimeToLive(defaultTimeToLive); return channel; } } MessagingChannel channel = defaultChannelBuilder.buildMessagingChannel(channelType, id, serverApp, transport, codec); if (channel == null) throw new RuntimeException("Could not build channel for type " + channelType + " and server " + serverApp.getServerName()); if (defaultTimeToLive != null) channel.setDefaultTimeToLive(defaultTimeToLive); return channel; }
public void start() { Platform platform = Platform.getInstance(); platform.setContext(context); if (remotingTransport == null) remotingTransport = Platform.getInstance().newRemotingTransport(); if (!remotingTransport.isStarted() && !remotingTransport.start()) throw new TransportException("Could not start remoting transport: " + remotingTransport); if (messagingTransport == null) { messagingTransport = Platform.getInstance().newMessagingTransport(); if (messagingTransport == null) messagingTransport = remotingTransport; } else if (!messagingTransport.isStarted() && !messagingTransport.start()) throw new TransportException("Could not start messaging transport: " + messagingTransport); if (aliasRegistry == null) aliasRegistry = new ClientAliasRegistry(); if (scanPackageNames != null) aliasRegistry.scan(scanPackageNames); }
@Override public RemotingChannel newRemotingChannel(String id, ServerApp serverApp, int maxConcurrentRequests) { if (getRemotingTransport() == null) throw new RuntimeException("Remoting transport not defined, start the ChannelFactory first"); if (!getRemotingTransport().isStarted() && !getRemotingTransport().start()) throw new TransportException("Could not start remoting transport: " + getRemotingTransport()); RemotingChannel channel = defaultChannelBuilder.buildRemotingChannel(getRemotingChannelClass(), id, serverApp, maxConcurrentRequests, getRemotingTransport(), newMessagingCodec(AMF0Message.class)); if (defaultTimeToLive != null) channel.setDefaultTimeToLive(defaultTimeToLive); return channel; }
@Override public RemotingChannel newRemotingChannel(String id, URI uri, int maxConcurrentRequests) { if (getRemotingTransport() == null) throw new RuntimeException("Remoting transport not defined, start the ChannelFactory first"); if (!getRemotingTransport().isStarted() && !getRemotingTransport().start()) throw new TransportException("Could not start remoting transport: " + getRemotingTransport()); RemotingChannel channel = defaultChannelBuilder.buildRemotingChannel(getRemotingChannelClass(), id, uri, maxConcurrentRequests, getRemotingTransport(), newMessagingCodec(AMF0Message.class)); if (defaultTimeToLive != null) channel.setDefaultTimeToLive(defaultTimeToLive); return channel; }
@Override public synchronized void stop() { if (httpClient == null) return; log.info("Stopping Apache HttpAsyncClient transport..."); super.stop(); try { httpClient.close(); } catch (Exception e) { getStatusHandler().handleException(new TransportException("Could not stop Apache HttpAsyncClient", e)); log.error(e, "Apache HttpAsyncClient failed to stop properly."); } finally { httpClient = null; } log.info("Apache HttpAsyncClient transport stopped."); } }