You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by or...@apache.org on 2017/10/12 11:05:25 UTC
qpid-broker-j git commit: QPID-7799: [Java Broker] Introduce
operation to set and remove individual context variable
Repository: qpid-broker-j
Updated Branches:
refs/heads/master 538c917e6 -> d8e033abc
QPID-7799: [Java Broker] Introduce operation to set and remove individual context variable
Project: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/commit/d8e033ab
Tree: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/tree/d8e033ab
Diff: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/diff/d8e033ab
Branch: refs/heads/master
Commit: d8e033abc5a228fa5e4de18ec7e4a6aa700dc2bf
Parents: 538c917
Author: Alex Rudyy <or...@apache.org>
Authored: Thu Oct 12 12:04:07 2017 +0100
Committer: Alex Rudyy <or...@apache.org>
Committed: Thu Oct 12 12:04:07 2017 +0100
----------------------------------------------------------------------
.../server/model/AbstractConfiguredObject.java | 17 +++++++
.../qpid/server/model/ConfiguredObject.java | 13 ++++++
.../singleton/AbstractConfiguredObjectTest.java | 49 ++++++++++++++++++++
3 files changed, 79 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/d8e033ab/broker-core/src/main/java/org/apache/qpid/server/model/AbstractConfiguredObject.java
----------------------------------------------------------------------
diff --git a/broker-core/src/main/java/org/apache/qpid/server/model/AbstractConfiguredObject.java b/broker-core/src/main/java/org/apache/qpid/server/model/AbstractConfiguredObject.java
index 4b15161..3b01324 100644
--- a/broker-core/src/main/java/org/apache/qpid/server/model/AbstractConfiguredObject.java
+++ b/broker-core/src/main/java/org/apache/qpid/server/model/AbstractConfiguredObject.java
@@ -3184,6 +3184,23 @@ public abstract class AbstractConfiguredObject<X extends ConfiguredObject<X>> im
return map;
}
+ @Override
+ public String setContextVariable(final String name, final String value)
+ {
+ Map<String, String> context = new LinkedHashMap<>(getContext());
+ String previousValue = context.put(name, value);
+ setAttributes(Collections.singletonMap(CONTEXT, context));
+ return previousValue;
+ }
+
+ @Override
+ public String removeContextVariable(final String name)
+ {
+ Map<String, String> context = new LinkedHashMap<>(getContext());
+ String previousValue = context.remove(name);
+ setAttributes(Collections.singletonMap(CONTEXT, context));
+ return previousValue;
+ }
@Override
public <Y extends ConfiguredObject<Y>> Y findConfiguredObject(Class<Y> clazz, String name)
http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/d8e033ab/broker-core/src/main/java/org/apache/qpid/server/model/ConfiguredObject.java
----------------------------------------------------------------------
diff --git a/broker-core/src/main/java/org/apache/qpid/server/model/ConfiguredObject.java b/broker-core/src/main/java/org/apache/qpid/server/model/ConfiguredObject.java
index a38352f..6f70709 100644
--- a/broker-core/src/main/java/org/apache/qpid/server/model/ConfiguredObject.java
+++ b/broker-core/src/main/java/org/apache/qpid/server/model/ConfiguredObject.java
@@ -176,6 +176,19 @@ public interface ConfiguredObject<X extends ConfiguredObject<X>> extends Context
Map<String, Object> getStatistics(@Param(name = "statistics", defaultValue = "[]",
description = "Optional list of statistic values to retrieve") List<String> statistics);
+ @ManagedOperation(description = "Set context variable with given name to given value."
+ + " Previous value is returned or null if not set directly on configured object.",
+ changesConfiguredObjectState = true,
+ skipAclCheck = true)
+ String setContextVariable(@Param(name = "name", description = "Context variable name") String name,
+ @Param(name = "value", description = "Context variable value") String value);
+
+ @ManagedOperation(description = "Remove context variable with given name."
+ + " Variable value is returned or null if not set directly on configured object.",
+ changesConfiguredObjectState = true,
+ skipAclCheck = true)
+ String removeContextVariable(@Param(name = "name", description = "Context variable name") String name);
+
/**
* Get the names of attributes that are set on this object
*
http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/d8e033ab/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/singleton/AbstractConfiguredObjectTest.java
----------------------------------------------------------------------
diff --git a/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/singleton/AbstractConfiguredObjectTest.java b/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/singleton/AbstractConfiguredObjectTest.java
index e29ac7f..47461b3 100644
--- a/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/singleton/AbstractConfiguredObjectTest.java
+++ b/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/singleton/AbstractConfiguredObjectTest.java
@@ -1111,6 +1111,55 @@ public class AbstractConfiguredObjectTest extends QpidTestCase
assertEquals("Unexpected member of update set", Sets.newHashSet(TestSingleton.DESCRIPTION),
object.takeLastReportedSetAttributes());
}
+
+ public void testSetContextVariable()
+ {
+ final String objectName = "myName";
+ final String contextVariableName = "myContextVariable";
+ final String contextVariableValue = "myContextVariableValue";
+
+ TestSingleton object = _model.getObjectFactory().create(TestSingleton.class,
+ Collections.singletonMap(TestSingleton.NAME, objectName),
+ null);
+
+ String previousValue = object.setContextVariable(contextVariableName, contextVariableValue);
+
+ assertNull("Previous value should be null", previousValue);
+
+ Map<String, String> context = object.getContext();
+ assertTrue("Context variable should be present in context", context.containsKey(contextVariableName));
+ assertEquals("Unexpected context variable", contextVariableValue, context.get(contextVariableName));
+
+ previousValue = object.setContextVariable(contextVariableName, "newValue");
+
+ assertEquals("Unexpected previous value", contextVariableValue, previousValue);
+ }
+
+ public void testRemoveContextVariable()
+ {
+ final String objectName = "myName";
+ final String contextVariableName = "myContextVariable";
+ final String contextVariableValue = "myContextVariableValue";
+
+ Map<String, Object> attributes = new HashMap<>();
+ attributes.put(TestSingleton.NAME, objectName);
+ attributes.put(TestSingleton.CONTEXT, Collections.singletonMap(contextVariableName, contextVariableValue));
+
+ TestSingleton object = _model.getObjectFactory().create(TestSingleton.class, attributes, null);
+
+ Map<String, String> context = object.getContext();
+ assertEquals("Unexpected context variable", contextVariableValue, context.get(contextVariableName));
+
+ String previousValue = object.removeContextVariable(contextVariableName);
+ assertEquals("Unexpected context variable value", contextVariableValue, previousValue);
+
+ context = object.getContext();
+ assertFalse("Context variable should not be present in context", context.containsKey(contextVariableName));
+
+ previousValue = object.removeContextVariable(contextVariableName);
+ assertNull("Previous value should be null", previousValue);
+ }
+
private Subject createTestAuthenticatedSubject(final String username)
{
return new Subject(true,
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org