| Method from org.jboss.jmx.connector.invoker.InvokerAdaptorService Detail: |
public void addNotificationListener(ObjectName name,
RMINotificationListener listener,
NotificationFilter filter,
Object handback) throws InstanceNotFoundException, RemoteException {
if( log.isTraceEnabled() )
log.trace("addNotificationListener, name="+name+", listener="+listener);
NotificationListenerDelegate delegate =
new NotificationListenerDelegate(listener, name);
remoteListeners.put(listener, delegate);
getServer().addNotificationListener(name, delegate, filter, handback);
}
|
public Class[] getExportedInterfaces() {
return exportedInterfaces;
}
|
public Map getMethodMap() {
return marshalledInvocationMapping;
}
Expose the service interface mapping as a read-only attribute |
public Object invoke(Invocation invocation) throws Exception {
try
{
// Make sure we have the correct classloader before unmarshalling
ClassLoader oldCL = SecurityActions.getContextClassLoader();
ClassLoader newCL = null;
// Get the MBean this operation applies to
ObjectName objectName = (ObjectName) invocation.getValue("JMX_OBJECT_NAME");
if (objectName != null)
{
// Obtain the ClassLoader associated with the MBean deployment
newCL = server.getClassLoaderFor(objectName);
}
if (newCL != null && newCL != oldCL)
SecurityActions.setContextClassLoader(newCL);
try
{
// Set the method hash to Method mapping
if (invocation instanceof MarshalledInvocation)
{
MarshalledInvocation mi = (MarshalledInvocation) invocation;
mi.setMethodMap(marshalledInvocationMapping);
}
// Invoke the MBeanServer method via reflection
Method method = invocation.getMethod();
Object[] args = invocation.getArguments();
Principal principal = invocation.getPrincipal();
Object credential = invocation.getCredential();
Object value = null;
SecurityContext sc = SecurityActions.createSecurityContext(SecurityConstants.DEFAULT_APPLICATION_POLICY);
SecurityActions.setSecurityContext(sc);
// Associate the method
SecurityActions.pushSubjectContext(principal, credential, null);
try
{
if( addNotificationListeners.contains(method) )
{
ObjectName name = (ObjectName) args[0];
RMINotificationListener listener = (RMINotificationListener)
args[1];
NotificationFilter filter = (NotificationFilter) args[2];
Object handback = args[3];
addNotificationListener(name, listener, filter, handback);
}
else if( removeNotificationListeners.contains(method) )
{
ObjectName name = (ObjectName) args[0];
RMINotificationListener listener = (RMINotificationListener)
args[1];
removeNotificationListener(name, listener);
}
else
{
String name = method.getName();
Class[] paramTypes = method.getParameterTypes();
Method mbeanServerMethod = MBeanServer.class.getMethod(name,
paramTypes);
value = mbeanServerMethod.invoke(server, args);
}
}
catch(InvocationTargetException e)
{
Throwable t = e.getTargetException();
if( t instanceof Exception )
throw (Exception) t;
else
throw new UndeclaredThrowableException(t, method.toString());
}
return value;
}
finally
{
// Restore the input security context
SecurityActions.popSubjectContext();
SecurityActions.clearSecurityContext();
// Restore the input class loader
if (newCL != null && newCL != oldCL)
SecurityActions.setContextClassLoader(oldCL);
}
}
catch (Throwable t)
{
throw new InvokerAdaptorException(t);
}
}
Expose the MBeanServer service via JMX to invokers. |
public void removeNotificationListener(ObjectName name,
RMINotificationListener listener) throws InstanceNotFoundException, ListenerNotFoundException, RemoteException {
if( log.isTraceEnabled() )
log.trace("removeNotificationListener, name="+name+", listener="+listener);
NotificationListenerDelegate delegate = (NotificationListenerDelegate)
remoteListeners.remove(listener);
if( delegate == null )
throw new ListenerNotFoundException("No listener matches: "+listener);
getServer().removeNotificationListener(name, delegate);
}
|
public void setExportedInterfaces(Class[] exportedInterfaces) {
this.exportedInterfaces = exportedInterfaces;
}
|
protected void startService() throws Exception {
// Build the interface method map
HashMap tmpMap = new HashMap(61);
for(int n = 0; n < exportedInterfaces.length; n ++)
{
Class iface = exportedInterfaces[n];
Method[] methods = iface.getMethods();
for(int m = 0; m < methods.length; m ++)
{
Method method = methods[m];
Long hash = new Long(MarshalledInvocation.calculateHash(method));
tmpMap.put(hash, method);
}
/* Look for a void addNotificationListener(ObjectName name,
RMINotificationListener listener, NotificationFilter filter,
Object handback)
*/
try
{
Class[] sig = {ObjectName.class, RMINotificationListener.class,
NotificationFilter.class, Object.class};
Method addNotificationListener = iface.getMethod(
"addNotificationListener", sig);
addNotificationListeners.add(addNotificationListener);
}
catch(Exception e)
{
log.debug(iface+"No addNotificationListener(ObjectName, RMINotificationListener)");
}
/* Look for a void removeNotificationListener(ObjectName,
RMINotificationListener)
*/
try
{
Class[] sig = {ObjectName.class, RMINotificationListener.class};
Method removeNotificationListener = iface.getMethod(
"removeNotificationListener", sig);
removeNotificationListeners.add(removeNotificationListener);
}
catch(Exception e)
{
log.debug(iface+"No removeNotificationListener(ObjectName, RMINotificationListener)");
}
}
marshalledInvocationMapping = Collections.unmodifiableMap(tmpMap);
// Place our ObjectName hash into the Registry so invokers can resolve it
Registry.bind(new Integer(serviceName.hashCode()), serviceName);
}
|
protected void stopService() throws Exception {
// Remove the method hashses
if( exportedInterfaces != null )
{
for(int n = 0; n < exportedInterfaces.length; n ++)
MarshalledInvocation.removeHashes(exportedInterfaces[n]);
}
marshalledInvocationMapping = null;
remoteListeners.clear();
Registry.unbind(new Integer(serviceName.hashCode()));
}
|