move decision about being a slave from the Broker to the ConnectionContext - so can be done on a Connection basis if required

git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@557748 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Davies 2007-07-19 19:24:31 +00:00
parent 993f78caac
commit 83a6eff431
13 changed files with 73 additions and 51 deletions

View File

@ -192,11 +192,6 @@ public interface Broker extends Region, Service {
*/ */
public void processDispatch(MessageDispatch messageDispatch); public void processDispatch(MessageDispatch messageDispatch);
/**
* @return true if the broker is running as a slave
*/
public boolean isSlaveBroker();
/** /**
* @return true if the broker has stopped * @return true if the broker has stopped
*/ */

View File

@ -201,10 +201,6 @@ public class BrokerFilter implements Broker {
next.processDispatchNotification(messageDispatchNotification); next.processDispatchNotification(messageDispatchNotification);
} }
public boolean isSlaveBroker(){
return next.isSlaveBroker();
}
public boolean isStopped(){ public boolean isStopped(){
return next.isStopped(); return next.isStopped();
} }

View File

@ -154,6 +154,7 @@ public class BrokerService implements Service {
private boolean useLocalHostBrokerName = false; private boolean useLocalHostBrokerName = false;
private CountDownLatch stoppedLatch = new CountDownLatch(1); private CountDownLatch stoppedLatch = new CountDownLatch(1);
private boolean supportFailOver = false; private boolean supportFailOver = false;
private boolean clustered = false;
static{ static{
String localHostName = "localhost"; String localHostName = "localhost";
@ -1121,6 +1122,20 @@ public class BrokerService implements Service {
this.supportFailOver=supportFailOver; this.supportFailOver=supportFailOver;
} }
/**
* @return the clustered
*/
public boolean isClustered(){
return this.clustered;
}
/**
* @param clustered the clustered to set
*/
public void setClustered(boolean clustered){
this.clustered=clustered;
}
// Implementation methods // Implementation methods
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
/** /**
@ -1698,5 +1713,4 @@ public class BrokerService implements Service {
} }
} }
} }
} }

View File

@ -59,6 +59,7 @@ public class ConnectionContext {
private final AtomicBoolean stopping = new AtomicBoolean(); private final AtomicBoolean stopping = new AtomicBoolean();
private final MessageEvaluationContext messageEvaluationContext = new MessageEvaluationContext(); private final MessageEvaluationContext messageEvaluationContext = new MessageEvaluationContext();
private boolean dontSendReponse; private boolean dontSendReponse;
private boolean clientMaster=true;
public ConnectionContext() { public ConnectionContext() {
} }
@ -269,4 +270,27 @@ public class ConnectionContext {
return dontSendReponse; return dontSendReponse;
} }
/**
* @return the slave
*/
public boolean isSlave(){
return (this.broker!=null&&this.broker.getBrokerService().isSlave())||!this.clientMaster;
}
/**
* @return the clientMaster
*/
public boolean isClientMaster(){
return this.clientMaster;
}
/**
* @param clientMaster the clientMaster to set
*/
public void setClientMaster(boolean clientMaster){
this.clientMaster=clientMaster;
}
} }

View File

@ -199,9 +199,6 @@ public class EmptyBroker implements Broker {
} }
public boolean isSlaveBroker() {
return false;
}
public boolean isStopped() { public boolean isStopped() {
return false; return false;

View File

@ -197,9 +197,6 @@ public class ErrorBroker implements Broker {
throw new BrokerStoppedException(this.message); throw new BrokerStoppedException(this.message);
} }
public boolean isSlaveBroker() {
throw new BrokerStoppedException(this.message);
}
public boolean isStopped() { public boolean isStopped() {
return true; return true;

View File

@ -209,9 +209,6 @@ public class MutableBrokerFilter implements Broker {
getNext().processDispatchNotification(messageDispatchNotification); getNext().processDispatchNotification(messageDispatchNotification);
} }
public boolean isSlaveBroker(){
return getNext().isSlaveBroker();
}
public boolean isStopped(){ public boolean isStopped(){
return getNext().isStopped(); return getNext().isStopped();

View File

@ -658,6 +658,7 @@ public class TransportConnection implements Service,Connection,Task,CommandVisit
context.setClientId(clientId); context.setClientId(clientId);
context.setUserName(info.getUserName()); context.setUserName(info.getUserName());
context.setConnectionId(info.getConnectionId()); context.setConnectionId(info.getConnectionId());
context.setClientMaster(info.isClientMaster());
context.setWireFormatInfo(wireFormatInfo); context.setWireFormatInfo(wireFormatInfo);
context.setNetworkConnection(networkConnection); context.setNetworkConnection(networkConnection);
context.incrementReference(); context.incrementReference();
@ -1211,6 +1212,7 @@ public class TransportConnection implements Service,Connection,Task,CommandVisit
} }
} }
public int getProtocolVersion() { public int getProtocolVersion() {
return protocolVersion.get(); return protocolVersion.get();
} }

View File

