Skip to content
This repository has been archived by the owner on Mar 31, 2023. It is now read-only.

Commit

Permalink
Revert "Have a global and thread local observer in QueryObserverHolder"
Browse files Browse the repository at this point in the history
This reverts commit 141e30f.
  • Loading branch information
albertogpz committed Oct 5, 2021
1 parent 141e30f commit 37d2180
Showing 1 changed file with 4 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
*/
package org.apache.geode.cache.query.internal;


import org.apache.geode.annotations.Immutable;
import org.apache.geode.annotations.internal.MakeNotStatic;

Expand Down Expand Up @@ -46,53 +45,35 @@ public class QueryObserverHolder {
*/
@Immutable
private static final QueryObserver NO_OBSERVER = new QueryObserverAdapter();
/**
* The threadlocal current observer which will be notified of all query events.
*/
private static final ThreadLocal<QueryObserver> _instance = new ThreadLocal<>();

/**
* The current observer which will be notified of all query events.
*/
@MakeNotStatic
private static volatile QueryObserver _globalInstance = NO_OBSERVER;
private static ThreadLocal<QueryObserver> _instance = ThreadLocal.withInitial(() -> NO_OBSERVER);

/**
* Set the given observer to be notified of query events. Returns the current observer.
*/
public static QueryObserver setInstance(QueryObserver observer) {
Support.assertArg(observer != null, "setInstance expects a non-null argument!");
QueryObserver oldObserver;
if (_instance.get() != null) {
oldObserver = _instance.get();
} else {
oldObserver = _globalInstance;
}
QueryObserver oldObserver = _instance.get();
_instance.set(observer);
_globalInstance = observer;
return oldObserver;
}

public static boolean hasObserver() {
if (_instance.get() != null) {
return _instance.get() != NO_OBSERVER;
}
return _globalInstance != NO_OBSERVER;
return _instance.get() != NO_OBSERVER;
}

/** Return the current QueryObserver instance */
public static QueryObserver getInstance() {
if (_instance.get() != null) {
return _instance.get();
}
return _globalInstance;
return _instance.get();
}

/**
* Only for test purposes.
*/
public static void reset() {
_instance.set(NO_OBSERVER);
_globalInstance = NO_OBSERVER;
}
}

0 comments on commit 37d2180

Please sign in to comment.