Stephan Coboos wrote:
I want to share a component between two or more methods within another component. So I can't release them in one method because the other methods will not able to access the component.

here's a complete example which shows the use of a getConnection() method to share connections between methods. Note that you need some smart synchronization if you're writing for thread safety (which you aren't here I think).


public class AnotherComponent implements Serviceable,
AnotherInterface, Recyclable
{
   private ServiceManager m_sm;
   private ComponentDatasource m_ds = null;
   private Connection m_connection = null;

   public void processSomething()
   {
      final Connection con = getConnection();

       // Do something here with con...
       // but do not close!
   }


public void processSomething2() { final Connection con = getConnection();

       // Do something here with con...
       // but do not close!
   }
   public Connection getConnection()
   {
    if( m_ds == null )
    {
      m_ds = m_sm.lookup( "ds" );
      m_connection = m_ds.getConnection();
    }
    return m_connection;
   }

   public void recycle()
   {
     if( m_connection != null )
       m_connection.close();

       m_sm.release(ds);
   }

   public void service( final ServiceManager sm )
   {
       m_sm = sm;
   }
}

I would also point out that the answer to "How to initialize a component coming from the pool?" would be "the container does that by calling initialize()".

You're getting a component from a component coming from the pool, and the contract surrounding the initialization of this "component from a component" (in this case the connection) hasn't really got much to do with avalon...it depends on the component. IOW, the above example is more general than avalon :D

--
cheers,

- Leo Simons

-----------------------------------------------------------------------
Weblog              -- http://leosimons.com/
IoC Component Glue  -- http://jicarilla.org/
Articles & Opinions -- http://articles.leosimons.com/
-----------------------------------------------------------------------
"We started off trying to set up a small anarchist community, but
 people wouldn't obey the rules."
                                                        -- Alan Bennett



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



Reply via email to