[New] Assert that elements being passes are read-only for DefaultObserverHandler
This commit is contained in:
parent
7cf17f0876
commit
67d71173c7
|
@ -15,19 +15,6 @@
|
|||
*/
|
||||
package li.strolch.agent.impl;
|
||||
|
||||
import static li.strolch.model.Tags.AGENT;
|
||||
import static li.strolch.runtime.StrolchConstants.SYSTEM_USER_AGENT;
|
||||
import static li.strolch.utils.collections.SynchronizedCollections.synchronizedMapOfLists;
|
||||
import static li.strolch.utils.helper.StringHelper.formatNanoDuration;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.concurrent.BlockingDeque;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.LinkedBlockingDeque;
|
||||
|
||||
import li.strolch.agent.api.*;
|
||||
import li.strolch.handler.operationslog.OperationsLog;
|
||||
import li.strolch.model.Locator;
|
||||
|
@ -39,6 +26,19 @@ import li.strolch.utils.collections.MapOfLists;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.concurrent.BlockingDeque;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.LinkedBlockingDeque;
|
||||
|
||||
import static li.strolch.model.Tags.AGENT;
|
||||
import static li.strolch.runtime.StrolchConstants.SYSTEM_USER_AGENT;
|
||||
import static li.strolch.utils.collections.SynchronizedCollections.synchronizedMapOfLists;
|
||||
import static li.strolch.utils.helper.StringHelper.formatNanoDuration;
|
||||
|
||||
/**
|
||||
* A simple {@link ObserverHandler} which keeps a reference to all registered {@link Observer Observers} and notifies
|
||||
* them when one of the notify methods are called
|
||||
|
@ -80,10 +80,24 @@ public class DefaultObserverHandler implements ObserverHandler {
|
|||
|
||||
@Override
|
||||
public void notify(ObserverEvent event) {
|
||||
assertReadOnly(event);
|
||||
if (!(event.added.isEmpty() && event.updated.isEmpty() && event.removed.isEmpty()))
|
||||
this.eventQueue.addLast(event);
|
||||
}
|
||||
|
||||
private static void assertReadOnly(ObserverEvent event) {
|
||||
event.added.values().forEach(DefaultObserverHandler::assertReadOnly);
|
||||
event.updated.values().forEach(DefaultObserverHandler::assertReadOnly);
|
||||
event.removed.values().forEach(DefaultObserverHandler::assertReadOnly);
|
||||
}
|
||||
|
||||
private static void assertReadOnly(StrolchRootElement element) {
|
||||
if (!element.isReadOnly())
|
||||
throw new IllegalStateException(
|
||||
"Only allow to update elements which are read-only. Element " + element.getLocator() +
|
||||
" is not read-only!");
|
||||
}
|
||||
|
||||
protected void doUpdates() {
|
||||
while (this.run) {
|
||||
try {
|
||||
|
|
Loading…
Reference in New Issue