You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by "Eero Nevalainen (JIRA)" <ji...@apache.org> on 2007/04/24 15:28:19 UTC

[jira] Created: (DIRMINA-372) Generics support for IoHandler

Generics support for IoHandler
------------------------------

                 Key: DIRMINA-372
                 URL: https://issues.apache.org/jira/browse/DIRMINA-372
             Project: MINA
          Issue Type: Improvement
    Affects Versions: 1.1.0
            Reporter: Eero Nevalainen
            Priority: Minor
             Fix For: 1.1.1, 2.0.0-M1


It would be nice to have generics support for IoHandler so that messageReceived and messageSent would be called with the appropriate generic types.

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


Re: [jira] Commented: (DIRMINA-372) Generics support for IoHandler

Posted by 向秦贤 <fy...@gmail.com>.
I have not see DemuxingIoHandler implementation.
I tried a generics version solution, but there is no way to get a clean
solution by using java generics.
codes like follows:
interface Decoder<T> {
T decode(E input);
}

handler = new IoHandler<T>{
public void onMessageReceived(session, T message){
}
}
connect(address, ..., handler);//there must be a parameter type pass
through,
//otherwise there  must be many CW(arning)s if using Decoder<?> or
//IoHandler<?>, so feel not good, isnt is?

It's a simle case, but if Decoder<T>s is organized by heirarchy or chain, it
would be a another desaster:P)

I'm doing  meditation:)(a WORK or JOB of india like people, if you know it,
you can capature and see why india not go advancing:) just personal opion)

Maybe it's a not bad option that obseleting interface and using annotation.

Ok, I would check it out DemuxingIoHandler.

Regards.

2007/6/13, Trustin Lee (JIRA) <ji...@apache.org>:
>
>
>     [
> https://issues.apache.org/jira/browse/DIRMINA-372?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12504105]
>
> Trustin Lee commented on DIRMINA-372:
> -------------------------------------
>
> I agree with Mark because DemuxingIoHandler already provides such a
> functionality.  Adding an ExceptionHandler sounds very useful, so it will be
> taken care in a separate issue.
>
> DispatchingIoHandler is also a cool idea although it overlaps with
> DemuxingIoHandler.  Once done right, we could deprecate
> DemuxingIoHandler.  Otherwise, we could make this feature built-in so all
> IoHandler implementations get the benefit.  I guess the overhead will be
> minimal.  WDYT?
>
> public class MyHandler implements IoHandler {
>     public void messageReceived(IoSession session, MyMessage message) {
>         // invoked when the received message is MyMessage.
>     }
>
>     public void messageReceived(IoSession session, Object message) {
>         // invoked for all other type of messages,
>     }
> }
>
> > Generics support for IoHandler
> > ------------------------------
> >
> >                 Key: DIRMINA-372
> >                 URL: https://issues.apache.org/jira/browse/DIRMINA-372
> >             Project: MINA
> >          Issue Type: Improvement
> >    Affects Versions: 1.1.0
> >            Reporter: Eero Nevalainen
> >            Priority: Minor
> >             Fix For: 1.1.1, 2.0.0-M1
> >
> >
> > It would be nice to have generics support for IoHandler so that
> messageReceived and messageSent would be called with the appropriate generic
> types.
>
> --
> This message is automatically generated by JIRA.
> -
> You can reply to this email to add a comment to the issue online.
>
>


-- 
向秦贤

[jira] Commented: (DIRMINA-372) Generics support for IoHandler

Posted by "Niklas Therning (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/DIRMINA-372?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12491294 ] 

Niklas Therning commented on DIRMINA-372:
-----------------------------------------

I've thought of something similar: provide an IoHandler implementation base class which dispatches events to the method in the derived class which have a method signature which closest matches the message type. E.g:

class MyIoHandler extends DispatchingIoHandler {

   void messageReceived(IoSession session, CommandA cmd) {
        session.write(new CommandAResponse());
   }

   void messageReceived(IoSession session, CommandB cmd) {
        session.write(new CommandBResponse());
   }

    void exceptionCaught(IoSession session, CommandParseException cpe) {
        session.write(new BadCommandResponse());
    }
}


DispatchinIoHandler implements IoHandler.messageReceived() and IoHandler.exceptionCaught() and uses reflection to determine what Method in MyIoHandler it should dispatch to depending on the types of the objects passed to messageReceived/exceptionCaught. I'm doing something similar in mina-sm and it works quite well. mina-sm would probably be overkill for simpler servers. In those cases something like DispatchingIoHandler could be a better fit.


> Generics support for IoHandler
> ------------------------------
>
>                 Key: DIRMINA-372
>                 URL: https://issues.apache.org/jira/browse/DIRMINA-372
>             Project: MINA
>          Issue Type: Improvement
>    Affects Versions: 1.1.0
>            Reporter: Eero Nevalainen
>            Priority: Minor
>             Fix For: 1.1.1, 2.0.0-M1
>
>
> It would be nice to have generics support for IoHandler so that messageReceived and messageSent would be called with the appropriate generic types.

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


[jira] Resolved: (DIRMINA-372) Generics support for IoHandler

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

Trustin Lee resolved DIRMINA-372.
---------------------------------

    Resolution: Won't Fix
      Assignee: Trustin Lee

I modified DemuxingIoHandler so it can take care of exceptionCaught and messageSent events, too.  As Mike pointed out, DemuxingIoHandler already provides what Eero requested, so let me resolve this issue as won't fix.

Someone might argue that DemuxingIoHandler is an overkill if there are only one or two messages to handle.  However, explicit down-casting is not that a big overhead in that case, either IMHO.

Please review the following changes and close this issue if it satisfies your concern.

http://svn.apache.org/viewvc?view=rev&revision=594424

> Generics support for IoHandler
> ------------------------------
>
>                 Key: DIRMINA-372
>                 URL: https://issues.apache.org/jira/browse/DIRMINA-372
>             Project: MINA
>          Issue Type: Improvement
>            Reporter: Eero Nevalainen
>            Assignee: Trustin Lee
>            Priority: Minor
>             Fix For: 2.0.0-M1
>
>
> It would be nice to have generics support for IoHandler so that messageReceived and messageSent would be called with the appropriate generic types.

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


[jira] Commented: (DIRMINA-372) Generics support for IoHandler

Posted by "peter royal (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/DIRMINA-372?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12491528 ] 

peter royal commented on DIRMINA-372:
-------------------------------------

eero: decent idea. patches welcome :)

