private void logUsedEncoder(CoderWrapper<Encoder> encoder, Session session) { if (LOGGER.isLoggable(Level.FINEST)) { if (session instanceof TyrusSession) { ((TyrusSession) session).getDebugContext() .appendLogMessage(LOGGER, Level.FINEST, DebugContext.Type.MESSAGE_OUT, "Encoding with: ", encoder); } } }
private void logUsedEncoder(CoderWrapper<Encoder> encoder, Session session) { if (LOGGER.isLoggable(Level.FINEST)) { if (session instanceof TyrusSession) { ((TyrusSession) session).getDebugContext() .appendLogMessage(LOGGER, Level.FINEST, DebugContext.Type.MESSAGE_OUT, "Encoding with: ", encoder); } } }
private ArrayList<CoderWrapper<Decoder>> findApplicableDecoders(TyrusSession session, Object message, boolean isString) { ArrayList<CoderWrapper<Decoder>> result = new ArrayList<CoderWrapper<Decoder>>(); for (CoderWrapper<Decoder> dec : decoders) { if (isString && (Decoder.Text.class.isAssignableFrom(dec.getCoderClass()))) { final Decoder.Text decoder = (Decoder.Text) getCoderInstance(session, dec); if (decoder.willDecode((String) message)) { result.add(dec); } } else if (!isString && (Decoder.Binary.class.isAssignableFrom(dec.getCoderClass()))) { final Decoder.Binary decoder = (Decoder.Binary) getCoderInstance(session, dec); if (decoder.willDecode((ByteBuffer) message)) { result.add(dec); } } else if (isString && (Decoder.TextStream.class.isAssignableFrom(dec.getCoderClass()))) { result.add(dec); } else if (!isString && (Decoder.BinaryStream.class.isAssignableFrom(dec.getCoderClass()))) { result.add(dec); } } session.getDebugContext() .appendLogMessage(LOGGER, Level.FINEST, DebugContext.Type.MESSAGE_IN, "Applicable decoders: ", result); return result; }
private ArrayList<CoderWrapper<Decoder>> findApplicableDecoders(TyrusSession session, Object message, boolean isString) { ArrayList<CoderWrapper<Decoder>> result = new ArrayList<CoderWrapper<Decoder>>(); for (CoderWrapper<Decoder> dec : decoders) { if (isString && (Decoder.Text.class.isAssignableFrom(dec.getCoderClass()))) { final Decoder.Text decoder = (Decoder.Text) getCoderInstance(session, dec); if (decoder.willDecode((String) message)) { result.add(dec); } } else if (!isString && (Decoder.Binary.class.isAssignableFrom(dec.getCoderClass()))) { final Decoder.Binary decoder = (Decoder.Binary) getCoderInstance(session, dec); if (decoder.willDecode((ByteBuffer) message)) { result.add(dec); } } else if (isString && (Decoder.TextStream.class.isAssignableFrom(dec.getCoderClass()))) { result.add(dec); } else if (!isString && (Decoder.BinaryStream.class.isAssignableFrom(dec.getCoderClass()))) { result.add(dec); } } session.getDebugContext() .appendLogMessage(LOGGER, Level.FINEST, DebugContext.Type.MESSAGE_IN, "Applicable decoders: ", result); return result; }
final Decoder.Text decoder = (Decoder.Text) getCoderInstance(session, selectedDecoder); session.getDebugContext() .appendLogMessage(LOGGER, Level.FINEST, DebugContext.Type.MESSAGE_IN, "Decoding with ", selectedDecoder); final Decoder.Binary decoder = (Decoder.Binary) getCoderInstance(session, selectedDecoder); session.getDebugContext() .appendLogMessage(LOGGER, Level.FINEST, DebugContext.Type.MESSAGE_IN, "Decoding with ", selectedDecoder); if (type != null && type.isAssignableFrom(selectedDecoder.getType())) { session.getDebugContext() .appendLogMessage(LOGGER, Level.FINEST, DebugContext.Type.MESSAGE_IN, "Decoding with ", selectedDecoder); byte[] array = ((ByteBuffer) message).array(); session.getDebugContext() .appendLogMessage(LOGGER, Level.FINEST, DebugContext.Type.MESSAGE_IN, "Decoding with ", selectedDecoder);
final Decoder.Text decoder = (Decoder.Text) getCoderInstance(session, selectedDecoder); session.getDebugContext() .appendLogMessage(LOGGER, Level.FINEST, DebugContext.Type.MESSAGE_IN, "Decoding with ", selectedDecoder); final Decoder.Binary decoder = (Decoder.Binary) getCoderInstance(session, selectedDecoder); session.getDebugContext() .appendLogMessage(LOGGER, Level.FINEST, DebugContext.Type.MESSAGE_IN, "Decoding with ", selectedDecoder); if (type != null && type.isAssignableFrom(selectedDecoder.getType())) { session.getDebugContext() .appendLogMessage(LOGGER, Level.FINEST, DebugContext.Type.MESSAGE_IN, "Decoding with ", selectedDecoder); byte[] array = ((ByteBuffer) message).array(); session.getDebugContext() .appendLogMessage(LOGGER, Level.FINEST, DebugContext.Type.MESSAGE_IN, "Decoding with ", selectedDecoder);
@Override public void sendText(String partialMessage, boolean isLast) throws IOException { checkNotNull(partialMessage, "partialMessage"); session.getDebugContext().appendLogMessage(LOGGER, Level.FINEST, DebugContext.Type.MESSAGE_OUT, "Sending partial text message: ", partialMessage); final Future<?> future = webSocket.sendText(partialMessage, isLast); try { processFuture(future); } finally { session.restartIdleTimeoutExecutor(); } }
@Override public void sendText(String partialMessage, boolean isLast) throws IOException { checkNotNull(partialMessage, "partialMessage"); session.getDebugContext().appendLogMessage(LOGGER, Level.FINEST, DebugContext.Type.MESSAGE_OUT, "Sending partial text message: ", partialMessage); final Future<?> future = webSocket.sendText(partialMessage, isLast); try { processFuture(future); } finally { session.restartIdleTimeoutExecutor(); } }
/** * Called by the provider when the web socket connection * has an incoming ping message from the given remote endpoint. * <p> * The endpoint needs to respond as soon as possible (see the websocket RFC). * No involvement from application layer, there is no ping listener. * * @param socket {@link TyrusWebSocket} who sent the message. * @param bytes the message. */ void onPing(TyrusWebSocket socket, ByteBuffer bytes) { TyrusSession session = getSession(socket); if (session == null) { LOGGER.log(Level.FINE, "Ping received on already closed connection."); return; } session.getDebugContext() .appendLogMessage(LOGGER, Level.FINEST, DebugContext.Type.MESSAGE_IN, "Received ping message"); session.restartIdleTimeoutExecutor(); try { session.getBasicRemote().sendPong(bytes); } catch (IOException e) { // do nothing. // we might consider calling onError, but there should be better defined exception. } }
@Override public void sendText(String text) throws IOException { checkNotNull(text, "text"); session.getDebugContext() .appendLogMessage(LOGGER, Level.FINEST, DebugContext.Type.MESSAGE_OUT, "Sending text message: ", text); final Future<?> future = webSocket.sendText(text); try { processFuture(future); } finally { session.restartIdleTimeoutExecutor(); } }
@Override public void sendText(String text) throws IOException { checkNotNull(text, "text"); session.getDebugContext() .appendLogMessage(LOGGER, Level.FINEST, DebugContext.Type.MESSAGE_OUT, "Sending text message: ", text); final Future<?> future = webSocket.sendText(text); try { processFuture(future); } finally { session.restartIdleTimeoutExecutor(); } }
/** * Called by the provider when the web socket connection * has an incoming ping message from the given remote endpoint. * <p> * The endpoint needs to respond as soon as possible (see the websocket RFC). * No involvement from application layer, there is no ping listener. * * @param socket {@link TyrusWebSocket} who sent the message. * @param bytes the message. */ void onPing(TyrusWebSocket socket, ByteBuffer bytes) { TyrusSession session = getSession(socket); if (session == null) { LOGGER.log(Level.FINE, "Ping received on already closed connection."); return; } session.getDebugContext() .appendLogMessage(LOGGER, Level.FINEST, DebugContext.Type.MESSAGE_IN, "Received ping message"); session.restartIdleTimeoutExecutor(); try { session.getBasicRemote().sendPong(bytes); } catch (IOException e) { // do nothing. // we might consider calling onError, but there should be better defined exception. } }
@Override public void sendBinary(ByteBuffer data) throws IOException { checkNotNull(data, "data"); session.getDebugContext() .appendLogMessage(LOGGER, Level.FINEST, DebugContext.Type.MESSAGE_OUT, "Sending binary message"); final Future<?> future = webSocket.sendBinary(Utils.getRemainingArray(data)); try { processFuture(future); } finally { session.restartIdleTimeoutExecutor(); } }
@Override public void sendBinary(ByteBuffer partialByte, boolean isLast) throws IOException { checkNotNull(partialByte, "partialByte"); session.getDebugContext().appendLogMessage(LOGGER, Level.FINEST, DebugContext.Type.MESSAGE_OUT, "Sending partial binary message"); final Future<?> future = webSocket.sendBinary(Utils.getRemainingArray(partialByte), isLast); try { processFuture(future); } finally { session.restartIdleTimeoutExecutor(); } }
@Override public void sendBinary(ByteBuffer data) throws IOException { checkNotNull(data, "data"); session.getDebugContext() .appendLogMessage(LOGGER, Level.FINEST, DebugContext.Type.MESSAGE_OUT, "Sending binary message"); final Future<?> future = webSocket.sendBinary(Utils.getRemainingArray(data)); try { processFuture(future); } finally { session.restartIdleTimeoutExecutor(); } }
Object toSend; try { session.getDebugContext() .appendLogMessage(LOGGER, Level.FINEST, DebugContext.Type.MESSAGE_OUT, "Sending object: ", o); toSend = endpointWrapper.doEncode(session, o);
@Override public void sendBinary(ByteBuffer partialByte, boolean isLast) throws IOException { checkNotNull(partialByte, "partialByte"); session.getDebugContext().appendLogMessage(LOGGER, Level.FINEST, DebugContext.Type.MESSAGE_OUT, "Sending partial binary message"); final Future<?> future = webSocket.sendBinary(Utils.getRemainingArray(partialByte), isLast); try { processFuture(future); } finally { session.restartIdleTimeoutExecutor(); } }
Object toSend; try { session.getDebugContext() .appendLogMessage(LOGGER, Level.FINEST, DebugContext.Type.MESSAGE_OUT, "Sending object: ", o); toSend = endpointWrapper.doEncode(session, o);
session.getDebugContext() .appendLogMessage(LOGGER, Level.FINEST, DebugContext.Type.MESSAGE_IN, "Received binary message");
session.getDebugContext() .appendLogMessage(LOGGER, Level.FINEST, DebugContext.Type.MESSAGE_IN, "Received text message");