You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by "boB Gage (JIRA)" <ji...@apache.org> on 2009/06/18 15:41:07 UTC

[jira] Created: (DIRMINA-719) Serial Filter Chain Broken For Outbound Data

Serial Filter Chain Broken For Outbound Data
--------------------------------------------

                 Key: DIRMINA-719
                 URL: https://issues.apache.org/jira/browse/DIRMINA-719
             Project: MINA
          Issue Type: Bug
          Components: Transport
    Affects Versions: 2.0.0-M6, 2.0.0-M4
         Environment: Linux & Windows, serial-transport only
            Reporter: boB Gage


IoFilterAdapter-descended filter's messageSent() hook called only with 0-byte (Mina internal indicator, I'm told) IoBuffer data, not with IoBuffer containing data actually sent out the serial port.

Filter object looks like:

{code}
public class CaptureLogFilter extends IoFilterAdapter {
...
   @Override
   public void messageReceived(NextFilter nextFilter, IoSession
session, Object message) throws Exception {
       log("RECEIVED: ", message);
       if (nextFilter != null ) nextFilter.messageReceived(session,
message);
   }

   @Override
   public void messageSent(NextFilter nextFilter, IoSession session,
WriteRequest writeRequest) throws Exception {
       log("SENT: ", writeRequest.getMessage());
       if (nextFilter != null ) nextFilter.messageSent(session,
writeRequest);
   }
...
   private void log(String event, Object arg) {
       if (arg != null && arg instanceof IoBuffer) {
           byte b[] = IoBufferUtils.asBytes((IoBuffer) arg);
           log(event + b.length + " bytes: " + ByteUtils.toHex(b));
//            IoBuffer i = (IoBuffer)arg;
//            log("DBG: " + event + "pos: " + i.position() + ", lim:
"+i.limit());
// Previous debug was added to confirm IoBufferUtils operation, the IoBuffer 'arg' is confirmed empty (both position & limit are 0)
       }
       else log(event);
   }
...
}
{code}


And is hooked in the IoConnector set up:

