Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SEVERE: Could not dispatch event: Eventbus com.google.common.eventbus.SubscriberExceptionContext

Tags:

java

spring

guava

For EventBus, I merged the code inside my java Spring app and have full control of it but the result didn't change.

When I run The EventBus in spring sts (javaw), there is no issue but when I run in the server with java -jar project.jar it gives the same SEVERE: Could not dispatch event: error

The below didn't work for me..

package edu.uams.event;

import java.awt.EventQueue;
import java.lang.reflect.InvocationTargetException;
import java.util.concurrent.Executor;

import org.apache.log4j.Logger;

import com.google.common.eventbus.AsyncEventBus;
import com.google.common.eventbus.EventHandler;
import com.google.common.eventbus.SubscriberExceptionHandler;


import edu.uams.domain.TirEvent;
import edu.uams.pacs.IncomingFileMonitor;

public class AysncTraumaEventBus extends AsyncEventBus {

    private final static Logger logger = Logger.getLogger(AysncTraumaEventBus.class);
    private String name = null;

    public AysncTraumaEventBus(Executor executor,
            SubscriberExceptionHandler subscriberExceptionHandler) {
        super(executor, subscriberExceptionHandler);    

        logger.info("AysncTraumaEventBus created.");
    }

    public AysncTraumaEventBus(String name, Executor executor) {
        super(name,executor);
        this.name=name;
        logger.info("AysncTraumaEventBus created. Name:"+this.name);
    }

    @Override
    public void register(Object object) {
        super.register(object);
    }

    @Override
    public void unregister(Object object) {
        super.unregister(object);
    }   

    @Override
    public void dispatch(Object event, EventHandler wrapper) {
        try {
          logger.info("Let's dispatch Aysnchroneous Trauma Event:"+ ((TirEvent) event).getResultMessage());
          wrapper.handleEvent(event);
        } catch (InvocationTargetException e) {
          // My logger
          logger.error("Could not dispatch event: " + event + " to handler " + wrapper+"  e:"+e.getMessage());
          logger.info("Lets try to disptach again!");
          super.post(new ExceptionEvent(event, e));         
        }
      }


    public static final class ExceptionEvent {
        public final Object event;
        public final InvocationTargetException exception;

        public ExceptionEvent(final Object event, final InvocationTargetException exception) {
            this.event = event;
            this.exception = exception;
        }
    }

}

Somehow the EventHandler can't invoke the target event..

wrapper.handleEvent(event);

When you look the wrapper (EventHandler):

public void handleEvent(Object event) throws InvocationTargetException {
    checkNotNull(event);
    try {
      method.invoke(target, new Object[] { event });
    } catch (IllegalArgumentException e) {
      throw new Error("Method rejected target/argument: " + event, e);
    } catch (IllegalAccessException e) {
      throw new Error("Method became inaccessible: " + event, e);
    } catch (InvocationTargetException e) {
      if (e.getCause() instanceof Error) {
        throw (Error) e.getCause();
      }
      throw e;
    }
  }

You see that method.invoke(target, new Object[] { event }); throws the InvocationTargetException from the Method.class

public Object invoke(Object obj, Object... args)
        throws IllegalAccessException, IllegalArgumentException,
           InvocationTargetException
    {
        if (!override) {
            if (!Reflection.quickCheckMemberAccess(clazz, modifiers)) {
                Class<?> caller = Reflection.getCallerClass(1);

                checkAccess(caller, clazz, obj, modifiers);
            }
        }
        MethodAccessor ma = methodAccessor;             // read volatile
        if (ma == null) {
            ma = acquireMethodAccessor();
        }
        return ma.invoke(obj, args);
    }

Somehow it can't invoke.. But the most interesting part is that the same jar file along with EventBus can run fine in STS Run (javaw) but when I run java from commandline as java -jar project.jar it can't dispatch the event..

like image 545
mehmetsen80 Avatar asked Aug 18 '14 16:08

mehmetsen80


1 Answers

@Subscribe
@AllowConcurrentEvents
    public void receivedDicomFile(TirEvent event){                  

        try {



            } catch (ClassNotFoundException e) {
                logger.error(e.getMessage());
            } catch (SQLException e) {
                logger.error(e.getMessage());
            } catch(Exception e){
                logger.error(e.getMessage());
            }



    }

It always needs an try catch.. Thanks @dwnz for your help

like image 84
mehmetsen80 Avatar answered Oct 09 '22 15:10

mehmetsen80