You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by "Mike Heath (JIRA)" <ji...@apache.org> on 2007/12/27 18:54:43 UTC

[jira] Reopened: (DIRMINA-495) IoConnector needs a way to store information into the IoSession before the IoHandler gets ahold of it

     [ https://issues.apache.org/jira/browse/DIRMINA-495?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Mike Heath reopened DIRMINA-495:
--------------------------------


I've been trying to retrofit some of my existing code to use the IoSessionInitializer.  This code is a client that has its own API and uses MINA under the hood.  I need to be able to cancel a pending connect future from my API.  To facilitate this, I discovered that it would greatly simplify my code if the ConnectFuture instance is passed into the IoSessionInitializer.

Modifying the IoSessionInitializer interface to look like:

public interface IoSessionInitializer {
    void initializeSession(IoSession session, IoFuture future);
}

would fix my problem.  The future object passed into the initializeSession method would be the ConnectFuture that is returned by IoConnector.connect(...);

> IoConnector needs a way to store information into the IoSession before the IoHandler gets ahold of it
> -----------------------------------------------------------------------------------------------------
>
>                 Key: DIRMINA-495
>                 URL: https://issues.apache.org/jira/browse/DIRMINA-495
>             Project: MINA
>          Issue Type: New Feature
>          Components: Core
>            Reporter: David M. Lloyd
>            Assignee: Mike Heath
>             Fix For: 2.0.0-M1
>
>         Attachments: DIRMINA-495-3.patch, DIRMINA-495-mikeheath.patch, IoConnector.patch
>
>
> It is often necessary to pass information into the IoHandler associated with an IoConnector.  Sometimes this information is needed even as early as IoSession creation time.  A mechanism is needed to pass information in to the IoSession at the time you call IoConnector.connect().  Discussing this with Mike Heath, we determined that a logical approach could be to have variants of the connect() methods that accept information that can be attached to the IoSession when it is created.
> One option is to simply pass a Map in to the connect method.  The contents of the Map would be copied into the IoSession's attribute map after it is constructed but before the IoHandler.sessionCreated method is created.  In addition, it seems likely that in many cases only one entry would need to be added - in this case the user could simply do this:
>    ioConnector.connect(addr, Collections.singletonMap(MY_KEY, theValue));
> Another option would be to use variable argument lists to accept any number of key-value pairs.  The pairs could be represented by a class - AttributePair for example.  It could look like this:
>    public final class AttributePair<K, V> {
>        private final K key;
>        private final V value;
>        private AttributePair(K key, V value) { this.key = key; this.value = value; }
>        public static <K, V> AttributePair<K,V> pair(K key, V value) { return new AttributePair<K, V>(key, value); }
>    }
> Then the user can use static imports to pull in the "pair" method.  The connect() method on IoConnector could accept a variable list of AttributePair objects, so the user could write code like this:
>     ioConnector.connect(addr, pair(MY_KEY1, myValue), pair(MY_KEY2, myValue2));
> Though this approach is somewhat more complicated than just using a Map.
> Other approaches may also be discussed.

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