private void replaceConnection() { EndPoint endPoint = getEndPoint(); Connection connection = client.getConnectionFactory().newConnection(channel, endPoint, attachment); endPoint.getConnection().onClose(); endPoint.setConnection(connection); connection.onOpen(); }
private void upgradeConnection(ClientUpgradeResponse response) { EndPoint endp = getEndPoint(); Executor executor = getExecutor(); WebSocketClientConnection connection = new WebSocketClientConnection(endp, executor, client); // Initialize / Negotiate Extensions EventDriver websocket = client.getWebSocket(); WebSocketPolicy policy = client.getPolicy(); String acceptedSubProtocol = response.getAcceptedSubProtocol(); WebSocketSession session = new WebSocketSession(request.getRequestURI(), websocket, connection); session.setPolicy(policy); session.setNegotiatedSubprotocol(acceptedSubProtocol); connection.setSession(session); List<Extension> extensions = client.getFactory().initExtensions(response.getExtensions()); // Start with default routing. IncomingFrames incoming = session; // OutgoingFrames outgoing = connection; // Connect extensions if (extensions != null) { connection.getParser().configureFromExtensions(extensions); connection.getGenerator().configureFromExtensions(extensions); // FIXME // Iterator<Extension> extIter; // // Connect outgoings // extIter = extensions.iterator(); // while (extIter.hasNext()) // { // Extension ext = extIter.next(); // ext.setNextOutgoingFrames(outgoing); // outgoing = ext; // } // // // Connect incomings // Collections.reverse(extensions); // extIter = extensions.iterator(); // while (extIter.hasNext()) // { // Extension ext = extIter.next(); // ext.setNextIncomingFrames(incoming); // incoming = ext; // } } // configure session for outgoing flows // session.setOutgoing(outgoing); // configure connection for incoming flows connection.getParser().setIncomingFramesHandler(incoming); // Now swap out the connection endp.setConnection(connection); connection.onOpen(); }