KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > cli > commands > PingConnectionPoolCommand


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.cli.commands;
25
26 import com.sun.enterprise.cli.framework.*;
27 import javax.management.Attribute JavaDoc;
28 import javax.management.AttributeList JavaDoc;
29 import javax.management.ObjectName JavaDoc;
30 import javax.management.MBeanServerConnection JavaDoc;
31 import javax.management.MalformedObjectNameException JavaDoc;
32 import javax.management.InstanceNotFoundException JavaDoc;
33 import javax.management.IntrospectionException JavaDoc;
34 import javax.management.ReflectionException JavaDoc;
35
36
37 import java.util.Vector JavaDoc;
38 import java.io.IOException JavaDoc;
39 import java.util.StringTokenizer JavaDoc;
40
41 /**
42  * This is to find out if connection pool is alive or not
43  * @version $Revision: 1.3 $
44  */

45 public class PingConnectionPoolCommand extends S1ASCommand
46 {
47
48     /**
49      * A method that validates the options
50      * on the specification in the xml properties file
51      * This method verifies for the correctness of number of
52      * operands and if all the required options are supplied by the client.
53      * @return boolean returns true if success else returns false
54      */

55     public boolean validateOptions() throws CommandValidationException
56     {
57         return super.validateOptions();
58     }
59    
60     /**
61      * Executes the command
62      * @throws CommandException
63      */

64     public void runCommand() throws CommandException, CommandValidationException
65     {
66         if (!validateOptions())
67             throw new CommandValidationException("Validation is false");
68         String JavaDoc objectName = getObjectName();
69         Object JavaDoc[] params = getParamsInfo();
70         String JavaDoc operationName = getOperationName();
71         String JavaDoc[] types = getTypesInfo();
72
73     MBeanServerConnection JavaDoc mbsc = getMBeanServerConnection(getHost(),
74                                   getPort(),
75                                   getUser(),
76                                   getPassword());
77
78         try
79         {
80             Boolean JavaDoc returnValue = (Boolean JavaDoc)mbsc.invoke(new ObjectName JavaDoc(objectName),
81                          operationName, params, types);
82         if (returnValue.booleanValue()) {
83                 // Ping was successful
84
CLILogger.getInstance().printDetailMessage(getLocalizedString(
85                                "CommandSuccessful",
86                                new Object JavaDoc[] {name}));
87         }
88             else {
89                 // Ping was not successful
90
CLILogger.getInstance().printMessage(getLocalizedString(
91                              "UnableToPing", new Object JavaDoc[]
92                              {(String JavaDoc)getOperands().get(0)}));
93
94            }
95         }
96         catch(Exception JavaDoc e)
97         {
98         if (e.getLocalizedMessage() != null)
99         CLILogger.getInstance().printDetailMessage(e.getLocalizedMessage());
100             throw new CommandException(getLocalizedString("CommandUnSuccessful",
101                              new Object JavaDoc[] {name} ), e);
102         }
103     }
104
105 }
106
Popular Tags