KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > tests > j2eeserver > plugin > ServerLifecycle


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.tests.j2eeserver.plugin;
21
22 import javax.enterprise.deploy.spi.DeploymentManager JavaDoc;
23 import javax.enterprise.deploy.spi.status.ProgressObject JavaDoc;
24 import javax.enterprise.deploy.spi.Target JavaDoc;
25 import javax.enterprise.deploy.shared.CommandType JavaDoc;
26
27 import org.netbeans.modules.j2ee.deployment.plugins.api.*;
28 import org.netbeans.tests.j2eeserver.plugin.jsr88.*;
29 import org.netbeans.modules.j2ee.deployment.plugins.api.StartServer;
30
31 /**
32  *
33  * @author nn136682
34  */

35 public class ServerLifecycle extends StartServer {
36
37     private DepManager dm;
38
39     /** Creates a new instance of StartServer */
40     public ServerLifecycle(DeploymentManager JavaDoc dm) {
41         this.dm = (DepManager)dm;
42     }
43     
44     public ServerDebugInfo getDebugInfo(Target JavaDoc target) {
45         return null;
46     }
47     
48     public boolean isAlsoTargetServer(Target JavaDoc target) {
49         return true;
50     }
51     
52     public boolean isDebuggable(Target JavaDoc target) {
53         return false; //target.getName().equals("Target 1");
54
}
55     
56     public boolean isRunning() {
57         return dm.getState() == DepManager.RUNNING;
58     }
59     
60     public boolean needsStartForConfigure() {
61         return false;
62     }
63     
64     public void setDeploymentManager(DeploymentManager JavaDoc manager) {
65         this.dm = (DepManager) manager;
66     }
67     
68     public ProgressObject JavaDoc startDebugging(Target JavaDoc target) {
69         return dm.createServerProgress();
70     }
71     
72     public ProgressObject JavaDoc startDeploymentManager() {
73         final ServerProgress sp = dm.createServerProgress();
74         Runnable JavaDoc r = new Runnable JavaDoc() {
75             public void run() {
76                 try { Thread.sleep(500); //latency
77
} catch (Exception JavaDoc e) {}
78                 dm.setState(DepManager.STARTING);
79                 sp.setStatusStartRunning("TestPluginDM: "+dm.getName()+" is starting.");
80                 try { Thread.sleep(2000); //super server starting time
81
} catch (Exception JavaDoc e) {}
82                 if (dm.getTestBehavior() == DepManager.START_FAILED) {
83                     dm.setState(DepManager.FAILED);
84                     sp.setStatusStartFailed("TestPluginDM: "+dm.getName()+" startup failed");
85                 } else {
86                     dm.setState(DepManager.RUNNING);
87                     sp.setStatusStartCompleted("TestPluginDM "+dm.getName()+" startup finished");
88                 }
89             }
90         };
91         
92         (new Thread JavaDoc(r)).start();
93         return sp;
94     }
95     
96     public ProgressObject JavaDoc stopDeploymentManager() {
97         final ServerProgress sp = dm.createServerProgress();
98         Runnable JavaDoc r = new Runnable JavaDoc() {
99             public void run() {
100                 try { Thread.sleep(500); //latency
101
} catch (Exception JavaDoc e) {}
102                 dm.setState(DepManager.STOPPING);
103                 sp.setStatusStopRunning("TestPluginDM is preparing to stop "+dm.getName()+"...");
104                 try { Thread.sleep(2000); //super server stop time
105
} catch (Exception JavaDoc e) {}
106                 if (dm.getTestBehavior() == DepManager.STOP_FAILED) {
107                     dm.setState(DepManager.FAILED);
108                     sp.setStatusStopFailed("TestPluginDM stop "+dm.getName()+" failed");
109                 } else {
110                     dm.setState(DepManager.STOPPED);
111                     sp.setStatusStopCompleted("TestPluginDM startup "+dm.getName()+" finished");
112                 }
113             }
114         };
115
116         (new Thread JavaDoc(r)).start();
117         return sp;
118     }
119     
120     public boolean supportsStartDeploymentManager() {
121         return true;
122     }
123     
124     public boolean needsStartForAdminConfig() {
125         return true;
126     }
127     
128     public boolean needsStartForTargetList() {
129         return true;
130     }
131     
132 }
133
Popular Tags