org.mockserver.ui.MockServerEventLogNotifier Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mockserver-core Show documentation
Show all versions of mockserver-core Show documentation
Functionality used by all MockServer modules for matching and expectations
package org.mockserver.ui;
import org.mockserver.log.MockServerEventLog;
import org.mockserver.model.ObjectWithReflectiveEqualsHashCodeToString;
import org.mockserver.scheduler.Scheduler;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
* @author jamesdbloom
*/
public class MockServerEventLogNotifier extends ObjectWithReflectiveEqualsHashCodeToString {
private boolean listenerAdded = false;
private final List listeners = Collections.synchronizedList(new ArrayList<>());
private final Scheduler scheduler;
public MockServerEventLogNotifier(Scheduler scheduler) {
this.scheduler = scheduler;
}
protected void notifyListeners(final MockServerEventLog notifier) {
if (listenerAdded && !listeners.isEmpty()) {
scheduler.submit(() -> {
for (MockServerLogListener listener : listeners.toArray(new MockServerLogListener[0])) {
listener.updated(notifier);
}
});
}
}
public void registerListener(MockServerLogListener listener) {
listeners.add(listener);
listenerAdded = true;
}
public void unregisterListener(MockServerLogListener listener) {
listeners.remove(listener);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy