blob: e4094e672b93dfb086a6977891a4decc3932cd91 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.component.provider;
import com.google.common.util.concurrent.ExecutionList;
import java.util.concurrent.Executor;
/**
* A convenience superclass for listenable freezables.
*
* @author bratseth
* @since 5.1.13
*/
public class ListenableFreezableClass extends FreezableClass implements ListenableFreezable {
private ExecutionList executionList = new ExecutionList();
/**
* Freezes this class to prevent further changes. Override this to freeze internal data
* structures and dependent objects. Overrides must call super.
* Calling freeze on an already frozen registry must have no effect.
* <p>
* Notifies listeners that freezing has happened.
*/
public synchronized void freeze() {
super.freeze();
executionList.execute();
}
/** Adds a listener which will be invoked when this has become frozen. */
@Override
public void addFreezeListener(Runnable runnable, Executor executor) {
executionList.add(runnable,executor);
}
/** Clones this. The clone is <i>not</i> frozen and has no listeners. */
@Override
public ListenableFreezableClass clone() {
ListenableFreezableClass clone=(ListenableFreezableClass)super.clone();
clone.executionList = new ExecutionList();
return clone;
}
}
|