Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[jetty-dev] Jetty-9 WebSocket API Usage.

Hi I am trying to adopt jetty-9 web socket library. I am using the current snapshot version.

I have a problem with getting the connection after connect on client side.

I have created a class which extends the WebSocketAdapter.
But WebSocketAdapter.onWebSocketConnect() seems to be invoked after the completion of the get method shown below.

Basically the code looks like this.

WebSocketClient client  = factory.newWebSocketClient(myAdapter);
UpgradeResponse response = client.connect(uri).get(timeout, TimeUnit.MILISECONDS);

// If I sleep a little more here everything is ok.
myAdapter.getConnection().write(...);

If am too fast with using the connection it could be null.

I found that the code that notifies the WebSocketListener (myAdapter) and  unblocks the upgrade request future is in the UpgradeConnection#read() method when response is got.
More specifically 
  notifyConnect - unblocks (completes) the future
  upgradeConnection - calls the connection.onOpen and down the road onWebSocketConnect of myAdapter.

If I change the code there to invoke first upgradeConnection and then the notifiyConnect method everything works as expected on my side,
also all test seems to pass. 

Can someone, please fix this or if it is intended to be so and I missed something point me to way to handle this.

--
Vlado



Back to the top