{code}
   private final IoConnector buildIoConnector() {
...
       if ( codecFilter == null )
           codecFilter = new ProtocolCodecFilter(createCodecFactory());
...
       DefaultIoFilterChainBuilder fc = connector.getFilterChain();
       if ( fc.contains("logging") ) fc.remove("logging");
       if ( fc.contains("codec") ) fc.remove("codec");
       fc.addLast("logging", new
CaptureLogFilter(getClass().getSimpleName()));
       fc.addLast("codec", codecFilter);
...
}
{code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (DIRMINA-719) Serial Filter Chain Broken For Outbound Data

Posted by "Julien Vermillard (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/DIRMINA-719?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12744050#action_12744050 ] 

Julien Vermillard commented on DIRMINA-719:
-------------------------------------------

I committed a possible fix (http://svn.apache.org/viewvc?view=rev&revision=804964) , can you try it ? I'm out of test platform for serial communication

> Serial Filter Chain Broken For Outbound Data
> --------------------------------------------
>
>                 Key: DIRMINA-719
>                 URL: https://issues.apache.org/jira/browse/DIRMINA-719
>             Project: MINA
>          Issue Type: Bug
>          Components: Transport
>    Affects Versions: 2.0.0-M4, 2.0.0-M6
>         Environment: Linux & Windows, serial-transport only
>            Reporter: boB Gage
>            Assignee: Julien Vermillard
>
> IoFilterAdapter-descended filter's messageSent() hook called only with 0-byte (Mina internal indicator, I'm told) IoBuffer data, not with IoBuffer containing data actually sent out the serial port.
> Filter object looks like:
> {code}
> public class CaptureLogFilter extends IoFilterAdapter {
> ...
>    @Override
>    public void messageReceived(NextFilter nextFilter, IoSession
> session, Object message) throws Exception {
>        log("RECEIVED: ", message);
>        if (nextFilter != null ) nextFilter.messageReceived(session,
> message);
>    }
>    @Override
>    public void messageSent(NextFilter nextFilter, IoSession session,
> WriteRequest writeRequest) throws Exception {
>        log("SENT: ", writeRequest.getMessage());
>        if (nextFilter != null ) nextFilter.messageSent(session,
> writeRequest);
>    }
> ...
>    private void log(String event, Object arg) {
>        if (arg != null && arg instanceof IoBuffer) {
>            byte b[] = IoBufferUtils.asBytes((IoBuffer) arg);
>            log(event + b.length + " bytes: " + ByteUtils.toHex(b));
> //            IoBuffer i = (IoBuffer)arg;
> //            log("DBG: " + event + "pos: " + i.position() + ", lim:
> "+i.limit());
> // Previous debug was added to confirm IoBufferUtils operation, the IoBuffer 'arg' is confirmed empty (both position & limit are 0)
>        }
>        else log(event);
>    }
> ...
> }
> {code}
> And is hooked in the IoConnector set up:
> {code}
>    private final IoConnector buildIoConnector() {
> ...
>        if ( codecFilter == null )
>            codecFilter = new ProtocolCodecFilter(createCodecFactory());
> ...
>        DefaultIoFilterChainBuilder fc = connector.getFilterChain();
>        if ( fc.contains("logging") ) fc.remove("logging");
>        if ( fc.contains("codec") ) fc.remove("codec");
>        fc.addLast("logging", new
> CaptureLogFilter(getClass().getSimpleName()));
>        fc.addLast("codec", codecFilter);
> ...
> }
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (DIRMINA-719) Serial Filter Chain Broken For Outbound Data

Posted by "Emmanuel Lecharny (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/DIRMINA-719?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12721275#action_12721275 ] 

Emmanuel Lecharny commented on DIRMINA-719:
-------------------------------------------

The way MINA works make it mandatory that the MessageSent event is sent when a empty message is received. I know it sounds a bit strange, but in any case, it won't forbid your program to work, *except* that you are expecting to trace the message being sent.

The reason it works this way is because you can perfectly well send your response in small chunks (for instance if you want to stream a big file to a client), thus you have no way to know when the message has been sent.

Obviously, you have to ilmplement your own ProtocolEncoderOutput class to split your message in chunks, but it's not irrealistic to think that it could be done somewhere (in fact, we at Apache Directory are thinking about doing so for images).

Now, you are not totally lost in the desert without water and solar cream : a workaround for you would be to store the sent message in the session (as an attribute), so when you receive the MessageSent event, you just have to grab it from the session attributes, print it and discard it.

Hope it helps.

> Serial Filter Chain Broken For Outbound Data
> --------------------------------------------
>
>                 Key: DIRMINA-719
>                 URL: https://issues.apache.org/jira/browse/DIRMINA-719
>             Project: MINA
>          Issue Type: Bug
>          Components: Transport
>    Affects Versions: 2.0.0-M4, 2.0.0-M6
>         Environment: Linux & Windows, serial-transport only
>            Reporter: boB Gage
>
> IoFilterAdapter-descended filter's messageSent() hook called only with 0-byte (Mina internal indicator, I'm told) IoBuffer data, not with IoBuffer containing data actually sent out the serial port.
> Filter object looks like:
> {code}
> public class CaptureLogFilter extends IoFilterAdapter {
> ...
>    @Override
>    public void messageReceived(NextFilter nextFilter, IoSession
> session, Object message) throws Exception {
>        log("RECEIVED: ", message);
>        if (nextFilter != null ) nextFilter.messageReceived(session,
> message);
>    }
>    @Override
>    public void messageSent(NextFilter nextFilter, IoSession session,
> WriteRequest writeRequest) throws Exception {
>        log("SENT: ", writeRequest.getMessage());
>        if (nextFilter != null ) nextFilter.messageSent(session,
> writeRequest);
>    }
> ...
>    private void log(String event, Object arg) {
>        if (arg != null && arg instanceof IoBuffer) {
>            byte b[] = IoBufferUtils.asBytes((IoBuffer) arg);
>            log(event + b.length + " bytes: " + ByteUtils.toHex(b));
> //            IoBuffer i = (IoBuffer)arg;
> //            log("DBG: " + event + "pos: " + i.position() + ", lim:
> "+i.limit());
> // Previous debug was added to confirm IoBufferUtils operation, the IoBuffer 'arg' is confirmed empty (both position & limit are 0)
>        }
>        else log(event);
>    }
> ...
> }
> {code}
> And is hooked in the IoConnector set up:
> {code}
>    private final IoConnector buildIoConnector() {
> ...
>        if ( codecFilter == null )
>            codecFilter = new ProtocolCodecFilter(createCodecFactory());
> ...
>        DefaultIoFilterChainBuilder fc = connector.getFilterChain();
>        if ( fc.contains("logging") ) fc.remove("logging");
>        if ( fc.contains("codec") ) fc.remove("codec");
>        fc.addLast("logging", new
> CaptureLogFilter(getClass().getSimpleName()));
>        fc.addLast("codec", codecFilter);
> ...
> }
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (DIRMINA-719) Serial Filter Chain Broken For Outbound Data

