Search in sources :

Example 11 with ConfiguredObject

use of org.apache.qpid.server.model.ConfiguredObject in project qpid-broker-j by apache.

the class ConfiguredObjectQueryTest method testQuery_EnumEquality.

public void testQuery_EnumEquality() {
    final UUID objectUuid = UUID.randomUUID();
    ConfiguredObject obj = createCO(new HashMap<String, Object>() {

        {
            put(ConfiguredObject.ID, objectUuid);
            put(ENUM_ATTR, Snakes.PYTHON);
            put(ENUM2_ATTR, Snakes.PYTHON);
        }
    });
    _objects.add(obj);
    _query = new ConfiguredObjectQuery(_objects, String.format("%s", ConfiguredObject.ID), String.format("%s = '%s'", ENUM_ATTR, Snakes.PYTHON));
    List<List<Object>> results = _query.getResults();
    assertEquals("Unexpected number of results - enumAttr equality with enum constant", 1, results.size());
    List<Object> row = _query.getResults().iterator().next();
    assertEquals("Unexpected row", objectUuid, row.get(0));
    _query = new ConfiguredObjectQuery(_objects, String.format("%s", ConfiguredObject.ID), String.format("'%s' = %s", Snakes.PYTHON, ENUM_ATTR));
    results = _query.getResults();
    assertEquals("Unexpected number of results - enum constant equality with enumAttr", 1, results.size());
    row = _query.getResults().iterator().next();
    assertEquals("Unexpected row", objectUuid, row.get(0));
    _query = new ConfiguredObjectQuery(_objects, String.format("%s", ConfiguredObject.ID), String.format("%s <> '%s'", ENUM_ATTR, "toad"));
    results = _query.getResults();
    assertEquals("Unexpected number of results - enumAttr not equal enum constant", 1, results.size());
    _query = new ConfiguredObjectQuery(_objects, String.format("%s", ConfiguredObject.ID), String.format("%s = %s", ENUM_ATTR, ENUM2_ATTR));
    results = _query.getResults();
    assertEquals("Unexpected number of results - two attributes of type enum", 1, results.size());
}
Also used : ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) ArrayList(java.util.ArrayList) List(java.util.List) UUID(java.util.UUID)

Example 12 with ConfiguredObject

use of org.apache.qpid.server.model.ConfiguredObject in project qpid-broker-j by apache.

the class ConfiguredObjectQueryTest method testSelectClause.

public void testSelectClause() {
    final UUID objectUuid = UUID.randomUUID();
    ConfiguredObject obj = createCO(new HashMap<String, Object>() {

        {
            put(ConfiguredObject.ID, objectUuid);
            put(NUMBER_ATTR, 1234);
        }
    });
    _objects.add(obj);
    _query = new ConfiguredObjectQuery(_objects, String.format("%s,%s", ConfiguredObject.ID, NUMBER_ATTR), null);
    List<List<Object>> results = _query.getResults();
    assertEquals("Unexpected number of results", 1, results.size());
    final List<String> headers = _query.getHeaders();
    assertEquals("Unexpected headers", Lists.newArrayList(ConfiguredObject.ID, NUMBER_ATTR), headers);
    final Iterator<List<Object>> iterator = results.iterator();
    List<Object> row = iterator.next();
    assertEquals("Unexpected row", Lists.newArrayList(objectUuid, 1234), row);
}
Also used : ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) ArrayList(java.util.ArrayList) List(java.util.List) UUID(java.util.UUID)

Example 13 with ConfiguredObject

use of org.apache.qpid.server.model.ConfiguredObject in project qpid-broker-j by apache.

the class ConfiguredObjectToMapConverterTest method createTestModel.

private Model createTestModel() {
    Model model = mock(Model.class);
    final List<Class<? extends ConfiguredObject>> list = new ArrayList<Class<? extends ConfiguredObject>>();
    list.add(TestChild.class);
    when(model.getChildTypes(ConfiguredObject.class)).thenReturn(list);
    final ConfiguredObjectTypeRegistry typeRegistry = mock(ConfiguredObjectTypeRegistry.class);
    final Map<String, ConfiguredObjectAttribute<?, ?>> attrTypes = mock(Map.class);
    when(attrTypes.get(any(String.class))).thenReturn(mock(ConfiguredObjectMethodAttribute.class));
    when(typeRegistry.getAttributeTypes(any(Class.class))).thenReturn(attrTypes);
    when(model.getTypeRegistry()).thenReturn(typeRegistry);
    return model;
}
Also used : ConfiguredObjectAttribute(org.apache.qpid.server.model.ConfiguredObjectAttribute) Model(org.apache.qpid.server.model.Model) ArrayList(java.util.ArrayList) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) ConfiguredObjectMethodAttribute(org.apache.qpid.server.model.ConfiguredObjectMethodAttribute) ConfiguredObjectTypeRegistry(org.apache.qpid.server.model.ConfiguredObjectTypeRegistry)

