org.drools.impl.adapters.KnowledgeRuntimeAdapter 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.KnowledgeBase;
import org.drools.event.process.ProcessEventListener;
import org.drools.event.rule.AgendaEventListener;
import org.drools.event.rule.WorkingMemoryEventListener;
import org.drools.runtime.Calendars;
import org.drools.runtime.Channel;
import org.drools.runtime.Environment;
import org.drools.runtime.ExitPoint;
import org.drools.runtime.Globals;
import org.drools.runtime.KnowledgeSessionConfiguration;
import org.drools.runtime.ObjectFilter;
import org.drools.runtime.process.ProcessInstance;
import org.drools.runtime.process.WorkItemManager;
import org.drools.runtime.rule.Agenda;
import org.drools.runtime.rule.FactHandle;
import org.drools.runtime.rule.LiveQuery;
import org.drools.runtime.rule.QueryResults;
import org.drools.runtime.rule.ViewChangedEventListener;
import org.drools.runtime.rule.WorkingMemoryEntryPoint;
import org.drools.time.SessionClock;
import org.drools.time.SessionPseudoClock;
import org.kie.api.event.rule.RuleRuntimeEventListener;
import org.kie.api.runtime.rule.EntryPoint;
import org.kie.api.runtime.rule.Row;
import org.kie.internal.runtime.KnowledgeRuntime;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import static org.drools.impl.adapters.FactHandleAdapter.adaptFactHandles;
import static org.drools.impl.adapters.ProcessInstanceAdapter.adaptProcessInstances;
public class KnowledgeRuntimeAdapter implements org.drools.runtime.KnowledgeRuntime {
public final KnowledgeRuntime delegate;
private final Map wimListeners = new HashMap();
private final Map processListeners = new HashMap();
private final Map agendaListeners = new HashMap();
public KnowledgeRuntimeAdapter(KnowledgeRuntime delegate) {
this.delegate = delegate;
}
public T getSessionClock() {
final org.kie.api.time.SessionClock delegateClock = delegate.getSessionClock();
if (delegateClock instanceof org.drools.core.time.SessionPseudoClock) {
return (T) new SessionPseudoClock() {
@Override
public long advanceTime(long amount, TimeUnit unit) {
return ((org.drools.core.time.SessionPseudoClock)delegateClock).advanceTime(amount, unit);
}
@Override
public long getCurrentTime() {
return delegateClock.getCurrentTime();
}
};
}
return (T)new SessionClock() {
@Override
public long getCurrentTime() {
return delegateClock.getCurrentTime();
}
};
}
public void setGlobal(String identifier, Object value) {
delegate.setGlobal(identifier, value);
}
public Object getGlobal(String identifier) {
return delegate.getGlobal(identifier);
}
public Globals getGlobals() {
return new GlobalsAdapter(delegate.getGlobals());
}
public Calendars getCalendars() {
return new CalendarsAdapter(delegate.getCalendars());
}
public Environment getEnvironment() {
return new EnvironmentAdapter(delegate.getEnvironment());
}
public KnowledgeBase getKnowledgeBase() {
return new KnowledgeBaseAdapter((org.kie.internal.KnowledgeBase)delegate.getKieBase());
}
public void registerExitPoint(String name, ExitPoint exitPoint) {
throw new UnsupportedOperationException("This operation is no longer supported");
}
public void unregisterExitPoint(String name) {
throw new UnsupportedOperationException("This operation is no longer supported");
}
public void registerChannel(String name, Channel channel) {
delegate.registerChannel(name, new ChannelAdapter(channel));
}
@Override
public void unregisterChannel(String name) {
delegate.unregisterChannel(name);
}
@Override
public Map getChannels() {
Map channels = new HashMap();
for (final Map.Entry entry : delegate.getChannels().entrySet()) {
channels.put(entry.getKey(), new Channel() {
@Override
public void send(Object object) {
entry.getValue().send(object);
}
});
}
return channels;
}
@Override
public KnowledgeSessionConfiguration getSessionConfiguration() {
return new KnowledgeSessionConfigurationAdapter(delegate.getSessionConfiguration());
}
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 ProcessInstance startProcess(String processId) {
return new ProcessInstanceAdapter(delegate.startProcess(processId));
}
public ProcessInstance startProcess(String processId, Map parameters) {
return new ProcessInstanceAdapter(delegate.startProcess(processId, parameters));
}
public ProcessInstance createProcessInstance(String processId, Map parameters) {
return new ProcessInstanceAdapter(delegate.createProcessInstance(processId, parameters));
}
public ProcessInstance startProcessInstance(long processInstanceId) {
return new ProcessInstanceAdapter(delegate.startProcessInstance(processInstanceId));
}
public void signalEvent(String type, Object event) {
delegate.signalEvent(type, event);
}
public void signalEvent(String type, Object event, long processInstanceId) {
delegate.signalEvent(type, event, processInstanceId);
}
public Collection getProcessInstances() {
return adaptProcessInstances(delegate.getProcessInstances());
}
public ProcessInstance getProcessInstance(long processInstanceId) {
return new ProcessInstanceAdapter(delegate.getProcessInstance(processInstanceId));
}
public ProcessInstance getProcessInstance(long processInstanceId, boolean readonly) {
return new ProcessInstanceAdapter(delegate.getProcessInstance(processInstanceId, readonly));
}
public void abortProcessInstance(long processInstanceId) {
delegate.abortProcessInstance(processInstanceId);
}
public WorkItemManager getWorkItemManager() {
return new WorkItemManagerAdapter(delegate.getWorkItemManager());
}
public void halt() {
delegate.halt();
}
public Agenda getAgenda() {
return new AgendaAdapter(delegate.getAgenda());
}
public WorkingMemoryEntryPoint getWorkingMemoryEntryPoint(String name) {
return new WorkingMemoryEntryPointAdapter(delegate.getEntryPoint(name));
}
public Collection extends WorkingMemoryEntryPoint> getWorkingMemoryEntryPoints() {
Collection result = new ArrayList();
for (EntryPoint ep : delegate.getEntryPoints()) {
result.add(new WorkingMemoryEntryPointAdapter(ep));
}
return result;
}
public QueryResults getQueryResults(String query, Object... arguments) {
return new QueryResultsAdapter(delegate.getQueryResults(query, arguments));
}
public LiveQuery openLiveQuery(String query, Object[] arguments, final ViewChangedEventListener listener) {
return new LiveQueryAdapter(delegate.openLiveQuery(query, arguments, new org.kie.api.runtime.rule.ViewChangedEventListener() {
@Override
public void rowInserted(Row row) {
listener.rowAdded(new RowAdapter(row));
}
@Override
public void rowDeleted(Row row) {
listener.rowRemoved(new RowAdapter(row));
}
@Override
public void rowUpdated(Row row) {
listener.rowUpdated(new RowAdapter(row));
}
}));
}
public String getEntryPointId() {
return delegate.getEntryPointId();
}
public FactHandle insert(Object object) {
return new FactHandleAdapter(delegate.insert(object));
}
public void retract(FactHandle handle) {
delegate.retract(((FactHandleAdapter) handle).getDelegate());
}
public void update(FactHandle handle, Object object) {
delegate.update(((FactHandleAdapter) handle).getDelegate(), object);
}
public FactHandle getFactHandle(Object object) {
return new FactHandleAdapter(delegate.getFactHandle(object));
}
public Object getObject(FactHandle factHandle) {
return delegate.getObject(((FactHandleAdapter)factHandle).getDelegate());
}
public Collection
© 2015 - 2024 Weber Informatics LLC | Privacy Policy