/** Processes (at least) the first event in the queue. */ void serviceEvent() { checkState(); ClientSessionServiceImpl sessionService = ClientSessionServiceImpl.getInstance(); ManagedQueue<SessionEvent> eventQueue = getQueue(); DataService dataService = ClientSessionServiceImpl.getDataService(); for (int i = 0; i < sessionService.eventsPerTxn; i++) { SessionEvent event = eventQueue.poll(); if (event == null) { // no more events break; } logger.log(Level.FINEST, "processing event:{0}", event); int cost = event.getCost(); if (cost > 0) { dataService.markForUpdate(this); writeBufferAvailable += cost; if (logger.isLoggable(Level.FINEST)) { logger.log( Level.FINEST, "{0} cleared reservation of " + "{1,number,#} bytes, leaving {2,number,#}", this, cost, writeBufferAvailable); } } event.serviceEvent(this); } }
/** * Attempts to enqueue the specified {@code event}, and returns {@code true} if successful, and * {@code false} otherwise. * * @param event the event * @return {@code true} if successful, and {@code false} otherwise * @throws MessageRejectedException if the cost of the event exceeds the available buffer space * in the queue */ boolean offer(SessionEvent event) { int cost = event.getCost(); if (cost > writeBufferAvailable) { ClientSessionServiceImpl sessionService = ClientSessionServiceImpl.getInstance(); if (sessionService.receiveMessageRejectedOp != null) { sessionService.receiveMessageRejectedOp.report(); } throw new MessageRejectedException( "Not enough queue space: " + writeBufferAvailable + " bytes available, " + cost + " requested"); } boolean success = getQueue().offer(event); if (success && cost > 0) { ClientSessionServiceImpl.getDataService().markForUpdate(this); writeBufferAvailable -= cost; if (logger.isLoggable(Level.FINEST)) { logger.log( Level.FINEST, "{0} reserved {1,number,#} leaving {2,number,#}", this, cost, writeBufferAvailable); } } return success; }