if (!queueRunning) {
JSONStreamEncoder.encode(new QueueStopMessage().getParts(), outstream);
return;
}
Message m = null;
checkSession();
if (lock.tryAcquire()) {
outstream.write('[');
int payLoadSize = 0;
try {
if (wait) {
m = queue.poll(45, TimeUnit.SECONDS);
}
else {
m = queue.poll();
}
if (m instanceof HasEncoded) {
outstream.write(((HasEncoded) m).getEncoded().getBytes());
}
else if (m instanceof QueueStopMessage) {
JSONStreamEncoder.encode(m.getParts(), outstream);
queueRunning = false;
bus.closeQueue(this);
}
else if (m != null) {
JSONStreamEncoder.encode(m.getParts(), outstream);
}
if (_windowPolling) {
windowPolling = true;
_windowPolling = false;
}
else if (windowPolling) {
while (!queue.isEmpty() && payLoadSize < MAXIMUM_PAYLOAD_SIZE
&& !isWindowExceeded()) {
outstream.write(',');
if ((m = queue.poll()) instanceof HasEncoded) {
outstream.write(((HasEncoded) m).getEncoded().getBytes());
}
else {
JSONStreamEncoder.encode(m.getParts(), outstream);
}
payLoadSize++;
try {
if (queue.isEmpty())