Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/bennidi/mbassador
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamin committed Sep 10, 2013
2 parents 69e6d57 + bc267cd commit 078e374
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 5 deletions.
50 changes: 47 additions & 3 deletions src/main/java/net/engio/mbassy/bus/config/BusConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,57 @@ public Thread newThread(Runnable r) {
}
};

/**
* Creates a new instance, using the Default settings of 2 dispatchers, and
* asynchronous handlers with an initial count equal to the number of
* available processors in the machine, with maximum count equal to
* 2 * the number of available processors. Uses {@link Runtime#availableProcessors()} to
* determine the number of available processors
*
* @return a Default BusConfiguration
*/
public static BusConfiguration Default() {
BusConfiguration defaultConfig = new BusConfiguration();
return Default(2);
}

/**
* Creates a new instance, using the specified number of dispatchers, and
* asynchronous handlers with an initial count equal to the number of
* available processors in the machine, with maximum count equal to
* 2 * the number of available processors. Uses {@link Runtime#availableProcessors()} to
* determine the number of available processors
*
* @return a Default BusConfiguration
*/
public static BusConfiguration Default(int numberOfDispatchers) {
int numberOfCoreThreads = Runtime.getRuntime().availableProcessors();
defaultConfig.setExecutorForAsynchronousHandlers(new ThreadPoolExecutor(numberOfCoreThreads, numberOfCoreThreads*2, 1, TimeUnit.MINUTES, new LinkedBlockingQueue<Runnable>(), AsynchronousHandlerThreadFactory));
return Default(numberOfDispatchers, numberOfCoreThreads, numberOfCoreThreads * 2);
}

/**
* Creates a new instance, using the specified number of dispatchers, and
* asynchronous handlers with initial threads and maximum threads specified by the calling
* parameters.
*
* @return a Default BusConfiguration
*/
public static BusConfiguration Default(int numberOfDispatchers, int initialCoreThreads, int maximumCoreThreads) {
ThreadPoolExecutor executor = new ThreadPoolExecutor(initialCoreThreads, maximumCoreThreads, 1, TimeUnit.MINUTES, new LinkedBlockingQueue<Runnable>(), AsynchronousHandlerThreadFactory);
return Default(numberOfDispatchers, executor);
}

/**
* Creates a new instance, using the specified number of dispatchers, and
* asynchronous handlers that use the provided ThreadPoolExecutor.
*
* @return a Default BusConfiguration
*/
public static BusConfiguration Default(int numberOfDispatchers, ThreadPoolExecutor executor) {
BusConfiguration defaultConfig = new BusConfiguration();
defaultConfig.setExecutorForAsynchronousHandlers(executor);
defaultConfig.setMetadataReader(new MetadataReader());
defaultConfig.setSubscriptionFactory(new SubscriptionFactory());
defaultConfig.setNumberOfMessageDispatchers(2);
defaultConfig.setNumberOfMessageDispatchers(numberOfDispatchers);
defaultConfig.setMessagePublicationFactory(new MessagePublication.Factory());
defaultConfig.setPendingMessagesQueue(new LinkedBlockingQueue<MessagePublication>(Integer.MAX_VALUE));
defaultConfig.setThreadFactoryForAsynchronousMessageDispatch(DispatcherThreadFactory);
Expand Down
9 changes: 7 additions & 2 deletions src/test/java/net/engio/mbassy/common/MessageManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

import java.util.Collection;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Created with IntelliJ IDEA.
* User: benjamin
Expand All @@ -12,6 +15,8 @@
* To change this template use File | Settings | File Templates.
*/
public class MessageManager {
private static final Logger LOG =
LoggerFactory.getLogger(MessageManager.class);


private StrongConcurrentSet<MessageContext> messages = new StrongConcurrentSet();
Expand Down Expand Up @@ -90,7 +95,7 @@ private void pause(long ms) {
}

private void logSuccess(MessageContext mCtx){
System.out.println("Message " + mCtx.getMessage() + " was successfully handled " + mCtx.getExpectedCount() + " times by " + mCtx.printListeners());
LOG.info("Message " + mCtx.getMessage() + " was successfully handled " + mCtx.getExpectedCount() + " times by " + mCtx.printListeners());
}


Expand All @@ -100,7 +105,7 @@ private void logFailingMessages(StrongConcurrentSet<MessageContext> failing){
errorMessage.append("Failing messages:\n");
for(MessageContext failingMessage : failing)
errorMessage.append(failingMessage);
System.out.println(errorMessage.toString());
LOG.info(errorMessage.toString());
}

private class MessageContext{
Expand Down

0 comments on commit 078e374

Please sign in to comment.