KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > weblogic9 > optional > WLStartServer


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 package org.netbeans.modules.j2ee.weblogic9.optional;
20
21 import java.io.*;
22 import java.net.*;
23 import java.util.*;
24
25 import javax.enterprise.deploy.shared.*;
26 import javax.enterprise.deploy.spi.*;
27 import javax.enterprise.deploy.spi.exceptions.*;
28 import javax.enterprise.deploy.spi.status.*;
29
30 import org.openide.*;
31 import org.openide.util.*;
32 import org.netbeans.modules.j2ee.deployment.plugins.api.*;
33
34 import org.netbeans.modules.j2ee.weblogic9.*;
35 import org.netbeans.modules.j2ee.weblogic9.util.*;
36
37 /**
38  * This class provides functionality used to start and stop a particular server
39  * instance. It also supports starting the server in debug mode, so that
40  * NetBeans can connect to it using its built-in JPDA debugger.
41  *
42  * @author Kirill Sorokin
43  */

44 public class WLStartServer extends StartServer {
45     
46     private static final int SERVER_CHECK_TIMEOUT = 2000;
47     
48     /**
49      * The server's deployment manager, to be exact the plugin's wrapper for it
50      */

51     private WLDeploymentManager dm;
52     
53     /**
54      * WL server process instance
55      */

56     private Process JavaDoc serverProcess;
57     
58     /**
59      * Creates a new instance of WLStartServer
60      *
61      * @param the server's deployment manager
62      */

63     public WLStartServer(DeploymentManager dm) {
64         // cast the deployment manager to the plugin's wrapper class and save
65
this.dm = (WLDeploymentManager) dm;
66     }
67     
68     /**
69      * Starts the server (or even a particular target supplied by admin server)
70      * in debug mode. We do not support this completely thus always start the
71      * server instance defined in the deployment maanger supplied during
72      * WSStartServer construction.
73      *
74      * @param target target thst should be started
75      *
76      * @return a progress object that describes the startup process
77      */

78     public ProgressObject startDebugging(Target target) {
79         if (WLDebug.isEnabled()) // debug output
80
WLDebug.notify(getClass(), "starting server in " + // NOI18N
81
"debug mode"); // NOI18N
82

83         // create a new progress object
84
WLServerProgress serverProgress = new WLServerProgress(this);
85         
86         // send a message denoting that the startup process has begun
87
String JavaDoc serverName = dm.getInstanceProperties().getProperty(InstanceProperties.DISPLAY_NAME_ATTR);
88         serverProgress.notifyStart(StateType.RUNNING, NbBundle.getMessage(WLStartServer.class, "MSG_START_SERVER_IN_PROGRESS", serverName)); // NOI18N
89

90         // run the startup process in a separate thread
91
RequestProcessor.getDefault().post(new WLStartDebugRunnable(
92                 serverProgress), 0, Thread.NORM_PRIORITY);
93         
94         // set the debuggable marker
95
isDebuggable = true;
96         
97         // return the progress object
98
return serverProgress;
99     }
100     
101     /**
102      * Marker describing whether the server is started in debug mode
103      */

104     private boolean isDebuggable;
105     
106     /**
107      * Specifies whether the server instance is started in debug mode. The
108      * detalization can go as deep as an individual target, but we do not
109      * support this
110      *
111      * @param target target to be checked
112      *
113      * @return whether the instance is started in debug mode
114      */

115     public boolean isDebuggable(Target target) {
116         return isDebuggable;
117     }
118     
119     /**
120      * Tells whether the target is also the target server
121      *
122      * @return true
123      */

124     public boolean isAlsoTargetServer(Target target) {
125         return true;
126     }
127     
128     /**
129      * Returns the information for attaching the JPDA debugger to the server
130      * (host and port). The detalization can be down to a specific target, but
131      * we do not support this
132      *
133      * @param target target for which the information is requested
134      *
135      * @return the debug information
136      */

137     public ServerDebugInfo getDebugInfo(Target target) {
138         return new ServerDebugInfo(dm.getHost(), new Integer JavaDoc(
139                 dm.getInstanceProperties().getProperty(
140                 WLPluginProperties.DEBUGGER_PORT_ATTR)).intValue());
141     }
142     
143     /**
144      * Tells whether the normal startup of the server is supported.
145      *
146      * @return if the server is local, its true, false otherwise
147      */

148     public boolean supportsStartDeploymentManager() {
149         // if the server is local we can start it
150
if (dm.getInstanceProperties().getProperty(
151                 WLPluginProperties.IS_LOCAL_ATTR).equals("true")) { // NOI18N
152
return true;
153         } else {
154             return false;
155         }
156     }
157     
158     /**
159      * Stops the server instance identified by the deployment manager.
160      *
161      * @return the progress object describing the shutdown process
162      */

163     public ProgressObject stopDeploymentManager() {
164         if (WLDebug.isEnabled()) // debug output
165
WLDebug.notify(getClass(), "stopping server!"); // NOI18N
166

167         // create a new progress object
168
WLServerProgress serverProgress = new WLServerProgress(this);
169         
170         // send a message denoting that the shutdown process has begun
171
String JavaDoc serverName = dm.getInstanceProperties().getProperty(InstanceProperties.DISPLAY_NAME_ATTR);
172         serverProgress.notifyStart(StateType.RUNNING, NbBundle.getMessage(WLStartServer.class, "MSG_STOP_SERVER_IN_PROGRESS", serverName)); // NOI18N
173

174         // run the shutdown process in a separate thread
175
RequestProcessor.getDefault().post(new WLStopRunnable(serverProgress), 0, Thread.NORM_PRIORITY);
176         
177         // set the debugguable marker to false as the server is stopped
178
isDebuggable = false;
179         
180         // return the progress object
181
return serverProgress;
182     }
183     
184     /**
185      * Starts a server instance identified by the deployment manager.
186      *
187      * @return a progress object describing the server startup process
188      */

189     public ProgressObject startDeploymentManager() {
190         if (WLDebug.isEnabled()) // debug output
191
WLDebug.notify(getClass(), "starting server!"); // NOI18N
192

193         // create a new progress object
194
WLServerProgress serverProgress = new WLServerProgress(this);
195         
196         // send a message denoting that the startup process has begun
197
String JavaDoc serverName = dm.getInstanceProperties().getProperty(InstanceProperties.DISPLAY_NAME_ATTR);
198         serverProgress.notifyStart(StateType.RUNNING, NbBundle.getMessage(WLStartServer.class, "MSG_START_SERVER_IN_PROGRESS", serverName)); // NOI18N
199

200         // run the startup process in a separate thread
201
RequestProcessor.getDefault().post(new WLStartRunnable(
202                 serverProgress), 0, Thread.NORM_PRIORITY);
203         
204         // set the debuggble marker to false as we do not start the server in
205
// debug mode
206
isDebuggable = false;
207         
208         // return the progress object
209
return serverProgress;
210     }
211     
212     /**
213      * Tells whether we need to start the server instance in order to get a
214      * list of deployment targets.
215      *
216      * @return true
217      */

218     public boolean needsStartForTargetList() {
219         return true;
220     }
221     
222     /**
223      * Tells whether we need to start the server instance in order to configure
224      * an application
225      *
226      * @return false
227      */

228     public boolean needsStartForConfigure() {
229         return false;
230     }
231     
232     /**
233      * Tells whether we need to start the server instance in order to configure
234      * the admin server
235      *
236      * @return true
237      */

238     public boolean needsStartForAdminConfig() {
239         return true;
240     }
241     
242     /**
243      * Tells whether the server instance identified by the deployment manager is
244      * currently started
245      *
246      * @return true is the server is running, false otherwise
247      */

248     public boolean isRunning() {
249         return isRunning(true);
250     }
251     
252     /**
253      * Returns true if the server is running.
254      *
255      * @param checkResponse should be checked whether is the server responding - is really up?
256      * @return <code>true</code> if the server is running.
257      */

258     public boolean isRunning(boolean checkResponse) {
259         Process JavaDoc proc = dm.getServerProcess();
260         if (proc != null) {
261             try {
262                 proc.exitValue();
263                 // process is stopped
264
return false;
265             } catch (IllegalThreadStateException JavaDoc e) {
266                 // process is running
267
if (!checkResponse) {
268                     return true;
269                 }
270             }
271         }
272         if (checkResponse) {
273             String JavaDoc host = dm.getHost();
274             int port = new Integer JavaDoc(dm.getPort()).intValue();
275             return ping(host, port, SERVER_CHECK_TIMEOUT); // is server responding?
276
} else {
277             return false; // cannot resolve the state
278
}
279     }
280
281     /** Return true if the server is stopped. If the server was started from within
282      * the IDE, determin the server state from the process exit code, otherwise try
283      * to ping it.
284      */

285     private boolean isStopped() {
286         Process JavaDoc proc = dm.getServerProcess();
287         if (proc != null) {
288             try {
289                 proc.exitValue();
290                 // process is stopped
291
return true;
292             } catch (IllegalThreadStateException JavaDoc e) {
293                 // process is still running
294
return false;
295             }
296         } else {
297             String JavaDoc host = dm.getHost();
298             int port = new Integer JavaDoc(dm.getPort()).intValue();
299             return !ping(host, port, SERVER_CHECK_TIMEOUT); // is server responding?
300
}
301     }
302     
303     /** Return true if a WL server is running on the specifed host:port */
304     public static boolean ping(String JavaDoc host, int port, int timeout) {
305         // checking whether a socket can be created is not reliable enough, see #47048
306
Socket socket = new Socket();
307         try {
308             try {
309                 socket.connect(new InetSocketAddress(host, port), timeout); // NOI18N
310
socket.setSoTimeout(timeout);
311                 PrintWriter out = new PrintWriter(socket.getOutputStream(), true);
312                 try {
313                     BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
314                     try {
315                         // request for the login form - we guess that OK response means pinging the WL server
316
out.println("GET /console/login/LoginForm.jsp HTTP/1.1\nHost:\n"); // NOI18N
317

318                         // check response
319
return "HTTP/1.1 200 OK".equals(in.readLine()); // NOI18N
320
} finally {
321                         in.close();
322                     }
323                 } finally {
324                     out.close();
325                 }
326             } finally {
327                 socket.close();
328             }
329         } catch (IOException ioe) {
330             return false;
331         }
332     }
333     
334     /**
335      * An utility method that transforms a Properties object to an array of
336      * Strings each containing a property in the form of
337      * <i>'&lt;name&gt;=&lt;value&gt;'</i>
338      *
339      * @param properties properties to be converted
340      *
341      * @return an array of strings with the converted properties
342      */

343     private static String JavaDoc[] properties2StringArray(Properties properties) {
344         // initiate the list that will be converted to array for returning
345
List list = new ArrayList();
346         
347         // get the properties keys
348
Enumeration keys = properties.keys();
349         
350         // iterate over the enumeration
351
while (keys.hasMoreElements()) {
352             // get the property key
353
String JavaDoc key = (String JavaDoc) keys.nextElement();
354             
355             // get the value associated with this key and store them in the list
356
list.add(key + "=" + properties.getProperty(key));
357         }
358         
359         // convert the list into an array and return
360
return (String JavaDoc[]) list.toArray(new String JavaDoc[list.size()]);
361     }
362
363     public boolean supportsStartDebugging(Target target) {
364         //if we can start it we can debug it
365
return supportsStartDeploymentManager();
366     }
367     
368     /**
369      * Runnable that starts the server in normal mode. It is used to start the
370      * server in a separate thread, so that the IDE does not hang up during the
371      * startup process.
372      *
373      * @author Kirill Sorokin
374      */

375     private class WLStartRunnable implements Runnable JavaDoc {
376         
377         /**
378          * Root directory for the selected profile
379          */

380         private String JavaDoc domainHome;
381         
382         /**
383          * Progress object that describes the startup process. It will be
384          * notified of the progress and the success/failure of the process
385          */

386         private WLServerProgress serverProgress;
387         
388         /**
389          * Creates a new instance of WSStartRunnable.
390          *
391          * @param serverProgress the prgress object that the thread should
392          * notify of anything that happens with the startup process
393          */

394         public WLStartRunnable(WLServerProgress serverProgress) {
395             // save the progress object
396
this.serverProgress = serverProgress;
397             
398             // get the profile root directory and the instance name from the
399
// deployment manager
400
domainHome = dm.getInstanceProperties().getProperty(
401                     WLPluginProperties.DOMAIN_ROOT_ATTR);
402         }
403         
404         /**
405          * Implementation of the run() method from the Runnable interface
406          */

407         public void run() {
408             try {
409                 // save the current time so that we can deduct that the startup
410
// failed due to timeout
411
long start = System.currentTimeMillis();
412                 
413                 // create the startup process
414
serverProcess = Runtime.getRuntime().exec(
415                         domainHome + "/" + (Utilities.isWindows() ? // NOI18N
416
STARTUP_BAT : STARTUP_SH));
417                 
418                 dm.setServerProcess(serverProcess);
419                 
420                 // create a tailer to the server's output stream so that a user
421
// can observe the progress
422
new WLTailer(serverProcess.getInputStream(), dm.getURI());
423                 
424                 String JavaDoc serverName = dm.getInstanceProperties().getProperty(InstanceProperties.DISPLAY_NAME_ATTR);
425
426                 // wait till the timeout happens, or if the server starts before
427
// send the completed event to j2eeserver
428
while (System.currentTimeMillis() - start < TIMEOUT) {
429                     // send the 'completed' event and return when the server is running
430
if (isRunning()) {
431                         serverProgress.notifyStart(StateType.COMPLETED, NbBundle.getMessage(WLStartServer.class, "MSG_SERVER_STARTED", serverName)); // NOI18N
432
return;
433                     }
434
435                     // sleep for a little so that we do not make our checks too
436
// often
437
try {
438                         Thread.sleep(DELAY);
439                     } catch (InterruptedException JavaDoc e) {}
440                 }
441
442                 // if the server did not start in the designated time limits
443
// we consider the startup as failed and warn the user
444
serverProgress.notifyStart(StateType.FAILED, NbBundle.getMessage(WLStartServer.class, "MSG_StartServerTimeout"));
445             } catch (IOException e) {
446                 ErrorManager.getDefault().notify(ErrorManager.EXCEPTION, e);
447             }
448         }
449         
450         /**
451          * The amount of time in milliseconds during which the server should
452          * start
453          */

454         private static final int TIMEOUT = 900000;
455         
456         /**
457          * The amount of time in milliseconds that we should wait between checks
458          */

459         private static final int DELAY = 5000;
460         
461         /**
462          * Name of the startup script for windows
463          */

464         private static final String JavaDoc STARTUP_SH = "startWebLogic.sh"; // NOI18N
465

466         /**
467          * Name of the startup script for Unices
468          */

469         private static final String JavaDoc STARTUP_BAT = "startWebLogic.cmd"; // NOI18N
470
}
471     
472     /**
473      * Runnable that starts the server in debug mode. It is used to start the
474      * server in a separate thread, so that the IDE does not hang up during the
475      * startup process.
476      *
477      * @author Kirill Sorokin
478      */

479     private class WLStartDebugRunnable implements Runnable JavaDoc {
480         
481         /**
482          * Root directory for the selected profile
483          */

484         private String JavaDoc domainHome;
485         
486         /**
487          * The debugger port that the JPDA debugger should connect to, basically
488          * this integer will be added to the server's startup command line, to
489          * make the JVM listen for debugger connection on this port
490          */

491         private String JavaDoc debuggerPort;
492         
493         /**
494          * Progress object that describes the startup process. It will be
495          * notified of the progress and the success/failure of the process
496          */

497         private WLServerProgress serverProgress;
498         
499         /**
500          * Creates a new instance of WSStartDebugRunnable.
501          *
502          * @param serverProgress the prgress object that the thread should
503          * notify of anything that happens with the startup process
504          */

505         public WLStartDebugRunnable(WLServerProgress serverProgress) {
506             // save the progress object
507
this.serverProgress = serverProgress;
508             
509             // get the profile root directory, the debugger port and the
510
// instance name from the deployment manager
511
domainHome = dm.getInstanceProperties().getProperty(
512                     WLPluginProperties.DOMAIN_ROOT_ATTR);
513             debuggerPort = dm.getInstanceProperties().getProperty(
514                     WLPluginProperties.DEBUGGER_PORT_ATTR);
515         }
516         
517         /**
518          * Implementation of the run() method from the Runnable interface
519          */

520         public void run() {
521             try {
522                 // save the current time so that we can deduct that the startup
523
// failed due to timeout
524
long start = System.currentTimeMillis();
525                 
526                 
527                 // create the startup process
528
File cwd = new File (domainHome);
529                 assert cwd.isDirectory() : "Working directory for weblogic does not exist:" + domainHome; //NOI18N
530
org.openide.execution.NbProcessDescriptor pd = new org.openide.execution.NbProcessDescriptor(domainHome + "/" + (Utilities.isWindows() ? STARTUP_BAT : STARTUP_SH), "");
531                 String JavaDoc envp[];
532                 envp = new String JavaDoc[] {"JAVA_OPTIONS=-Xdebug -Xnoagent -Djava.compiler=none -Xrunjdwp:server=y,suspend=n,transport=dt_socket,address=" + debuggerPort}; // NOI18N
533

534                 serverProcess = pd.exec(null, envp, true, cwd);
535                 
536                 dm.setServerProcess(serverProcess);
537                 
538                 // create a tailer to the server's output stream so that a user
539
// can observe the progress
540
new WLTailer(serverProcess.getInputStream(), dm.getURI());
541                 
542                 String JavaDoc serverName = dm.getInstanceProperties().getProperty(InstanceProperties.DISPLAY_NAME_ATTR);
543                 
544                 // wait till the timeout happens, or if the server starts before
545
// send the completed event to j2eeserver
546
while (System.currentTimeMillis() - start < TIMEOUT) {
547                     // send the 'completed' event and return when the server is running
548
if (isRunning()) {
549                         serverProgress.notifyStart(StateType.COMPLETED, NbBundle.getMessage(WLStartServer.class, "MSG_SERVER_STARTED", serverName)); // NOI18N
550
return;
551                     }
552
553                     // sleep for a little so that we do not make our checks too
554
// often
555
try {
556                         Thread.sleep(DELAY);
557                     } catch (InterruptedException JavaDoc e) {}
558                 }
559
560                 // if the server did not start in the designated time limits
561
// we consider the startup as failed and warn the user
562
serverProgress.notifyStart(StateType.FAILED, NbBundle.getMessage(WLStartServer.class, "MSG_StartServerTimeout"));
563             } catch (IOException e) {
564                 ErrorManager.getDefault().notify(ErrorManager.EXCEPTION, e);
565             }
566         }
567         
568         /**
569          * The amount of time in milliseconds during which the server should
570          * start
571          */

572         private static final int TIMEOUT = 900000;
573         
574         /**
575          * The amount of time in milliseconds that we should wait between checks
576          */

577         private static final int DELAY = 5000;
578         
579         /**
580          * Name of the startup script for windows
581          */

582         private static final String JavaDoc STARTUP_SH = "startWebLogic.sh"; // NOI18N
583

584         /**
585          * Name of the startup script for Unices
586          */

587         private static final String JavaDoc STARTUP_BAT = "startWebLogic.cmd"; // NOI18N
588
}
589     
590     /**
591      * Runnable that stops the server. It is used to stop the server in a
592      * separate thread, so that the IDE does not hang up during the stop
593      * process.
594      *
595      * @author Kirill Sorokin
596      */

597     private class WLStopRunnable implements Runnable JavaDoc {
598         
599         /**
600          * Root directory for the selected profile
601          */

602         private String JavaDoc domainHome;
603         
604         /**
605          * Progress object that describes the stop process. It will be
606          * notified of the progress and the success/failure of the process
607          */

608         private WLServerProgress serverProgress;
609         
610         /**
611          * Creates a new instance of WSStopRunnable.
612          *
613          * @param serverProgress the prgress object that the thread should
614          * notify of anything that happens with the stop process
615          */

616         public WLStopRunnable(WLServerProgress serverProgress) {
617             // save the progress pbject
618
this.serverProgress = serverProgress;
619             
620             // get the profile home directory and the instance name from the
621
// deployment manager
622
domainHome = dm.getInstanceProperties().getProperty(
623                     WLPluginProperties.DOMAIN_ROOT_ATTR);
624         }
625         
626         /**
627          * Implementation of the run() method from the Runnable interface
628          */

629         public void run() {
630             try {
631                 // save the current time so that we can deduct that the startup
632
// failed due to timeout
633
long start = System.currentTimeMillis();
634                 
635                 // create the stop process
636
Process JavaDoc serverProcess = Runtime.getRuntime().exec(
637                         domainHome + "/bin/" + (Utilities.isWindows() ? // NOI18N
638
SHUTDOWN_BAT : SHUTDOWN_SH));
639                 
640                 // create a tailer to the server's output stream so that a user
641
// can observe the progress
642
new WLTailer(serverProcess.getInputStream(), dm.getURI());
643
644                 String JavaDoc serverName = dm.getInstanceProperties().getProperty(InstanceProperties.DISPLAY_NAME_ATTR);
645                 
646                 while (System.currentTimeMillis() - start < TIMEOUT) {
647                     if (!isStopped()) {
648                         serverProgress.notifyStop(StateType.RUNNING, NbBundle.getMessage(WLStartServer.class, "MSG_STOP_SERVER_IN_PROGRESS", serverName)); // NOI18N
649
} else {
650                         try {
651                             serverProcess.waitFor();
652                         } catch (InterruptedException JavaDoc ex) {
653                         }
654                         long pbLagTime = (System.currentTimeMillis() - start) / 4;
655                         try {
656                             Thread.sleep(pbLagTime);
657                         } catch (InterruptedException JavaDoc e) {}
658                         serverProgress.notifyStop(StateType.COMPLETED, NbBundle.getMessage(WLStartServer.class, "MSG_SERVER_STOPPED", serverName)); // NOI18N
659
return;
660                     }
661
662                     // sleep for a while so that we do not make our checks too often
663
try {
664                         Thread.sleep(DELAY);
665                     } catch (InterruptedException JavaDoc e) {}
666                 }
667                     
668                 // if the server did not stop in the designated time limits
669
// we consider the stop process as failed and kill the process
670
serverProgress.notifyStop(StateType.FAILED, NbBundle.getMessage(WLStartServer.class, "MSG_StopServerTimeout"));
671                 serverProcess.destroy();
672             } catch (IOException e) {
673                 ErrorManager.getDefault().notify(ErrorManager.EXCEPTION, e);
674             }
675         }
676         
677         /**
678          * The amount of time in milliseconds during which the server should
679          * stop
680          */

681         private static final int TIMEOUT = 120000;
682         
683         /**
684          * The amount of time in milliseconds that we should wait between checks
685          */

686         private static final int DELAY = 5000;
687         
688         /**
689          * Name of the shutdown script for windows
690          */

691         private static final String JavaDoc SHUTDOWN_SH = "stopWebLogic.sh"; // NOI18N
692

693         /**
694          * Name of the shutdown script for unices
695          */

696         private static final String JavaDoc SHUTDOWN_BAT = "stopWebLogic.cmd"; // NOI18N
697
}
698     
699     /**
700      * An implementation of the ProgressObject interface targeted at tracking
701      * the server instance's startup/shutdown progress
702      *
703      * @author Kirill Sorokin
704      */

705     private static class WLServerProgress implements ProgressObject {
706         
707         /**
708          * Listeners vector
709          */

710         private Vector listeners = new Vector();
711         
712         /**
713          * Current startus of the startup/shutdown process
714          */

715         private DeploymentStatus deploymentStatus;
716         
717         /**
718          * Progress events source
719          */

720         private Object JavaDoc source;
721         
722         /**
723          * Creates a new instance of WSServerProgress. The source supplied will
724          * be used as the source for all the events. Ususally it is the parent
725          * WSStartServerObject
726          *
727          * @param source the events' source
728          */

729         public WLServerProgress(Object JavaDoc source) {
730             this.source = source;
731         }
732         
733         /**
734          * Sends a startup event to the listeners.
735          *
736          * @param state the new state of the startup process
737          * @param message the attached string message
738          */

739         public void notifyStart(StateType state, String JavaDoc message) {
740             // call the general notify method with the specific startup event
741
// parameters set
742
notify(new WLDeploymentStatus(ActionType.EXECUTE, CommandType.START, state, message));
743         }
744         
745         /**
746          * Sends a shutdown event to the listeners.
747          *
748          * @param state the new state of the shutdown process
749          * @param message the attached string message
750          */

751         public void notifyStop(StateType state, String JavaDoc message) {
752             // call the general notify method with the specific shutdown event
753
// parameters set
754
notify(new WLDeploymentStatus(ActionType.EXECUTE, CommandType.STOP, state, message));
755         }
756         
757         /**
758          * Notifies the listeners of the new process status
759          *
760          * @param deploymentStatus the new status of the startup/shutdown
761          * process
762          */

763         public void notify(DeploymentStatus deploymentStatus) {
764             // construct a new progress event from the source and the supplied
765
// new process status
766
ProgressEvent evt = new ProgressEvent(source, null, deploymentStatus);
767             
768             // update the saved process status
769
this.deploymentStatus = deploymentStatus;
770             
771             
772             // get a copy of the listeners vector so that we do not get any
773
// conflicts when multithreading
774
java.util.Vector JavaDoc targets = null;
775             synchronized (this) {
776                 if (listeners != null) {
777                     targets = (java.util.Vector JavaDoc) listeners.clone();
778                 }
779             }
780             
781             
782             // traverse the listeners, notifying each with the new event
783
if (targets != null) {
784                 for (int i = 0; i < targets.size(); i++) {
785                     ProgressListener target = (ProgressListener) targets.elementAt(i);
786                     target.handleProgressEvent(evt);
787                 }
788             }
789         }
790         
791         ////////////////////////////////////////////////////////////////////////////
792
// ProgressObject implementation
793
////////////////////////////////////////////////////////////////////////////
794
/**
795          * A dummy implementation of the ProgressObject method, since this
796          * method is not used anywhere, we omit the reasonable implementation
797          */

798         public ClientConfiguration getClientConfiguration(TargetModuleID targetModuleID) {
799             return null;
800         }
801         
802         /**
803          * Removes the registered listener
804          *
805          * @param progressListener the listener to be removed
806          */

807         public void removeProgressListener(ProgressListener progressListener) {
808             listeners.remove(progressListener);
809         }
810         
811         /**
812          * Adds a new listener
813          *
814          * @param progressListener the listener to be added
815          */

816         public void addProgressListener(ProgressListener progressListener) {
817             listeners.add(progressListener);
818         }
819         
820         /**
821          * Returns the current state of the startup/shutdown process
822          *
823          * @return current state of the process
824          */

825         public DeploymentStatus getDeploymentStatus() {
826             return deploymentStatus;
827         }
828         
829         /**
830          * A dummy implementation of the ProgressObject method, since this
831          * method is not used anywhere, we omit the reasonable implementation
832          */

833         public TargetModuleID[] getResultTargetModuleIDs() {
834             return new TargetModuleID[]{};
835         }
836         
837         /**
838          * A dummy implementation of the ProgressObject method, since this
839          * method is not used anywhere, we omit the reasonable implementation
840          */

841         public boolean isStopSupported() {
842             return false;
843         }
844         
845         /**
846          * A dummy implementation of the ProgressObject method, since this
847          * method is not used anywhere, we omit the reasonable implementation
848          */

849         public void stop() throws OperationUnsupportedException {
850             throw new OperationUnsupportedException(""); // NOI18N
851
}
852         
853         /**
854          * A dummy implementation of the ProgressObject method, since this
855          * method is not used anywhere, we omit the reasonable implementation
856          */

857         public boolean isCancelSupported() {
858             return false;
859         }
860         
861         /**
862          * A dummy implementation of the ProgressObject method, since this
863          * method is not used anywhere, we omit the reasonable implementation
864          */

865         public void cancel() throws OperationUnsupportedException {
866             throw new OperationUnsupportedException(""); // NOI18N
867
}
868     }
869     
870     /**
871      * A class that describes the startup/shutdown process state. It is an
872      * implementation of the DeploymentStatus interface.
873      */

874     private static class WLDeploymentStatus implements DeploymentStatus {
875         /**
876          * Current action
877          */

878         private ActionType action;
879         
880         /**
881          * Current command
882          */

883         private CommandType command;
884         
885         /**
886          * Current state
887          */

888         private StateType state;
889         
890         /**
891          * Current message
892          */

893         private String JavaDoc message;
894
895         /**
896          * Creates a new WSDeploymentStatus object.
897          *
898          * @param action current action
899          * @param command current command
900          * @param state current state
901          * @param message current message
902          */

903         public WLDeploymentStatus(ActionType action, CommandType command, StateType state, String JavaDoc message) {
904             // save the supplied parameters
905
this.action = action;
906             this.command = command;
907             this.state = state;
908             this.message = message;
909         }
910
911         /**
912          * Returns the current action
913          *
914          * @return current action
915          */

916         public ActionType getAction() {
917             return action;
918         }
919         
920         /**
921          * Returns the current command
922          *
923          * @return current command
924          */

925         public CommandType getCommand() {
926             return command;
927         }
928         
929         /**
930          * Returns the current message
931          *
932          * @return current message
933          */

934         public String JavaDoc getMessage() {
935             return message;
936         }
937         
938         /**
939          * Returns the current state
940          *
941          * @return current state
942          */

943         public StateType getState() {
944             return state;
945         }
946         
947         /**
948          * Tells whether the current action has completed successfully
949          *
950          * @return true if the action has completed successfully, false
951          * otherwise
952          */

953         public boolean isCompleted() {
954             return StateType.COMPLETED.equals(state);
955         }
956         
957         /**
958          * Tells whether the current action has failed
959          *
960          * @return true if the action has failed, false otherwise
961          */

962         public boolean isFailed() {
963             return StateType.FAILED.equals(state);
964         }
965         
966         /**
967          * Tells whether the current action is still running
968          *
969          * @return true if the action is still running, false otherwise
970          */

971         public boolean isRunning() {
972             return StateType.RUNNING.equals(state);
973         }
974     };
975     
976     ////////////////////////////////////////////////////////////////////////////
977
// Constants section
978
////////////////////////////////////////////////////////////////////////////
979
// These introduce two additional states to the instance - starting and
980
// stopping son that we can filter sunsequent requests. They are currently
981
// not used, but may be if problems wth multiple startup arise again
982
// private static final int STATE_STOPPED = 0;
983
// private static final int STATE_STARTING = 1;
984
// private static final int STATE_STARTED = 2;
985
// private static final int STATE_STOPPING = 3;
986
}
Popular Tags