[JBoss Seam] - Re: seam and batch/queue-processing
by kenglover
Maybe this will help...
I needed to schedule a regular recurring job from startup to shutdown. This job polls out LDAP servers and keeps a list of the ones that are up.
There are 2 components, a controller, and the asynchronous job. The controller runs at startup and schedules the job, keeping a timer handle in the application scope.
The async job compares the timer handle from the controller and terminates if it does not work (to ensure we only have one job running). Note that a crash or kill of the JBoss server may leave an extra scheduled job, which is why the official one is checked for.
Here is the controller:
| @Name("LDAPWatcherController")
| @Startup
| @Scope(ScopeType.APPLICATION)
| public class LDAPWatcherController {
|
| @In(create=true)
| private LDAPWatcher LDAPWatcher;
|
| @Logger
| private Log log;
|
| private TimerHandle timerHandle;
|
| @Create
| public void startup() throws Exception
| {
| log.debug("Starting checkLDAP timer");
| Timer timer = LDAPWatcher.checkLDAP( new Long(60000));
| timerHandle = timer.getHandle();
| }
|
| @Destroy
| public void shutdown()
| {
| log.debug("Shutting down timed event " + timerHandle.toString());
| timerHandle.getTimer().cancel();
| }
|
| public Timer getTimerHandle()
| {
| return timerHandle.getTimer();
| }
|
| }
|
Here is the LDAP Watcher (async job). The LDAPWatcher that is implemented is a simple interface class that defines the public method with an @Asynchronous above it.
| @Stateless
| @Name("LDAPWatcher")
| public class LDAPWatcherImpl implements LDAPWatcher {
| @Logger
| private Log log;
|
| @In
| private Timer timer;
|
| public Timer checkLDAP(Long interval) {
| log.info("Checking LDAPs " + this.toString());
|
| // Make sure this is the "official" job and that we do not have too many of these running.
| LDAPWatcherController appStart = (LDAPWatcherController) Contexts.getApplicationContext().get("LDAPWatcherController");
| log.debug("My Info :" + this.timer.getInfo().toString());
| log.debug("App Info:" + appStart.getTimerHandle().getInfo().toString());
| if (this.timer.getInfo() != appStart.getTimerHandle().getInfo())
| {
| log.info("I am not the timer that should be running. Stopping myself...");
| this.timer.cancel();
| return null;
| }
|
| // Now on with the work
| [... snip ...]
|
| return null;
| }
|
| }
|
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4090341#4090341
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4090341
16Â years, 9Â months
[JBoss Seam] - Semantics of @Name, @DataModelSelection
by djfjboss
In an attempt to learn Seam I am experimenting with a simple CRUD example, partly based on the Yuan/Heute book.
The integration example shows an edit link as:
<a href="person.seam?pid=#{fan.id}">Edit</a>
With the Person class having:
@Entity
| @Name("person")
| public class Person {
| private long id;
| @Id @GeneratedValue
| public long getId() { return id;}
| public void setId(long id) { this.id = id; }
and person.xhtml having:
<h2>Edit #{person.name}</h2>
| <h:form>
| <input type="hidden" name="pid"
| value="#{person.id}"/>
and the ManagerAction class having:
@Stateful
| @Name("manager")
| public class ManagerAction implements Manager {
|
| @In (required=false) @Out (required=false)
| private Person person;
|
| // @RequestParameter
| Long pid;
|
| @DataModel
| private List <Person> fans;
|
| @DataModelSelection
| private Person selectedFan;
|
| public void setPid (Long pid) {
| this.pid = pid;
|
| if (pid != null) {
| person = (Person) em.find(Person.class, pid);
| } else {
| person = new Person ();
| }
| }
|
| public Long getPid () {
| return pid;
| }
Apologies for taking so long to get to the point but the issue I have is that I keep getting property X not found on type Y. I had assumed that a Person instance would be maintained in the session state and injected/outjected as appropriate.
I had also assumed that the setPid method would be invoked via the edit link and thereby set person to the appropriate entity via the id, but this method isn't even called for me. The fact that the RequestParameter annotation is commented out is a little disconcerting.
To make this work, up to a point, I have had to add @Scope(SESSION) to the entity and session beans but I still find that I am faced with a newly constructed Person instance rather than the one I thought I was operating on and that had been outjected into the shared context.
In desperation, I've also tried using the @DataModelSelection but without success - property not found again.
I suspect I'm missing something fundamental and have read about bijection and studied the example which look straightforward enough but something is missing and I can't figure out what it is!
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4090337#4090337
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4090337
16Â years, 9Â months