1 22 package org.objectweb.petals.kernel.admin; 23 24 import java.io.IOException ; 25 import java.util.Hashtable ; 26 import java.util.Set ; 27 28 import javax.management.InstanceNotFoundException ; 29 import javax.management.MBeanException ; 30 import javax.management.MBeanServerConnection ; 31 import javax.management.MalformedObjectNameException ; 32 import javax.management.ObjectName ; 33 import javax.management.QueryExp ; 34 import javax.management.ReflectionException ; 35 import javax.management.remote.JMXConnector ; 36 37 42 public class DistributedJMXServer { 43 44 47 public static final String PETALS_DOMAIN = "Petals"; 48 49 52 public static final String GET_SERVICE_DESCRITION = "getServiceDescription"; 53 54 57 public static final String IS_OK_WITH_CONS = "isExchangeWithConsumerOkayForComponent"; 58 59 62 public static final String IS_OK_WITH_PROV = "isExchangeWithProviderOkayForComponent"; 63 64 67 private MBeanServerConnection connection; 68 69 72 private JMXConnector connector; 73 74 public DistributedJMXServer(JMXConnector connector) { 75 this.connector = connector; 76 } 77 78 protected MBeanServerConnection getMBeanServerConnection() { 79 if (connection == null) { 80 try { 81 connector.connect(); 82 connection = connector.getMBeanServerConnection(); 83 } catch (IOException e) { 84 e.printStackTrace(); 85 } 86 } 87 return this.connection; 88 } 89 90 98 public ObjectName getAdminServiceMBeanName() throws IOException , 99 MalformedObjectNameException , NullPointerException { 100 if (connection == null) { 101 connector.connect(); 102 connection = connector.getMBeanServerConnection(); 103 } 104 ObjectName result = null; 105 Set objNames; 106 Hashtable <String , String > attrs = new Hashtable <String , String >(); 107 attrs.put("name", "Admin"); 108 attrs.put("type", "service"); 109 ObjectName objName = new ObjectName (PETALS_DOMAIN, attrs); 110 objNames = connection.queryNames(objName, null); 111 if (objNames != null && objNames.size() == 1) { 112 result = (ObjectName ) objNames.iterator().next(); 113 } 114 return result; 115 } 116 117 public Object invoke(ObjectName name, String operationName, 118 Object [] params, String [] signature) 119 throws InstanceNotFoundException , MBeanException , ReflectionException , 120 IOException { 121 if (connection == null) { 122 connector.connect(); 123 connection = connector.getMBeanServerConnection(); 124 } 125 Object out = null; 126 out = connection.invoke(name, operationName, params, signature); 127 return out; 128 } 129 130 public Set queryNames(ObjectName name, QueryExp queryExp) 131 throws InstanceNotFoundException , MBeanException , ReflectionException , 132 IOException { 133 if (connection == null) { 134 connector.connect(); 135 connection = connector.getMBeanServerConnection(); 136 } 137 Set out = null; 138 out = connection.queryNames(name, queryExp); 139 return out; 140 } 141 142 public void closeConnector() throws IOException { 143 connector.close(); 144 } 145 146 } 147 | Popular Tags |