Author: julien(a)jboss.com
Date: 2007-05-17 17:40:09 -0400 (Thu, 17 May 2007)
New Revision: 7270
Modified:
trunk/jems/src/main/org/jboss/portal/jems/as/system/POJOInjection.java
trunk/jems/src/main/org/jboss/portal/jems/as/system/POJOInjector.java
Log:
if the pojo target is unregistered from the mbean server then we inject null in the target
setter
Modified: trunk/jems/src/main/org/jboss/portal/jems/as/system/POJOInjection.java
===================================================================
--- trunk/jems/src/main/org/jboss/portal/jems/as/system/POJOInjection.java 2007-05-17
10:27:41 UTC (rev 7269)
+++ trunk/jems/src/main/org/jboss/portal/jems/as/system/POJOInjection.java 2007-05-17
21:40:09 UTC (rev 7270)
@@ -30,10 +30,6 @@
import javax.management.MBeanServer;
import javax.management.ObjectName;
import javax.management.InstanceNotFoundException;
-import javax.management.MBeanException;
-import javax.management.ReflectionException;
-import javax.management.MalformedObjectNameException;
-import java.lang.reflect.Proxy;
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
@@ -42,27 +38,28 @@
public class POJOInjection
{
- /** . */
+ /** The dispatcher. */
private final Interceptor dispatcher;
- /** . */
- private final Invocation invocation;
+ /** The setter invocation. */
+ private final Invocation setter;
- /** . */
+ /** The mbean server. */
private final MBeanServer server;
- /** . */
+ /** The pojo object name. */
private final ObjectName pojoName;
- /** . */
- private boolean resolved;
+ /** The injection status. */
+ private boolean injected;
- public POJOInjection(MBeanProxyExt pojoHandler, Interceptor dispatcher, Invocation
invocation)
+ public POJOInjection(MBeanProxyExt pojoHandler, Interceptor dispatcher, Invocation
setter)
{
this.dispatcher = dispatcher;
- this.invocation = invocation;
+ this.setter = setter;
this.server = pojoHandler.getMBeanProxyMBeanServer();
this.pojoName = pojoHandler.getMBeanProxyObjectName();
+ this.injected = false;
}
public ObjectName getPOJOName()
@@ -72,7 +69,7 @@
public synchronized void resolve()
{
- if (!resolved)
+ if (!injected)
{
if (server.isRegistered(pojoName))
{
@@ -88,18 +85,19 @@
Object pojo = entry.getInvoker().getResource();
// Replace the proxy by the service
- invocation.getArgs()[0] = pojo;
+ setter.getArgs()[0] = pojo;
// Dispatch the invocation finally
- dispatcher.invoke(invocation);
+ dispatcher.invoke(setter);
+
+ //
+ this.injected = true;
}
-
- //
- this.resolved = true;
}
catch (InstanceNotFoundException ignore)
{
- // Not found will resolve later
+ // It means that between the registration check and the get
+ // the service was removed
}
catch (Throwable e)
{
@@ -107,7 +105,26 @@
}
}
}
- }
+ else
+ {
+ if (!server.isRegistered(pojoName))
+ {
+ try
+ {
+ // Replace the proxy by the service
+ setter.getArgs()[0] = null;
+ // Dispatch the invocation finally
+ dispatcher.invoke(setter);
+ //
+ this.injected = false;
+ }
+ catch (Throwable e)
+ {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
}
Modified: trunk/jems/src/main/org/jboss/portal/jems/as/system/POJOInjector.java
===================================================================
--- trunk/jems/src/main/org/jboss/portal/jems/as/system/POJOInjector.java 2007-05-17
10:27:41 UTC (rev 7269)
+++ trunk/jems/src/main/org/jboss/portal/jems/as/system/POJOInjector.java 2007-05-17
21:40:09 UTC (rev 7270)
@@ -55,7 +55,7 @@
public void handleNotification(Notification notification, Object object)
{
String type = notification.getType();
- if (MBeanServerNotification.REGISTRATION_NOTIFICATION.equals(type))
+ if (MBeanServerNotification.REGISTRATION_NOTIFICATION.equals(type) ||
MBeanServerNotification.UNREGISTRATION_NOTIFICATION.equals(type))
{
MBeanServerNotification msn = (MBeanServerNotification)notification;
ObjectName name = msn.getMBeanName();
@@ -65,10 +65,5 @@
injection.resolve();
}
}
- else if (MBeanServerNotification.UNREGISTRATION_NOTIFICATION.equals(type))
- {
- MBeanServerNotification msn = (MBeanServerNotification)notification;
- // ObjectName name = msn.getMBeanName();
- }
}
}
Show replies by date