org.apache.mina.core.write.WriteRequestWrapper Java Examples

The following examples show how to use org.apache.mina.core.write.WriteRequestWrapper. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ModbusMasterProtocolFilter.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void filterWrite ( final NextFilter nextFilter, final IoSession session, final WriteRequest writeRequest ) throws Exception
{
    if ( writeRequest.getMessage () instanceof BaseMessage )
    {
        final Pdu pdu = ModbusProtocol.encodeAsMaster ( (BaseMessage)writeRequest.getMessage () );
        nextFilter.filterWrite ( session, new WriteRequestWrapper ( writeRequest ) {
            @Override
            public Object getMessage ()
            {
                return pdu;
            };
        } );
    }
    else
    {
        nextFilter.filterWrite ( session, writeRequest );
    }
}
 
Example #2
Source File: ModbusSlaveProtocolFilter.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void filterWrite ( final NextFilter nextFilter, final IoSession session, final WriteRequest writeRequest ) throws Exception
{
    if ( writeRequest.getMessage () instanceof BaseMessage )
    {
        final Pdu pdu = ModbusProtocol.encodeAsSlave ( (BaseMessage)writeRequest.getMessage () );
        nextFilter.filterWrite ( session, new WriteRequestWrapper ( writeRequest ) {
            @Override
            public Object getMessage ()
            {
                return pdu;
            };
        } );
    }
    else
    {
        nextFilter.filterWrite ( session, writeRequest );
    }
}
 
Example #3
Source File: COTPFilter.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Handle data transmission
 * 
 * @param nextFilter
 * @param session
 * @param writeRequest
 */
private void handleDT ( final NextFilter nextFilter, final IoSession session, final WriteRequest writeRequest )
{
    final DataTPDU userData = (DataTPDU)writeRequest.getMessage ();
    final IoBuffer data = IoBuffer.allocate ( userData.getData ().remaining () + 3 );

    data.put ( (byte)0x02 ); // header length
    data.put ( (byte) ( COMMAND_DATA << 4 ) );

    final byte seq = (byte)0x80; // bit 8 to 1 (last packet)... bit 7..1 to zero (packet #0)

    data.put ( seq );

    data.put ( userData.getData () );

    data.flip ();

    nextFilter.filterWrite ( session, new WriteRequestWrapper ( writeRequest ) {
        @Override
        public Object getMessage ()
        {
            return data;
        }
    } );
}
 
Example #4
Source File: TPKTFilter.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void filterWrite ( final NextFilter nextFilter, final IoSession session, final WriteRequest writeRequest ) throws Exception
{
    // we only handle IoBuffers
    if ( writeRequest.getMessage () instanceof IoBuffer )
    {
        final IoBuffer inData = (IoBuffer)writeRequest.getMessage ();
        final IoBuffer outData = IoBuffer.allocate ( inData.remaining () + 4 );

        // put the version, the reserved
        outData.put ( (byte)this.version );
        outData.put ( (byte)0 );

        // and the data length
        outData.putShort ( (short) ( inData.remaining () + 4 ) );

        // append the data itself
        outData.put ( inData );

        outData.flip ();

        logger.debug ( "TPKT out: {}", outData );

        // pass on data buffer
        nextFilter.filterWrite ( session, new WriteRequestWrapper ( writeRequest ) {
            @Override
            public Object getMessage ()
            {
                return outData;
            }
        } );
    }
    else
    {
        nextFilter.filterWrite ( session, writeRequest );
    }
}
 
Example #5
Source File: DataMessageFilter.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void filterWrite ( final NextFilter nextFilter, final IoSession session, final WriteRequest writeRequest ) throws Exception
{
    final Object message = this.messageProtocol.getEncoder ().encodeMessage ( writeRequest.getMessage () );

    nextFilter.filterWrite ( session, new WriteRequestWrapper ( writeRequest ) {
        @Override
        public Object getMessage ()
        {
            return message;
        }
    } );
}