public void longPoll() throws InterruptedException {
  final String dolphinId=getDolphinId();
  if (dolphinId == null) {
    throw new IllegalStateException("longPoll was called outside a dolphin session");
  }
  final Receiver receiverInSession=getOrCreateReceiverInSession(dolphinId);
  if (!receiverInSession.isListeningToEventBus()) {
    receiverInSession.register(eventBus);
  }
  final DataflowQueue receiverQueue=receiverInSession.getReceiverQueue();
  boolean somethingHandled=false;
  while (!somethingHandled) {
    Object val=receiverQueue.getVal();
    final long startTime=System.currentTimeMillis();
    while (val != null) {
      if (val == releaseVal) {
        return;
      }
      if (val instanceof Message) {
        final Message event=(Message)val;
        somethingHandled|=receiverInSession.handle(event);
      }
      if (System.currentTimeMillis() - startTime <= MAX_POLL_DURATION) {
        val=receiverQueue.getVal(TIMEOUT,MILLISECONDS);
      }
 else {
        val=null;
      }
    }
  }
}

public void longPoll ( ) throws InterruptedException { final String dolphinId = getDolphinId ( ) ; if ( dolphinId == null ) { throw new IllegalStateException ( "longPoll was called outside a dolphin session" ) ; } final Receiver receiverInSession = getOrCreateReceiverInSession ( dolphinId ) ; if ( ! receiverInSession . isListeningToEventBus ( ) ) { receiverInSession . register ( eventBus ) ; } final DataflowQueue receiverQueue = receiverInSession . getReceiverQueue ( ) ; boolean somethingHandled = false ; while ( ! somethingHandled ) { Object val = receiverQueue . getVal ( ) ; final long startTime = System . currentTimeMillis ( ) ; while ( val != null ) { if ( val == releaseVal ) { return ; } if ( val instanceof Message ) { final Message event = ( Message ) val ; somethingHandled |= receiverInSession . handle ( event ) ; } if ( System . currentTimeMillis ( ) - startTime <= MAX_POLL_DURATION ) { val = receiverQueue . getVal ( TIMEOUT , MILLISECONDS ) ; } else { val = null ; } } } }
this method blocks till a release event occurs or there is something to handle in this session . this is the only location where we subscribe to our internal eventbus . so if longpoll is not called from client , we will never listen to the eventbus .