Posted by "boB Gage (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/DIRMINA-719?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12721312#action_12721312 ] 

boB Gage commented on DIRMINA-719:
----------------------------------

It appears the fix is just a matter of a one line change -- I currently 
lack the facilities to test that theory.

We'll see who's priority pile moves quicker.  :-)    This one only affects 
my debug logging, so it's fairly low priority.

The problem is NOT the 0-byte IoBuffer calls at all.   Those are Mina 
internals and I don't need to mess with them; I won't depend on them for 
the same reason.

The problem is the data-bearing (ie non-0-byte) IoBuffer calls that 
*happen* on a socket connection *DO NOT HAPPEN* on a serial connection.

Yes, I could hack around this problem but I would prefer not to.

Especially since that's how it works for socket connections.    My hack 
would have to take transport mechanism into account, and one of the 
strengths of Mina is abstracting that.





> Serial Filter Chain Broken For Outbound Data
> --------------------------------------------
>
>                 Key: DIRMINA-719
>                 URL: https://issues.apache.org/jira/browse/DIRMINA-719
>             Project: MINA
>          Issue Type: Bug
>          Components: Transport
>    Affects Versions: 2.0.0-M4, 2.0.0-M6
>         Environment: Linux & Windows, serial-transport only
>            Reporter: boB Gage
>
> IoFilterAdapter-descended filter's messageSent() hook called only with 0-byte (Mina internal indicator, I'm told) IoBuffer data, not with IoBuffer containing data actually sent out the serial port.
> Filter object looks like:
> {code}
> public class CaptureLogFilter extends IoFilterAdapter {
> ...
>    @Override
>    public void messageReceived(NextFilter nextFilter, IoSession
> session, Object message) throws Exception {
>        log("RECEIVED: ", message);
>        if (nextFilter != null ) nextFilter.messageReceived(session,
> message);
>    }
>    @Override
>    public void messageSent(NextFilter nextFilter, IoSession session,
> WriteRequest writeRequest) throws Exception {
>        log("SENT: ", writeRequest.getMessage());
>        if (nextFilter != null ) nextFilter.messageSent(session,
> writeRequest);
>    }
> ...
>    private void log(String event, Object arg) {
>        if (arg != null && arg instanceof IoBuffer) {
>            byte b[] = IoBufferUtils.asBytes((IoBuffer) arg);
>            log(event + b.length + " bytes: " + ByteUtils.toHex(b));
> //            IoBuffer i = (IoBuffer)arg;
> //            log("DBG: " + event + "pos: " + i.position() + ", lim:
> "+i.limit());
> // Previous debug was added to confirm IoBufferUtils operation, the IoBuffer 'arg' is confirmed empty (both position & limit are 0)
>        }
>        else log(event);
>    }
> ...
> }
> {code}
> And is hooked in the IoConnector set up:
> {code}
>    private final IoConnector buildIoConnector() {
> ...
>        if ( codecFilter == null )
>            codecFilter = new ProtocolCodecFilter(createCodecFactory());
> ...
>        DefaultIoFilterChainBuilder fc = connector.getFilterChain();
>        if ( fc.contains("logging") ) fc.remove("logging");
>        if ( fc.contains("codec") ) fc.remove("codec");
>        fc.addLast("logging", new
> CaptureLogFilter(getClass().getSimpleName()));
>        fc.addLast("codec", codecFilter);
> ...
> }
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (DIRMINA-719) Serial Filter Chain Broken For Outbound Data

Posted by "boB Gage (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/DIRMINA-719?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12721260#action_12721260 ] 

boB Gage commented on DIRMINA-719:
----------------------------------

Opps...   pretend like {code} markers in description start  & stop block-quote-like code quotes.  They are NOT part of my code...  :-)

Theory presented on list is that this is caused by org.apache.mina.transport.serial.SerialSessionImpl in the flushWrites() method.

