You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ra...@apache.org on 2006/01/11 19:15:18 UTC

svn commit: r368075 - in /incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq: broker/BrokerBroadcaster.java command/BrokerInfo.java openwire/v1/BrokerInfoMarshaller.java

Author: rajdavies
Date: Wed Jan 11 10:15:13 2006
New Revision: 368075

URL: http://svn.apache.org/viewcvs?rev=368075&view=rev
Log:
Adding some changes to support master/slave

Added:
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/BrokerBroadcaster.java   (with props)
Modified:
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/command/BrokerInfo.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/openwire/v1/BrokerInfoMarshaller.java

Added: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/BrokerBroadcaster.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/BrokerBroadcaster.java?rev=368075&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/BrokerBroadcaster.java (added)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/BrokerBroadcaster.java Wed Jan 11 10:15:13 2006
@@ -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;
+    }
+}

Propchange: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/BrokerBroadcaster.java
------------------------------------------------------------------------------
    svn:executable = *

Modified: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/command/BrokerInfo.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/command/BrokerInfo.java?rev=368075&r1=368074&r2=368075&view=diff
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/command/BrokerInfo.java (original)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/command/BrokerInfo.java Wed Jan 11 10:15:13 2006
@@ -33,6 +33,7 @@
     public static final byte DATA_STRUCTURE_TYPE=CommandTypes.BROKER_INFO;
     BrokerId brokerId;
     String brokerURL;
+    boolean slaveBroker;
     
     BrokerInfo peerBrokerInfos[];
     String brokerName;
@@ -87,6 +88,18 @@
 	
     public Response visit(CommandVisitor visitor) throws Throwable {
         return visitor.processBrokerInfo( this );
+    }
+
+    /**
+     * @openwire:property version=1 cache=true
+     */
+    public boolean isSlaveBroker(){
+        return slaveBroker;
+    }
+
+   
+    public void setSlaveBroker(boolean slaveBroker){
+        this.slaveBroker=slaveBroker;
     }
 
 }

Modified: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/openwire/v1/BrokerInfoMarshaller.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/openwire/v1/BrokerInfoMarshaller.java?rev=368075&r1=368074&r2=368075&view=diff
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/openwire/v1/BrokerInfoMarshaller.java (original)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/openwire/v1/BrokerInfoMarshaller.java Wed Jan 11 10:15:13 2006
@@ -79,6 +79,7 @@
 		        }
         			
         info.setBrokerName(readString(dataIn, bs));
+        info.setSlaveBroker(bs.readBoolean());
 
     }
 
@@ -95,6 +96,7 @@
         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 @@
         writeString(info.getBrokerURL(), dataOut, bs);
         marshalObjectArray(wireFormat, info.getPeerBrokerInfos(), dataOut, bs);
         writeString(info.getBrokerName(), dataOut, bs);
+        bs.readBoolean();
 
     }
 }