Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

REVIEW: Stop forking Guava event bus #21

Merged
merged 1 commit into from
Feb 25, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@
* See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
*/

package org.sonatype.sisu.goodies.eventbus.internal;
package com.google.common.eventbus;

import javax.inject.Named;
import javax.inject.Singleton;

import org.sonatype.sisu.goodies.eventbus.internal.guava.EventBus;
import org.sonatype.sisu.goodies.eventbus.internal.guava.EventHandler;
import org.sonatype.sisu.goodies.eventbus.internal.DefaultEventBus;

/**
* @since 1.5
Expand All @@ -29,7 +28,7 @@ public class DefaultGuavaEventBus
{

@Override
protected void dispatch(final Object event, final EventHandler wrapper) {
public void dispatch(final Object event, final EventSubscriber wrapper) {
DefaultEventBus.LOG.trace(DefaultEventBus.DISPATCHING, "Dispatching '{}' to {}", event, wrapper);
super.dispatch(event, wrapper);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,14 @@
* See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
*/

package org.sonatype.sisu.goodies.eventbus.internal;
package com.google.common.eventbus;

import java.util.List;
import java.util.LinkedList;
import java.util.Queue;

import javax.inject.Named;
import javax.inject.Singleton;

import org.sonatype.sisu.goodies.eventbus.internal.guava.EventBus;
import org.sonatype.sisu.goodies.eventbus.internal.guava.EventHandler;

import com.google.common.collect.Lists;

/**
* A Guava {@link EventBus} that differs from default one by dispatching events as they appear (is re-entrant).
* Guava will queue up all event and dispatch them in the order they were posted, without re-entrance.
Expand All @@ -36,26 +32,29 @@ public class ReentrantGuavaEventBus
{

/**
* List of events for the current thread to dispatch
* Queues of events for the current thread to dispatch.
*/
private final ThreadLocal<List<EventWithHandler>> eventsToDispatch = new ThreadLocal<List<EventWithHandler>>();
private final ThreadLocal<Queue<EventWithSubscriber>> eventsToDispatch =
new ThreadLocal<Queue<EventWithSubscriber>>()
{
@Override
protected Queue<EventWithSubscriber> initialValue() {
return new LinkedList<EventWithSubscriber>();
}
};

@Override
protected void enqueueEvent(final Object event, final EventHandler handler) {
if (eventsToDispatch.get() == null) {
eventsToDispatch.set(Lists.<EventWithHandler>newArrayList());
}
eventsToDispatch.get().add(new EventWithHandler(event, handler));
void enqueueEvent(Object event, EventSubscriber subscriber) {
eventsToDispatch.get().offer(new EventWithSubscriber(event, subscriber));
}

@Override
protected void dispatchQueuedEvents() {
final List<EventWithHandler> eventWithHandlers = eventsToDispatch.get();
if (eventWithHandlers != null) {
eventsToDispatch.remove();
for (final EventWithHandler eventWithHandler : eventWithHandlers) {
dispatch(eventWithHandler.event, eventWithHandler.handler);
}
void dispatchQueuedEvents() {
Queue<EventWithSubscriber> events = eventsToDispatch.get();
eventsToDispatch.remove();
EventWithSubscriber eventWithSubscriber;
while ((eventWithSubscriber = events.poll()) != null) {
dispatch(eventWithSubscriber.event, eventWithSubscriber.subscriber);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,16 @@ public class DefaultEventBus
implements EventBus
{

static final Logger LOG = LoggerFactory.getLogger(DefaultEventBus.class);
public static final Logger LOG = LoggerFactory.getLogger(DefaultEventBus.class);

private static final Marker REGISTRATION = MarkerFactory.getMarker("registration");

private static final Marker EVENTS = MarkerFactory.getMarker("events");
public static final Marker DISPATCHING = MarkerFactory.getMarker("dispatching");

static final Marker DISPATCHING = MarkerFactory.getMarker("dispatching");

private final org.sonatype.sisu.goodies.eventbus.internal.guava.EventBus eventBus;
private final com.google.common.eventbus.EventBus eventBus;

@Inject
public DefaultEventBus(final @Named("${guava.eventBus:-reentrant}")
org.sonatype.sisu.goodies.eventbus.internal.guava.EventBus eventBus)
{
public DefaultEventBus(final @Named("${guava.eventBus:-reentrant}") com.google.common.eventbus.EventBus eventBus) {
this.eventBus = checkNotNull(eventBus);
LOG.info("Using {}", eventBus);
}
Expand Down

This file was deleted.

This file was deleted.

Loading