mirror of https://github.com/apache/activemq.git
Added request(Command. timeout) to transport and added a timeout on
close from ActiveMQConnection git-svn-id: https://svn.apache.org/repos/asf/incubator/activemq/trunk@384853 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
f51ac13f85
commit
5fe0a4ca8a
|
@ -116,6 +116,7 @@ public class ActiveMQConnection extends DefaultTransportListener implements Conn
|
|||
protected boolean asyncDispatch = true;
|
||||
private boolean useAsyncSend = false;
|
||||
private boolean useRetroactiveConsumer;
|
||||
private int closeTimeout = 15000;
|
||||
|
||||
private long flowControlSleepTime = 0;
|
||||
private final JMSConnectionStatsImpl stats;
|
||||
|
@ -541,7 +542,7 @@ public class ActiveMQConnection extends DefaultTransportListener implements Conn
|
|||
|
||||
|
||||
if (isConnectionInfoSentToBroker) {
|
||||
syncSendPacket(info.createRemoveCommand());
|
||||
syncSendPacket(info.createRemoveCommand(),closeTimeout);
|
||||
}
|
||||
|
||||
asyncSendPacket(new ShutdownInfo());
|
||||
|
@ -734,6 +735,22 @@ public class ActiveMQConnection extends DefaultTransportListener implements Conn
|
|||
this.optimizedMessageDispatch = dispatchOptimizedMessage;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the closeTimeout.
|
||||
*/
|
||||
public int getCloseTimeout(){
|
||||
return closeTimeout;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param closeTimeout The closeTimeout to set.
|
||||
*/
|
||||
public void setCloseTimeout(int closeTimeout){
|
||||
this.closeTimeout=closeTimeout;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @return Returns the onSendPrepareMessageBody.
|
||||
|
@ -1078,6 +1095,41 @@ public class ActiveMQConnection extends DefaultTransportListener implements Conn
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a packet through a Connection - for internal use only
|
||||
*
|
||||
* @param command
|
||||
* @return
|
||||
* @throws JMSException
|
||||
*/
|
||||
public Response syncSendPacket(Command command, int timeout) throws JMSException {
|
||||
if (isClosed()) {
|
||||
throw new ConnectionClosedException();
|
||||
} else {
|
||||
|
||||
if (command.isMessage() && flowControlSleepTime > 0) {
|
||||
try {
|
||||
Thread.sleep(flowControlSleepTime);
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
Response response = this.transport.request(command,timeout);
|
||||
if (response.isException()) {
|
||||
ExceptionResponse er = (ExceptionResponse) response;
|
||||
if (er.getException() instanceof JMSException)
|
||||
throw (JMSException) er.getException();
|
||||
else
|
||||
throw JMSExceptionSupport.create(er.getException());
|
||||
}
|
||||
return response;
|
||||
} catch (IOException e) {
|
||||
throw JMSExceptionSupport.create(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isClosed() {
|
||||
return closed.get();
|
||||
}
|
||||
|
|
|
@ -81,6 +81,7 @@ public class ActiveMQConnectionFactory extends JNDIBaseStorable implements Conne
|
|||
private boolean objectMessageSerializationDefered = false;
|
||||
protected boolean asyncDispatch = true;
|
||||
private boolean useAsyncSend = false;
|
||||
private int closeTimeout = 15000;
|
||||
private boolean useRetroactiveConsumer;
|
||||
|
||||
JMSStatsImpl factoryStats = new JMSStatsImpl();
|
||||
|
@ -415,6 +416,7 @@ public class ActiveMQConnectionFactory extends JNDIBaseStorable implements Conne
|
|||
props.setProperty("useCompression", Boolean.toString(isUseCompression()));
|
||||
props.setProperty("useRetroactiveConsumer", Boolean.toString(isUseRetroactiveConsumer()));
|
||||
props.setProperty("userName", getUserName());
|
||||
props.setProperty("closeTimeout", Integer.toString(getCloseTimeout()));
|
||||
}
|
||||
|
||||
public boolean isOnSendPrepareMessageBody() {
|
||||
|
@ -448,4 +450,18 @@ public class ActiveMQConnectionFactory extends JNDIBaseStorable implements Conne
|
|||
public void setAsyncDispatch(boolean asyncDispatch) {
|
||||
this.asyncDispatch = asyncDispatch;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the closeTimeout.
|
||||
*/
|
||||
public int getCloseTimeout(){
|
||||
return closeTimeout;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param closeTimeout The closeTimeout to set.
|
||||
*/
|
||||
public void setCloseTimeout(int closeTimeout){
|
||||
this.closeTimeout=closeTimeout;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,6 +19,8 @@ package org.apache.activemq.transport;
|
|||
import edu.emory.mathcs.backport.java.util.concurrent.Callable;
|
||||
import edu.emory.mathcs.backport.java.util.concurrent.ExecutionException;
|
||||
import edu.emory.mathcs.backport.java.util.concurrent.FutureTask;
|
||||
import edu.emory.mathcs.backport.java.util.concurrent.TimeUnit;
|
||||
import edu.emory.mathcs.backport.java.util.concurrent.TimeoutException;
|
||||
|
||||
import org.apache.activemq.command.Response;
|
||||
import org.apache.activemq.util.IOExceptionSupport;
|
||||
|
@ -52,6 +54,23 @@ public class FutureResponse extends FutureTask {
|
|||
}
|
||||
}
|
||||
|
||||
public synchronized Response getResult(int timeout) throws IOException {
|
||||
try {
|
||||
return (Response) super.get(timeout,TimeUnit.MILLISECONDS);
|
||||
} catch (InterruptedException e) {
|
||||
throw new InterruptedIOException("Interrupted.");
|
||||
} catch (ExecutionException e) {
|
||||
Throwable target = e.getCause();
|
||||
if( target instanceof IOException ) {
|
||||
throw (IOException)target;
|
||||
} else {
|
||||
throw IOExceptionSupport.create(target);
|
||||
}
|
||||
}catch(TimeoutException e){
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void set(Object result) {
|
||||
super.set(result);
|
||||
}
|
||||
|
|
|
@ -51,6 +51,12 @@ public class MutexTransport extends TransportFilter {
|
|||
}
|
||||
}
|
||||
|
||||
public Response request(Command command,int timeout) throws IOException {
|
||||
synchronized(writeMutex){
|
||||
return next.request(command,timeout);
|
||||
}
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return next.toString();
|
||||
}
|
||||
|
|
|
@ -67,6 +67,11 @@ final public class ResponseCorrelator extends TransportFilter {
|
|||
return response.getResult();
|
||||
}
|
||||
|
||||
public Response request(Command command,int timeout) throws IOException {
|
||||
FutureResponse response = asyncRequest(command);
|
||||
return response.getResult(timeout);
|
||||
}
|
||||
|
||||
public void onCommand(Command command) {
|
||||
boolean debug = log.isDebugEnabled();
|
||||
if( command.isResponse() ) {
|
||||
|
|
|
@ -32,30 +32,53 @@ public interface Transport extends Service {
|
|||
|
||||
/**
|
||||
* A one way asynchronous send
|
||||
* @param command
|
||||
* @throws IOException
|
||||
*/
|
||||
public void oneway(Command command) throws IOException;
|
||||
|
||||
/**
|
||||
* An asynchronous request response where the Receipt will be returned
|
||||
* in the future
|
||||
* @param command
|
||||
* @return the FutureResponse
|
||||
* @throws IOException
|
||||
*/
|
||||
public FutureResponse asyncRequest(Command command) throws IOException;
|
||||
|
||||
/**
|
||||
* A synchronous request response
|
||||
* @param command
|
||||
* @return the response
|
||||
* @throws IOException
|
||||
*/
|
||||
public Response request(Command command) throws IOException;
|
||||
|
||||
/**
|
||||
* A synchronous request response
|
||||
* @param command
|
||||
* @param timeout
|
||||
* @return the repsonse or null if timeout
|
||||
* @throws IOException
|
||||
*/
|
||||
public Response request(Command command, int timeout) throws IOException;
|
||||
|
||||
/**
|
||||
* Returns the current transport listener
|
||||
* @return
|
||||
*/
|
||||
public TransportListener getTransportListener();
|
||||
|
||||
/**
|
||||
* Registers an inbound command listener
|
||||
* @param commandListener
|
||||
*/
|
||||
public void setTransportListener(TransportListener commandListener);
|
||||
|
||||
/**
|
||||
* @param target
|
||||
* @return the target
|
||||
*/
|
||||
public Object narrow(Class target);
|
||||
|
||||
}
|
||||
|
|
|
@ -94,6 +94,10 @@ public class TransportFilter extends DefaultTransportListener implements Transpo
|
|||
return next.request(command);
|
||||
}
|
||||
|
||||
public Response request(Command command,int timeout) throws IOException {
|
||||
return next.request(command,timeout);
|
||||
}
|
||||
|
||||
public void onException(IOException error) {
|
||||
transportListener.onException(error);
|
||||
}
|
||||
|
|
|
@ -74,6 +74,10 @@ public abstract class TransportSupport extends ServiceSupport implements Transpo
|
|||
throw new AssertionError("Unsupported Method");
|
||||
}
|
||||
|
||||
public Response request(Command command,int timeout) throws IOException {
|
||||
throw new AssertionError("Unsupported Method");
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the inbound command
|
||||
*/
|
||||
|
|
|
@ -390,6 +390,10 @@ public class FailoverTransport implements CompositeTransport {
|
|||
throw new AssertionError("Unsupported Method");
|
||||
}
|
||||
|
||||
public Response request(Command command,int timeout) throws IOException {
|
||||
throw new AssertionError("Unsupported Method");
|
||||
}
|
||||
|
||||
public void add(URI u[]) {
|
||||
for (int i = 0; i < u.length; i++) {
|
||||
if( !uris.contains(u[i]) )
|
||||
|
|
|
@ -419,6 +419,10 @@ public class FanoutTransport implements CompositeTransport {
|
|||
throw new AssertionError("Unsupported Method");
|
||||
}
|
||||
|
||||
public Response request(Command command,int timeout) throws IOException {
|
||||
throw new AssertionError("Unsupported Method");
|
||||
}
|
||||
|
||||
public void reconnect() {
|
||||
log.debug("Waking up reconnect task");
|
||||
try {
|
||||
|
|
|
@ -103,6 +103,10 @@ public class MockTransport extends DefaultTransportListener implements Transport
|
|||
return next.request(command);
|
||||
}
|
||||
|
||||
public Response request(Command command,int timeout) throws IOException {
|
||||
return next.request(command, timeout);
|
||||
}
|
||||
|
||||
synchronized public void onException(IOException error) {
|
||||
transportListener.onException(error);
|
||||
}
|
||||
|
|
|
@ -87,6 +87,10 @@ public class VMTransport implements Transport{
|
|||
throw new AssertionError("Unsupported Method");
|
||||
}
|
||||
|
||||
public Response request(Command command,int timeout) throws IOException {
|
||||
throw new AssertionError("Unsupported Method");
|
||||
}
|
||||
|
||||
public synchronized TransportListener getTransportListener() {
|
||||
return transportListener;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue