Preventing access to object if it is being updated
<p>Wondering if anyone could help out with this scenario - </p>

<p>I have a class (Processor) that I configure using Netflix's Archaius properties which is a simple wrapper around ElasticSearch Java BulkProcessor. I also hook up some callbacks to the properties so if a value changes, the BulkProcessor properties should get updated as well. My problem is, BulkProcessor is immutable, and the only way to update a property is to close an instance and create a new one. I don't want anything to call any method from my class while the callback is being invoked - is there a way to do this with Java? </p>

<p>Edit: While I could update configuration files and restart a service, I am trying to avoid that.</p>

<p>My current thinking was to use an AtomicBoolean to indicate if the class is updating - if true, then access to the class is blocked, which doesn't seem very efficient -</p>

<pre><code>// Processor.class
class Processor {
    public Processor() {
        this.bulkProcessor = /** BulkProcessor setup **/
        this.updating = new AtomicBoolean(false);
    }
    public void add(Object payload) {
        while (updating.get()) {
            // Do something here to prevent access when updating
        }
        bulkProcessor.add(payload);
    }
    /** The callback method used by Dynamic*Property **/
    public void update() {
        updating.set(true);
        bulkProcessor.awaitClose(30L, TimeUnit.SECONDS);
        bulkProcessor = /** BulkProcessor setup **/
        updating.set(false);
    }
}
</code></pre>

<p>Any help or pointers is much appreciated!</p>