if (LOG.isDebugEnabled())
LOG.debug("connect websocket {} to {}",websocket,toUri);
// Grab Connection Manager
initializeClient();
ConnectionManager manager = getConnectionManager();
// Setup Driver for user provided websocket
EventDriver driver = null;
if (websocket instanceof EventDriver)
{
// Use the EventDriver as-is
driver = (EventDriver)websocket;
}
else
{
// Wrap websocket with appropriate EventDriver
driver = eventDriverFactory.wrap(websocket);
}
if (driver == null)
{
throw new IllegalStateException("Unable to identify as websocket object: " + websocket.getClass().getName());
}
// Create the appropriate (physical vs virtual) connection task
ConnectPromise promise = manager.connect(this,driver,request);
if (upgradeListener != null)
{
promise.setUpgradeListener(upgradeListener);
}