}
}
private void upgradeConnection(ClientUpgradeResponse response)
{
EndPoint endp = getEndPoint();
Executor executor = getExecutor();
EventDriver websocket = connectPromise.getDriver();
WebSocketPolicy policy = websocket.getPolicy();
WebSocketClientConnection connection = new WebSocketClientConnection(endp,executor,connectPromise,policy);
SessionFactory sessionFactory = connectPromise.getClient().getSessionFactory();
WebSocketSession session = sessionFactory.createSession(request.getRequestURI(),websocket,connection);
session.setPolicy(policy);
session.setUpgradeResponse(response);
connection.setSession(session);
// Initialize / Negotiate Extensions
ExtensionStack extensionStack = new ExtensionStack(connectPromise.getClient().getExtensionFactory());
extensionStack.negotiate(response.getExtensions());
extensionStack.configure(connection.getParser());
extensionStack.configure(connection.getGenerator());
// Setup Incoming Routing
connection.setNextIncomingFrames(extensionStack);
extensionStack.setNextIncoming(session);
// Setup Outgoing Routing
session.setOutgoingHandler(extensionStack);
extensionStack.setNextOutgoing(connection);
session.addBean(extensionStack);
connectPromise.getClient().addBean(session);
// Now swap out the connection
endp.setConnection(connection);
connection.onOpen();
}