> Generics support for IoHandler
> ------------------------------
>
>                 Key: DIRMINA-372
>                 URL: https://issues.apache.org/jira/browse/DIRMINA-372
>             Project: MINA
>          Issue Type: Improvement
>    Affects Versions: 1.1.0
>            Reporter: Eero Nevalainen
>            Priority: Minor
>             Fix For: 1.1.1, 2.0.0-M1
>
>
> It would be nice to have generics support for IoHandler so that messageReceived and messageSent would be called with the appropriate generic types.

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


[jira] Commented: (DIRMINA-372) Generics support for IoHandler

Posted by "Trustin Lee (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/DIRMINA-372?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12491585 ] 

Trustin Lee commented on DIRMINA-372:
-------------------------------------

Wouldn't DemuxingIoHandler and MessageHandlers suffice for you?  Let's figure out what we need more on top of DemuxingIoHandler.

> Generics support for IoHandler
> ------------------------------
>
>                 Key: DIRMINA-372
>                 URL: https://issues.apache.org/jira/browse/DIRMINA-372
>             Project: MINA
>          Issue Type: Improvement
>    Affects Versions: 1.1.0
>            Reporter: Eero Nevalainen
>            Priority: Minor
>             Fix For: 1.1.1, 2.0.0-M1
>
>
> It would be nice to have generics support for IoHandler so that messageReceived and messageSent would be called with the appropriate generic types.

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


[jira] Commented: (DIRMINA-372) Generics support for IoHandler

Posted by "Mike Heath (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/DIRMINA-372?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12503902 ] 

Mike Heath commented on DIRMINA-372:
------------------------------------

I'm of the opinion that IoHandler should remain as is and DemuxingIoHandler solves the typing problem.  I think we should resolve this issue as "Won't Fix".

However, I do like Niklas' suggestion for Exception handling.  I think it would be nice to have such a feature in DemuxingIoHandler.


> Generics support for IoHandler
> ------------------------------
>
>                 Key: DIRMINA-372
>                 URL: https://issues.apache.org/jira/browse/DIRMINA-372
>             Project: MINA
>          Issue Type: Improvement
>    Affects Versions: 1.1.0
>            Reporter: Eero Nevalainen
>            Priority: Minor
>             Fix For: 1.1.1, 2.0.0-M1
>
>
> It would be nice to have generics support for IoHandler so that messageReceived and messageSent would be called with the appropriate generic types.

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


[jira] Commented: (DIRMINA-372) Generics support for IoHandler

Posted by "Eero Nevalainen (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/DIRMINA-372?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12491446 ] 

Eero Nevalainen commented on DIRMINA-372:
-----------------------------------------

Julien: then you leave type unspecified and use Object like before :)

> Generics support for IoHandler
> ------------------------------
>
>                 Key: DIRMINA-372
>                 URL: https://issues.apache.org/jira/browse/DIRMINA-372
>             Project: MINA
>          Issue Type: Improvement
>    Affects Versions: 1.1.0
>            Reporter: Eero Nevalainen
>            Priority: Minor
>             Fix For: 1.1.1, 2.0.0-M1
>
>
> It would be nice to have generics support for IoHandler so that messageReceived and messageSent would be called with the appropriate generic types.

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


[jira] Commented: (DIRMINA-372) Generics support for IoHandler

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

Julien Vermillard commented on DIRMINA-372:
-------------------------------------------