@ -115,8 +115,8 @@ abstract public class AbstractSubscription implements Subscription {
public void gc() { public void gc() {
} }
public boolean isSlaveBroker(){ public boolean isSlave(){
return broker.isSlaveBroker(); return getContext().isSlave();
} }
public ConnectionContext getContext() { public ConnectionContext getContext() {

View File

@ -74,7 +74,7 @@ abstract public class PrefetchSubscription extends AbstractSubscription{
// The slave should not deliver pull messages. TODO: when the slave becomes a master, // The slave should not deliver pull messages. TODO: when the slave becomes a master,
// He should send a NULL message to all the consumers to 'wake them up' in case // He should send a NULL message to all the consumers to 'wake them up' in case
// they were waiting for a message. // they were waiting for a message.
if(getPrefetchSize()==0&&!isSlaveBroker()){ if(getPrefetchSize()==0&&!isSlave()){
prefetchExtension++; prefetchExtension++;
final long dispatchCounterBeforePull=dispatchCounter; final long dispatchCounterBeforePull=dispatchCounter;
dispatchMatched(); dispatchMatched();
@ -119,7 +119,7 @@ abstract public class PrefetchSubscription extends AbstractSubscription{
pendingEmpty=pending.isEmpty(); pendingEmpty=pending.isEmpty();
enqueueCounter++; enqueueCounter++;
if(!isFull()&&pendingEmpty&&!broker.isSlaveBroker()){ if(!isFull()&&pendingEmpty&&!isSlave()){
dispatch(node); dispatch(node);
}else{ }else{
optimizePrefetch(); optimizePrefetch();
@ -260,7 +260,7 @@ abstract public class PrefetchSubscription extends AbstractSubscription{
if(callDispatchMatched){ if(callDispatchMatched){
dispatchMatched(); dispatchMatched();
}else{ }else{
if(isSlaveBroker()){ if(isSlave()){
throw new JMSException("Slave broker out of sync with master: Acknowledgment ("+ack throw new JMSException("Slave broker out of sync with master: Acknowledgment ("+ack
+") was not in the dispatch list: "+dispatched); +") was not in the dispatch list: "+dispatched);
}else{ }else{
@ -295,7 +295,7 @@ abstract public class PrefetchSubscription extends AbstractSubscription{
* @return * @return
*/ */
protected synchronized boolean isFull(){ protected synchronized boolean isFull(){
return isSlaveBroker()||dispatched.size()-prefetchExtension>=info.getPrefetchSize(); return isSlave()||dispatched.size()-prefetchExtension>=info.getPrefetchSize();
} }
/** /**
@ -377,7 +377,7 @@ abstract public class PrefetchSubscription extends AbstractSubscription{
} }
protected synchronized void dispatchMatched() throws IOException{ protected synchronized void dispatchMatched() throws IOException{
if(!broker.isSlaveBroker()){ if(!isSlave()){
try{ try{
int numberToDispatch=countBeforeFull(); int numberToDispatch=countBeforeFull();
if(numberToDispatch>0){ if(numberToDispatch>0){
@ -412,7 +412,7 @@ abstract public class PrefetchSubscription extends AbstractSubscription{
return false; return false;
} }
// Make sure we can dispatch a message. // Make sure we can dispatch a message.
if(canDispatch(node)&&!isSlaveBroker()){ if(canDispatch(node)&&!isSlave()){
MessageDispatch md=createMessageDispatch(node,message); MessageDispatch md=createMessageDispatch(node,message);
// NULL messages don't count... they don't get Acked. // NULL messages don't count... they don't get Acked.
if(node!=QueueMessageReference.NULL_MESSAGE){ if(node!=QueueMessageReference.NULL_MESSAGE){

View File

@ -111,7 +111,7 @@ public interface Subscription extends SubscriptionRecovery {
/** /**
* @return true if the broker is currently in slave mode * @return true if the broker is currently in slave mode
*/ */
boolean isSlaveBroker(); boolean isSlave();
/** /**
* @return number of messages pending delivery * @return number of messages pending delivery

View File

@ -74,7 +74,7 @@ public class TopicSubscription extends AbstractSubscription{
public void add(MessageReference node) throws Exception{ public void add(MessageReference node) throws Exception{
enqueueCounter.incrementAndGet(); enqueueCounter.incrementAndGet();
node.incrementReferenceCount(); node.incrementReferenceCount();
if(!isFull()&&!isSlaveBroker()){ if(!isFull()&&!isSlave()){
optimizePrefetch(); optimizePrefetch();
// if maximumPendingMessages is set we will only discard messages which // if maximumPendingMessages is set we will only discard messages which
// have not been dispatched (i.e. we allow the prefetch buffer to be filled) // have not been dispatched (i.e. we allow the prefetch buffer to be filled)

View File

@ -36,7 +36,7 @@ public class ConnectionInfo extends BaseCommand {
protected BrokerId[] brokerPath; protected BrokerId[] brokerPath;
protected boolean brokerMasterConnector; protected boolean brokerMasterConnector;
protected boolean manageable; protected boolean manageable;
protected boolean clientMaster; protected boolean clientMaster=true;
protected transient Object transportContext; protected transient Object transportContext;
public ConnectionInfo() { public ConnectionInfo() {