replace guava eventbus with legman

This commit is contained in:
Sebastian Sdorra
2014-01-03 12:56:18 +01:00
parent 5e6259f3b7
commit 0c7d6fa62f
17 changed files with 114 additions and 454 deletions

View File

@@ -46,7 +46,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import sonia.scm.event.ScmEventBus;
import sonia.scm.event.Subscriber;
/**
*
@@ -85,34 +84,11 @@ public class ScmEventBusModule extends AbstractModule
logger.trace("register subscriber {}", clazz);
ScmEventBus.getInstance().register(object, isAsync(clazz));
ScmEventBus.getInstance().register(object);
}
});
}
});
}
//~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
* @param clazz
*
* @return
*/
private boolean isAsync(Class<?> clazz)
{
boolean async = true;
Subscriber subscriber = clazz.getAnnotation(Subscriber.class);
if (subscriber != null)
{
async = subscriber.async();
}
return async;
}
}

View File

@@ -35,8 +35,8 @@ package sonia.scm.api.rest.resources;
//~--- non-JDK imports --------------------------------------------------------
import com.github.legman.Subscribe;
import com.google.common.base.Function;
import com.google.common.eventbus.Subscribe;
import com.google.inject.Inject;
import com.google.inject.Singleton;

View File

@@ -30,58 +30,41 @@
*/
package sonia.scm.event;
//~--- non-JDK imports --------------------------------------------------------
import com.google.common.eventbus.AsyncEventBus;
import com.google.common.eventbus.EventBus;
import com.google.common.eventbus.ThrowingEventBus;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import org.apache.shiro.concurrent.SubjectAwareExecutorService;
import com.github.legman.EventBus;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
//~--- JDK imports ------------------------------------------------------------
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
/**
*
* @author Sebastian Sdorra
*/
public class GuavaScmEventBus extends ScmEventBus
public class LegmanScmEventBus extends ScmEventBus
{
/** Field description */
private static final String THREAD_NAME = "EventBus-%s";
private static final String NAME = "ScmEventBus";
/**
* the logger for GuavaScmEventBus
* the logger for LegmanScmEventBus
*/
private static final Logger logger =
LoggerFactory.getLogger(GuavaScmEventBus.class);
LoggerFactory.getLogger(LegmanScmEventBus.class);
//~--- constructors ---------------------------------------------------------
/**
* Constructs a new ScmEventBus
* Constructs ...
*
*/
public GuavaScmEventBus()
public LegmanScmEventBus()
{
eventBus = new ThrowingEventBus();
//J-
ThreadFactory factory = new ThreadFactoryBuilder()
.setNameFormat(THREAD_NAME).build();
asyncEventBus = new AsyncEventBus(
new SubjectAwareExecutorService(Executors.newCachedThreadPool(factory))
);
//J+
eventBus = new EventBus(NAME);
}
//~--- methods --------------------------------------------------------------
@@ -96,43 +79,21 @@ public class GuavaScmEventBus extends ScmEventBus
public void post(Object event)
{
logger.debug("post {} to event bus", event);
asyncEventBus.post(event);
eventBus.post(event);
}
/**
* {@inheritDoc}
*
*
* @param object
*/
@Override
public void register(Object object)
{
register(object, true);
}
/**
* Registers a object to the eventbus.
*
* @param object object to register
* @param async handle event asynchronously
*
* @see {@link #register(java.lang.Object)}
*/
@Override
public void register(Object object, boolean async)
public void register(Object object)
{
logger.debug("register {} to event bus, async = {}", object, async);
if (async)
{
asyncEventBus.register(object);
}
else
{
eventBus.register(object);
}
logger.debug("register {} to event bus", object);
eventBus.register(object);
}
/**
@@ -145,34 +106,19 @@ public class GuavaScmEventBus extends ScmEventBus
public void unregister(Object object)
{
logger.debug("unregister {} from event bus", object);
unregister(asyncEventBus, object);
unregister(eventBus, object);
}
/**
* Unregisters the object from eventbus.
*
*
* @param bus event bus
* @param object object to unregister
*/
private void unregister(EventBus bus, Object object)
{
try
{
bus.unregister(object);
eventBus.unregister(object);
}
catch (IllegalArgumentException ex)
{
logger.trace("object {} was not registered at {}", object, bus);
logger.trace("object {} was not registered", object);
}
}
//~--- fields ---------------------------------------------------------------
/** asynchronous event bus */
private AsyncEventBus asyncEventBus;
/** synchronous event bus */
private EventBus eventBus;
/** event bus */
private final EventBus eventBus;
}

View File

@@ -35,8 +35,8 @@ package sonia.scm.plugin;
//~--- non-JDK imports --------------------------------------------------------
import com.github.legman.Subscribe;
import com.google.common.collect.Sets;
import com.google.common.eventbus.Subscribe;
import com.google.common.io.Files;
import com.google.inject.Inject;
import com.google.inject.Provider;

View File

@@ -35,12 +35,12 @@ package sonia.scm.security;
//~--- non-JDK imports --------------------------------------------------------
import com.github.legman.Subscribe;
import com.google.common.base.Objects;
import com.google.common.base.Preconditions;
import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSet.Builder;
import com.google.common.eventbus.Subscribe;
import com.google.inject.Inject;
import com.google.inject.Singleton;

View File

@@ -30,14 +30,16 @@
*/
package sonia.scm.security;
//~--- non-JDK imports --------------------------------------------------------
import com.github.legman.Subscribe;
import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableList.Builder;
import com.google.common.eventbus.Subscribe;
import com.google.inject.Inject;
import com.google.inject.Singleton;
@@ -48,7 +50,6 @@ import org.slf4j.LoggerFactory;
import sonia.scm.HandlerEvent;
import sonia.scm.event.ScmEventBus;
import sonia.scm.event.Subscriber;
import sonia.scm.group.GroupEvent;
import sonia.scm.store.ConfigurationEntryStore;
import sonia.scm.store.ConfigurationEntryStoreFactory;
@@ -79,7 +80,6 @@ import javax.xml.bind.annotation.XmlRootElement;
* @since 1.31
*/
@Singleton
@Subscriber(async = true)
public class DefaultSecuritySystem implements SecuritySystem
{
@@ -445,7 +445,7 @@ public class DefaultSecuritySystem implements SecuritySystem
return classLoader;
}
//~--- inner classes --------------------------------------------------------
/**