public String popAndEncode(boolean fromOnlineEvent){
synchronized (this) {
    if (activeBridgeMode == null) {
      return null;
    }
    activeBridgeMode.notifyOfFlush(this,fromOnlineEvent);
    if (queue.isEmpty()) {
      return null;
    }
    int totalPayloadLen=0;
    int numMessagesToSend=0;
    for (    JsMessage message : queue) {
      int messageSize=calculatePackedMessageLength(message);
      if (numMessagesToSend > 0 && totalPayloadLen + messageSize > MAX_PAYLOAD_SIZE && MAX_PAYLOAD_SIZE > 0) {
        break;
      }
      totalPayloadLen+=messageSize;
      numMessagesToSend+=1;
    }
    StringBuilder sb=new StringBuilder(totalPayloadLen);
    for (int i=0; i < numMessagesToSend; ++i) {
      JsMessage message=queue.removeFirst();
      packMessage(message,sb);
    }
    if (!queue.isEmpty()) {
      sb.append('*');
    }
    String ret=sb.toString();
    return ret;
  }
}

public String popAndEncode ( boolean fromOnlineEvent ) { synchronized ( this ) { if ( activeBridgeMode == null ) { return null ; } activeBridgeMode . notifyOfFlush ( this , fromOnlineEvent ) ; if ( queue . isEmpty ( ) ) { return null ; } int totalPayloadLen = 0 ; int numMessagesToSend = 0 ; for ( JsMessage message : queue ) { int messageSize = calculatePackedMessageLength ( message ) ; if ( numMessagesToSend > 0 && totalPayloadLen + messageSize > MAX_PAYLOAD_SIZE && MAX_PAYLOAD_SIZE > 0 ) { break ; } totalPayloadLen += messageSize ; numMessagesToSend += 1 ; } StringBuilder sb = new StringBuilder ( totalPayloadLen ) ; for ( int i = 0 ; i < numMessagesToSend ; ++ i ) { JsMessage message = queue . removeFirst ( ) ; packMessage ( message , sb ) ; } if ( ! queue . isEmpty ( ) ) { sb . append ( '*' ) ; } String ret = sb . toString ( ) ; return ret ; } }
combines and returns queued messages combined into a single string . combines as many messages as possible , while staying under max_payload_size . returns null if the queue is empty .
