X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;ds=sidebyside;f=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2FDatastoreContextPropertiesUpdater.java;fp=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2FDatastoreContextPropertiesUpdater.java;h=7dc01fc8431fd76250a6c364777cd7e77da765c9;hb=f8b768f558e8f77509f1e37de6da382f821c8be0;hp=0000000000000000000000000000000000000000;hpb=f0968198ac30c729b9aad78eafc0e309bcee6865;p=controller.git diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DatastoreContextPropertiesUpdater.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DatastoreContextPropertiesUpdater.java new file mode 100644 index 0000000000..7dc01fc843 --- /dev/null +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DatastoreContextPropertiesUpdater.java @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2017 Pantheon Technologies, s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.controller.cluster.datastore; + +import java.util.Map; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Update DatastoreContext settings on invoke update method. + * + */ +public class DatastoreContextPropertiesUpdater implements AutoCloseable { + + public interface Listener { + void onDatastoreContextUpdated(DatastoreContextFactory contextFactory); + } + + private static final Logger LOG = LoggerFactory.getLogger(DatastoreContextPropertiesUpdater.class); + + private final DatastoreContextIntrospector introspector; + private Listener listener; + + /** + * Base init of updater for DatastoreContext settings with base properties. + * + * @param introspector + * - introspection on DatastoreContext + * @param props + * - base properties + */ + public DatastoreContextPropertiesUpdater(final DatastoreContextIntrospector introspector, + final Map props) { + this.introspector = introspector; + update(props); + } + + public void setListener(final Listener listener) { + this.listener = listener; + } + + public void update(final Map properties) { + LOG.debug("Overlaying settings: {}", properties); + + if (introspector.update(properties) && listener != null) { + listener.onDatastoreContextUpdated(introspector.newContextFactory()); + } + } + + @Override + public void close() { + listener = null; + } +}