Niclas Hedhman wrote:

[...]



So, call ServiceManager.lookup() at any other time in AnotherComponent, such as;

public interface AnotherInterface
{
  static String ROLE = "org.hedhman.niclas.AnotherService";

  void processSomething();
}

public class AnotherComponent implements Serviceable, AnotherInterface
{
private ServiceManager m_ServiceManager;


   public void service( ServiceManager man )
   {
       m_ServiceManager = man;
   }

public void processSomething()
{
MyComponent c = (MyComponent) m_ServiceManager.lookup( AnotherInterface.ROLE );


c.myMethod();

       m_ServiceManager.release( c );
   }
}

(Exception handling removed for clarity.)

And if you have declared MyComponent to provide for the AnotherInterface.ROLE, somewhere in Cocoon (I think it is in cocoon.xconf), things should be poolable as expected.

I.e. It is not required that components are created, initialized and so on, upon application start, but can be deferred indefinately.


Is this what you are looking for?



Not at all. 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. For example a database connection:


public class AnotherComponent implements Serviceable, AnotherInterface, Recyclable, Initializable
{
private ServiceManager m_ServiceManager;
private ComponentDatasource ds;
private Connection con;


   public void processSomething()
   {
        Connection con = this.con;

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


public void processSomething2()
{ Connection con = this.con;


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

public void initialize() {

this.ds = ... // Getting the datasource from the serviceManager
this.con = this.ds.getConnection(); }


public void recycle() {

     // Here close the connection and return them to the pool
     this.con.close();

     // Release the datasource
     this.serviceManager.release(ds);
   }

   public void service( ServiceManager man )
   {
       m_ServiceManager = man;
   }
}

Please have a look into the code above. In the method initialize() I'am creating the datasource and the connection. The connection will be used by the two methods processSomething() and processSomething2(). I dont want to create a new connection or close it in each method. After the component will not be longer in use, I'am returning it into the pool and therefore the method recycle() will be called which closes the connection and releases the datsource. But what happens if I get the component the next time from the pool? Where is the initialization process to get the datasource and connection called? In intialize()? I think not because initialize() will be called only once at instanciation time and after that never more. So where to put the initialization code if I have a pooled component?

I need a initializantion method for pooled components (initialization() doesnt work). Thats all.

I hope I had described my problem correctly? I it is not so, please ask me.

I thank you very much for your help.

Best Regards
Stephan




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



Reply via email to