tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christoph Mertins <c.mert...@gmail.com>
Subject Re: Tomcat web socket not sending more than one message to the client
Date Thu, 19 Oct 2017 14:48:00 GMT
Hello,

after waiting 35 minutes suddenly some events get forwarded for a second or
two and then again silence.
This is really strange.

Kind Regards,
Christoph

Mit freundlichen Grüßen
Christoph Mertins

On Thu, Oct 19, 2017 at 10:21 AM, Christoph Mertins <c.mertins@gmail.com>
wrote:

> Hello,
>
> I have a problem with Tomcat only sending the first message to the client
> and then no message anymore till the client reconnects.
>
> The code was working for some versions but then stopped working:
>
>         public void handleEvent(EventObject eventObject) {
>                 Enumeration<String> keySet = userSessions.keys();
>
>                 while (keySet.hasMoreElements()) {
>                         String key = keySet.nextElement();
>
>                         Session session = userSessions.get(key);
>
>                         synchronized (session) {
>
>                                 if (session.isOpen()) {
>                                         try {
>                                                 Semaphore semaphore = new
> Semaphore(1);
>                                                 Async async =
> session.getAsyncRemote();
>                                                 SendHandler handler = new
> SemaphoreSendHandler(semaphore, async);
>
>                                                 String text =
> eventTranscoder.encode(eventObject);
>
>                                                 LogManager.getLogger(this.
> getClass())
>
> .info("Eventbus Sending to " + session.getId() + " key: " + key + " text: "
> + text);
>
>                                                 if
> (async.getBatchingAllowed()) {
>
> async.setBatchingAllowed(false);
>                                                 }
>
>                                                 semaphore.
> acquireUninterruptibly();
>
>                                                 async.sendText(text,
> handler);
>                                                 async.flushBatch();
>
>                                                 //
> session.getBasicRemote().sendObject(eventObject);
>                                         } catch (IllegalStateException |
> EncodeException | IOException e) {
>                                                 LogManager.getLogger(this.getClass()).info("Sending
> failed", e);
>                                                 //
> userSessions.remove(key);
>                                         }
>                                 } else {
>                                         LogManager.getLogger(this.getClass()).info("Session
> not open" + key);
>                                         // userSessions.remove(key);
>                                 }
>                         }
>                 }
>         }
>
>         private class SemaphoreSendHandler implements SendHandler {
>
>                 private final Semaphore semaphore;
>                 private RemoteEndpoint remoteEndpoint;
>
>                 private SemaphoreSendHandler(Semaphore semaphore,
> RemoteEndpoint remoteEndpoint) {
>                         this.semaphore = semaphore;
>                         this.remoteEndpoint = remoteEndpoint;
>                 }
>
>                 @Override
>                 public void onResult(SendResult result) {
>                         LogManager.getLogger(
> EventBusEndpoint.class).info("Eventbus Sent ok: " + result.isOK());
>                         try {
>                                 remoteEndpoint.flushBatch();
>                                 remoteEndpoint.sendPing(ByteBuffer.wrap(new
> byte[0]));
>                         } catch (IOException e) {
>                                 LogManager.getLogger(this.getClass()).info("Flushing
> failed", e);
>                         }
>
>                         semaphore.release();
>                 }
>         }
>
> I can see the SemaphoreSendHandler putting out a true for the
> result.isOK() call.
>
> But I can’t see any network traffic and no message on the client side. I
> am checking the with a Chrome Extension (Simple Web Socket Client) on
> Chrome 61 and 62.
>
> Versions:
>
> Tomcat 8.5.21
> Java: Oracle JDK 1.8 151 (tested 131 too)
> OS: Raspbian Stretch
>
> I cannot see any reason why this is not working.
>
> Kind Regards,
> Christoph

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message