Adding some changes to support master/slave

git-svn-id: https://svn.apache.org/repos/asf/incubator/activemq/trunk@368075 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Davies 2006-01-11 18:15:13 +00:00
parent 1c44792498
commit af9f61015d
3 changed files with 252 additions and 0 deletions

View File

@ -0,0 +1,236 @@
/**
*
* Copyright 2005-2006 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
package org.apache.activemq.broker;
import java.util.ArrayList;
import java.util.List;
import org.apache.activemq.broker.region.Destination;
import org.apache.activemq.command.ActiveMQDestination;
import org.apache.activemq.command.ConnectionInfo;
import org.apache.activemq.command.ConsumerInfo;
import org.apache.activemq.command.Message;
import org.apache.activemq.command.MessageAck;
import org.apache.activemq.command.ProducerInfo;
import org.apache.activemq.command.RemoveSubscriptionInfo;
import org.apache.activemq.command.SessionInfo;
import org.apache.activemq.command.TransactionId;
/**
* Used to add listeners for Broker actions
*
* @version $Revision: 1.10 $
*/
public class BrokerBroadcaster extends BrokerFilter{
protected transient volatile Broker[] listeners=new Broker[0];
public BrokerBroadcaster(Broker next){
super(next);
}
public void acknowledge(ConnectionContext context,MessageAck ack) throws Throwable{
next.acknowledge(context,ack);
Broker brokers[]=getListeners();
for(int i=0;i<brokers.length;i++){
brokers[i].acknowledge(context,ack);
}
}
public void addConnection(ConnectionContext context,ConnectionInfo info) throws Throwable{
next.addConnection(context,info);
Broker brokers[]=getListeners();
for(int i=0;i<brokers.length;i++){
brokers[i].addConnection(context,info);
}
}
public void addConsumer(ConnectionContext context,ConsumerInfo info) throws Throwable{
next.addConsumer(context,info);
Broker brokers[]=getListeners();
for(int i=0;i<brokers.length;i++){
brokers[i].addConsumer(context,info);
}
}
public void addProducer(ConnectionContext context,ProducerInfo info) throws Throwable{
next.addProducer(context,info);
Broker brokers[]=getListeners();
for(int i=0;i<brokers.length;i++){
brokers[i].addProducer(context,info);
}
}
public void commitTransaction(ConnectionContext context,TransactionId xid,boolean onePhase) throws Throwable{
next.commitTransaction(context,xid,onePhase);
Broker brokers[]=getListeners();
for(int i=0;i<brokers.length;i++){
brokers[i].commitTransaction(context,xid,onePhase);
}
}
public void removeSubscription(ConnectionContext context,RemoveSubscriptionInfo info) throws Throwable{
next.removeSubscription(context,info);
Broker brokers[]=getListeners();
for(int i=0;i<brokers.length;i++){
brokers[i].removeSubscription(context,info);
}
}
public int prepareTransaction(ConnectionContext context,TransactionId xid) throws Throwable{
int result=next.prepareTransaction(context,xid);
Broker brokers[]=getListeners();
for(int i=0;i<brokers.length;i++){
// TODO decide what to do with return values
brokers[i].prepareTransaction(context,xid);
}
return result;
}
public void removeConnection(ConnectionContext context,ConnectionInfo info,Throwable error) throws Throwable{
next.removeConnection(context,info,error);
Broker brokers[]=getListeners();
for(int i=0;i<brokers.length;i++){
brokers[i].removeConnection(context,info,error);
}
}
public void removeConsumer(ConnectionContext context,ConsumerInfo info) throws Throwable{
next.removeConsumer(context,info);
Broker brokers[]=getListeners();
for(int i=0;i<brokers.length;i++){
brokers[i].removeConsumer(context,info);
}
}
public void removeProducer(ConnectionContext context,ProducerInfo info) throws Throwable{
next.removeProducer(context,info);
Broker brokers[]=getListeners();
for(int i=0;i<brokers.length;i++){
brokers[i].removeProducer(context,info);
}
}
public void rollbackTransaction(ConnectionContext context,TransactionId xid) throws Throwable{
next.rollbackTransaction(context,xid);
Broker brokers[]=getListeners();
for(int i=0;i<brokers.length;i++){
brokers[i].rollbackTransaction(context,xid);
}
}
public void send(ConnectionContext context,Message messageSend) throws Throwable{
next.send(context,messageSend);
Broker brokers[]=getListeners();
for(int i=0;i<brokers.length;i++){
brokers[i].send(context,messageSend);
}
}
public void beginTransaction(ConnectionContext context,TransactionId xid) throws Throwable{
next.beginTransaction(context,xid);
Broker brokers[]=getListeners();
for(int i=0;i<brokers.length;i++){
brokers[i].beginTransaction(context,xid);
}
}
public void forgetTransaction(ConnectionContext context,TransactionId transactionId) throws Throwable{
next.forgetTransaction(context,transactionId);
Broker brokers[]=getListeners();
for(int i=0;i<brokers.length;i++){
brokers[i].forgetTransaction(context,transactionId);
}
}
public Destination addDestination(ConnectionContext context,ActiveMQDestination destination) throws Throwable{
Destination result=next.addDestination(context,destination);
Broker brokers[]=getListeners();
for(int i=0;i<brokers.length;i++){
brokers[i].addDestination(context,destination);
}
return result;
}
public void removeDestination(ConnectionContext context,ActiveMQDestination destination,long timeout)
throws Throwable{
next.removeDestination(context,destination,timeout);
Broker brokers[]=getListeners();
for(int i=0;i<brokers.length;i++){
brokers[i].removeDestination(context,destination,timeout);
}
}
public void start() throws Exception{
next.start();
Broker brokers[]=getListeners();
for(int i=0;i<brokers.length;i++){
brokers[i].start();
}
}
public void stop() throws Exception{
next.stop();
Broker brokers[]=getListeners();
for(int i=0;i<brokers.length;i++){
brokers[i].stop();
}
}
public void addSession(ConnectionContext context,SessionInfo info) throws Throwable{
next.addSession(context,info);
Broker brokers[]=getListeners();
for(int i=0;i<brokers.length;i++){
brokers[i].addSession(context,info);
}
}
public void removeSession(ConnectionContext context,SessionInfo info) throws Throwable{
next.removeSession(context,info);
Broker brokers[]=getListeners();
for(int i=0;i<brokers.length;i++){
brokers[i].removeSession(context,info);
}
}
public void gc(){
Broker brokers[]=getListeners();
for(int i=0;i<brokers.length;i++){
brokers[i].gc();
}
next.gc();
}
protected Broker[] getListeners(){
return listeners;
}
public synchronized void addInteceptor(Broker broker){
List tmp=getInterceptorsAsList();
tmp.add(broker);
listeners=(Broker[]) tmp.toArray(new Broker[tmp.size()]);
}
public synchronized void removeInterceptor(Broker broker){
List tmp=getInterceptorsAsList();
tmp.remove(broker);
listeners=(Broker[]) tmp.toArray(new Broker[tmp.size()]);
}
protected List getInterceptorsAsList(){
List tmp=new ArrayList();
Broker brokers[]=getListeners();
for(int i=0;i<brokers.length;i++){
tmp.add(brokers[i]);
}
return tmp;
}
}