Example 14 with ConfiguredObject

use of org.apache.qpid.server.model.ConfiguredObject in project qpid-broker-j by apache.

the class ConfiguredObjectQuery method filterObjects.

private List<ConfiguredObject<?>> filterObjects(final List<ConfiguredObject<?>> objects, final String whereClause) {
    List<ConfiguredObject<?>> filteredObjects = new ArrayList<>();
    ConfiguredObjectFilterParser parser = new ConfiguredObjectFilterParser();
    parser.setConfiguredObjectExpressionFactory(_expressionFactory);
    try {
        final BooleanExpression<ConfiguredObject> expression = parser.parseWhere(whereClause);
        for (ConfiguredObject<?> object : objects) {
            try {
                if (expression.matches(object)) {
                    filteredObjects.add(object);
                }
            } catch (RuntimeException e) {
                throw new EvaluationException("Error while evaluating object against where clause", e);
            }
        }
    } catch (ParseException | TokenMgrError e) {
        throw new SelectorParsingException("Unable to parse where clause", e);
    }
    return filteredObjects;
}
Also used : SelectorParsingException(org.apache.qpid.server.filter.SelectorParsingException) ArrayList(java.util.ArrayList) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject)

Example 15 with ConfiguredObject

use of org.apache.qpid.server.model.ConfiguredObject in project qpid-broker-j by apache.

the class AbstractServlet method getConfiguredObjectFinder.

protected final ConfiguredObjectFinder getConfiguredObjectFinder(final ConfiguredObject<?> root) {
    ConfiguredObjectFinder finder = _configuredObjectFinders.get(root);
    if (finder == null) {
        finder = new ConfiguredObjectFinder(root);
        final ConfiguredObjectFinder existingValue = _configuredObjectFinders.putIfAbsent(root, finder);
        if (existingValue != null) {
            finder = existingValue;
        } else {
            final AbstractConfigurationChangeListener deletionListener = new AbstractConfigurationChangeListener() {

                @Override
                public void stateChanged(final ConfiguredObject<?> object, final State oldState, final State newState) {
                    if (newState == State.DELETED) {
                        _configuredObjectFinders.remove(root);
                    }
                }
            };
            root.addChangeListener(deletionListener);
            if (root.getState() == State.DELETED) {
                _configuredObjectFinders.remove(root);
                root.removeChangeListener(deletionListener);
            }
        }
    }
    return finder;
}
Also used : State(org.apache.qpid.server.model.State) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) ConfiguredObjectFinder(org.apache.qpid.server.model.ConfiguredObjectFinder) AbstractConfigurationChangeListener(org.apache.qpid.server.model.AbstractConfigurationChangeListener)

Aggregations

ConfiguredObject (org.apache.qpid.server.model.ConfiguredObject)91 ArrayList (java.util.ArrayList)37 HashMap (java.util.HashMap)28 List (java.util.List)23 AbstractConfiguredObject (org.apache.qpid.server.model.AbstractConfiguredObject)22 LinkedHashMap (java.util.LinkedHashMap)20 UUID (java.util.UUID)20 Map (java.util.Map)18 AbstractConfigurationChangeListener (org.apache.qpid.server.model.AbstractConfigurationChangeListener)12 ManagedObject (org.apache.qpid.server.model.ManagedObject)11 Date (java.util.Date)7 TreeMap (java.util.TreeMap)6 CountDownLatch (java.util.concurrent.CountDownLatch)6 InternalMessageHeader (org.apache.qpid.server.message.internal.InternalMessageHeader)6 State (org.apache.qpid.server.model.State)6 Collection (java.util.Collection)5 ConfiguredObjectFinder (org.apache.qpid.server.model.ConfiguredObjectFinder)5 Model (org.apache.qpid.server.model.Model)5 Preference (org.apache.qpid.server.model.preferences.Preference)5 IllegalConfigurationException (org.apache.qpid.server.configuration.IllegalConfigurationException)4