KickJava   Java API By Example, From Geeks To Geeks.

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


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.Collections JavaDoc;
27 import java.util.Map JavaDoc;
28 import java.util.HashMap JavaDoc;
29 import java.util.Iterator JavaDoc;
30
31 import com.sun.enterprise.util.i18n.StringManager;
32
33 /**
34  * This registry singleton class will maintain a list of
35  * oustanding DeploymentRequest instances keyed by the
36  * DeploymentID they are serving.
37  *
38  * @author Jerome Dochez
39  */

40 public class DeploymentRequestRegistry {
41     
42     // singleton instance
43
static DeploymentRequestRegistry instance=null;
44     
45     // the map of deployment id to deployment requests
46
Map JavaDoc idToRequest = Collections.synchronizedMap(new HashMap JavaDoc());
47     
48     /** string manager */
49     private static StringManager localStrings =
50         StringManager.getManager( DeploymentRequestRegistry.class );
51
52     /** Creates a new instance of DeploymentRequestRegistry */
53     private DeploymentRequestRegistry() {
54     }
55     
56     /**
57      * @return the singleton instance of this registry
58      */

59     public static DeploymentRequestRegistry getRegistry() {
60         if (instance==null) {
61             synchronized(DeploymentRequestRegistry.class) {
62                 if (instance==null) {
63                     instance = new DeploymentRequestRegistry();
64                 }
65             };
66         }
67         return instance;
68     }
69     
70     /**
71      * add new new request to the registry
72      * @param the module identifier
73      * @param the deployment request
74      */

75     public void addDeploymentRequest(String JavaDoc id,
76         DeploymentRequest request) throws IASDeploymentException {
77         synchronized(DeploymentRequestRegistry.class) {
78             // if there is another thread operating on the same module
79
// at the same time, we need to abort this deployment
80
if (idToRequest.containsKey(id)) {
81                 String JavaDoc msg = localStrings.getString(
82                     "another_thread_access_same_module",
83                     new Object JavaDoc[]{ id });
84                 throw new IASDeploymentException(msg);
85             }
86             idToRequest.put(id, request);
87         }
88     }
89
90     /**
91      * remove request from the registry
92      * @param the module identifier
93      */

94     public void removeDeploymentRequest(String JavaDoc id) {
95         idToRequest.remove(id);
96     }
97
98     
99     /**
100      * @return the deployment request associated with the passed module ID
101      */

102     public DeploymentRequest getDeploymentRequest(String JavaDoc id) {
103         return (DeploymentRequest) idToRequest.get(id);
104     }
105 }
106
Popular Tags