View File

@ -33,6 +33,7 @@ public class BrokerInfo extends BaseCommand {
public static final byte DATA_STRUCTURE_TYPE=CommandTypes.BROKER_INFO;
BrokerId brokerId;
String brokerURL;
boolean slaveBroker;
BrokerInfo peerBrokerInfos[];
String brokerName;
@ -89,4 +90,16 @@ public class BrokerInfo extends BaseCommand {
return visitor.processBrokerInfo( this );
}
/**
* @openwire:property version=1 cache=true
*/
public boolean isSlaveBroker(){
return slaveBroker;
}
public void setSlaveBroker(boolean slaveBroker){
this.slaveBroker=slaveBroker;
}
}

View File

@ -79,6 +79,7 @@ public class BrokerInfoMarshaller extends BaseCommandMarshaller {
}
info.setBrokerName(readString(dataIn, bs));
info.setSlaveBroker(bs.readBoolean());
}
@ -95,6 +96,7 @@ public class BrokerInfoMarshaller extends BaseCommandMarshaller {
rc += writeString(info.getBrokerURL(), bs);
rc += marshalObjectArray(wireFormat, info.getPeerBrokerInfos(), bs);
rc += writeString(info.getBrokerName(), bs);
bs.writeBoolean(info.isSlaveBroker());
return rc+0;
}
@ -114,6 +116,7 @@ public class BrokerInfoMarshaller extends BaseCommandMarshaller {
writeString(info.getBrokerURL(), dataOut, bs);
marshalObjectArray(wireFormat, info.getPeerBrokerInfos(), dataOut, bs);
writeString(info.getBrokerName(), dataOut, bs);
bs.readBoolean();
}
}