src/main/java/js/net/EventStream.java
protected boolean loop() {
		Event event = null;
		try {
			event = eventsQueue.poll(keepAlivePeriod, TimeUnit.MILLISECONDS);
		} catch (InterruptedException unused) {
			if (!active.get()) {
				log.debug("Events stream |%s| thread is interrupted. Break events stream loop.", this);
				return false;
			}
			// in a perfect world, now would be the right moment to stop the events stream, returning false...
			// but i'm not sure interruption occurs only when current thread is interrupted
			// for now i play safe, allowing events stream to continue and use shutdown event to break it
			log.warn("Events stream |%s| thread is interrupted. Continue events stream loop.", this);
			return true;
		}

		if (event == null) {
			// we are here due to keep-alive period expiration
			// returns true to signal event stream should continue
			sendKeepAlive();
			log.debug("Keep-alive was sent to event stream |%s|.", this);
			return !writer.checkError();
		}

		// close method puts this event into queue; returns false to break this events stream loop
		if (event instanceof ShutdownEvent) {
			log.debug("Got shutdown event. Break event stream loop.");
			return false;
		}

		sendEvent(event);
		onSent(event);
		log.debug("Event |%s| was sent to event stream |%s|.", event, this);
		return !writer.checkError();
	}
protected boolean loop() {
		Event event = null;
		try {
			event = eventsQueue.poll(keepAlivePeriod, TimeUnit.MILLISECONDS);
		} catch (InterruptedException unused) {
			if (!active.get()) {
				log.debug("Events stream |%s| thread is interrupted. Break events stream loop.", this);
				return false;
			}
			// in a perfect world, now would be the right moment to stop the events stream, returning false...
			// but i'm not sure interruption occurs only when current thread is interrupted
			// for now i play safe, allowing events stream to continue and use shutdown event to break it
			log.warn("Events stream |%s| thread is interrupted. Continue events stream loop.", this);
			return true;
		}

		if (event == null) {
			// we are here due to keep-alive period expiration
			// returns true to signal event stream should continue
			sendKeepAlive();
			log.debug("Keep-alive was sent to event stream |%s|.", this);
			return !writer.checkError();
		}

		// close method puts this event into queue; returns false to break this events stream loop
		if (event instanceof ShutdownEvent) {
			log.debug("Got shutdown event. Break event stream loop.");
			return false;
		}

		sendEvent(event);
		onSent(event);
		log.debug("Event |%s| was sent to event stream |%s|.", event, this);
		return !writer.checkError();
	}
protected boolean loop ( ) { Event event = null ; try { event = eventsQueue . poll ( keepAlivePeriod , TimeUnit . MILLISECONDS ) ; } catch ( InterruptedException unused ) { if ( ! active . get ( ) ) { log . debug ( "Events stream |%s| thread is interrupted. Break events stream loop." , this ) ; return false ; } // in a perfect world, now would be the right moment to stop the events stream, returning false...
 // but i'm not sure interruption occurs only when current thread is interrupted
 // for now i play safe, allowing events stream to continue and use shutdown event to break it
 log . warn ( "Events stream |%s| thread is interrupted. Continue events stream loop." , this ) ; return true ; } if ( event == null ) { // we are here due to keep-alive period expiration
 // returns true to signal event stream should continue
 sendKeepAlive ( ) ; log . debug ( "Keep-alive was sent to event stream |%s|." , this ) ; return ! writer . checkError ( ) ; } // close method puts this event into queue; returns false to break this events stream loop
 if ( event instanceof ShutdownEvent ) { log . debug ( "Got shutdown event. Break event stream loop." ) ; return false ; } sendEvent ( event ) ; onSent ( event ) ; log . debug ( "Event |%s| was sent to event stream |%s|." , event , this ) ; return ! writer . checkError ( ) ; }
Event stream main loop repeated for every event. Waits for an event and push it to the client via {@link #writer}, writer
initialized by {@link EventStreamServlet} on this event stream creation. Note that this logic is executed into HTTP
request thread; it blocks the thread till an event become available. This method always returns true allowing event
stream to continue. It returns false only when got {@link ShutdownEvent}, pushed on queue by {@link #close()} method or
there is an error on print writer. Checking for print writer errors is especially useful to detect that remote client
closes its socket and to gracefully close this stream and release parent servlet instance.
<p>
Also this method takes care to periodically send keep alive events, see {@link #keepAlivePeriod}. Keep alive is used to
ensure server side and client logic that peer is still running and to avoid connection drop due to routers idle
connection timeout.

@return true if event stream should continue running.
Event stream main loop repeated for every event . Waits for an event and push it to the client via { @link #writer } writer initialized by { @link EventStreamServlet } on this event stream creation . Note that this logic is executed into HTTP request thread ; it blocks the thread till an event become available . This method always returns true allowing event stream to continue . It returns false only when got { @link ShutdownEvent } pushed on queue by { @link #close () } method or there is an error on print writer . Checking for print writer errors is especially useful to detect that remote client closes its socket and to gracefully close this stream and release parent servlet instance . <p > Also this method takes care to periodically send keep alive events see { @link #keepAlivePeriod } . Keep alive is used to ensure server side and client logic that peer is still running and to avoid connection drop due to routers idle connection timeout .