re-introduce optimize dispatch for queues

git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@634588 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Davies 2008-03-07 09:02:37 +00:00
parent 4c481ec6a9
commit 3f9d6e2ef8
3 changed files with 37 additions and 20 deletions

View File

@ -78,6 +78,7 @@ import org.apache.commons.logging.LogFactory;
*/ */
public class Queue extends BaseDestination implements Task { public class Queue extends BaseDestination implements Task {
protected final Log log; protected final Log log;
protected TaskRunnerFactory taskFactory;
protected TaskRunner taskRunner; protected TaskRunner taskRunner;
protected final List<Subscription> consumers = new ArrayList<Subscription>(50); protected final List<Subscription> consumers = new ArrayList<Subscription>(50);
protected PendingMessageCursor messages; protected PendingMessageCursor messages;
@ -93,6 +94,7 @@ public class Queue extends BaseDestination implements Task {
private boolean useConsumerPriority=true; private boolean useConsumerPriority=true;
private boolean strictOrderDispatch=false; private boolean strictOrderDispatch=false;
private QueueDispatchSelector dispatchSelector; private QueueDispatchSelector dispatchSelector;
private boolean optimizedDispatch=false;
private final Runnable sendMessagesWaitingForSpaceTask = new Runnable() { private final Runnable sendMessagesWaitingForSpaceTask = new Runnable() {
public void run() { public void run() {
wakeup(); wakeup();
@ -109,11 +111,9 @@ public class Queue extends BaseDestination implements Task {
public Queue(BrokerService brokerService, final ActiveMQDestination destination, MessageStore store,DestinationStatistics parentStats, public Queue(BrokerService brokerService, final ActiveMQDestination destination, MessageStore store,DestinationStatistics parentStats,
TaskRunnerFactory taskFactory) throws Exception { TaskRunnerFactory taskFactory) throws Exception {
super(brokerService, store, destination, parentStats); super(brokerService, store, destination, parentStats);
this.taskFactory=taskFactory;
this.log = LogFactory.getLog(getClass().getName() + "." + destination.getPhysicalName()); this.log = LogFactory.getLog(getClass().getName() + "." + destination.getPhysicalName());
this.dispatchSelector=new QueueDispatchSelector(destination); this.dispatchSelector=new QueueDispatchSelector(destination);
} }
public void initialize() throws Exception { public void initialize() throws Exception {
@ -133,7 +133,9 @@ public class Queue extends BaseDestination implements Task {
memoryUsage.setParent(systemUsage.getMemoryUsage()); memoryUsage.setParent(systemUsage.getMemoryUsage());
} }
if (isOptimizedDispatch()) {
this.taskRunner = taskFactory.createTaskRunner(this, "TempQueue: " + destination.getPhysicalName());
}else {
this.executor = Executors.newSingleThreadExecutor(new ThreadFactory() { this.executor = Executors.newSingleThreadExecutor(new ThreadFactory() {
public Thread newThread(Runnable runnable) { public Thread newThread(Runnable runnable) {
Thread thread = new Thread(runnable, "QueueThread:"+destination); Thread thread = new Thread(runnable, "QueueThread:"+destination);
@ -144,6 +146,7 @@ public class Queue extends BaseDestination implements Task {
}); });
this.taskRunner = new DeterministicTaskRunner(this.executor,this); this.taskRunner = new DeterministicTaskRunner(this.executor,this);
}
super.initialize(); super.initialize();
if (store != null) { if (store != null) {
// Restore the persistent messages. // Restore the persistent messages.
@ -584,6 +587,15 @@ public class Queue extends BaseDestination implements Task {
this.strictOrderDispatch = strictOrderDispatch; this.strictOrderDispatch = strictOrderDispatch;
} }
public boolean isOptimizedDispatch() {
return optimizedDispatch;
}
public void setOptimizedDispatch(boolean optimizedDispatch) {
this.optimizedDispatch = optimizedDispatch;
}
// Implementation methods // Implementation methods
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
private QueueMessageReference createMessageReference(Message message) { private QueueMessageReference createMessageReference(Message message) {
@ -956,12 +968,16 @@ public class Queue extends BaseDestination implements Task {
} }
protected void wakeup() { protected void wakeup() {
if (optimizedDispatch) {
iterate();
}else {
try { try {
taskRunner.wakeup(); taskRunner.wakeup();
} catch (InterruptedException e) { } catch (InterruptedException e) {
log.warn("Task Runner failed to wakeup ", e); log.warn("Task Runner failed to wakeup ", e);
} }
} }
}
private List<QueueMessageReference> doPageIn(boolean force) throws Exception { private List<QueueMessageReference> doPageIn(boolean force) throws Exception {
List<QueueMessageReference> result = null; List<QueueMessageReference> result = null;
@ -1075,4 +1091,5 @@ public class Queue extends BaseDestination implements Task {
private void removeFromConsumerList(Subscription sub) { private void removeFromConsumerList(Subscription sub) {
consumers.remove(sub); consumers.remove(sub);
} }
} }

View File

@ -32,7 +32,7 @@ import org.apache.activemq.thread.TaskRunnerFactory;
*/ */
public class TempQueue extends Queue{ public class TempQueue extends Queue{
private final ActiveMQTempDestination tempDest; private final ActiveMQTempDestination tempDest;
private TaskRunnerFactory taskFactory;
/** /**
* @param brokerService * @param brokerService
@ -48,7 +48,6 @@ public class TempQueue extends Queue{
throws Exception { throws Exception {
super(brokerService, destination, store, parentStats, taskFactory); super(brokerService, destination, store, parentStats, taskFactory);
this.tempDest = (ActiveMQTempDestination) destination; this.tempDest = (ActiveMQTempDestination) destination;
this.taskFactory=taskFactory;
} }
public void initialize() throws Exception { public void initialize() throws Exception {

View File

@ -86,6 +86,7 @@ public class PolicyEntry extends DestinationMapEntry {
queue.setMinimumMessageSize((int) getMinimumMessageSize()); queue.setMinimumMessageSize((int) getMinimumMessageSize());
queue.setUseConsumerPriority(isUseConsumerPriority()); queue.setUseConsumerPriority(isUseConsumerPriority());
queue.setStrictOrderDispatch(isStrictOrderDispatch()); queue.setStrictOrderDispatch(isStrictOrderDispatch());
queue.setOptimizedDispatch(isOptimizedDispatch());
} }
public void configure(Topic topic) { public void configure(Topic topic) {