You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Michael Prescott <mi...@gmail.com> on 2013/04/01 18:36:39 UTC

Tapestry-Hibernate outside of web requests

How do I make @CommitAfter work outside of a normal web request?

(By way of background, I have a web app that also receives messages that
require database work via JGroups.  These aren't web requests, but I want
to use the same hibernate configuration and infrastructure if at all
possible.)

Right now the basic code looks like this:

// The service that listens to incoming JGroups messages
public class MyReceiverServiceImpl extends /*JGroups*/ReceiverAdapter {

@Inject
private PerthreadManager threadManager;

@Inject
 private PeerMessageProcessor messageProcessor;

@Override
public void receive(final Message message) {
 threadManager.run(new Runnable() {
@Override
public void run() {
 messageProcessor.receive(message);
}
});
 }

// The service that tries to save the serialized entities via
tapestry-hibernate

public class PeerMessageProcessorImpl implements PeerMessageProcessor {
 @Inject
private Session session;

@CommitAfter
 public void receive(Message message) {
Object payload = message.getObject();
session.save(payload);
 }

Unfortunately, the transaction is never committed.

As far as I know:

1. The CommitAfter advisor does advise my service methods (but I'm not sure
how to verify this).

2. My methods are properly invoked (which I've verified)

It feels like this should be straight forward!

Gratefully,

Michael

Re: Tapestry-Hibernate outside of web requests

Posted by Michael Prescott <mi...@gmail.com>.
Okay, I assume this is because of how the CommitAfter advise is applied -
when I write my own advice, I have no trouble finding methods that only
declare the annotation on the service method implementation.  This method,
for example, will successfully advise service implementations even when
there's no annotation on the interface method:

@Advise
@Match("*")
public static void supportCommitAfterOutsideRequests(
 /* CommitAfterAdvisor advisor, */MethodAdviceReceiver receiver) {
// advisor.advise(receiver);

 MethodAdvice commit = new MethodAdvice() {
public void advise(MethodInvocation invocation) {

 System.err.println("=========TX BEGIN");

invocation.proceed();

 System.err.println("=========TX COMMIT");
}
};

for (Method m : receiver.getInterface().getMethods()) {

if (receiver.getMethodAnnotation(m, CommitAfter.class) != null) {
 System.err.println("ADVISING "
+ receiver.getInterface().getSimpleName() + "."
 + m.getName() + "()");
receiver.adviseMethod(m, commit);
} else
 System.err.println("NOT advising "
+ receiver.getInterface().getSimpleName() + "."
 + m.getName() + "()");

}
}

Having said that, despite the fact that I have put @CommitAfter on the
service method AND on the service interface method, the transactions aren't
being committed.

Q: Is there any way to tell what advisors or decorators are in place around
a service method?



On 1 April 2013 13:15, Thiago H de Paula Figueiredo <th...@gmail.com>wrote:

> On Mon, 01 Apr 2013 13:36:39 -0300, Michael Prescott <
> michael.r.prescott@gmail.com> wrote:
>
>  How do I make @CommitAfter work outside of a normal web request?
>>
>
>  public class PeerMessageProcessorImpl implements PeerMessageProcessor {
>>  @Inject
>> private Session session;
>>
>> @CommitAfter
>>  public void receive(Message message) {
>> Object payload = message.getObject();
>> session.save(payload);
>>  }
>>
>
> Due to a limitation in the Tapestry-IoC service proxy creation, you need
> to put the @CommitAfter annotation in interface method, not in the class
> method.
>
> --
> Thiago H. de Paula Figueiredo
>
> ------------------------------**------------------------------**---------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.**apache.org<us...@tapestry.apache.org>
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

Re: Tapestry-Hibernate outside of web requests

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Mon, 01 Apr 2013 13:36:39 -0300, Michael Prescott  
<mi...@gmail.com> wrote:

> How do I make @CommitAfter work outside of a normal web request?

> public class PeerMessageProcessorImpl implements PeerMessageProcessor {
>  @Inject
> private Session session;
>
> @CommitAfter
>  public void receive(Message message) {
> Object payload = message.getObject();
> session.save(payload);
>  }

Due to a limitation in the Tapestry-IoC service proxy creation, you need  
to put the @CommitAfter annotation in interface method, not in the class  
method.

-- 
Thiago H. de Paula Figueiredo

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org