[Note: This is a cross-post; I have initially posted to the list
[EMAIL PROTECTED] but I guess the issue is more related to hivemind,
so I post here.]

Hi list,

I need to wrap "begin transaction" and "end transaction" actions around
a task (a Tapestry web request, actually). I've read about Hivemind,

  http://www.nabble.com/hivemind-factory-service-tf251931.html#a704856

and configured a service point (see below). This works very well: my
transaction is created, but I cannot see when it is ended (committed/
rolled back).

More precisely, I am struggling with:

* What method is called on the object created by the factory when it
  is discarded? It is threadDidDiscardService(), right?

* How can I catch exceptions from my actual task so that I can do a rollback
 instead of a commit?

I am new to Hivemind, so please excuse these rather simple questions.

Many thanks for you patience!
Kaspar

--
Here's my configuration:

<service-point interface="org.my.tapestry.alfresco.AlfrescoTransactionContext" id="alfrescoContext"> <invoke-factory service-id="AlfrescoTransactionFactory" model="threaded" />
 </service-point>
<service-point interface="org.apache.hivemind.ServiceImplementationFactory" id="AlfrescoTransactionFactory" parameters-occurs="none"> <create-instance class="org.my.tapestry.alfresco.AlfrescoTransactionFactory" />
 </service-point>

Here is my factory:

public class AlfrescoTransactionFactory implements ServiceImplementationFactory, Discardable {

public Object createCoreServiceImplementation (ServiceImplementationFactoryParameters factoryParameters)
  {
System.err.println("createCoreServiceImplementation"); // gets called!
    UserTransaction transaction;
    ServiceRegistry serviceRegistry;
    try {
transaction = AlfrescoApplicationInitializer.createAndBeginAuthenticatedTransaction (true); serviceRegistry = AlfrescoApplicationInitializer.getServiceRegistry();
    }
    catch (Exception e) {
throw new ApplicationRuntimeException("Could not create an Alfresco transactoin.", e);
    }
return new AlfrescoTransactionContextImpl(transaction, serviceRegistry);
  }

  public void threadDidDiscardService()
  {
    System.err.println("threadDidDiscardService"); // never called!
    // ... end the transaction here (todo)
  }
}

Reply via email to