mirror of https://github.com/apache/activemq.git
applied patch from John Heitmann for AMQ-932 - many thanks!
git-svn-id: https://svn.apache.org/repos/asf/incubator/activemq/trunk@449654 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
ef5fd15b84
commit
4b595ea6dc
|
@ -17,8 +17,6 @@
|
|||
*/
|
||||
package org.apache.activemq.broker;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.activemq.broker.ft.MasterBroker;
|
||||
import org.apache.activemq.command.BrokerInfo;
|
||||
import org.apache.activemq.command.Command;
|
||||
|
@ -30,8 +28,9 @@ import org.apache.activemq.transport.Transport;
|
|||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @version $Revision: 1.8 $
|
||||
*/
|
||||
public class TransportConnection extends AbstractConnection {
|
||||
|
@ -43,6 +42,8 @@ public class TransportConnection extends AbstractConnection {
|
|||
private boolean blocked;
|
||||
private boolean connected;
|
||||
private boolean active;
|
||||
private boolean starting;
|
||||
private boolean pendingStop;
|
||||
private long timeStamp = 0;
|
||||
private MasterBroker masterBroker; //used if this connection is used by a Slave
|
||||
|
||||
|
@ -63,6 +64,7 @@ public class TransportConnection extends AbstractConnection {
|
|||
dispatch(response);
|
||||
}
|
||||
}
|
||||
|
||||
public void onException(IOException exception) {
|
||||
serviceTransportException(exception);
|
||||
}
|
||||
|
@ -70,14 +72,35 @@ public class TransportConnection extends AbstractConnection {
|
|||
connected = true;
|
||||
}
|
||||
|
||||
public void start() throws Exception {
|
||||
public synchronized void start() throws Exception {
|
||||
starting = true;
|
||||
try {
|
||||
transport.start();
|
||||
active = true;
|
||||
super.start();
|
||||
connector.onStarted(this);
|
||||
}
|
||||
finally {
|
||||
// stop() can be called from within the above block,
|
||||
// but we want to be sure start() completes before
|
||||
// stop() runs, so queue the stop until right now:
|
||||
starting = false;
|
||||
if (pendingStop) {
|
||||
log.debug("Calling the delayed stop()");
|
||||
stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void stop() throws Exception {
|
||||
// If we're in the middle of starting
|
||||
// then go no further... for now.
|
||||
pendingStop = true;
|
||||
if (starting) {
|
||||
log.debug("stop() called in the middle of start(). Delaying...");
|
||||
return;
|
||||
}
|
||||
|
||||
public void stop() throws Exception {
|
||||
connector.onStopped(this);
|
||||
try {
|
||||
if (masterBroker != null) {
|
||||
|
@ -89,7 +112,8 @@ public class TransportConnection extends AbstractConnection {
|
|||
if (transportException == null) {
|
||||
transport.oneway(new ShutdownInfo());
|
||||
}
|
||||
} catch (Exception ignore) {
|
||||
}
|
||||
catch (Exception ignore) {
|
||||
//ignore.printStackTrace();
|
||||
}
|
||||
|
||||
|
@ -105,22 +129,23 @@ public class TransportConnection extends AbstractConnection {
|
|||
public boolean isBlockedCandidate() {
|
||||
return blockedCandidate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param blockedCandidate
|
||||
* The blockedCandidate to set.
|
||||
* @param blockedCandidate The blockedCandidate to set.
|
||||
*/
|
||||
public void setBlockedCandidate(boolean blockedCandidate) {
|
||||
this.blockedCandidate = blockedCandidate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the markedCandidate.
|
||||
*/
|
||||
public boolean isMarkedCandidate() {
|
||||
return markedCandidate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param markedCandidate
|
||||
* The markedCandidate to set.
|
||||
* @param markedCandidate The markedCandidate to set.
|
||||
*/
|
||||
public void setMarkedCandidate(boolean markedCandidate) {
|
||||
this.markedCandidate = markedCandidate;
|
||||
|
@ -129,19 +154,21 @@ public class TransportConnection extends AbstractConnection {
|
|||
blockedCandidate = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param slow
|
||||
* The slow to set.
|
||||
* @param slow The slow to set.
|
||||
*/
|
||||
public void setSlow(boolean slow) {
|
||||
this.slow = slow;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if the Connection is slow
|
||||
*/
|
||||
public boolean isSlow() {
|
||||
return slow;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if the Connection is potentially blocked
|
||||
*/
|
||||
|
@ -157,46 +184,71 @@ public class TransportConnection extends AbstractConnection {
|
|||
timeStamp = System.currentTimeMillis();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return if after being marked, the Connection is still writing
|
||||
*/
|
||||
public boolean isBlocked() {
|
||||
return blocked;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if the Connection is connected
|
||||
*/
|
||||
public boolean isConnected() {
|
||||
return connected;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param blocked
|
||||
* The blocked to set.
|
||||
* @param blocked The blocked to set.
|
||||
*/
|
||||
public void setBlocked(boolean blocked) {
|
||||
this.blocked = blocked;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param connected
|
||||
* The connected to set.
|
||||
* @param connected The connected to set.
|
||||
*/
|
||||
public void setConnected(boolean connected) {
|
||||
this.connected = connected;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if the Connection is active
|
||||
*/
|
||||
public boolean isActive() {
|
||||
return active;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param active
|
||||
* The active to set.
|
||||
* @param active The active to set.
|
||||
*/
|
||||
public void setActive(boolean active) {
|
||||
this.active = active;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if the Connection is starting
|
||||
*/
|
||||
public synchronized boolean isStarting() {
|
||||
return starting;
|
||||
}
|
||||
|
||||
synchronized protected void setStarting(boolean starting) {
|
||||
this.starting = starting;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if the Connection needs to stop
|
||||
*/
|
||||
public synchronized boolean isPendingStop() {
|
||||
return pendingStop;
|
||||
}
|
||||
|
||||
protected synchronized void setPendingStop(boolean pendingStop) {
|
||||
this.pendingStop = pendingStop;
|
||||
}
|
||||
|
||||
public Response processBrokerInfo(BrokerInfo info) {
|
||||
if (info.isSlaveBroker()) {
|
||||
//stream messages from this broker (the master) to
|
||||
|
@ -214,9 +266,11 @@ public class TransportConnection extends AbstractConnection {
|
|||
setMarkedCandidate(true);
|
||||
transport.oneway(command);
|
||||
getStatistics().onCommand(command);
|
||||
}catch(IOException e){
|
||||
}
|
||||
catch (IOException e) {
|
||||
serviceException(e);
|
||||
}finally{
|
||||
}
|
||||
finally {
|
||||
setMarkedCandidate(false);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -58,7 +58,11 @@ public class ManagedTransportConnection extends TransportConnection {
|
|||
setConnectionId(connectionId);
|
||||
}
|
||||
|
||||
public void stop() throws Exception {
|
||||
public synchronized void stop() throws Exception {
|
||||
if (isStarting()) {
|
||||
setPendingStop(true);
|
||||
return;
|
||||
}
|
||||
unregisterMBean();
|
||||
super.stop();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue