diff options
| author | Robert Godfrey <rgodfrey@apache.org> | 2014-04-29 10:50:27 +0000 |
|---|---|---|
| committer | Robert Godfrey <rgodfrey@apache.org> | 2014-04-29 10:50:27 +0000 |
| commit | adcecf75d67969485f4e61e76b89caf239d63a39 (patch) | |
| tree | 4bf3c59fd22c72b4ee793da10ead88c3260e00e7 /qpid/java | |
| parent | 7f4570b9a410081c12920da2ee483d42e3169f9e (diff) | |
| download | qpid-python-adcecf75d67969485f4e61e76b89caf239d63a39.tar.gz | |
QPID-5730 : [Java Broker] allow configured object attributes to be maked as not to be persisted
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1590945 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/java')
8 files changed, 317 insertions, 46 deletions
diff --git a/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/virtualhostnode/berkeleydb/BDBHAVirtualHostNode.java b/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/virtualhostnode/berkeleydb/BDBHAVirtualHostNode.java index 0e92ac83de..c135803717 100644 --- a/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/virtualhostnode/berkeleydb/BDBHAVirtualHostNode.java +++ b/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/virtualhostnode/berkeleydb/BDBHAVirtualHostNode.java @@ -63,7 +63,7 @@ public interface BDBHAVirtualHostNode<X extends BDBHAVirtualHostNode<X>> extends @ManagedAttribute(automate = true, defaultValue = "0") int getQuorumOverride(); - @ManagedAttribute(automate = true) + @ManagedAttribute(automate = true, persist = false) String getRole(); @ManagedAttribute(automate = true) diff --git a/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/virtualhostnode/berkeleydb/BDBHAVirtualHostNodeImpl.java b/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/virtualhostnode/berkeleydb/BDBHAVirtualHostNodeImpl.java index 8b2dce4168..9b72440280 100644 --- a/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/virtualhostnode/berkeleydb/BDBHAVirtualHostNodeImpl.java +++ b/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/virtualhostnode/berkeleydb/BDBHAVirtualHostNodeImpl.java @@ -23,7 +23,6 @@ package org.apache.qpid.server.virtualhostnode.berkeleydb; import java.security.PrivilegedAction; import java.util.HashMap; import java.util.Map; -import java.util.UUID; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; @@ -31,7 +30,11 @@ import java.util.concurrent.atomic.AtomicReference; import javax.security.auth.Subject; +import com.sleepycat.je.rep.ReplicatedEnvironment; +import com.sleepycat.je.rep.StateChangeEvent; +import com.sleepycat.je.rep.StateChangeListener; import org.apache.log4j.Logger; + import org.apache.qpid.server.configuration.IllegalConfigurationException; import org.apache.qpid.server.logging.messages.ConfigStoreMessages; import org.apache.qpid.server.model.Broker; @@ -45,7 +48,6 @@ import org.apache.qpid.server.model.VirtualHost; import org.apache.qpid.server.model.VirtualHostNode; import org.apache.qpid.server.plugin.ConfiguredObjectTypeFactory; import org.apache.qpid.server.security.SecurityManager; -import org.apache.qpid.server.store.ConfiguredObjectRecord; import org.apache.qpid.server.store.DurableConfigurationStore; import org.apache.qpid.server.store.VirtualHostStoreUpgraderAndRecoverer; import org.apache.qpid.server.store.berkeleydb.BDBHAVirtualHost; @@ -56,10 +58,6 @@ import org.apache.qpid.server.util.ServerScopedRuntimeException; import org.apache.qpid.server.virtualhost.VirtualHostState; import org.apache.qpid.server.virtualhostnode.AbstractVirtualHostNode; -import com.sleepycat.je.rep.ReplicatedEnvironment; -import com.sleepycat.je.rep.StateChangeEvent; -import com.sleepycat.je.rep.StateChangeListener; - @ManagedObject( category = false, type = "BDB_HA" ) public class BDBHAVirtualHostNodeImpl extends AbstractVirtualHostNode<BDBHAVirtualHostNodeImpl> implements BDBHAVirtualHostNode<BDBHAVirtualHostNodeImpl> { @@ -563,42 +561,6 @@ public class BDBHAVirtualHostNodeImpl extends AbstractVirtualHostNode<BDBHAVirtu } } - // TODO - need a better way of suppressing the persistence of the role field. - @Override - public ConfiguredObjectRecord asObjectRecord() - { - final ConfiguredObjectRecord underlying = super.asObjectRecord(); - return new ConfiguredObjectRecord() - { - - @Override - public String getType() - { - return underlying.getType(); - } - - @Override - public Map<String, ConfiguredObjectRecord> getParents() - { - return underlying.getParents(); - } - - @Override - public UUID getId() - { - return underlying.getId(); - } - - @Override - public Map<String, Object> getAttributes() - { - Map<String, Object> copy = new HashMap<String, Object>(underlying.getAttributes()); - copy.remove(BDBHAVirtualHostNode.ROLE); - return copy; - } - }; - } - private class ReplicaVirtualHost extends BDBHAVirtualHost { ReplicaVirtualHost(Map<String, Object> attributes, VirtualHostNode<?> virtualHostNode) diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/AbstractConfiguredObject.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/AbstractConfiguredObject.java index 3c2763575f..8b0e726c54 100644 --- a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/AbstractConfiguredObject.java +++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/AbstractConfiguredObject.java @@ -843,7 +843,7 @@ public abstract class AbstractConfiguredObject<X extends ConfiguredObject<X>> im return getClass().getSimpleName() + " [id=" + _id + ", name=" + getName() + "]"; } - public ConfiguredObjectRecord asObjectRecord() + public final ConfiguredObjectRecord asObjectRecord() { return new ConfiguredObjectRecord() { @@ -868,9 +868,18 @@ public abstract class AbstractConfiguredObject<X extends ConfiguredObject<X>> im public Map<String, Object> run() { Map<String,Object> actualAttributes = new HashMap<String, Object>(getActualAttributes()); - for(Map.Entry<String,Object> entry : actualAttributes.entrySet()) + Iterator<Map.Entry<String,Object>> attributeIterator = actualAttributes.entrySet().iterator(); + + while(attributeIterator.hasNext()) { - if(entry.getValue() instanceof ConfiguredObject) + Map.Entry<String, Object> entry = attributeIterator.next(); + ConfiguredObjectAttribute<?, ?> attributeDefinition = + _attributeTypes.get(entry.getKey()); + if(attributeDefinition != null && !attributeDefinition.getAnnotation().persist()) + { + attributeIterator.remove(); + } + else if(entry.getValue() instanceof ConfiguredObject) { entry.setValue(((ConfiguredObject)entry.getValue()).getId()); } diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/ManagedAttribute.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/ManagedAttribute.java index 4360e97c7e..53f5fbc0d9 100644 --- a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/ManagedAttribute.java +++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/ManagedAttribute.java @@ -32,5 +32,6 @@ public @interface ManagedAttribute boolean automate() default false; boolean state() default false; boolean mandatory() default false; + boolean persist() default true; String defaultValue() default ""; } diff --git a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/AbstractConfiguredObjectTest.java b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/AbstractConfiguredObjectTest.java new file mode 100644 index 0000000000..8167f915e9 --- /dev/null +++ b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/AbstractConfiguredObjectTest.java @@ -0,0 +1,77 @@ +/* + * + * 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. + * + */ +package org.apache.qpid.server.model; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +import junit.framework.TestCase; + +import org.apache.qpid.server.model.testmodel.TestModel; +import org.apache.qpid.server.model.testmodel.TestRootCategory; +import org.apache.qpid.server.store.ConfiguredObjectRecord; + +public class AbstractConfiguredObjectTest extends TestCase +{ + + + public void testNonPersistAttributes() + { + Model model = TestModel.getInstance(); + + final String objectName = "testNonPersistAttributes"; + TestRootCategory object = + model.getObjectFactory().create(TestRootCategory.class, + Collections.<String, Object>singletonMap(ConfiguredObject.NAME, + objectName)); + + assertEquals(objectName, object.getName()); + assertNull(object.getAutomatedNonPersistedValue()); + assertNull(object.getAutomatedPersistedValue()); + + ConfiguredObjectRecord record = object.asObjectRecord(); + + assertEquals(objectName, record.getAttributes().get(ConfiguredObject.NAME)); + + assertFalse(record.getAttributes().containsKey(TestRootCategory.AUTOMATED_PERSISTED_VALUE)); + assertFalse(record.getAttributes().containsKey(TestRootCategory.AUTOMATED_NONPERSISTED_VALUE)); + + + Map<String,Object> updatedAttributes = new HashMap<>(); + + final String newValue = "newValue"; + + updatedAttributes.put(TestRootCategory.AUTOMATED_PERSISTED_VALUE, newValue); + updatedAttributes.put(TestRootCategory.AUTOMATED_NONPERSISTED_VALUE, newValue); + object.setAttributes(updatedAttributes); + + assertEquals(newValue, object.getAutomatedPersistedValue()); + assertEquals(newValue, object.getAutomatedNonPersistedValue()); + + record = object.asObjectRecord(); + assertEquals(objectName, record.getAttributes().get(ConfiguredObject.NAME)); + assertEquals(newValue, record.getAttributes().get(TestRootCategory.AUTOMATED_PERSISTED_VALUE)); + + assertFalse(record.getAttributes().containsKey(TestRootCategory.AUTOMATED_NONPERSISTED_VALUE)); + + } +} diff --git a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestModel.java b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestModel.java new file mode 100644 index 0000000000..a87ed710a4 --- /dev/null +++ b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestModel.java @@ -0,0 +1,99 @@ +/* + * + * 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. + * + */ +package org.apache.qpid.server.model.testmodel; + +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; + +import org.apache.qpid.server.model.ConfiguredObject; +import org.apache.qpid.server.model.ConfiguredObjectFactory; +import org.apache.qpid.server.model.ConfiguredObjectFactoryImpl; +import org.apache.qpid.server.model.Model; + +public class TestModel extends Model +{ + private static final Model INSTANCE = new TestModel(); + private Class<? extends ConfiguredObject>[] _supportedClasses = + new Class[] { + TestRootCategory.class + }; + + private final ConfiguredObjectFactory _objectFactory; + + private TestModel() + { + this(null); + } + + public TestModel(final ConfiguredObjectFactory objectFactory) + { + _objectFactory = objectFactory == null ? new ConfiguredObjectFactoryImpl(this) : objectFactory; + } + + + @Override + public Collection<Class<? extends ConfiguredObject>> getSupportedCategories() + { + return Arrays.asList(_supportedClasses); + } + + @Override + public Collection<Class<? extends ConfiguredObject>> getChildTypes(final Class<? extends ConfiguredObject> parent) + { + return Collections.emptySet(); + } + + @Override + public Class<? extends ConfiguredObject> getRootCategory() + { + return TestRootCategory.class; + } + + @Override + public Collection<Class<? extends ConfiguredObject>> getParentTypes(final Class<? extends ConfiguredObject> child) + { + return Collections.emptySet(); + } + + @Override + public int getMajorVersion() + { + return 99; + } + + @Override + public int getMinorVersion() + { + return 99; + } + + @Override + public ConfiguredObjectFactory getObjectFactory() + { + return _objectFactory; + } + + public static Model getInstance() + { + return INSTANCE; + } +} diff --git a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestRootCategory.java b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestRootCategory.java new file mode 100644 index 0000000000..c4cf787d56 --- /dev/null +++ b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestRootCategory.java @@ -0,0 +1,38 @@ +/* + * + * 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. + * + */ +package org.apache.qpid.server.model.testmodel; + +import org.apache.qpid.server.model.ConfiguredObject; +import org.apache.qpid.server.model.ManagedAttribute; +import org.apache.qpid.server.model.ManagedObject; + +@ManagedObject( defaultType = "test" ) +public interface TestRootCategory<X extends TestRootCategory<X>> extends ConfiguredObject<X> +{ + String AUTOMATED_PERSISTED_VALUE = "automatedPersistedValue"; + String AUTOMATED_NONPERSISTED_VALUE = "automatedNonPersistedValue"; + + @ManagedAttribute( automate = true ) + String getAutomatedPersistedValue(); + + @ManagedAttribute( automate = true, persist = false ) + String getAutomatedNonPersistedValue(); +} diff --git a/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestRootCategoryImpl.java b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestRootCategoryImpl.java new file mode 100644 index 0000000000..9dccae9646 --- /dev/null +++ b/qpid/java/broker-core/src/test/java/org/apache/qpid/server/model/testmodel/TestRootCategoryImpl.java @@ -0,0 +1,85 @@ +/* + * + * 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. + * + */ +package org.apache.qpid.server.model.testmodel; + +import java.util.Map; + +import org.apache.qpid.server.configuration.updater.CurrentThreadTaskExecutor; +import org.apache.qpid.server.configuration.updater.TaskExecutor; +import org.apache.qpid.server.model.AbstractConfiguredObject; +import org.apache.qpid.server.model.ManagedAttributeField; +import org.apache.qpid.server.model.ManagedObject; +import org.apache.qpid.server.model.ManagedObjectFactoryConstructor; +import org.apache.qpid.server.model.State; + +@ManagedObject( category = false , type = "test" ) +public class TestRootCategoryImpl extends AbstractConfiguredObject<TestRootCategoryImpl> + implements TestRootCategory<TestRootCategoryImpl> +{ + @ManagedAttributeField + private String _automatedPersistedValue; + + @ManagedAttributeField + private String _automatedNonPersistedValue; + + @ManagedObjectFactoryConstructor + public TestRootCategoryImpl(final Map<String, Object> attributes) + { + super(parentsMap(), attributes, newTaskExecutor(), TestModel.getInstance()); + } + + private static CurrentThreadTaskExecutor newTaskExecutor() + { + CurrentThreadTaskExecutor currentThreadTaskExecutor = new CurrentThreadTaskExecutor(); + currentThreadTaskExecutor.start(); + return currentThreadTaskExecutor; + } + + public TestRootCategoryImpl(final Map<String, Object> attributes, + final TaskExecutor taskExecutor) + { + super(parentsMap(), attributes, taskExecutor); + } + + @Override + protected boolean setState(final State currentState, final State desiredState) + { + return false; + } + + @Override + public String getAutomatedPersistedValue() + { + return _automatedPersistedValue; + } + + @Override + public String getAutomatedNonPersistedValue() + { + return _automatedNonPersistedValue; + } + + @Override + public State getState() + { + return null; + } +} |
