Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 /*
  * Copyright 2008 the original author or authors.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
  *     http://www.apache.org/licenses/LICENSE-2.0
  *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package groovy.jmx.builder;
The JmxEventListner class is used by the builder to listen to events on the event bus. It is used internally by JmxBuilder to handle attribute-change and operation-invoke events on the bean() node.

Author(s):
Vladimir Vivien
See also:
JmxBeanFactory
public class JmxEventListener implements NotificationListener {
    private static JmxEventListener listener;

    
Factory method that returns an instance of the listener.

Returns:
- JmxEventListener instance.
    public static synchronized JmxEventListener getListner() {
        if ( == null) {
             = new JmxEventListener();
        }
        return ;
    }

    
This is the mplemented method for NotificationListener. It is called by an event emitter to dispatch JMX events to listeners. Here it handles internal JmxBuilder events.

Parameters:
notification the notification object passed to closure used to handle JmxBuilder events.
handback - In this case, the handback is the closure to execute when the event is handled.
    public void handleNotification(Notification notificationObject handback) {
        Map event = (Maphandback;
        if (event != null) {
            Object del = event.get("managedObject");
            Object callback = event.get("callback");
            if (callback != null && callback instanceof Closure) {
                Closure closure = (Closurecallback;
                closure.setDelegate(del);
                if (closure.getMaximumNumberOfParameters() == 1)
                    closure.call(buildOperationNotificationPacket(notification));
                else closure.call();
            }
        }
    }
    private static Map buildOperationNotificationPacket(Notification note) {
        Map<StringObjectresult = new HashMap<StringObject>();
        result.put("event"note.getType());
        result.put("source"note.getSource());
        result.put("sequenceNumber"note.getSequenceNumber());
        result.put("timeStamp"note.getTimeStamp());
        result.put("data"note.getUserData());
        return result;
    }
New to GrepCode? Check out our FAQ X