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;
|
package org.apache.activemq.broker;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import org.apache.activemq.broker.ft.MasterBroker;
|
import org.apache.activemq.broker.ft.MasterBroker;
|
||||||
import org.apache.activemq.command.BrokerInfo;
|
import org.apache.activemq.command.BrokerInfo;
|
||||||
import org.apache.activemq.command.Command;
|
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.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @version $Revision: 1.8 $
|
* @version $Revision: 1.8 $
|
||||||
*/
|
*/
|
||||||
public class TransportConnection extends AbstractConnection {
|
public class TransportConnection extends AbstractConnection {
|
||||||
|
@ -43,6 +42,8 @@ public class TransportConnection extends AbstractConnection {
|
||||||
private boolean blocked;
|
private boolean blocked;
|
||||||
private boolean connected;
|
private boolean connected;
|
||||||
private boolean active;
|
private boolean active;
|
||||||
|
private boolean starting;
|
||||||
|
private boolean pendingStop;
|
||||||
private long timeStamp = 0;
|
private long timeStamp = 0;
|
||||||
private MasterBroker masterBroker; //used if this connection is used by a Slave
|
private MasterBroker masterBroker; //used if this connection is used by a Slave
|
||||||
|
|
||||||
|
@ -63,6 +64,7 @@ public class TransportConnection extends AbstractConnection {
|
||||||
dispatch(response);
|
dispatch(response);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onException(IOException exception) {
|
public void onException(IOException exception) {
|
||||||
serviceTransportException(exception);
|
serviceTransportException(exception);
|
||||||
}
|
}
|
||||||
|
@ -70,14 +72,35 @@ public class TransportConnection extends AbstractConnection {
|
||||||
connected = true;
|
connected = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void start() throws Exception {
|
public synchronized void start() throws Exception {
|
||||||
|
starting = true;
|
||||||
|
try {
|
||||||
transport.start();
|
transport.start();
|
||||||
active = true;
|
active = true;
|
||||||
super.start();
|
super.start();
|
||||||
connector.onStarted(this);
|
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);
|
connector.onStopped(this);
|
||||||
try {
|
try {
|
||||||
if (masterBroker != null) {
|
if (masterBroker != null) {
|
||||||
|
@ -89,7 +112,8 @@ public class TransportConnection extends AbstractConnection {
|
||||||
if (transportException == null) {
|
if (transportException == null) {
|
||||||
transport.oneway(new ShutdownInfo());
|
transport.oneway(new ShutdownInfo());
|
||||||
}
|
}
|
||||||
} catch (Exception ignore) {
|
}
|
||||||
|
catch (Exception ignore) {
|
||||||
//ignore.printStackTrace();
|
//ignore.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,22 +129,23 @@ public class TransportConnection extends AbstractConnection {
|
||||||
public boolean isBlockedCandidate() {
|
public boolean isBlockedCandidate() {
|
||||||
return blockedCandidate;
|
return blockedCandidate;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param blockedCandidate
|
* @param blockedCandidate The blockedCandidate to set.
|
||||||
* The blockedCandidate to set.
|
|
||||||
*/
|
*/
|
||||||
public void setBlockedCandidate(boolean blockedCandidate) {
|
public void setBlockedCandidate(boolean blockedCandidate) {
|
||||||
this.blockedCandidate = blockedCandidate;
|
this.blockedCandidate = blockedCandidate;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Returns the markedCandidate.
|
* @return Returns the markedCandidate.
|
||||||
*/
|
*/
|
||||||
public boolean isMarkedCandidate() {
|
public boolean isMarkedCandidate() {
|
||||||
return markedCandidate;
|
return markedCandidate;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param markedCandidate
|
* @param markedCandidate The markedCandidate to set.
|
||||||
* The markedCandidate to set.
|
|
||||||
*/
|
*/
|
||||||
public void setMarkedCandidate(boolean markedCandidate) {
|
public void setMarkedCandidate(boolean markedCandidate) {
|
||||||
this.markedCandidate = markedCandidate;
|
this.markedCandidate = markedCandidate;
|
||||||
|
@ -129,19 +154,21 @@ public class TransportConnection extends AbstractConnection {
|
||||||
blockedCandidate = false;
|
blockedCandidate = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param slow
|
* @param slow The slow to set.
|
||||||
* The slow to set.
|
|
||||||
*/
|
*/
|
||||||
public void setSlow(boolean slow) {
|
public void setSlow(boolean slow) {
|
||||||
this.slow = slow;
|
this.slow = slow;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return true if the Connection is slow
|
* @return true if the Connection is slow
|
||||||
*/
|
*/
|
||||||
public boolean isSlow() {
|
public boolean isSlow() {
|
||||||
return slow;
|
return slow;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return true if the Connection is potentially blocked
|
* @return true if the Connection is potentially blocked
|
||||||
*/
|
*/
|
||||||
|
@ -157,46 +184,71 @@ public class TransportConnection extends AbstractConnection {
|
||||||
timeStamp = System.currentTimeMillis();
|
timeStamp = System.currentTimeMillis();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return if after being marked, the Connection is still writing
|
* @return if after being marked, the Connection is still writing
|
||||||
*/
|
*/
|
||||||
public boolean isBlocked() {
|
public boolean isBlocked() {
|
||||||
return blocked;
|
return blocked;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return true if the Connection is connected
|
* @return true if the Connection is connected
|
||||||
*/
|
*/
|
||||||
public boolean isConnected() {
|
public boolean isConnected() {
|
||||||
return connected;
|
return connected;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param blocked
|
* @param blocked The blocked to set.
|
||||||
* The blocked to set.
|
|
||||||
*/
|
*/
|
||||||
public void setBlocked(boolean blocked) {
|
public void setBlocked(boolean blocked) {
|
||||||
this.blocked = blocked;
|
this.blocked = blocked;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param connected
|
* @param connected The connected to set.
|
||||||
* The connected to set.
|
|
||||||
*/
|
*/
|
||||||
public void setConnected(boolean connected) {
|
public void setConnected(boolean connected) {
|
||||||
this.connected = connected;
|
this.connected = connected;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return true if the Connection is active
|
* @return true if the Connection is active
|
||||||
*/
|
*/
|
||||||
public boolean isActive() {
|
public boolean isActive() {
|
||||||
return active;
|
return active;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param active
|
* @param active The active to set.
|
||||||
* The active to set.
|
|
||||||
*/
|
*/
|
||||||
public void setActive(boolean active) {
|
public void setActive(boolean active) {
|
||||||
this.active = 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) {
|
public Response processBrokerInfo(BrokerInfo info) {
|
||||||
if (info.isSlaveBroker()) {
|
if (info.isSlaveBroker()) {
|
||||||
//stream messages from this broker (the master) to
|
//stream messages from this broker (the master) to
|
||||||
|
@ -214,9 +266,11 @@ public class TransportConnection extends AbstractConnection {
|
||||||
setMarkedCandidate(true);
|
setMarkedCandidate(true);
|
||||||
transport.oneway(command);
|
transport.oneway(command);
|
||||||
getStatistics().onCommand(command);
|
getStatistics().onCommand(command);
|
||||||
}catch(IOException e){
|
}
|
||||||
|
catch (IOException e) {
|
||||||
serviceException(e);
|
serviceException(e);
|
||||||
}finally{
|
}
|
||||||
|
finally {
|
||||||
setMarkedCandidate(false);
|
setMarkedCandidate(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,7 +58,11 @@ public class ManagedTransportConnection extends TransportConnection {
|
||||||
setConnectionId(connectionId);
|
setConnectionId(connectionId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stop() throws Exception {
|
public synchronized void stop() throws Exception {
|
||||||
|
if (isStarting()) {
|
||||||
|
setPendingStop(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
unregisterMBean();
|
unregisterMBean();
|
||||||
super.stop();
|
super.stop();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue