1 23 24 package com.sun.enterprise.management.model; 25 26 import java.util.*; 27 import javax.management.*; 28 import javax.naming.*; 29 import javax.naming.event.*; 30 31 public class J2EEDomainMdl extends J2EEEventProviderMOMdl { public static String DOMAINNAME; 33 private static ObjectName jmImpl; 34 private boolean debug = false; 35 36 37 static { 38 try { 39 DOMAINNAME = java.net.InetAddress.getLocalHost().getHostName(); 40 jmImpl = new ObjectName("JMImplementation:type=MBeanServerDelegate"); 41 } catch (Exception e) { 42 DOMAINNAME = "J2EE_1.3.1_RI"; 43 } 44 } 45 46 private static String MANAGED_OBJECT_TYPE = "J2EEDomain"; 47 48 private String [] eventTypes = new String [] {"j2ee.object.created","j2ee.object.deleted"}; 49 50 public J2EEDomainMdl() { 51 super(DOMAINNAME, false, false); 52 59 } 60 public J2EEDomainMdl(String domainname) { 61 super(domainname, false, false); 62 DOMAINNAME = domainname; 63 70 } 71 72 76 public String [] getservers(){ 77 Set servers = findNames("j2eeType=J2EEServer"); 78 79 Iterator it = servers.iterator(); 80 String [] ret = new String [servers.size()]; 81 int i =0; 82 while(it.hasNext()) { 83 ret[i++] = ((ObjectName)it.next()).toString(); 84 } 85 return ret; 86 } 87 88 public String [] geteventTypes(){ 89 return eventTypes; 90 } 91 92 public void handleNotification(Notification n, Object handback) { 93 96 if (debug) { 97 System.out.println(handback); 98 System.out.println("message: " + n.getMessage()); 99 System.out.println("sequence: " + n.getSequenceNumber()); 100 System.out.println("source: " + n.getSource()); 101 System.out.println("timestamp: " + n.getTimeStamp()); 102 System.out.println("type: " + n.getType()); 103 System.out.println("user data: " + n.getUserData()); 104 System.out.println(""); 105 } 106 107 if(n instanceof MBeanServerNotification) { 108 MBeanServerNotification n2 = null; 109 if (n.getType().equalsIgnoreCase("jmx.mbean.registered")) { 110 ObjectName oname = ((MBeanServerNotification)n).getMBeanName(); 111 if (debug) System.out.println("MBean name: " + oname); 112 if (!((String )oname.getKeyProperty("name")).equals(getname())) { try { 114 Boolean b = (Boolean )getMBSUtility().getAttribute(oname, "eventProvider"); 115 if (b.booleanValue()){ 116 if (debug) System.out.println("J2EEDomain adding myself as listener to " + oname); 117 } 120 } catch (Exception e) { 121 if (debug) e.printStackTrace(); 122 } 123 } 124 n2 = new MBeanServerNotification("j2ee.object.created", getobjectName(), n.getSequenceNumber(), oname); 125 } else if (n.getType().equalsIgnoreCase("jmx.mbean.unregistered")) { 126 n2 = new MBeanServerNotification("j2ee.object.deleted", getobjectName(), n.getSequenceNumber(), ((MBeanServerNotification)n).getMBeanName()); 127 } 128 if (n2 != null) { 129 sendNotification(n2); 130 return; 131 } 132 } 133 if (debug) System.out.println("Forwarding original notification " + n); 134 sendNotification(n); 135 } 136 137 140 public String getj2eeType() { 141 return MANAGED_OBJECT_TYPE; 142 } 143 144 148 public String getobjectName() { 149 Set s = findNames("j2eeType="+getj2eeType()+",name="+DOMAINNAME); 150 Object [] objs = s.toArray(); 151 if (objs.length > 0) { 152 String name = ((ObjectName)objs[0]).toString(); 153 return name; 154 } else { 155 return null; 156 } 157 } 158 159 } 160 | Popular Tags |