Executing scheduled task by MBeans in Glassfish

In last blog the implementation of cron was described. I used lifecycle module and Timer bean in this approach. This solution was used since lifecycle listeners (similar as you know in web module) are missing for EJB module. It seems as lack of the specification. Therefore, server's vendors used some proprietary solutions like WebLogic defines some lifecycle methods in server specific deployment descriptors. Sankara suggested to use MBean with predefined Timer rules. Therefore, I decided to implement this task by MBean. We can use Netbeans plugin for JMX that is avalaible on update center and tutorial is here.
Now, let's create new J2SE project in Netbeans and create CronMB interface that tipically consists of named and typed attributes that can be read, written, and named typed operations that can be invoked, e.g. stop cron, change action, ... Then, create new class CronMBean class that implements this and javax.management.NotificationListener interfaces. Add business logic in handleNotification method. Now, build your module.
Logg in web admin console, select Custom MBeans node, click Deploy button and choose location of the jar with your cron MBean. Click Next and specify MBean class name. Now, we should create action that occurs based on timer action. Select Management Rules node and click Nwe button. Specify name and select timer as event type. In next panel specify additional info related to this timer and assign your MBean to the action.
I think that using custom MBean is better since this approach is more flexible then lifecycle module. Also, we can remote administrate this MBean.
Comments:

Thanks petr for writing this down and also for pointing to a tutorial to write MBeans using NetBeans .</br> regards sankar

Posted by sankara on February 26, 2006 at 12:53 AM CET #

Post a Comment:
Comments are closed for this entry.
About

pblaha

Search

Categories
Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today
Bookmarks