Java – severe: unable to schedule event: eventbus com google. common. eventbus. SubscriberExceptionContext

For eventbus, I merged the code in my java spring application and took full control of it, but the result did not change

When I run eventbus in spring STS (javaw), there is no problem, but when I use Java - jar project When jar runs in the server, it gives the same sever: unable to dispatch event: error

There is no work for me below

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, EventHandler failed to call the target event

wrapper. Handleevent (event);

When you look at the package (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}); From method Invocationtargetexception thrown in 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 call But the most interesting part is that the same jar file and eventbus can run well in STS run (javaw), but when I run Java from the command line as Java - jar project Jar, it cannot schedule events

Solution

@Subscribe
@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 a try catch Thanks @dwnz for your help

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>