1 23 24 package com.sun.enterprise.connectors.system; 25 26 import java.util.Properties ; 27 import java.util.logging.*; 28 import javax.management.Attribute ; 29 import javax.management.AttributeList ; 30 import javax.management.MBeanServerConnection ; 31 import javax.management.ObjectName ; 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 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 target = null; 56 57 60 public MQAdministrator() { 61 } 62 63 68 public MQAdministrator(String target) 69 throws ConnectorRuntimeException{ 70 this.target = target; 71 } 72 73 74 public void createPhysicalDestination(String 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 mbsc = mqInfo.getMQMBeanServerConnection(); 85 ObjectName on = new ObjectName ( 86 MQObjectName.DESTINATION_MANAGER_CONFIG_MBEAN_NAME); 87 String [] signature = null; 88 AttributeList destAttrs = null; 89 Object [] params = null; 90 String destType = DestinationType.TOPIC; 91 92 destAttrs = new AttributeList (); 93 if (isQueue) { 94 destAttrs.add(new Attribute (IASJmsUtil.getMaxActiveConsumersAttribute(), 95 new Long (IASJmsUtil.getDefaultMaxActiveConsumers()))); 96 destType = DestinationType.QUEUE; 97 } 98 if (mqInfo.getBrokerType().equalsIgnoreCase(ActiveJmsResourceAdapter.LOCAL)) { 99 destAttrs.add( new Attribute ("LocalDeliveryPreferred", 100 new Boolean ("true"))); 101 } 102 if ((destAttrs == null) || (destAttrs.size() == 0)){ 103 signature = new String [] { 104 "java.lang.String", 105 "java.lang.String"}; 106 params = new Object [] {destType, destName}; 107 } else { 108 signature = new String [] { 109 "java.lang.String", 110 "java.lang.String", 111 "javax.management.AttributeList"}; 112 params = new Object [] {destType, destName, destAttrs}; 113 } 114 mbsc.invoke(on, "create", params, signature); 115 } catch (Exception e) { 116 handleException(e); 117 } finally { 118 try { 119 if(mqInfo != null) { 120 mqInfo.closeMQMBeanServerConnection(); 121 } 122 } catch (Exception e) { 123 handleException(e); 124 } 125 } 126 } 127 128 private String getClusterName() throws ConfigException { 129 return ClusterHelper.getClusterForInstance( 130 ApplicationServer.getServerContext().getConfigContext(), 131 ApplicationServer.getServerContext().getInstanceName()).getName(); 132 } 133 134 135 private ConnectorRuntimeException handleException(Exception 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 |