Search in sources :

Example 1 with ConfigurationReadOnlyException

use of org.apache.ignite.configuration.ConfigurationReadOnlyException in project ignite-3 by apache.

the class DynamicProperty method update.

/**
 * {@inheritDoc}
 */
@Override
public CompletableFuture<Void> update(T newValue) {
    Objects.requireNonNull(newValue, "Configuration value cannot be null.");
    if (listenOnly) {
        throw listenOnlyException();
    }
    if (readOnly) {
        throw new ConfigurationReadOnlyException("Read only mode: " + keys);
    }
    assert keys instanceof RandomAccess;
    assert !keys.isEmpty();
    ConfigurationSource src = new ConfigurationSource() {

        /**
         * Current index in the {@code keys}.
         */
        private int level = 0;

        /**
         * {@inheritDoc}
         */
        @Override
        public void descend(ConstructableTreeNode node) {
            assert level < keys.size();
            node.construct(keys.get(level++), this, true);
        }

        /**
         * {@inheritDoc}
         */
        @Override
        public <T> T unwrap(Class<T> clazz) {
            assert level == keys.size();
            assert clazz.isInstance(newValue);
            return clazz.cast(newValue);
        }

        /**
         * {@inheritDoc}
         */
        @Override
        public void reset() {
            level = 0;
        }
    };
    // Use resulting tree as update request for the storage.
    return changer.change(src);
}
Also used : ConfigurationSource(org.apache.ignite.internal.configuration.tree.ConfigurationSource) ConfigurationReadOnlyException(org.apache.ignite.configuration.ConfigurationReadOnlyException) RandomAccess(java.util.RandomAccess) ConstructableTreeNode(org.apache.ignite.internal.configuration.tree.ConstructableTreeNode)

Aggregations

RandomAccess (java.util.RandomAccess)1 ConfigurationReadOnlyException (org.apache.ignite.configuration.ConfigurationReadOnlyException)1 ConfigurationSource (org.apache.ignite.internal.configuration.tree.ConfigurationSource)1 ConstructableTreeNode (org.apache.ignite.internal.configuration.tree.ConstructableTreeNode)1