org.drools.impl.adapters.StatelessKnowledgeSessionAdapter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of knowledge-api Show documentation
Show all versions of knowledge-api Show documentation
The Drools and jBPM public API which is backwards compatible between releases.
package org.drools.impl.adapters;
import org.drools.command.Command;
import org.drools.event.process.ProcessEventListener;
import org.drools.event.rule.AgendaEventListener;
import org.drools.event.rule.WorkingMemoryEventListener;
import org.drools.runtime.Globals;
import org.kie.api.event.rule.RuleRuntimeEventListener;
import org.kie.internal.runtime.StatelessKnowledgeSession;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
public class StatelessKnowledgeSessionAdapter implements org.drools.runtime.StatelessKnowledgeSession {
private final StatelessKnowledgeSession delegate;
private final Map wimListeners = new HashMap();
private final Map processListeners = new HashMap();
private final Map agendaListeners = new HashMap();
public StatelessKnowledgeSessionAdapter(StatelessKnowledgeSession delegate) {
this.delegate = delegate;
}
public Globals getGlobals() {
return new GlobalsAdapter(delegate.getGlobals());
}
public void setGlobal(String identifer, Object value) {
delegate.setGlobal(identifer, value);
}
public T execute(Command command) {
throw new UnsupportedOperationException("This operation is no longer supported");
}
public void addEventListener(ProcessEventListener listener) {
org.kie.api.event.process.ProcessEventListener adapted = new ProcessEventListenerAdapter(listener);
processListeners.put(listener, adapted);
delegate.addEventListener(adapted);
}
public void removeEventListener(ProcessEventListener listener) {
delegate.removeEventListener(processListeners.remove(listener));
}
public Collection getProcessEventListeners() {
return processListeners.keySet();
}
public void execute(Object object) {
delegate.execute(object);
}
public void execute(Iterable objects) {
delegate.execute(objects);
}
public void addEventListener(WorkingMemoryEventListener listener) {
RuleRuntimeEventListener adapted = new WorkingMemoryEventListenerAdapter(listener);
wimListeners.put(listener, adapted);
delegate.addEventListener(adapted);
}
public void removeEventListener(WorkingMemoryEventListener listener) {
delegate.removeEventListener(wimListeners.remove(listener));
}
public Collection getWorkingMemoryEventListeners() {
return wimListeners.keySet();
}
public void addEventListener(AgendaEventListener listener) {
org.kie.api.event.rule.AgendaEventListener adapted = new AgendaEventListenerAdapter(listener);
agendaListeners.put(listener, adapted);
delegate.addEventListener(adapted);
}
public void removeEventListener(AgendaEventListener listener) {
delegate.removeEventListener(agendaListeners.remove(listener));
}
public Collection getAgendaEventListeners() {
return agendaListeners.keySet();
}
@Override
public int hashCode() {
return delegate.hashCode();
}
@Override
public boolean equals(Object obj) {
return obj instanceof StatelessKnowledgeSessionAdapter && delegate.equals(((StatelessKnowledgeSessionAdapter)obj).delegate);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy