activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chir...@apache.org
Subject svn commit: r784736 - in /activemq/sandbox/activemq-flow/activemq-broker/src: main/java/org/apache/activemq/apollo/broker/Broker.java main/java/org/apache/activemq/apollo/broker/VirtualHost.java test/java/org/apache/activemq/broker/BrokerTestBase.java
Date Mon, 15 Jun 2009 11:42:39 GMT
Author: chirino
Date: Mon Jun 15 11:42:38 2009
New Revision: 784736

URL: http://svn.apache.org/viewvc?rev=784736&view=rev
Log:
Pushed the store config down into the virtual host section.


Modified:
    activemq/sandbox/activemq-flow/activemq-broker/src/main/java/org/apache/activemq/apollo/broker/Broker.java
    activemq/sandbox/activemq-flow/activemq-broker/src/main/java/org/apache/activemq/apollo/broker/VirtualHost.java
    activemq/sandbox/activemq-flow/activemq-broker/src/test/java/org/apache/activemq/broker/BrokerTestBase.java

Modified: activemq/sandbox/activemq-flow/activemq-broker/src/main/java/org/apache/activemq/apollo/broker/Broker.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-flow/activemq-broker/src/main/java/org/apache/activemq/apollo/broker/Broker.java?rev=784736&r1=784735&r2=784736&view=diff
==============================================================================
--- activemq/sandbox/activemq-flow/activemq-broker/src/main/java/org/apache/activemq/apollo/broker/Broker.java
(original)
+++ activemq/sandbox/activemq-flow/activemq-broker/src/main/java/org/apache/activemq/apollo/broker/Broker.java
Mon Jun 15 11:42:38 2009
@@ -24,8 +24,6 @@
 
 import org.apache.activemq.Service;
 import org.apache.activemq.apollo.Connection;
-import org.apache.activemq.broker.store.Store;
-import org.apache.activemq.broker.store.StoreFactory;
 import org.apache.activemq.dispatch.DispatcherAware;
 import org.apache.activemq.dispatch.IDispatcher;
 import org.apache.activemq.dispatch.PriorityDispatcher;
@@ -51,7 +49,6 @@
     private VirtualHost defaultVirtualHost;
 	private String name;
     private IDispatcher dispatcher;
-    private BrokerDatabase database;
     
     private final class BrokerAcceptListener implements TransportAcceptListener {
 		public void onAccept(final Transport transport) {
@@ -75,24 +72,34 @@
 	}
 
 	enum State { 
-    	CONFIGURATION, STARTING, RUNNING, STOPPING {
+    	CONFIGURATION("CONFIGURATION"), STARTING("STARTING"), RUNNING("RUNNING"), STOPPING("STOPPING")
{
     		@Override
     		public boolean isStopping() {
     			return true;
     		}
     	}
-    	, STOPPED {
+    	, STOPPED("STOPPED") {
     		@Override
     		public boolean isStopping() {
     			return true;
     		}
     	}, 
-    	UNKNOWN;
+    	UNKNOWN("UNKNOWN");
+    	
+    	private final String name;
+
+		private State(String name) {
+			this.name = name;
+    	}
     	
     	public boolean isStopping() {
     		return false;
     	}
     	
+    	@Override
+    	public String toString() {
+    		return name;
+    	}
     };
     
     private final AtomicReference<State> state = new AtomicReference<State>(State.CONFIGURATION);
@@ -104,7 +111,7 @@
     public final void start() throws Exception {
 
 		if ( state.get()!=State.CONFIGURATION ) {
-    		throw new IllegalStateException("Can only start a broker that has never been started
before");
+    		throw new IllegalStateException("Can only start a broker that is in the "+State.CONFIGURATION
+" state.  Broker was "+state.get());
     	}
 
 		// Don't change the state to STARTING yet as we may need to 
@@ -113,20 +120,15 @@
 			int threads = Runtime.getRuntime().availableProcessors();
 			dispatcher = PriorityDispatcher.createPriorityDispatchPool("Broker: "+getName(), Broker.MAX_PRIORITY,
threads);
 		}
-		if ( database == null ) {
-			Store store = StoreFactory.createStore("kaha-db");
-			database = new BrokerDatabase(store);
-		}
+		
 	    addVirtualHost(getDefaultVirtualHost());
 
 	    // Ok now we are ready to start the broker up....
 		if ( !state.compareAndSet(State.CONFIGURATION, State.STARTING) ) {
-    		throw new IllegalStateException("Can only start a broker that has never been started
before");
+    		throw new IllegalStateException("Can only start a broker that is in the "+State.CONFIGURATION
+" state.  Broker was "+state.get());
     	}
     	try {
 		    dispatcher.start();
-		    database.setDispatcher(dispatcher);
-		    database.start();
 
 	    	synchronized(virtualHosts) {
 			    for (VirtualHost virtualHost : virtualHosts.values()) {
@@ -154,7 +156,7 @@
 
     public final void stop() throws Exception {
     	if ( !state.compareAndSet(State.RUNNING, State.STOPPING) ) {
-    		throw new IllegalStateException("Can only stop a broker that is running");
+    		throw new IllegalStateException("Can only stop a broker that is in the "+State.RUNNING
+" state.  Broker was "+state.get());
     	}
     	
     	synchronized(transportServers) {
@@ -170,7 +172,6 @@
         for (VirtualHost virtualHost : virtualHosts.values()) {
         	stop(virtualHost);
         }
-        stop(database);
         dispatcher.shutdown();
     	state.set(State.STOPPED);
 
@@ -262,15 +263,12 @@
     }
 
     public void setDefaultVirtualHost(VirtualHost defaultVirtualHost) {
-    	assertInConfigurationState();
     	synchronized (virtualHosts) {
             this.defaultVirtualHost = defaultVirtualHost;
         }
     }
 
     public void addVirtualHost(VirtualHost host) throws Exception {
-    	assertInConfigurationState();
-    	
         synchronized (virtualHosts) {
             // Make sure it's valid.
             ArrayList<AsciiBuffer> hostNames = host.getHostNames();
@@ -296,7 +294,6 @@
     }
 
 	public synchronized void removeVirtualHost(VirtualHost host) throws Exception {
-    	assertInConfigurationState();
         synchronized (virtualHosts) {
             for (AsciiBuffer name : host.getHostNames()) {
                 virtualHosts.remove(name);
@@ -345,25 +342,13 @@
         this.dispatcher = dispatcher;
     }
 
-    public BrokerDatabase getDatabase() {
-        return database;
-    }
-    public void setDatabase(BrokerDatabase database) {
-    	assertInConfigurationState();
-        this.database = database;
-    }
-    public void setStore(Store store) {
-    	assertInConfigurationState();
-        database = new BrokerDatabase(store);
-    }
- 
     // /////////////////////////////////////////////////////////////////
     // Helper Methods
     // /////////////////////////////////////////////////////////////////
 
     private void assertInConfigurationState() {
 		if( state.get() != State.CONFIGURATION ) {
-			throw new IllegalStateException("Broker is not in the configuration state.");
+			throw new IllegalStateException("Opperation only valid when broker is in the "+State.CONFIGURATION+"
state. Broker was "+state.get());
 		}
 	}
     

Modified: activemq/sandbox/activemq-flow/activemq-broker/src/main/java/org/apache/activemq/apollo/broker/VirtualHost.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-flow/activemq-broker/src/main/java/org/apache/activemq/apollo/broker/VirtualHost.java?rev=784736&r1=784735&r2=784736&view=diff
==============================================================================
--- activemq/sandbox/activemq-flow/activemq-broker/src/main/java/org/apache/activemq/apollo/broker/VirtualHost.java
(original)
+++ activemq/sandbox/activemq-flow/activemq-broker/src/main/java/org/apache/activemq/apollo/broker/VirtualHost.java
Mon Jun 15 11:42:38 2009
@@ -21,6 +21,8 @@
 
 import org.apache.activemq.Service;
 import org.apache.activemq.apollo.broker.ProtocolHandler.ConsumerContext;
+import org.apache.activemq.broker.store.Store;
+import org.apache.activemq.broker.store.StoreFactory;
 import org.apache.activemq.protobuf.AsciiBuffer;
 import org.apache.activemq.queue.AbstractFlowQueue;
 import org.apache.activemq.queue.ExclusivePersistentQueue;
@@ -38,6 +40,7 @@
     private ArrayList<AsciiBuffer> hostNames = new ArrayList<AsciiBuffer>();
     private Router router;
     private boolean started;
+    private BrokerDatabase database;
 
     public VirtualHost(Broker broker) {
         this.broker = broker;
@@ -64,6 +67,16 @@
     public Router getRouter() {
         return router;
     }
+    
+    public BrokerDatabase getDatabase() {
+        return database;
+    }
+    public void setDatabase(BrokerDatabase database) {
+        this.database = database;
+    }
+    public void setStore(Store store) {
+        database = new BrokerDatabase(store);
+    }
 
     public synchronized void start() throws Exception {
 
@@ -71,9 +84,15 @@
             return;
         }
 
-        router.setDatabase(broker.getDatabase());
+		if ( database == null ) {
+			Store store = StoreFactory.createStore("kaha-db");
+			database = new BrokerDatabase(store);
+		}
+	    database.setDispatcher(broker.getDispatcher());
+	    database.start();
 
-        queueStore.setDatabase(broker.getDatabase());
+        router.setDatabase(database);
+        queueStore.setDatabase(database);
         queueStore.setDispatcher(broker.getDispatcher());
         queueStore.loadQueues();
         // Create Queue instances
@@ -102,7 +121,8 @@
         for (AbstractFlowQueue<MessageDelivery> queue : queueStore.getDurableQueues())
{
             queue.shutdown(true);
         }
-
+        
+        database.stop();
         started = false;
     }
 

Modified: activemq/sandbox/activemq-flow/activemq-broker/src/test/java/org/apache/activemq/broker/BrokerTestBase.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-flow/activemq-broker/src/test/java/org/apache/activemq/broker/BrokerTestBase.java?rev=784736&r1=784735&r2=784736&view=diff
==============================================================================
--- activemq/sandbox/activemq-flow/activemq-broker/src/test/java/org/apache/activemq/broker/BrokerTestBase.java
(original)
+++ activemq/sandbox/activemq-flow/activemq-broker/src/test/java/org/apache/activemq/broker/BrokerTestBase.java
Mon Jun 15 11:42:38 2009
@@ -481,7 +481,7 @@
         broker.addTransportServer(TransportFactory.bind(new URI(bindURI)));
         broker.addConnectUri(connectUri);
         broker.setDispatcher(dispatcher);
-        broker.setStore(createStore(broker));
+        broker.getDefaultVirtualHost().setStore(createStore(broker));
         return broker;
     }
 



Mime
View raw message