The logic in that method calls this.getFilterChain().fireMessageSent(req) inside a if (buf.remaining() == 0) { ... } condition.    What it appears to lack, however, is a this.getFilterChain().fireMessageSent(req) called when the buffer is NOT empty.

This logic seems to reflect the behaviour I am seeing in that my filter is called with the 0-byte indicator but not the data-bearing IoBuffer.

> Serial Filter Chain Broken For Outbound Data
> --------------------------------------------
>
>                 Key: DIRMINA-719
>                 URL: https://issues.apache.org/jira/browse/DIRMINA-719
>             Project: MINA
>          Issue Type: Bug
>          Components: Transport
>    Affects Versions: 2.0.0-M4, 2.0.0-M6
>         Environment: Linux & Windows, serial-transport only
>            Reporter: boB Gage
>
> IoFilterAdapter-descended filter's messageSent() hook called only with 0-byte (Mina internal indicator, I'm told) IoBuffer data, not with IoBuffer containing data actually sent out the serial port.
> Filter object looks like:
> {code}
> public class CaptureLogFilter extends IoFilterAdapter {
> ...
>    @Override
>    public void messageReceived(NextFilter nextFilter, IoSession
> session, Object message) throws Exception {
>        log("RECEIVED: ", message);
>        if (nextFilter != null ) nextFilter.messageReceived(session,
> message);
>    }
>    @Override
>    public void messageSent(NextFilter nextFilter, IoSession session,
> WriteRequest writeRequest) throws Exception {
>        log("SENT: ", writeRequest.getMessage());
>        if (nextFilter != null ) nextFilter.messageSent(session,
> writeRequest);
>    }
> ...
>    private void log(String event, Object arg) {
>        if (arg != null && arg instanceof IoBuffer) {
>            byte b[] = IoBufferUtils.asBytes((IoBuffer) arg);
>            log(event + b.length + " bytes: " + ByteUtils.toHex(b));
> //            IoBuffer i = (IoBuffer)arg;
> //            log("DBG: " + event + "pos: " + i.position() + ", lim:
> "+i.limit());
> // Previous debug was added to confirm IoBufferUtils operation, the IoBuffer 'arg' is confirmed empty (both position & limit are 0)
>        }
>        else log(event);
>    }
> ...
> }
> {code}
> And is hooked in the IoConnector set up:
> {code}
>    private final IoConnector buildIoConnector() {
> ...
>        if ( codecFilter == null )
>            codecFilter = new ProtocolCodecFilter(createCodecFactory());
> ...
>        DefaultIoFilterChainBuilder fc = connector.getFilterChain();
>        if ( fc.contains("logging") ) fc.remove("logging");
>        if ( fc.contains("codec") ) fc.remove("codec");
>        fc.addLast("logging", new
> CaptureLogFilter(getClass().getSimpleName()));
>        fc.addLast("codec", codecFilter);
> ...
> }
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Closed: (DIRMINA-719) Serial Filter Chain Broken For Outbound Data

Posted by "Julien Vermillard (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/DIRMINA-719?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Julien Vermillard closed DIRMINA-719.
-------------------------------------

       Resolution: Fixed
    Fix Version/s: 2.0.0-M7

