public void decode(IoSession session, ByteBuffer in, ProtocolDecoderOutput out) throws Exception { synchronized (decoder) { decoder.decode(session, in, out); } }
public void dispose(IoSession session) throws Exception { synchronized (decoder) { decoder.dispose(session); } } }
public void encode(IoSession session, Object message, ProtocolEncoderOutput out) throws Exception { synchronized (encoder) { encoder.encode(session, message, out); } }
@Override public void sessionClosed(NextFilter nextFilter, IoSession session) throws Exception { // Call finishDecode() first when a connection is closed. ProtocolDecoder decoder = getDecoder(session); ProtocolDecoderOutput decoderOut = getDecoderOut(session, nextFilter); try { decoder.finishDecode(session, decoderOut); } catch (Throwable t) { ProtocolDecoderException pde; if (t instanceof ProtocolDecoderException) { pde = (ProtocolDecoderException) t; } else { pde = new ProtocolDecoderException(t); } throw pde; } finally { // Dispose all. disposeEncoder(session); disposeDecoder(session); disposeDecoderOut(session); decoderOut.flush(); } nextFilter.sessionClosed(session); }
@Override public void filterWrite(NextFilter nextFilter, IoSession session, WriteRequest writeRequest) throws Exception { Object message = writeRequest.getMessage(); if (message instanceof ByteBuffer) { nextFilter.filterWrite(session, writeRequest); return; } ProtocolEncoder encoder = getEncoder(session); ProtocolEncoderOutputImpl encoderOut = getEncoderOut(session, nextFilter, writeRequest); try { encoder.encode(session, message, encoderOut); encoderOut.flush(); nextFilter.filterWrite(session, new WriteRequest( new MessageByteBuffer(writeRequest.getMessage()), writeRequest.getFuture(), writeRequest.getDestination())); } catch (Throwable t) { ProtocolEncoderException pee; if (t instanceof ProtocolEncoderException) { pee = (ProtocolEncoderException) t; } else { pee = new ProtocolEncoderException(t); } throw pee; } }
@Override protected DecodingState finishDecode(final ByteBuffer product, final ProtocolDecoderOutput out) throws Exception { final String reasonPhrase = product.getString(m_asciiDecoder); out.write(reasonPhrase); return null; } }
public void encode(final IoSession session, final Object message, final ProtocolEncoderOutput out) throws Exception { s_encodeAttempts++; if (LOG.isDebugEnabled()) { LOG.debug("Attempted encodes: "+s_encodeAttempts); } final ByteBuffer buffer = this.m_encoder.encode((SipMessage) message); //LOG.debug("Writing buffer: \n{}", MinaUtils.toAsciiString(buffer)); out.write(buffer); }
@Override public void onPostRemove(IoFilterChain parent, String name, NextFilter nextFilter) throws Exception { disposeEncoder(parent.getSession()); disposeDecoder(parent.getSession()); disposeDecoderOut(parent.getSession()); }
private ProtocolDecoder getDecoder(IoSession session) throws Exception { ProtocolDecoder decoder = (ProtocolDecoder) session .getAttribute(DECODER); if (decoder == null) { decoder = factory.getDecoder(); session.setAttribute(DECODER, decoder); } return decoder; }
/** * Releases the cumulative buffer used by the specified <tt>session</tt>. * Please don't forget to call <tt>super.dispose( session )</tt> when * you override this method. */ public void dispose(IoSession session) throws Exception { removeSessionBuffer(session); }
@Override public void dispose(IoSession session) throws Exception { super.dispose(session); // ProtocolEncoder.dispose() already called disposeCodec(), // so there's nothing more we need to do. } }
public void dispose(IoSession session) throws Exception { synchronized (encoder) { encoder.dispose(session); } } }
public void finishDecode(IoSession session, ProtocolDecoderOutput out) throws Exception { synchronized (decoder) { decoder.finishDecode(session, out); } }
private ProtocolEncoderOutputImpl getEncoderOut(IoSession session, NextFilter nextFilter, WriteRequest writeRequest) { return new ProtocolEncoderOutputImpl(session, nextFilter, writeRequest); }
/** * Returns the message and the hexdump of the unknown part. */ public String getMessage() { String message = super.getMessage(); if (message == null) { message = ""; } if (hexdump != null) { return message + ((message.length() > 0) ? " " : "") + "(Hexdump: " + hexdump + ')'; } else { return message; } }
private ProtocolEncoder getEncoder(IoSession session) throws Exception { ProtocolEncoder encoder = (ProtocolEncoder) session .getAttribute(ENCODER); if (encoder == null) { encoder = factory.getEncoder(); session.setAttribute(ENCODER, encoder); } return encoder; }
@Override protected DecodingState finishDecode(final ByteBuffer product, final ProtocolDecoderOutput out) throws Exception { final String version = product.getString(m_asciiDecoder); out.write(version); return null; } };
public void encode(final IoSession session, final Object message, ProtocolEncoderOutput out) throws Exception { final TcpFrameEncoder encoder = new TcpFrameEncoder(); final TcpFrame frame = (TcpFrame) message; final ByteBuffer buf = encoder.encode(frame); out.write(buf); }
@Override protected DecodingState finishDecode(final ByteBuffer readData, final ProtocolDecoderOutput out) throws Exception { LOG.debug("Returning SIP message with body..."); final SipMessage message = m_messageFactory.createSipMessage(m_headers, readData); out.write(message); return null; } }
protected boolean doDecode(IoSession session, ByteBuffer in, ProtocolDecoderOutput out) throws Exception { if (!in.prefixedDataAvailable(4, maxObjectSize)) { return false; } out.write(in.getObject(classLoader)); return true; } }