mirror of https://github.com/apache/activemq.git
use async dispatch for vm:// transport by default
git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@515999 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
a08a4a84c7
commit
da13d596a5
|
@ -58,9 +58,10 @@ class DedicatedTaskRunner implements TaskRunner {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* shut down the task
|
* shut down the task
|
||||||
|
* @param timeout
|
||||||
* @throws InterruptedException
|
* @throws InterruptedException
|
||||||
*/
|
*/
|
||||||
public void shutdown() throws InterruptedException{
|
public void shutdown(long timeout) throws InterruptedException{
|
||||||
synchronized(mutex){
|
synchronized(mutex){
|
||||||
shutdown=true;
|
shutdown=true;
|
||||||
pending=true;
|
pending=true;
|
||||||
|
@ -68,11 +69,19 @@ class DedicatedTaskRunner implements TaskRunner {
|
||||||
|
|
||||||
// Wait till the thread stops.
|
// Wait till the thread stops.
|
||||||
if(!threadTerminated){
|
if(!threadTerminated){
|
||||||
mutex.wait();
|
mutex.wait(timeout);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* shut down the task
|
||||||
|
* @throws InterruptedException
|
||||||
|
*/
|
||||||
|
public void shutdown() throws InterruptedException{
|
||||||
|
shutdown(0);
|
||||||
|
}
|
||||||
|
|
||||||
private void runTask() {
|
private void runTask() {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -77,7 +77,7 @@ class PooledTaskRunner implements TaskRunner {
|
||||||
* shut down the task
|
* shut down the task
|
||||||
* @throws InterruptedException
|
* @throws InterruptedException
|
||||||
*/
|
*/
|
||||||
public void shutdown() throws InterruptedException{
|
public void shutdown(long timeout) throws InterruptedException{
|
||||||
synchronized(runable){
|
synchronized(runable){
|
||||||
shutdown=true;
|
shutdown=true;
|
||||||
//the check on the thread is done
|
//the check on the thread is done
|
||||||
|
@ -85,13 +85,17 @@ class PooledTaskRunner implements TaskRunner {
|
||||||
//shutDown() being called, which would wait forever
|
//shutDown() being called, which would wait forever
|
||||||
//waiting for iterating to finish
|
//waiting for iterating to finish
|
||||||
if(runningThread!=Thread.currentThread()){
|
if(runningThread!=Thread.currentThread()){
|
||||||
while(iterating==true){
|
if(iterating==true){
|
||||||
runable.wait();
|
runable.wait(timeout);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void shutdown() throws InterruptedException {
|
||||||
|
shutdown(0);
|
||||||
|
}
|
||||||
private void runTask() {
|
private void runTask() {
|
||||||
|
|
||||||
synchronized (runable) {
|
synchronized (runable) {
|
||||||
|
|
|
@ -25,4 +25,5 @@ package org.apache.activemq.thread;
|
||||||
public interface TaskRunner {
|
public interface TaskRunner {
|
||||||
public abstract void wakeup() throws InterruptedException;
|
public abstract void wakeup() throws InterruptedException;
|
||||||
public abstract void shutdown() throws InterruptedException;
|
public abstract void shutdown() throws InterruptedException;
|
||||||
|
public abstract void shutdown(long timeout) throws InterruptedException;
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@ import java.util.Iterator;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.LinkedBlockingQueue;
|
import java.util.concurrent.LinkedBlockingQueue;
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
import java.util.concurrent.atomic.AtomicLong;
|
import java.util.concurrent.atomic.AtomicLong;
|
||||||
import org.apache.activemq.command.Command;
|
import org.apache.activemq.command.Command;
|
||||||
import org.apache.activemq.thread.Task;
|
import org.apache.activemq.thread.Task;
|
||||||
|
@ -50,27 +51,32 @@ public class VMTransport implements Transport,Task{
|
||||||
protected boolean disposed;
|
protected boolean disposed;
|
||||||
protected boolean marshal;
|
protected boolean marshal;
|
||||||
protected boolean network;
|
protected boolean network;
|
||||||
protected boolean async=false;
|
protected boolean async=true;
|
||||||
protected boolean started=false;
|
protected AtomicBoolean started=new AtomicBoolean();
|
||||||
protected int asyncQueueDepth=2000;
|
protected int asyncQueueDepth=2000;
|
||||||
protected List prePeerSetQueue=Collections.synchronizedList(new LinkedList());
|
protected List prePeerSetQueue=Collections.synchronizedList(new LinkedList());
|
||||||
protected LinkedBlockingQueue messageQueue=null;
|
protected LinkedBlockingQueue messageQueue=null;
|
||||||
protected final URI location;
|
protected final URI location;
|
||||||
protected final long id;
|
protected final long id;
|
||||||
private TaskRunner taskRunner;
|
private TaskRunner taskRunner;
|
||||||
|
private final Object mutex=new Object();
|
||||||
|
|
||||||
public VMTransport(URI location){
|
public VMTransport(URI location){
|
||||||
this.location=location;
|
this.location=location;
|
||||||
this.id=nextId.getAndIncrement();
|
this.id=nextId.getAndIncrement();
|
||||||
}
|
}
|
||||||
|
|
||||||
synchronized public VMTransport getPeer(){
|
public VMTransport getPeer(){
|
||||||
|
synchronized(mutex){
|
||||||
return peer;
|
return peer;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
synchronized public void setPeer(VMTransport peer){
|
public void setPeer(VMTransport peer){
|
||||||
|
synchronized(mutex){
|
||||||
this.peer=peer;
|
this.peer=peer;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void oneway(Object command) throws IOException{
|
public void oneway(Object command) throws IOException{
|
||||||
if(disposed){
|
if(disposed){
|
||||||
|
@ -99,11 +105,13 @@ public class VMTransport implements Transport,Task{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected synchronized void asyncOneWay(Object command) throws IOException{
|
protected void asyncOneWay(Object command) throws IOException{
|
||||||
try{
|
try{
|
||||||
|
synchronized(mutex){
|
||||||
if(messageQueue==null){
|
if(messageQueue==null){
|
||||||
messageQueue=new LinkedBlockingQueue(this.asyncQueueDepth);
|
messageQueue=new LinkedBlockingQueue(this.asyncQueueDepth);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
messageQueue.put(command);
|
messageQueue.put(command);
|
||||||
wakeup();
|
wakeup();
|
||||||
}catch(final InterruptedException e){
|
}catch(final InterruptedException e){
|
||||||
|
@ -124,18 +132,22 @@ public class VMTransport implements Transport,Task{
|
||||||
throw new AssertionError("Unsupported Method");
|
throw new AssertionError("Unsupported Method");
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized TransportListener getTransportListener(){
|
public TransportListener getTransportListener(){
|
||||||
|
synchronized(mutex){
|
||||||
return transportListener;
|
return transportListener;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
synchronized public void setTransportListener(TransportListener commandListener){
|
public void setTransportListener(TransportListener commandListener){
|
||||||
|
synchronized(mutex){
|
||||||
this.transportListener=commandListener;
|
this.transportListener=commandListener;
|
||||||
|
}
|
||||||
wakeup();
|
wakeup();
|
||||||
peer.wakeup();
|
peer.wakeup();
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void start() throws Exception{
|
public void start() throws Exception{
|
||||||
started=true;
|
if(started.compareAndSet(false,true)){
|
||||||
if(transportListener==null)
|
if(transportListener==null)
|
||||||
throw new IOException("TransportListener not set.");
|
throw new IOException("TransportListener not set.");
|
||||||
if(!async){
|
if(!async){
|
||||||
|
@ -149,17 +161,19 @@ public class VMTransport implements Transport,Task{
|
||||||
wakeup();
|
wakeup();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public synchronized void stop() throws Exception{
|
public void stop() throws Exception{
|
||||||
started=false;
|
if(started.compareAndSet(true,false)){
|
||||||
if(!disposed){
|
if(!disposed){
|
||||||
disposed=true;
|
disposed=true;
|
||||||
}
|
}
|
||||||
if(taskRunner!=null){
|
if(taskRunner!=null){
|
||||||
taskRunner.shutdown();
|
taskRunner.shutdown(1000);
|
||||||
taskRunner=null;
|
taskRunner=null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public Object narrow(Class target){
|
public Object narrow(Class target){
|
||||||
if(target.isAssignableFrom(getClass())){
|
if(target.isAssignableFrom(getClass())){
|
||||||
|
@ -201,16 +215,16 @@ public class VMTransport implements Transport,Task{
|
||||||
public boolean iterate(){
|
public boolean iterate(){
|
||||||
final TransportListener tl=peer.transportListener;
|
final TransportListener tl=peer.transportListener;
|
||||||
Command command=null;
|
Command command=null;
|
||||||
// if(!disposed && !messageQueue.isEmpty()&&!peer.disposed&&tl!=null){
|
synchronized(mutex){
|
||||||
synchronized(this){
|
if(messageQueue!=null&&!disposed&&!peer.disposed&&tl!=null&&!messageQueue.isEmpty()){
|
||||||
if(messageQueue!=null&&!disposed&&!peer.disposed&&tl!=null &&!messageQueue.isEmpty()){
|
|
||||||
command=(Command)messageQueue.poll();
|
command=(Command)messageQueue.poll();
|
||||||
if (command != null) {
|
}
|
||||||
|
}
|
||||||
|
if(tl!=null&&command!=null){
|
||||||
tl.onCommand(command);
|
tl.onCommand(command);
|
||||||
}
|
}
|
||||||
}
|
boolean result=messageQueue!=null&&!messageQueue.isEmpty()&&!peer.disposed;
|
||||||
}
|
return result;
|
||||||
return messageQueue!=null&&!messageQueue.isEmpty()&&!peer.disposed;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -241,11 +255,13 @@ public class VMTransport implements Transport,Task{
|
||||||
this.asyncQueueDepth=asyncQueueDepth;
|
this.asyncQueueDepth=asyncQueueDepth;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected synchronized void wakeup(){
|
protected void wakeup(){
|
||||||
if(async){
|
if(async){
|
||||||
|
synchronized(mutex){
|
||||||
if(taskRunner==null){
|
if(taskRunner==null){
|
||||||
taskRunner=taskRunnerFactory.createTaskRunner(this,"VMTransport: "+toString());
|
taskRunner=taskRunnerFactory.createTaskRunner(this,"VMTransport: "+toString());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
try{
|
try{
|
||||||
taskRunner.wakeup();
|
taskRunner.wakeup();
|
||||||
}catch(InterruptedException e){
|
}catch(InterruptedException e){
|
||||||
|
|
Loading…
Reference in New Issue