Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
   * Copyright (C) 2007 The Guava 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,
  * 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 org.sonatype.sisu.goodies.eventbus.internal.guava;
Wraps a single-argument 'handler' method on a specific object.

This class only verifies the suitability of the method and event type if something fails. Callers are expected to verify their uses of this class.

Two EventHandlers are equivalent when they refer to the same method on the same object (not class). This property is used to ensure that no handler method is registered more than once.

Cliff Biffle
 public class EventHandler {

Object sporting the handler method.
   private final Object target;
Handler method.
   private final Method method;

Creates a new EventHandler to wrap method on

target object to which the method applies.
method handler method.
code target}.
   EventHandler(Object targetMethod method) {
         "EventHandler target cannot be null.");
     Preconditions.checkNotNull(method"EventHandler method cannot be null.");
     this. = target;
     this. = method;

Invokes the wrapped handler method to handle event.

event event to handle
java.lang.reflect.InvocationTargetException if the wrapped method throws any java.lang.Throwable that is not an java.lang.Error (Errors are propagated as-is).
   public void handleEvent(Object eventthrows InvocationTargetException {
     try {
       .invoke(new Object[] { event });
     } catch (IllegalArgumentException e) {
       throw new Error("Method rejected target/argument: " + evente);
     } catch (IllegalAccessException e) {
       throw new Error("Method became inaccessible: " + evente);
     } catch (InvocationTargetException e) {
       if (e.getCause() instanceof Error) {
         throw (Errore.getCause();
       throw e;
   @Override public String toString() {
     return "[wrapper " +  + "]";
   @Override public int hashCode() {
     final int PRIME = 31;
     return (PRIME + .hashCode()) * PRIME + .hashCode();
   @Override public boolean equals(Object obj) {
     if(this == obj) {
       return true;
     if(obj == null) {
       return false;
     if(getClass() != obj.getClass()) {
      return false;
    final EventHandler other = (EventHandlerobj;
    return .equals(other.method) &&  ==;
New to GrepCode? Check out our FAQ X