| career | drupal | java | mac | mysql | perl | scala | uml | unix  

Groovy example source code file (JmxListenerFactory.groovy)

This example Groovy source code file (JmxListenerFactory.groovy) is included in the "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Groovy tags/keywords

abstractfactory, instancenotfoundexception, jmxbuilder, jmxbuilder, jmxbuilderexception, jmxbuilderexception, jmxlistenerfactory, management, map, map, node, notificationfiltersupport, object, object, string

The Groovy JmxListenerFactory.groovy source code

 * 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
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * See the License for the specific language governing permissions and
 * limitations under the License.

package groovy.jmx.builder


 * This factory class is used to create an listener() node for JmxBuilder.  Listener nodes are used
 * to create a generic event listener (that is automatically registered with the MBean) that can handle
 * any event broadcasted on the MBeanServer's event bus.
 * <p> Syntax supported 

* * <pre> * JmxBuilder.listener(event:"event type", from:"Object Name"|ObjectName(), call:{event-> * // event handling code here. *}) * </pre> * * @author Vladimir Vivien * @see groovy.jmx.builder.JmxEventListener */ class JmxListenerFactory extends AbstractFactory { public Object newInstance(FactoryBuilderSupport builder, Object nodeName, Object nodeParam, Map nodeAttribs) { if (nodeParam) { throw new JmxBuilderException("Node '${nodeName}' only supports named attributes.") } JmxBuilder fsb = (JmxBuilder) builder def server = fsb.getMBeanServer() def map = JmxMetaMapBuilder.createListenerMap(nodeAttribs); def broadcaster = map.get("from"); try { def eventType = (String) map.get("event"); if (!server.isRegistered(broadcaster)) { throw new JmxBuilderException("MBean '${broadcaster.toString()}' is not registered in server.") } if (eventType) { NotificationFilterSupport filter = new NotificationFilterSupport(); filter.enableType(eventType); server.addNotificationListener(broadcaster, JmxEventListener.getListener(), filter, map); } else { server.addNotificationListener(broadcaster, JmxEventListener.getListener(), null, map); } } catch (InstanceNotFoundException e) { throw new JmxBuilderException(e); } map } public boolean onHandleNodeAttributes(FactoryBuilderSupport builder, Object node, Map nodeAttribs) { return false; } public boolean isLeaf() { return true; } public void onNodeCompleted(FactoryBuilderSupport builder, Object parentNode, Object thisNode) { if (parentNode != null) { parentNode.add(thisNode) } } }

Other Groovy examples (source code examples)

Here is a short list of links related to this Groovy JmxListenerFactory.groovy source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller


new blog posts


Copyright 1998-2021 Alvin Alexander,
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.