-
1. Re: NotificationListener equivalent
sfcoy May 8, 2013 8:52 AM (in response to ansur)I think that something like this might work:
{code:java}@Stateful
public class PollableWorkerBean implements PollableWorker {
private AtomicInteger progess;
public void reset() {
progress.set(0);
}
@Asynchronous
public Future<Result> performWork(String arg) {
while (progress.incrementAndGet() < 100) {
do some work;
}
return new AsyncResult<Result>(new Result(results));
}
public int getProgess() {
return progress.get();
}
}
{code}
and
{code:java}
PollableWorker worker = ...
worker.reset();
Future<Result> futureResult = worker.performWork("some arg");
while (!futureResult.isDone() && !futureResult.isCancelled()) {
int progress = worker.getProgress();
report progress
}
{code}
There's a chance that this may run afoul of the method call serialisation requirements on stateful session beans. I couldn't find anything in the spec regarding this and asynchronous method invocation.
-
2. Re: NotificationListener equivalent
ansur May 8, 2013 8:57 AM (in response to sfcoy)I forgot to mention a rather important piece of information: it's a remote EJB invocation. So client/server communication. Indeed what you suggest would work, but it's not a problem that the actual execution goes slowly, it's that we need to keep the client updated.
The actual work being done is installing/updating modules on the AS. So the whole process is downloading new EAR files, performing backups, undeploying, deploying, some DB configuration etc. We're sending back textual information to the client so he knows what the process is currently doing. This was working well with the NotificationListener/MBeanServerConnection combination, now I'm wondering whether we can send back this information when doing a remote EJB call using EJBClientConfiguration/Context lookup.
-
3. Re: NotificationListener equivalent
sfcoy May 8, 2013 9:13 AM (in response to ansur)The above (if it works at all) should work in a remote situation.
But a lot of what you're doing can be done programmatically using the management API, although there won't be any progress feedback. You should investigate this if you want to future proof yourself.
-
4. Re: NotificationListener equivalent
ansur May 8, 2013 9:20 AM (in response to sfcoy)Everything is done through the management API. That's not the problem. It's just the feedback I need to build in still between the steps.
-
5. Re: NotificationListener equivalent
genman May 8, 2013 1:34 PM (in response to ansur)Something that comes to mind is using JMS. Create a temporary queue on the client. Have the EJB send messages (non-transacted) to this temporary queue.
Here's some more info: http://activemq.apache.org/how-should-i-implement-request-response-with-jms.html
For JavaScript (web apps) you can use Ajax.
-
6. Re: NotificationListener equivalent
ansur May 14, 2013 1:18 PM (in response to ansur)In the end I used quite a similar solution as we had before, but just a bit adapted to JBoss 7: extend from NotificationBroadcasterSupport, make it a @Singleton and use the @PostConstruct and @PreDestroy functionality to register the instance as an MBean.