Here's our setup code:
HttpClient httpClient = new HttpClient();
httpClient.setConnectTimeout(TIMEOUT);
httpClient.setTimeout(TIMEOUT);
try {
httpClient.start();
} catch (Exception e) {
logger.e(e, "Unable to start httpClient");
}
LongPollingTransport transport = new LongPollingTransport(null,
httpClient) {
@Override
protected void customize(ContentExchange exchange) {
super.customize(exchange);
exchange.addRequestHeader(HEADER_SESSIONID,
sessionId);
}
};
client = new BayeuxClient(serverAddress, transport);
ClientSessionChannel.MessageListener handshakeListener = new HandshakeListener();
client.getChannel(Channel.META_HANDSHAKE)
.addListener(handshakeListener);
Map<String, Object> handshakeFields = new HashMap<String, Object>();
Map<String, Object> extFields = new HashMap<String, Object>();
extFields.put("uuid", uuid);
extFields.put("type", R.string.app_name);
handshakeFields.put("ext", extFields);
client.handshake(handshakeFields);
// Wait for the client to connect or else the client ID will be null
connected = client.waitFor(1000, BayeuxClient.State.CONNECTED);
It's worth noting that we're running CometD in an Android service and that we create it's own thread to run in. I noticed that where the warning is occurring, the ContentExchange variable _exchange that is being checked is volatile, so it seems possible that some thread is setting the _exchange variable to null.