KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jass > hls > ont > jboss > ONTService


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.hls.ont.jboss;
53
54
55 import org.objectweb.jass.hls.ont.ONT;
56
57 import javax.naming.Context JavaDoc;
58 import javax.naming.InitialContext JavaDoc;
59 import javax.naming.Reference JavaDoc;
60 import javax.naming.Name JavaDoc;
61 import javax.naming.spi.ObjectFactory JavaDoc;
62
63 import org.jboss.system.ServiceMBeanSupport;
64
65 import java.util.Hashtable JavaDoc;
66
67 /**
68  * MBean that creates the ONT service for the JBOSS application server.
69  * @author fran
70  * Date: Feb 11, 2004
71  * org.objectweb.jass.hls.ont.jbossONTService.java
72  */

73 public class ONTService
74         extends ServiceMBeanSupport
75         implements ONTServiceMBean,
76         ObjectFactory JavaDoc {
77
78 // Constants ------------------------------------------------------------------
79

80     // JNDI name to bind the the ONT service in JBOSS
81
public static final String JavaDoc ONT_JNDI_NAME = "UserOpenNested";
82     // The ONT service singleton instance
83
private static ONT ont = null;
84
85 // Public ---------------------------------------------------------------------
86

87     // ServiceMBeanSupport implementation -------------------------------------
88

89      /**
90       * Invoked when this JBOSS MBean is started.
91       */

92     public void startService() throws Exception JavaDoc {
93
94         log.info("Binding the ONT Service...");
95         ont = ONT.getSingleton();
96         bindRef(ONT_JNDI_NAME, "org.objectweb.jass.hls.ont.ONT");
97         log.info("Binding done!!!");
98     }
99
100     /**
101      * Invoked when this JBOSS MBean is stopped.
102      */

103     public void stopService() {
104
105         try {
106             Context JavaDoc ctx = new InitialContext JavaDoc();
107             ctx.unbind(ONT_JNDI_NAME);
108         } catch (Exception JavaDoc e) {
109             log.error("Failed to unbind", e);
110         }
111     }
112
113     // ObjectFactory implementation -------------------------------------------
114

115     /**
116      * It returns the unique ONT service instance when the service is requested.
117      */

118     public Object JavaDoc getObjectInstance(Object JavaDoc obj, Name JavaDoc name, Context JavaDoc nameCtx,
119                                     Hashtable JavaDoc environment) throws Exception JavaDoc {
120         log.info(Thread.currentThread() + " Obtaining the ONT singleton...");
121         return ont;
122     }
123
124     // ONTServiceMBean implementation -----------------------------------------
125

126     /**
127      * It returns the singleton ONT instance to the JBOSS-JMX.
128      */

129     public ONT getONT() {
130         return ont;
131     }
132
133
134 // My private -----------------------------------------------------------------
135

136     /**
137      * Binds the ONT service implementation class
138      * (org.objectweb.jass.hls.ont.ONT) with a JNDI name by means
139      * of a reference.
140      */

141     private void bindRef(String JavaDoc jndiName, String JavaDoc className)
142             throws Exception JavaDoc {
143         Reference JavaDoc ref = new Reference JavaDoc(className, getClass().getName(), null);
144         new InitialContext JavaDoc().bind(jndiName, ref);
145     }
146
147 }
Popular Tags