tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject tomee git commit: TOMEE-2146 system usage configuration for AMQ broker
Date Wed, 01 Nov 2017 17:54:07 GMT
Repository: tomee
Updated Branches:
  refs/heads/master 108abf0ff -> 118060ddc


TOMEE-2146 system usage configuration for AMQ broker


Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/118060dd
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/118060dd
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/118060dd

Branch: refs/heads/master
Commit: 118060ddc20ae38dbfd5695ef1eb8ecf29abedcb
Parents: 108abf0
Author: Romain Manni-Bucau <rmannibucau@apache.org>
Authored: Wed Nov 1 18:53:55 2017 +0100
Committer: Romain Manni-Bucau <rmannibucau@apache.org>
Committed: Wed Nov 1 18:53:55 2017 +0100

----------------------------------------------------------------------
 .../resource/activemq/ActiveMQ5Factory.java     | 52 ++++++++++++++++++++
 .../resource/activemq/ActiveMQ5FactoryTest.java | 27 ++++++----
 2 files changed, 70 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tomee/blob/118060dd/container/openejb-core/src/main/java/org/apache/openejb/resource/activemq/ActiveMQ5Factory.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/resource/activemq/ActiveMQ5Factory.java
b/container/openejb-core/src/main/java/org/apache/openejb/resource/activemq/ActiveMQ5Factory.java
index ffcd8cb..ae5fc43 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/resource/activemq/ActiveMQ5Factory.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/resource/activemq/ActiveMQ5Factory.java
@@ -28,6 +28,7 @@ import org.apache.activemq.store.PersistenceAdapter;
 import org.apache.activemq.store.PersistenceAdapterFactory;
 import org.apache.activemq.store.jdbc.JDBCPersistenceAdapter;
 import org.apache.activemq.store.memory.MemoryPersistenceAdapter;
+import org.apache.activemq.usage.SystemUsage;
 import org.apache.activemq.util.IntrospectionSupport;
 import org.apache.activemq.util.URISupport;
 import org.apache.openejb.loader.SystemInstance;
@@ -94,12 +95,24 @@ public class ActiveMQ5Factory implements BrokerFactoryHandler {
                 persistenceAdapter = null;
             }
 
+            final String systemUsage = params.remove("systemUsage");
+            final SystemUsage systemUsageInstance;
+            if ("true".equalsIgnoreCase(systemUsage)) {
+                systemUsageInstance = newSystemUsage(params);
+            } else {
+                systemUsageInstance = null;
+            }
+
             final BrokerPlugin[] plugins = createPlugins(params);
             final URI uri = new URI(cleanUpUri(brokerURI.getRawSchemeSpecificPart(), compositeData.getParameters(),
params));
             broker = "broker".equals(uri.getScheme()) ? newDefaultBroker(uri) : BrokerFactory.createBroker(uri);
             if (plugins != null) {
                 broker.setPlugins(plugins);
             }
+
+            if (systemUsageInstance != null) {
+                broker.setSystemUsage(systemUsageInstance);
+            }
             brokers.put(brokerURI, broker);
 
             if (persistenceAdapter != null) {
@@ -259,6 +272,45 @@ public class ActiveMQ5Factory implements BrokerFactoryHandler {
         return broker;
     }
 
+    private SystemUsage newSystemUsage(final Map<String, String> params) {
+        final SystemUsage systemUsage = new SystemUsage();
+
+        {
+            final String memory = params.remove("systemUsage.memory.limit");
+            if (memory != null) {
+                systemUsage.getMemoryUsage().setLimit(Integer.parseInt(memory.trim()));
+            } else {
+                systemUsage.getMemoryUsage().setLimit(1024L * 1024 * 1024);
+            }
+        }
+        {
+            final String memory = params.remove("systemUsage.temp.limit");
+            if (memory != null) {
+                systemUsage.getTempUsage().setLimit(Integer.parseInt(memory.trim()));
+            } else {
+                systemUsage.getTempUsage().setLimit(1024L * 1024 * 1024 * 50);
+            }
+        }
+        {
+            final String memory = params.remove("systemUsage.store.limit");
+            if (memory != null) {
+                systemUsage.getStoreUsage().setLimit(Integer.parseInt(memory.trim()));
+            } else {
+                systemUsage.getStoreUsage().setLimit(1024L * 1024 * 1024 * 100);
+            }
+        }
+        {
+            final String memory = params.remove("systemUsage.scheduler.limit");
+            if (memory != null) {
+                systemUsage.getJobSchedulerUsage().setLimit(Integer.parseInt(memory.trim()));
+            } else {
+                systemUsage.getJobSchedulerUsage().setLimit(1024L * 1024 * 1024);
+            }
+        }
+
+        return systemUsage;
+    }
+
     // forking org.apache.activemq.broker.DefaultBrokerFactory.createBroker() to support
network connector properties
     private BrokerService newDefaultBroker(final URI uri) throws Exception {
         final URISupport.CompositeData compositeData = URISupport.parseComposite(uri);

http://git-wip-us.apache.org/repos/asf/tomee/blob/118060dd/container/openejb-core/src/test/java/org/apache/openejb/resource/activemq/ActiveMQ5FactoryTest.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/test/java/org/apache/openejb/resource/activemq/ActiveMQ5FactoryTest.java
b/container/openejb-core/src/test/java/org/apache/openejb/resource/activemq/ActiveMQ5FactoryTest.java
index c554923..109dc35 100644
--- a/container/openejb-core/src/test/java/org/apache/openejb/resource/activemq/ActiveMQ5FactoryTest.java
+++ b/container/openejb-core/src/test/java/org/apache/openejb/resource/activemq/ActiveMQ5FactoryTest.java
@@ -1,19 +1,18 @@
 /**
- *
  * Licensed to the Apache Software Foundation (ASF) under one or more
  * contributor license agreements.  See the NOTICE file distributed with
  * this work for additional information regarding copyright ownership.
  * The ASF licenses this file to You 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.
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.openejb.resource.activemq;
 
@@ -34,6 +33,16 @@ import static org.junit.Assert.assertTrue;
 
 public class ActiveMQ5FactoryTest {
     @Test
+    public void systemUsage() throws Exception {
+        final URI brokerURI = new URI("amq5factory:broker:(tcp://localhost:" + getNextAvailablePort()
+ ")?" +
+                "systemUsage=true&systemUsage.memory.limit=1024");
+        final BrokerService bs = new ActiveMQ5Factory().createBroker(brokerURI);
+        bs.stop();
+        ActiveMQ5Factory.brokers.remove(brokerURI);
+        assertEquals(1024, bs.getSystemUsage().getMemoryUsage().getLimit());
+    }
+
+    @Test
     public void setPlugins() throws Exception {
         final URI brokerURI = new URI("amq5factory:broker:(tcp://localhost:" + getNextAvailablePort()
+ ")?" +
                 "amq.plugins=jaas&" +


Mime
View raw message