/** * Called by the ServerNotificationManager whenever a notification needs to be sent to the client. */ public void fireNotification(NotificationWrapper wrapr) { if (que.size() < bufsiz) { synchronized (que) { que.add(wrapr); que.notify(); } } }
/** Sends an empty notification to the client. An empty notification is sent every 10 seconds. */ public void fireWaitNotif() { if (!hasIOExceptionOccurred() && (que.size() < bufsiz) && !dispatching && isIdle()) { synchronized (que) { que.add(new NotificationWrapper(NotificationWrapper.WAIT, null, null)); que.notify(); } } }
/** * The notifications dispatch thread. The dispatch thread sends all pending notifications in the * buffer to the client. The dispatch thread exits, whenever an IOException occurs during actual * dispatch or whenever this connection is being closed (after a call to close()) */ public void run() { /* XXX: Even when we are exiting should we send the remaining notifications? * OR just drop the remaining notifications ? * * Currently we drop all the remaining notifications!! */ while (!isExiting() && !hasIOExceptionOccurred()) { synchronized (que) { while (que.isEmpty() && !isExiting() && !hasIOExceptionOccurred()) { try { que.wait(); } catch (InterruptedException intre) { } } } if (isExiting() || hasIOExceptionOccurred()) break; dispatching = true; while (!que.isEmpty() && !isExiting() && !hasIOExceptionOccurred()) { NotificationWrapper wrapr = (NotificationWrapper) que.remove(); try { sendNotificationMsg(wrapr); } catch (IOException ioe) { if (isExiting()) break; // XXX: Log it; drop the notification if (!isDisconnected(ioe)) break; isIOException = true; synchronized (this) { this.notify(); } break; } } lastNotifTime = System.currentTimeMillis(); dispatching = false; } }
/** * When the server-side connector webapp is shutdown by the servlet container, the * ServerNotificationManager calls this method. All pending notifications are dropped. */ public void close() { exiting = true; synchronized (que) { que.notify(); } try { dispatchThr.join(); } catch (InterruptedException intre) { } try { out.close(); } catch (IOException ioe) { // XXX: Log it } }