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 JmxEventEmitter is a JMX Broadcaster class that is used to send generic events on the MBeanServer's event bus. It is used by the Emitter node () to send event to registered listeners.
     def jmx = JmxBuilder()
     jmx.emitter(name:"Object name"|ObjectName(), event:"event type")
     ...
     jmx.emitter.send(object)
 

Author(s):
Vladimir Vivien
See also:
JmxEmitterFactory
 
 public class JmxEventEmitter extends NotificationBroadcasterSupport implements JmxEventEmitterMBean {
     private String event;
     private String message;

    
Event type getter

Returns:
- returns event type string thrown by this emitter
 
     public String getEvent() {
         return ;
     }

    
Event type setter

Parameters:
event - event type set for this emitter.
 
     public void setEvent(String event) {
         this. = event;
     }

    
Event message getter

Returns:
- message that is associated with event.
 
     public String getMessage() {
         return ;
     }

    
Event message setter.

Parameters:
message - message that is associated with event emitted.
 
     public void setMessage(String message) {
         this. = message;
     }

    
Called to broadcast message on MBeanServer event bus. Internally, it calls NotificationBroadCasterSupport.sendNotification() method to dispatch the event.

Parameters:
data - a data object sent as part of the event parameter.
Returns:
a sequence number associated with the emitted event.
 
     public long send(Object data) {
         long seq = NumberSequencer.getNextSequence();
         Notification note = new Notification(
                 this.getEvent(),
                 this,
                 seq,
                 System.currentTimeMillis(),
                 "Event notification " + this.getEvent()
         );
         note.setUserData(data);
         super.sendNotification(note);
         return seq;
     }
 
     private static class NumberSequencer {
         private static AtomicLong num;
 
         static {
              = new AtomicLong(0);
         }
 
        public static long getNextSequence() {
            return .incrementAndGet();
        }
    }
New to GrepCode? Check out our FAQ X