1 10 package org.mule.management.support; 11 12 import org.apache.commons.logging.Log; 13 import org.apache.commons.logging.LogFactory; 14 import org.mule.MuleManager; 15 import org.mule.impl.internal.notifications.ManagerNotification; 16 import org.mule.impl.internal.notifications.ManagerNotificationListener; 17 import org.mule.impl.internal.notifications.NotificationException; 18 import org.mule.umo.manager.UMOServerNotification; 19 20 31 public class JmxRegistrationContext 32 { 33 36 private final transient Log logger = LogFactory.getLog(getClass()); 37 38 43 private static final ThreadLocal contexts = new ThreadLocal (); 44 45 private String resolvedDomain; 46 47 48 private JmxRegistrationContext() 49 { 50 if (!MuleManager.isInstanciated()) 52 { 53 return; 54 } 55 56 try 57 { 58 MuleManager.getInstance().registerListener(new ManagerNotificationListener() 61 { 62 public void onNotification(UMOServerNotification notification) 63 { 64 ManagerNotification mn = (ManagerNotification) notification; 65 if (ManagerNotification.MANAGER_DISPOSED == mn.getAction()) 66 { 67 resolvedDomain = null; 69 contexts.set(null); 71 } 72 } 73 }); 74 } catch (NotificationException e) 75 { 76 logger.warn("Did not cleanup properly.", e); 77 } 78 } 79 80 84 public static JmxRegistrationContext getCurrent() 85 { 86 JmxRegistrationContext ctx = (JmxRegistrationContext) contexts.get(); 87 if (ctx == null) 88 { 89 ctx = new JmxRegistrationContext(); 90 } 91 contexts.set(ctx); 92 return ctx; 93 } 94 95 100 public String getResolvedDomain() 101 { 102 return resolvedDomain; 103 } 104 105 110 public void setResolvedDomain(String resolvedDomain) 111 { 112 this.resolvedDomain = resolvedDomain; 113 } 114 } 115 | Popular Tags |