1 23 package com.sun.enterprise.management; 24 25 import java.io.IOException ; 26 27 import java.util.Set ; 28 import java.util.HashSet ; 29 import java.util.Collections ; 30 31 import javax.management.ObjectName ; 32 import javax.management.MBeanServerConnection ; 33 import javax.management.InstanceNotFoundException ; 34 35 import com.sun.appserv.management.base.AMX; 36 import com.sun.appserv.management.base.Util; 37 38 import com.sun.appserv.management.util.jmx.MBeanRegistrationListener; 39 import com.sun.appserv.management.util.jmx.JMXUtil; 40 41 44 public class RegistrationListener extends MBeanRegistrationListener 45 { 46 private final MBeanServerConnection mConn; 47 48 private Set <ObjectName > mRegistered; 49 private Set <ObjectName > mUnregistered; 50 private Set <ObjectName > mCurrentlyRegistered; 51 52 public 53 RegistrationListener( final MBeanServerConnection conn ) 54 throws InstanceNotFoundException , java.io.IOException 55 { 56 super( conn, null ); 57 58 mConn = conn; 59 60 mRegistered = new HashSet <ObjectName >(); 61 mUnregistered = new HashSet <ObjectName >(); 62 mCurrentlyRegistered = new HashSet <ObjectName >(); 63 JMXUtil.listenToMBeanServerDelegate( conn, this, null, null ); 64 65 queryAllAMX(); 66 } 67 68 private void 69 queryAllAMX() 70 { 71 try 72 { 73 final ObjectName pat = Util.newObjectNamePattern( AMX.JMX_DOMAIN, "*" ); 74 final Set <ObjectName > all = JMXUtil.queryNames( mConn, pat, null ); 75 76 mCurrentlyRegistered.addAll( all ); 77 } 78 catch( IOException e ) 79 { 80 } 81 } 82 83 public void 84 notifsLost() 85 { 86 queryAllAMX(); 87 } 88 89 private boolean 90 isAMX( final ObjectName objectName ) 91 { 92 return objectName.getDomain().equals( AMX.JMX_DOMAIN ); 93 } 94 95 protected synchronized void 96 mbeanRegistered( final ObjectName objectName ) 97 { 98 if ( isAMX( objectName ) ) 99 { 100 mRegistered.add( objectName ); 101 mCurrentlyRegistered.add( objectName ); 102 } 103 } 104 105 protected synchronized void 106 mbeanUnregistered( final ObjectName objectName ) 107 { 108 if ( isAMX( objectName ) ) 109 { 110 mUnregistered.add( objectName ); 111 mCurrentlyRegistered.remove( objectName ); 112 } 113 } 114 115 public Set <ObjectName > 116 getRegistered() 117 { 118 return Collections.unmodifiableSet( mRegistered ); 119 } 120 121 public Set <ObjectName > 122 getUnregistered() 123 { 124 return Collections.unmodifiableSet( mUnregistered ); 125 } 126 127 public synchronized Set <ObjectName > 128 getCurrentlyRegistered() 129 { 130 final Set <ObjectName > all = new HashSet <ObjectName >( mCurrentlyRegistered ); 131 132 return all; 133 } 134 135 } 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 | Popular Tags |