> Serial Filter Chain Broken For Outbound Data
> --------------------------------------------
>
>                 Key: DIRMINA-719
>                 URL: https://issues.apache.org/jira/browse/DIRMINA-719
>             Project: MINA
>          Issue Type: Bug
>          Components: Transport
>    Affects Versions: 2.0.0-M4, 2.0.0-M6
>         Environment: Linux & Windows, serial-transport only
>            Reporter: boB Gage
>            Assignee: Julien Vermillard
>             Fix For: 2.0.0-M7
>
>
> IoFilterAdapter-descended filter's messageSent() hook called only with 0-byte (Mina internal indicator, I'm told) IoBuffer data, not with IoBuffer containing data actually sent out the serial port.
> Filter object looks like:
> {code}
> public class CaptureLogFilter extends IoFilterAdapter {
> ...
>    @Override
>    public void messageReceived(NextFilter nextFilter, IoSession
> session, Object message) throws Exception {
>        log("RECEIVED: ", message);
>        if (nextFilter != null ) nextFilter.messageReceived(session,
> message);
>    }
>    @Override
>    public void messageSent(NextFilter nextFilter, IoSession session,
> WriteRequest writeRequest) throws Exception {
>        log("SENT: ", writeRequest.getMessage());
>        if (nextFilter != null ) nextFilter.messageSent(session,
> writeRequest);
>    }
> ...
>    private void log(String event, Object arg) {
>        if (arg != null && arg instanceof IoBuffer) {
>            byte b[] = IoBufferUtils.asBytes((IoBuffer) arg);
>            log(event + b.length + " bytes: " + ByteUtils.toHex(b));
> //            IoBuffer i = (IoBuffer)arg;
> //            log("DBG: " + event + "pos: " + i.position() + ", lim:
> "+i.limit());
> // Previous debug was added to confirm IoBufferUtils operation, the IoBuffer 'arg' is confirmed empty (both position & limit are 0)
>        }
>        else log(event);
>    }
> ...
> }
> {code}
> And is hooked in the IoConnector set up:
> {code}
>    private final IoConnector buildIoConnector() {
> ...
>        if ( codecFilter == null )
>            codecFilter = new ProtocolCodecFilter(createCodecFactory());
> ...
>        DefaultIoFilterChainBuilder fc = connector.getFilterChain();
>        if ( fc.contains("logging") ) fc.remove("logging");
>        if ( fc.contains("codec") ) fc.remove("codec");
>        fc.addLast("logging", new
> CaptureLogFilter(getClass().getSimpleName()));
>        fc.addLast("codec", codecFilter);
> ...
> }
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Assigned: (DIRMINA-719) Serial Filter Chain Broken For Outbound Data

Posted by "Julien Vermillard (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/DIRMINA-719?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Julien Vermillard reassigned DIRMINA-719:
-----------------------------------------

    Assignee: Julien Vermillard

> Serial Filter Chain Broken For Outbound Data
> --------------------------------------------
>
>                 Key: DIRMINA-719
>                 URL: https://issues.apache.org/jira/browse/DIRMINA-719
>             Project: MINA
>          Issue Type: Bug
>          Components: Transport
>    Affects Versions: 2.0.0-M4, 2.0.0-M6
>         Environment: Linux & Windows, serial-transport only
>            Reporter: boB Gage
>            Assignee: Julien Vermillard
>
> IoFilterAdapter-descended filter's messageSent() hook called only with 0-byte (Mina internal indicator, I'm told) IoBuffer data, not with IoBuffer containing data actually sent out the serial port.
> Filter object looks like:
> {code}
> public class CaptureLogFilter extends IoFilterAdapter {
> ...
>    @Override
>    public void messageReceived(NextFilter nextFilter, IoSession
> session, Object message) throws Exception {
>        log("RECEIVED: ", message);
>        if (nextFilter != null ) nextFilter.messageReceived(session,
> message);
>    }
>    @Override
>    public void messageSent(NextFilter nextFilter, IoSession session,
> WriteRequest writeRequest) throws Exception {
>        log("SENT: ", writeRequest.getMessage());
>        if (nextFilter != null ) nextFilter.messageSent(session,
> writeRequest);
>    }
> ...
>    private void log(String event, Object arg) {
>        if (arg != null && arg instanceof IoBuffer) {
>            byte b[] = IoBufferUtils.asBytes((IoBuffer) arg);
>            log(event + b.length + " bytes: " + ByteUtils.toHex(b));
> //            IoBuffer i = (IoBuffer)arg;
> //            log("DBG: " + event + "pos: " + i.position() + ", lim:
> "+i.limit());
> // Previous debug was added to confirm IoBufferUtils operation, the IoBuffer 'arg' is confirmed empty (both position & limit are 0)
>        }
>        else log(event);
>    }
> ...
> }
> {code}
> And is hooked in the IoConnector set up:
> {code}
>    private final IoConnector buildIoConnector() {
> ...
>        if ( codecFilter == null )
>            codecFilter = new ProtocolCodecFilter(createCodecFactory());
> ...
>        DefaultIoFilterChainBuilder fc = connector.getFilterChain();
>        if ( fc.contains("logging") ) fc.remove("logging");
>        if ( fc.contains("codec") ) fc.remove("codec");
>        fc.addLast("logging", new
> CaptureLogFilter(getClass().getSimpleName()));
>        fc.addLast("codec", codecFilter);
> ...
> }
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.