KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > deployment > backend > ClientJarMakerRegistry


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.enterprise.deployment.backend;
25
26 import java.util.Map JavaDoc;
27 import java.util.Hashtable JavaDoc;
28 import java.util.logging.Level JavaDoc;
29
30 import com.sun.enterprise.util.i18n.StringManager;
31
32 /**
33  * All client jar file are created in a separate thread when the client
34  * jar file is not requested at deployment time. These threads are
35  * registered in this singleton registry so that when client jar files are
36  * requested from the deployment clients, we check if the client jar
37  * file is not in the process of being created.
38  *
39  * @author Jerome Dochez
40  */

41 public class ClientJarMakerRegistry {
42     
43     // I am a singleton class
44
private static ClientJarMakerRegistry theRegistry;
45     
46     // the registered client jar creator threads
47
Map JavaDoc registeredThreads=null;
48     
49     /** Creates a new instance of ClientJarMakerRegistry */
50     protected ClientJarMakerRegistry() {
51         // I use hashtable since it needs to synchronized
52
registeredThreads = new Hashtable JavaDoc();
53     }
54     
55     /**
56      * @return the singleton instance of ClientJarMakerRegistry
57      */

58     public static ClientJarMakerRegistry getInstance() {
59         
60         if (theRegistry==null) {
61             synchronized(ClientJarMakerRegistry.class) {
62                 if (theRegistry==null) {
63                     theRegistry = new ClientJarMakerRegistry();
64                 }
65             }
66         }
67         return theRegistry;
68     }
69     
70     
71     /**
72      * Register a new thread in the registry
73      * @param the module ID we are creating the client jar for
74      * @param the thread object responsible for creating the
75      * client jar file
76      */

77     public void register(String JavaDoc moduleID, Thread JavaDoc clientJarMaker) {
78         
79         registeredThreads.put(moduleID, clientJarMaker);
80     }
81     
82     /**
83      * @return true if the passed module ID has a registered thread
84      */

85     public boolean isRegistered(String JavaDoc moduleID) {
86         
87         return registeredThreads.containsKey(moduleID);
88     }
89     
90     /**
91      * Unregister a thread in the registry. This is done when the
92      * thread has finished its execution
93      * @param the module ID identifying the module this thread was
94      * creating the client jar for.
95      */

96     public void unregister(String JavaDoc moduleID) {
97         
98         registeredThreads.remove(moduleID);
99     }
100     
101     /**
102      * wait for a particular thread maker to finish process before
103      * returning
104      */

105     public void waitForCompletion(String JavaDoc moduleID) {
106         
107         Thread JavaDoc maker = (Thread JavaDoc) registeredThreads.get(moduleID);
108         if (maker==null)
109             return;
110         
111         try {
112             maker.join();
113         } catch(InterruptedException JavaDoc e) {
114             StringManager localStrings = StringManager.getManager( ClientJarMakerRegistry.class );
115             DeploymentLogger.get().log(Level.SEVERE,
116                 localStrings.getString("enterprise.deployment.error_creating_client_jar",
117                     e.getLocalizedMessage()) ,e);
118         }
119         
120         return;
121     }
122     
123 }
124
Popular Tags