Skip to content

Commit

Permalink
bugfix: museumsvictoria#237 timers could become orphaned (museumsvict…
Browse files Browse the repository at this point in the history
…oria#238)

Bugfix thanks to automatic.com.au
  • Loading branch information
justparking authored and scroix committed Apr 1, 2024
1 parent 4c6ede4 commit bb99817
Showing 1 changed file with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public class ManagedToolkit {
/**
* (for locking / synchronisation)
*/
private Object _lock = new Object();
private final Object _lock = new Object();

/**
* Keeps track of the number of threads in use.
Expand Down Expand Up @@ -271,6 +271,9 @@ public <T> ManagedToolkit call(final boolean threadSafe,
throw new IllegalArgumentException("No function provided.");

synchronized (_lock) {
if (_closed)
throw new IllegalStateException("Node is closed.");

final TimerEntry entry = new TimerEntry();
entry.timerTask = s_timers.schedule(s_threadPool, new TimerTask() {

Expand Down Expand Up @@ -335,6 +338,9 @@ public void releaseCalls() {
*/
public ManagedTimer createTimer(H0 func, long delay, long interval, boolean stopped) {
synchronized (_lock) {
if (_closed)
throw new IllegalStateException("Node is closed.");

// create a timer (will be stopped)
ManagedTimer timer = new ManagedTimer(func, stopped, _threadStateHandler, s_timers, s_threadPool, _timerExceptionHandler, _callbackQueue);

Expand Down Expand Up @@ -631,6 +637,9 @@ public ManagedNode createNode(String name) {
throw new IllegalArgumentException("Name cannot be empty");

synchronized (_lock) {
if (_closed)
throw new IllegalStateException("Node is closed.");

ManagedNode node = new ManagedNode(new SimpleName(name), _callbackQueue, _threadStateHandler);

_managedNodes.add(node);
Expand All @@ -647,6 +656,9 @@ public ManagedNode createSubnode(String suffix) {
throw new IllegalArgumentException("Suffix cannot be empty");

synchronized (_lock) {
if (_closed)
throw new IllegalStateException("Node is closed.");

ManagedNode node = new ManagedNode(new SimpleName(Nodel.reduce(_node.getName().getOriginalName(), true) + " " + suffix), _callbackQueue, _threadStateHandler);

_managedNodes.add(node);
Expand Down Expand Up @@ -979,6 +991,9 @@ public NodelHTTPClient getHttpClient() {
*/
public String getURL(String urlStr, String method, Map<String, String> query, String username, String password, Map<String, String> headers, String contentType, String post,
Integer connectTimeout, Integer readTimeout, boolean resultWithHeaders) throws IOException {
if (_closed)
throw new IllegalStateException("Node is closed.");

return getHttpClient().makeSimpleRequest(urlStr, method, query, username, password, headers, contentType, post, connectTimeout, readTimeout);
}

Expand Down

0 comments on commit bb99817

Please sign in to comment.