KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jass > as > jboss > JBOSSActivityService


1 /**
2  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
3  -
4  - JASS: Java Advanced tranSaction Support
5  -
6  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
7  -
8  - This module was originally developed by
9  -
10  - LSD (Distributed Systems Lab, http://lsd.ls.fi.upm.es/lsd/lsd.htm)
11  - at Universidad Politecnica de Madrid (UPM) as an ObjectWeb Consortium
12  - (http://www.objectweb.org) project.
13  -
14  - This project has been partially funded by the European Commission under
15  - the IST programme of V FP grant IST-2001-37126 and by the Spanish
16  - Ministry of Science & Technology (MCyT) grants TIC2002-10376-E and
17  - TIC2001-1586-C03-02
18  -
19  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
20  - The original code and portions created by LSD are
21  - Copyright (c) 2004 LSD (UPM)
22  - All rights reserved.
23  -
24  - Redistribution and use in source and binary forms, with or without
25  - modification, are permitted provided that the following conditions are met:
26  -
27  - -Redistributions of source code must retain the above copyright notice, this
28  - list of conditions and the following disclaimer.
29  -
30  - -Redistributions in binary form must reproduce the above copyright notice,
31  - this list of conditions and the following disclaimer in the documentation
32  - and/or other materials provided with the distribution.
33  -
34  - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
35  - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
36  - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
37  - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
38  - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
39  - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
40  - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
41  - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
42  - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
43  - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
44  - POSSIBILITY OF SUCH DAMAGE.
45  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
46  -
47  - Author: Francisco Perez Sorrosal (frperezs)
48  -
49  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
50 */

51
52 package org.objectweb.jass.as.jboss;
53
54 import javax.naming.Context JavaDoc;
55 import javax.naming.InitialContext JavaDoc;
56 import javax.naming.Reference JavaDoc;
57
58 import org.apache.log4j.Logger;
59 import org.jboss.system.ServiceMBeanSupport;
60 import org.objectweb.jass.as.ActivityIdGenerator;
61 import org.objectweb.jass.as.ActivityService;
62
63 /**
64  * MBean that creates and registers the Activity Service implementation
65  * classes for the JBOSS application server.
66  * @author fran
67  * Date: Feb 11, 2004
68  * org.objectweb.jass.hls.as.ActivityService.java
69  */

70 public class JBOSSActivityService
71     extends ServiceMBeanSupport
72     implements JBOSSActivityServiceMBean {
73
74     private static Logger log = Logger.getLogger(JBOSSActivityService.class);
75     
76     // Constants --------------------------------------------------------------
77

78     // The JNDI name of UserActivity and ActivityManager interfaces
79
public static final String JavaDoc UA_JNDI_NAME = "UserActivity";
80     public static final String JavaDoc AM_JNDI_NAME = "ActivityManager";
81
82     // ServiceMBeanSupport implementation -------------------------------------
83

84     /**
85      * Invoked when this JBOSS MBean is started.
86      */

87     public void startService() throws Exception JavaDoc {
88         
89         // The services are binded throught references
90
Reference JavaDoc uaRef =
91             new Reference JavaDoc(
92                 "org.objectweb.jass.as.ActivityService",
93                 "org.objectweb.jass.as.UserActivityObjectFactory",
94                 null);
95
96         Reference JavaDoc amRef =
97             new Reference JavaDoc(
98                 "org.objectweb.jass.as.ActivityService",
99                 "org.objectweb.jass.as.ActivityManagerObjectFactory",
100                 null);
101
102         Context JavaDoc ctx = new InitialContext JavaDoc();
103
104         // Get a reference to the ActivityIdGenerator singleton, used to assing
105
// unique Ids to activities, and set it in the UserActivityImpl
106
log.info("Looking for an Activity Id generator...");
107         ActivityIdGenerator activityIdGenerator =
108             (ActivityIdGenerator) ctx.lookup("ActivityIdGeneratorService");
109         log.info("A reference to the Activity Id Generator acquired!!!");
110         
111         log.info("Setting generator in the Activity Service implementation...");
112         ActivityService.setActivityIdGenerator(activityIdGenerator);
113         log.info("Activity Id Generator established as default generator!!!");
114
115         log.info("Binding UserActivity Service and ActivityManager Services");
116         ctx.bind(UA_JNDI_NAME, uaRef);
117         ctx.bind(AM_JNDI_NAME, amRef);
118         log.info("Bindings done!!!");
119     }
120
121     /**
122      * Invoked when this JBOSS MBean is stopped.
123      */

124     public void stopService() {
125         try {
126             Context JavaDoc ctx = new InitialContext JavaDoc();
127             ctx.unbind(UA_JNDI_NAME);
128             ctx.unbind(AM_JNDI_NAME);
129         } catch (Exception JavaDoc e) {
130             log.error("Failed to unbind", e);
131         }
132     }
133
134     // ActivityServiceMBean implementation ------------------------------------
135

136     /**
137      * Return the number of AS instances that HLSs has created. There is
138      * one AS instance per HLS.
139      *
140      * @return the number of AS instances.
141      */

142     public int getInstances() {
143         return ActivityService.getInstances();
144     }
145
146     /**
147      * TODO Not yet implemented.
148      */

149     public int numberOfActivities() {
150         return 0;
151     }
152
153 }
154
Popular Tags