Skip to content

Instantly share code, notes, and snippets.

Avatar

Vasiliy Zukanov techyourchance

View GitHub Profile
@techyourchance
techyourchance / BaseBusyObservable.java
Created Dec 21, 2019
Base class for Java Observable which needs to be aware of whether it's "busy" and expose this information to its clients
View BaseBusyObservable.java
public abstract class BaseBusyObservable<LISTENER_CLASS> extends BaseObservable<LISTENER_CLASS> {
private final AtomicBoolean mIsBusy = new AtomicBoolean(false);
public final boolean isBusy() {
return mIsBusy.get();
}
/**
* Atomically assert not busy and become busy
@techyourchance
techyourchance / BaseObservable.java
Last active May 8, 2020
Base class for Java Observable
View BaseObservable.java
public abstract class BaseObservable<LISTENER_CLASS> {
private final Object MONITOR = new Object();
private final Set<LISTENER_CLASS> mListeners = new HashSet<>();
public void registerListener(LISTENER_CLASS listener) {
synchronized (MONITOR) {
boolean hadNoListeners = mListeners.size() == 0;
mListeners.add(listener);
You can’t perform that action at this time.