Here is pass 2 at the session object approach.  It demonstrates that the
Session object is not as difficult to manage as one might think.  It
does
add some (minimal) complexity to the container, but it saves the
component
user and the component writer a lot of headaches.  It also allows the
instance to be pooled, or (better yet) used in a ThreadSafe manner.

Before I listed an interface without fully demonstrating how it would
work:

interface SessionEnabled
{
    Map getSession(); // could be a more formal session object....
}

The important thing is that each component is given their own instance
of a ComponentManager.  The client specific ComponentManager is what
handles the session objects.

The CM would work something like this:

class SessionEnabledCM implements ComponentManager
{
    Map m_sessions;
    Map m_proxies;

    // other methods ignored for clarity
    Object lookup(String role)
    {
        Object component = m_proxies.get(role);
        if ( null == component )
        {
            component = Container.createProxy(role);
            m_proxies.put( role, component );
        }

        return component;
    }

    // ....

    Map getSession(String role)
    {
        Map session = (Map)m_sessions.get(role);

        if ( null == session )
        {
             session = new HashMap();
             m_sessions.put( role, session );
        }

        return session;
    }
}


The createProxy() creates the wrapper--it can be a static method,
whatever.
The important thing is that the proxy adds this to the component:

class ProxyComponent implements SessionEnabled // ... Its dynamic....
{
    SessionEnabledCM m_parent;

    Map getSession()
    {
        return m_parent.getSession( role );
    }
}


This can be further speed up by using the Class of the interface instead
of the string representation because we don't have classloader issues
at this level.

The component itself would do something like this:

class MyComponent implements SessionEnabled, YinYang
{
    String yin( String value )
    {
        Map session = getSession();

        // do all sorts of things and store important
        // info in the session for later use

        return (String) session.get("answer");
    }

    String yang( String value )
    {
        Map session = getSession();

        // do all sorts of things and store important
        // info in the session for later use

        return (String) session.get("question");
    }
}


There are a couple of details to work out, but there is no reason why
the
YinYang component can't be either freely shared between all threads of
execution, or freely reclaimed by the container.
--

"They that give up essential liberty to obtain a little temporary safety
 deserve neither liberty nor safety."
                - Benjamin Franklin


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to