View Javadoc

1   /*******************************************************************************
2    * Copyright (c) 2007, 2014 Massimiliano Ziccardi
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   *******************************************************************************/
16  package it.jnrpe;
17  
18  import it.jnrpe.events.IJNRPEEventListener;
19  
20  import java.util.Collection;
21  
22  /**
23   * A simple utility class that helps in sending events.
24   * 
25   * @author Massimiliano Ziccardi
26   */
27  final class EventsUtil {
28  	/**
29  	 * Default private constructor to avoid instantiations.
30  	 */
31  	private EventsUtil() {
32  	}
33  
34  	/**
35  	 * Sends the given event to the given list of listeners.
36  	 * 
37  	 * @param vListeners
38  	 *            The list of listeners
39  	 * @param sender
40  	 *            The sender
41  	 * @param sEventName
42  	 *            The name of the event
43  	 * @param vParams
44  	 *            The event parameters
45  	 */
46  	public static void sendEvent(
47  			final Collection<IJNRPEEventListener> vListeners,
48  			final Object sender, final String sEventName, final Object[] vParams) {
49  		if (vListeners == null || vListeners.isEmpty()) {
50  			return;
51  		}
52  
53  		SimpleEvent se = new SimpleEvent(sEventName, vParams);
54  
55  		for (IJNRPEEventListener listener : vListeners) {
56  			listener.receive(sender, se);
57  		}
58  	}
59  }