KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > connectors > system > MQAdministrator


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.connectors.system;
25
26 import java.util.Properties JavaDoc;
27 import java.util.logging.*;
28 import javax.management.Attribute JavaDoc;
29 import javax.management.AttributeList JavaDoc;
30 import javax.management.MBeanServerConnection JavaDoc;
31 import javax.management.ObjectName JavaDoc;
32 import com.sun.logging.LogDomains;
33 import com.sun.enterprise.util.i18n.StringManager;
34 import com.sun.enterprise.config.serverbeans.ClusterHelper;
35 import com.sun.enterprise.config.ConfigException;
36 import com.sun.enterprise.server.ApplicationServer;
37 import com.sun.enterprise.jms.IASJmsUtil;
38 import com.sun.enterprise.connectors.ConnectorRuntimeException;
39 import com.sun.enterprise.connectors.ConnectorRuntime;
40
41 import com.sun.messaging.jms.management.server.DestinationType;
42 import com.sun.messaging.jms.management.server.MQObjectName;
43 /**
44  * Represents MQAdministrator of the default-jms-host of the
45  * target.
46  *
47  * @author Binod P.G
48  */

49 public class MQAdministrator {
50
51     static Logger logger = LogDomains.getLogger(LogDomains.RSR_LOGGER);
52     private static StringManager localStrings =
53         StringManager.getManager( ConnectorRuntime.class);
54
55     private String JavaDoc target = null;
56
57     /**
58      * Creates JMSAdmin object for the curremt Instance.
59      */

60     public MQAdministrator() {
61     }
62
63     /**
64      * Creates JMSAdmin object from the name of the target passed in.
65      *
66      * @param target Name of the target. Eg: cluster1 or server1
67      */

68     public MQAdministrator(String JavaDoc target)
69                       throws ConnectorRuntimeException{
70         this.target = target;
71     }
72
73
74     public void createPhysicalDestination(String JavaDoc destName,boolean isQueue )
75                        throws ConnectorRuntimeException {
76
77         MQJMXConnectorInfo mqInfo = null;
78         try {
79             if (this.target == null) {
80                 this.target = getClusterName();
81             }
82
83             mqInfo = MQJMXConnectorHelper.getMQJMXConnectorInfo(target) [0];
84             MBeanServerConnection JavaDoc mbsc = mqInfo.getMQMBeanServerConnection();
85             ObjectName JavaDoc on = new ObjectName JavaDoc(
86                  MQObjectName.DESTINATION_MANAGER_CONFIG_MBEAN_NAME);
87             String JavaDoc [] signature = null;
88             AttributeList JavaDoc destAttrs = null;
89             Object JavaDoc [] params = null;
90             String JavaDoc destType = DestinationType.TOPIC;
91
92             destAttrs = new AttributeList JavaDoc();
93             if (isQueue) {
94                 destAttrs.add(new Attribute JavaDoc(IASJmsUtil.getMaxActiveConsumersAttribute(),
95                           new Long JavaDoc(IASJmsUtil.getDefaultMaxActiveConsumers())));
96                 destType = DestinationType.QUEUE;
97             }
98             if (mqInfo.getBrokerType().equalsIgnoreCase(ActiveJmsResourceAdapter.LOCAL)) {
99                 destAttrs.add( new Attribute JavaDoc ("LocalDeliveryPreferred",
100                           new Boolean JavaDoc("true")));
101             }
102             if ((destAttrs == null) || (destAttrs.size() == 0)){
103                 signature = new String JavaDoc [] {
104                      "java.lang.String",
105                      "java.lang.String"};
106                 params = new Object JavaDoc [] {destType, destName};
107             } else {
108                 signature = new String JavaDoc [] {
109                      "java.lang.String",
110                      "java.lang.String",
111                      "javax.management.AttributeList"};
112                 params = new Object JavaDoc [] {destType, destName, destAttrs};
113             }
114             mbsc.invoke(on, "create", params, signature);
115         } catch (Exception JavaDoc e) {
116             handleException(e);
117         } finally {
118             try {
119                 if(mqInfo != null) {
120                      mqInfo.closeMQMBeanServerConnection();
121                 }
122             } catch (Exception JavaDoc e) {
123                 handleException(e);
124             }
125         }
126     }
127
128     private String JavaDoc getClusterName() throws ConfigException {
129         return ClusterHelper.getClusterForInstance(
130                         ApplicationServer.getServerContext().getConfigContext(),
131                         ApplicationServer.getServerContext().getInstanceName()).getName();
132     }
133
134
135     private ConnectorRuntimeException handleException(Exception JavaDoc e) {
136         logger.log(Level.WARNING,""+e.getMessage(), e);
137         ConnectorRuntimeException cre =
138              new ConnectorRuntimeException(e.getMessage());
139         cre.initCause(e);
140         return cre;
141     }
142
143 }
144
Popular Tags