Fix Deadlock in EventBus post #1493
This commit is contained in:
parent
6c4e684de9
commit
918d7229c2
@ -34,33 +34,35 @@ public class EventBus
|
|||||||
|
|
||||||
public void post(Object event)
|
public void post(Object event)
|
||||||
{
|
{
|
||||||
|
EventHandlerMethod[] handlers;
|
||||||
lock.readLock().lock();
|
lock.readLock().lock();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
EventHandlerMethod[] handlers = byEventBaked.get( event.getClass() );
|
handlers = byEventBaked.get( event.getClass() );
|
||||||
if ( handlers != null )
|
|
||||||
{
|
|
||||||
for ( EventHandlerMethod method : handlers )
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
method.invoke( event );
|
|
||||||
} catch ( IllegalAccessException ex )
|
|
||||||
{
|
|
||||||
throw new Error( "Method became inaccessible: " + event, ex );
|
|
||||||
} catch ( IllegalArgumentException ex )
|
|
||||||
{
|
|
||||||
throw new Error( "Method rejected target/argument: " + event, ex );
|
|
||||||
} catch ( InvocationTargetException ex )
|
|
||||||
{
|
|
||||||
logger.log( Level.WARNING, MessageFormat.format( "Error dispatching event {0} to listener {1}", event, method.getListener() ), ex.getCause() );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} finally
|
} finally
|
||||||
{
|
{
|
||||||
lock.readLock().unlock();
|
lock.readLock().unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( handlers != null )
|
||||||
|
{
|
||||||
|
for ( EventHandlerMethod method : handlers )
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
method.invoke( event );
|
||||||
|
} catch ( IllegalAccessException ex )
|
||||||
|
{
|
||||||
|
throw new Error( "Method became inaccessible: " + event, ex );
|
||||||
|
} catch ( IllegalArgumentException ex )
|
||||||
|
{
|
||||||
|
throw new Error( "Method rejected target/argument: " + event, ex );
|
||||||
|
} catch ( InvocationTargetException ex )
|
||||||
|
{
|
||||||
|
logger.log( Level.WARNING, MessageFormat.format( "Error dispatching event {0} to listener {1}", event, method.getListener() ), ex.getCause() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<Class<?>, Map<Byte, Set<Method>>> findHandlers(Object listener)
|
private Map<Class<?>, Map<Byte, Set<Method>>> findHandlers(Object listener)
|
||||||
|
Loading…
Reference in New Issue
Block a user