Package org.jboss.mx.remote.server

Source Code of org.jboss.mx.remote.server.NotificationJMXInvocationHandler

/**
* @(#)$Id: NotificationJMXInvocationHandler.java,v 1.1 2002/10/16 05:41:13 telrod Exp $
*/
package org.jboss.mx.remote.server;

import org.jboss.mx.util.JMXInvocationHandler;
import org.jboss.mx.util.MBeanProxyCreationException;

import javax.management.MBeanServer;
import javax.management.NotificationFilter;
import javax.management.NotificationListener;
import javax.management.ObjectName;
import java.lang.reflect.Method;

/**
* NotificationJMXInvocationHandler extends JMXInvocationHandler and takes into consideration
* <tt>addNotificationListener</tt> and <tt>removeNotificationListener</tt>.
*
* @author <a href="mailto:telrod@e2technologies.net">Tom Elrod</a>
* @author <a href="mailto:jhaynie@vocalocity.net">Jeff Haynie</a>
* @version $Revision: 1.1 $
*/
public class NotificationJMXInvocationHandler extends JMXInvocationHandler
{
    public NotificationJMXInvocationHandler(MBeanServer server, ObjectName name)
            throws MBeanProxyCreationException
    {
        super(server, name);
    }

    public Object invoke(Object proxy, Method method, Object[] args)
            throws Exception
    {
        String methodName = method.getName();

        if (methodName.equals("addNotificationListener") && args != null)
        {
            NotificationListener notiListener = (NotificationListener) args[0];
            NotificationFilter filter = (NotificationFilter) args[1];
            Object handback = args[2];

            // This will send along the real ObjectName and not the Proxy name.
            server.addNotificationListener(objectName, notiListener, filter, handback);
            return null;
        }
        else if (methodName.equals("removeNotificationListener") && args != null)
        {
            NotificationListener notiListener = (NotificationListener) args[0];

            // This will send along the real ObjectName and not the Proxy name.
            server.removeNotificationListener(objectName, notiListener);
            return null;
        }
        else
        {
            if (method.getDeclaringClass().getName().equals(Object.class.getName()))
            {
                String name = method.getName();
                if (name.equals("toString"))
                {
                    return toString();
                }
                else if (name.equals("hashCode"))
                {
                    return new Integer(hashCode());
                }
                else if (name.equals("equals"))
                {
                    return new Boolean(equals(args[0]));
                }
            }
            return super.invoke(proxy, method, args);
        }
    }
}
TOP

Related Classes of org.jboss.mx.remote.server.NotificationJMXInvocationHandler

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.