KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > server > AutoDeployer


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 /*
25  * @(#) AutoDeployer.java
26  *
27  * Copyright 2000-2001 by iPlanet/Sun Microsystems, Inc.,
28  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
29  * All rights reserved.
30  *
31  * This software is the confidential and proprietary information
32  * of iPlanet/Sun Microsystems, Inc. ("Confidential Information").
33  * You shall not disclose such Confidential Information and shall
34  * use it only in accordance with the terms of the license
35  * agreement you entered into with iPlanet/Sun Microsystems.
36  */

37 package com.sun.enterprise.server;
38
39 import java.io.File JavaDoc;
40
41 import com.sun.enterprise.util.io.FileUtils;
42 import com.sun.enterprise.instance.InstanceEnvironment;
43 import com.sun.enterprise.deployment.backend.DeploymentRequest;
44 import com.sun.enterprise.deployment.backend.DeploymentCommand;
45 import com.sun.enterprise.deployment.backend.DeployableObjectType;
46 import com.sun.enterprise.deployment.backend.Deployer;
47 import com.sun.enterprise.deployment.backend.DeployerFactory;
48 import com.sun.enterprise.deployment.backend.IASDeploymentException;
49
50 import java.util.logging.Level JavaDoc;
51 import java.util.logging.Logger JavaDoc;
52 import com.sun.logging.LogDomains;
53
54 /**
55  * This class is a listener implementation of the auto deploy callbacks.
56  * When auto deploy monitor detects a new archive under the auto deploy
57  * directory, this class handles the callback from the monitor.
58  *
59  * @author Nazrul Islam
60  * @since JDK1.4
61  */

62 class AutoDeployer implements MonitorListener {
63
64     /** logger for this auto deployer */
65     static Logger JavaDoc _logger=LogDomains.getLogger(LogDomains.CORE_LOGGER);
66
67     // ---- START OF MonitorListener METHOD -----------------------------------
68

69     /**
70      * No-op.
71      *
72      * @param entry monitored entry with a change in time stamp
73      *
74      * @return no-op; returns false
75      */

76     public boolean reload(MonitorableEntry entry) {
77         return false;
78     }
79
80     /**
81      * Handles the callbacks from the auto deploy monitor.
82      *
83      * @param entry entry thats being monitored
84      * @param archive newly detected archive under the auto deploy directory
85      *
86      * @return true if deployed successfully
87      */

88     public boolean deploy(MonitorableEntry entry, File JavaDoc archive) {
89
90         boolean status = false;
91
92         try {
93             DeploymentRequest req = deploy(archive);
94
95             // load/reload deployed application/stand alone module
96

97             // update the config context in server runtime
98

99             // notify admin server if necessary
100

101             status = true;
102         } catch (IASDeploymentException de) {
103             _logger.log(Level.WARNING, "core.exception", de);
104             status = false;
105         }
106
107         return status;
108     }
109
110     // ---- END OF MonitorListener METHOD -------------------------------------
111

112     /**
113      * Deploys the given archive. If it is already been deployed, this
114      * redeploys the application.
115      *
116      * @param archive archive to be deployed
117      * @return deployment request after the deployment; this provides
118      * information about the type of deployment being executed
119      * @throws IASDeploymentException if an error while deploying
120      */

121     private DeploymentRequest deploy(File JavaDoc archive)
122             throws IASDeploymentException {
123
124         // instance environment for this server
125
InstanceEnvironment env =
126             ApplicationServer.getServerContext().getInstanceEnvironment();
127
128         // sets the type of the archive being deployed
129
DeployableObjectType type = null;
130         if ( FileUtils.isEar(archive) ) {
131             type = DeployableObjectType.APP;
132         } else if ( FileUtils.isJar(archive) ) {
133             type = DeployableObjectType.EJB;
134         } else if ( FileUtils.isWar(archive) ) {
135             type = DeployableObjectType.WEB;
136         } else if ( FileUtils.isRar(archive) ) {
137             type = DeployableObjectType.CONN;
138         }
139
140         // constructs a deploy request with the given type
141
DeploymentRequest req =
142             new DeploymentRequest(env, type, DeploymentCommand.DEPLOY);
143
144         // sets the archive that needs to be deployed
145
req.setFileSource(archive);
146
147         // application is registered with the name of the
148
// archive without extension
149
String JavaDoc fileName = archive.getName();
150         int dotIdx = fileName.indexOf(fileName);
151         String JavaDoc regName = fileName.substring(0, dotIdx);
152         req.setName(regName);
153
154         // sets the web context root
155
if (type.isWEB()) {
156             req.setContextRoot(regName);
157         }
158
159         // redeploys the app if already deployed
160
req.setForced(true);
161
162         // does the actual deployment
163
Deployer deployer = DeployerFactory.getDeployer(req);
164         deployer.doRequest();
165
166         // any clean up other than cleaner thread invocation
167
deployer.cleanup();
168
169         return req;
170     }
171 }
172
173
Popular Tags