@Override public void onResult(SendResult result) { endpoint.endMessage(null, result); } }
@Override public final void flushBatch() throws IOException { base.flushBatch(); }
@Override public final boolean getBatchingAllowed() { return base.getBatchingAllowed(); }
sendStringByCompletion(msg, completion); return; Encoder encoder = findEncoder(obj); sendStringByCompletion(msg, completion); } else if (encoder instanceof Encoder.TextStream) { try (Writer w = getSendWriter()) { ((Encoder.TextStream) encoder).encode(obj, w); } else if (encoder instanceof Encoder.Binary) { ByteBuffer msg = ((Encoder.Binary) encoder).encode(obj); sendBytesByCompletion(msg, completion); } else if (encoder instanceof Encoder.BinaryStream) { try (OutputStream os = getSendStream()) { ((Encoder.BinaryStream) encoder).encode(obj, os);
nextFragmented = fragmented; nextText = text; doWrite(mp.getHandler(), outputBuffer); return; if (isMasked()) { mask = Util.generateMask(); } else { writeHeader(headerBuffer, mp.getOpCode(), mp.getPayload(), first, mp.isLast(), isMasked(), mask); headerBuffer.flip(); if (getBatchingAllowed() || isMasked()) { outputBuffer, !getBatchingAllowed(), this); obsh.write(); } else { doWrite(mp.getHandler(), headerBuffer, mp.getPayload());
Encoder encoder = findEncoder(obj); if (encoder == null && Util.isPrimitive(obj.getClass())) { String msg = obj.toString(); sendString(msg); return; sendBytes(msg); return; sendString(msg); } else if (encoder instanceof Encoder.TextStream) { try (Writer w = getSendWriter()) { ((Encoder.TextStream) encoder).encode(obj, w); sendBytes(msg); } else if (encoder instanceof Encoder.BinaryStream) { try (OutputStream os = getSendStream()) { ((Encoder.BinaryStream) encoder).encode(obj, os);
/** * Called when a close message is received. Should only ever happen once. * Also called after a protocol error when the ProtocolHandler needs to * force the closing of the connection. */ public void onClose(CloseReason closeReason) { synchronized (stateLock) { if (state != State.CLOSED) { try { wsRemoteEndpoint.setBatchingAllowed(false); } catch (IOException e) { log.warn(sm.getString("wsSession.flushFailOnClose"), e); fireEndpointOnError(e); } if (state == State.OPEN) { state = State.OUTPUT_CLOSED; sendCloseMessage(closeReason); fireEndpointOnClose(closeReason); } state = State.CLOSED; // Close the socket wsRemoteEndpoint.close(); } } }
if (Constants.OPCODE_CLOSE == mp.getOpCode() && getBatchingAllowed()) { writeMessagePart(mp);
@Override public void onResult(SendResult result) { if (result.isOK()) { if (outputBuffer.hasRemaining()) { endpoint.doWrite(this, blockingWriteTimeoutExpiry, outputBuffer); } else { outputBuffer.clear(); write(); } } else { handler.onResult(result); } } }
void startMessageBlock(byte opCode, ByteBuffer payload, boolean last) throws IOException { // Get the timeout before we send the message. The message may // trigger a session close and depending on timing the client // session may close before we can read the timeout. long timeout = getBlockingSendTimeout(); FutureToSendHandler f2sh = new FutureToSendHandler(wsSession, opCode == Constants.OPCODE_CLOSE); startMessage(opCode, payload, last, f2sh); try { if (timeout == -1) { f2sh.get(); } else { f2sh.get(timeout, TimeUnit.MILLISECONDS); } } catch (InterruptedException e) { handleSendFailure(e); } catch (ExecutionException e) { throw new IOException(e); } catch (TimeoutException e) { throw new IOException(e); } }
void startMessageBlock(byte opCode, ByteBuffer payload, boolean last) throws IOException { // Get the timeout before we send the message. The message may // trigger a session close and depending on timing the client // session may close before we can read the timeout. long timeout = getBlockingSendTimeout(); FutureToSendHandler f2sh = new FutureToSendHandler(wsSession); startMessage(opCode, payload, last, f2sh); try { if (timeout == -1) { f2sh.get(); } else { f2sh.get(timeout, TimeUnit.MILLISECONDS); } } catch (InterruptedException | ExecutionException | TimeoutException e) { throw new IOException(e); } }
writeMessagePart(mp); if (!bsh.getSendResult().isOK()) { messagePartInProgress.release(); endMessage(null, null);
wsRemoteEndpoint.startMessageBlock( Constants.OPCODE_CLOSE, msg, true); } catch (IOException ioe) { wsRemoteEndpoint.close();
public final void close() { for (EncoderEntry entry : encoderEntries) { entry.getEncoder().destroy(); } doClose(); }
@Override public long getSendTimeout() { return base.getSendTimeout(); }
@Override public OutputStream getSendStream() throws IOException { return base.getSendStream(); }
private long getTimeoutExpiry() { // Get the timeout before we send the message. The message may // trigger a session close and depending on timing the client // session may close before we can read the timeout. long timeout = getBlockingSendTimeout(); if (timeout < 0) { return Long.MAX_VALUE; } else { return System.currentTimeMillis() + timeout; } }
wsRemoteEndpoint.sendMessageBlock(Constants.OPCODE_CLOSE, msg, true); } catch (IOException | WritePendingException e) { log.debug(sm.getString("wsSession.sendCloseFail", id), e); wsRemoteEndpoint.close();
void sendPartialString(CharBuffer part, boolean last) throws IOException { try { // Get the timeout before we send the message. The message may // trigger a session close and depending on timing the client // session may close before we can read the timeout. long timeout = getBlockingSendTimeout(); FutureToSendHandler f2sh = new FutureToSendHandler(wsSession); TextMessageSendHandler tmsh = new TextMessageSendHandler(f2sh, part, last, encoder, encoderBuffer, this); tmsh.write(); if (timeout == -1) { f2sh.get(); } else { f2sh.get(timeout, TimeUnit.MILLISECONDS); } } catch (InterruptedException e) { handleSendFailure(e); } catch (ExecutionException e) { throw new IOException(e); } catch (TimeoutException e) { throw new IOException(e); } }
/** * Called when a close message is received. Should only ever happen once. * Also called after a protocol error when the ProtocolHandler needs to * force the closing of the connection. */ public void onClose(CloseReason closeReason) { synchronized (stateLock) { if (state == State.OPEN) { sendCloseMessage(closeReason); fireEndpointOnClose(closeReason); state = State.CLOSED; } // Close the socket wsRemoteEndpoint.close(); } }