why not, but if some codec produce Object of different types without a common super-type ?

> Generics support for IoHandler
> ------------------------------
>
>                 Key: DIRMINA-372
>                 URL: https://issues.apache.org/jira/browse/DIRMINA-372
>             Project: MINA
>          Issue Type: Improvement
>    Affects Versions: 1.1.0
>            Reporter: Eero Nevalainen
>            Priority: Minor
>             Fix For: 1.1.1, 2.0.0-M1
>
>
> It would be nice to have generics support for IoHandler so that messageReceived and messageSent would be called with the appropriate generic types.

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


[jira] Commented: (DIRMINA-372) Generics support for IoHandler

Posted by "Trustin Lee (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/DIRMINA-372?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12504105 ] 

Trustin Lee commented on DIRMINA-372:
-------------------------------------

I agree with Mark because DemuxingIoHandler already provides such a functionality.  Adding an ExceptionHandler sounds very useful, so it will be taken care in a separate issue.

DispatchingIoHandler is also a cool idea although it overlaps with DemuxingIoHandler.  Once done right, we could deprecate DemuxingIoHandler.  Otherwise, we could make this feature built-in so all IoHandler implementations get the benefit.  I guess the overhead will be minimal.  WDYT?

public class MyHandler implements IoHandler {
    public void messageReceived(IoSession session, MyMessage message) {
        // invoked when the received message is MyMessage.
    }

    public void messageReceived(IoSession session, Object message) {
        // invoked for all other type of messages,
    }
}

> Generics support for IoHandler
> ------------------------------
>
>                 Key: DIRMINA-372
>                 URL: https://issues.apache.org/jira/browse/DIRMINA-372
>             Project: MINA
>          Issue Type: Improvement
>    Affects Versions: 1.1.0
>            Reporter: Eero Nevalainen
>            Priority: Minor
>             Fix For: 1.1.1, 2.0.0-M1
>
>
> It would be nice to have generics support for IoHandler so that messageReceived and messageSent would be called with the appropriate generic types.

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


[jira] Updated: (DIRMINA-372) Generics support for IoHandler

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

Trustin Lee updated DIRMINA-372:
--------------------------------

    Affects Version/s:     (was: 1.1.0)
        Fix Version/s: 2.0.0-M1

Doh! This should be taken care of in 2.0.

> Generics support for IoHandler
> ------------------------------
>
>                 Key: DIRMINA-372
>                 URL: https://issues.apache.org/jira/browse/DIRMINA-372
>             Project: MINA
>          Issue Type: Improvement
>            Reporter: Eero Nevalainen
>            Priority: Minor
>             Fix For: 2.0.0-M1
>
>
> It would be nice to have generics support for IoHandler so that messageReceived and messageSent would be called with the appropriate generic types.

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


[jira] Updated: (DIRMINA-372) Generics support for IoHandler

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

Trustin Lee updated DIRMINA-372:
--------------------------------

    Fix Version/s:     (was: 2.0.0-M1)
                       (was: 1.1.1)

This issue needs further discussion, so won't be resolved in the next release.

> Generics support for IoHandler
> ------------------------------
>
>                 Key: DIRMINA-372
>                 URL: https://issues.apache.org/jira/browse/DIRMINA-372
>             Project: MINA
>          Issue Type: Improvement
>    Affects Versions: 1.1.0
>            Reporter: Eero Nevalainen
>            Priority: Minor
>
> It would be nice to have generics support for IoHandler so that messageReceived and messageSent would be called with the appropriate generic types.

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


[jira] Closed: (DIRMINA-372) Generics support for IoHandler

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

Eero Nevalainen closed DIRMINA-372.
-----------------------------------


Yeah, DemuxingIoHandler does the trick. Closing the issue.

> Generics support for IoHandler
> ------------------------------
>
>                 Key: DIRMINA-372
>                 URL: https://issues.apache.org/jira/browse/DIRMINA-372
>             Project: MINA
>          Issue Type: Improvement
>            Reporter: Eero Nevalainen
>            Assignee: Trustin Lee
>            Priority: Minor
>             Fix For: 2.0.0-M1
>
>
> It would be nice to have generics support for IoHandler so that messageReceived and messageSent would be called with the appropriate generic types.

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


[jira] Commented: (DIRMINA-372) Generics support for IoHandler

Posted by "Trustin Lee (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/DIRMINA-372?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12502290 ] 

Trustin Lee commented on DIRMINA-372:
-------------------------------------

any more idea?

> Generics support for IoHandler
> ------------------------------
>
>                 Key: DIRMINA-372
>                 URL: https://issues.apache.org/jira/browse/DIRMINA-372
>             Project: MINA
>          Issue Type: Improvement
>    Affects Versions: 1.1.0
>            Reporter: Eero Nevalainen
>            Priority: Minor
>             Fix For: 1.1.1, 2.0.0-M1
>
>
> It would be nice to have generics support for IoHandler so that messageReceived and messageSent would be called with the appropriate generic types.

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