jBPM distribution 6.0.0.Alpha9

org.droolsjbpm.services.impl.helpers
Class StatefulKnowledgeSessionDelegate

java.lang.Object
  extended by org.droolsjbpm.services.impl.helpers.StatefulKnowledgeSessionDelegate
All Implemented Interfaces:
KieRuntimeEventManager, ProcessEventManager, WorkingMemoryEventManager, CommandExecutor, KieRuntime, KieSession, ProcessRuntime, StatefulProcessSession, Session, SessionEntryPoint, StatefulRuleSession

public class StatefulKnowledgeSessionDelegate
extends Object
implements KieSession


Constructor Summary
StatefulKnowledgeSessionDelegate(String name, KieSession ksession, SessionManager sessionManager)
           
 
Method Summary
 void abortProcessInstance(long l)
          Aborts the process instance with the given id.
 void addEventListener(AgendaEventListener al)
          Add an event listener.
 void addEventListener(ProcessEventListener pl)
          Add a process event listener.
 void addEventListener(WorkingMemoryEventListener wl)
          Add an event listener.
 ProcessInstance createProcessInstance(String string, Map<String,Object> map)
          Creates a new process instance (but does not yet start it).
 void delete(FactHandle fh)
          Retracts the fact for which the given FactHandle was assigned.
 void dispose()
          Releases all the current session resources, setting up the session for garbage collection.
<T> T
execute(Command<T> cmnd)
          Execute the command and return a ExecutionResults for the results of the Command.
 int fireAllRules()
          Fire all Matches on the Agenda.
 int fireAllRules(AgendaFilter af)
          Fire all Matches on the Agenda
 int fireAllRules(AgendaFilter af, int i)
          Fire all Matches on the Agenda
 int fireAllRules(int i)
          Fire Matches on the Agenda up to the given maximum number of Matches, before returning the control to the application.
 void fireUntilHalt()
          Keeps firing Matches until a halt is called.
 void fireUntilHalt(AgendaFilter af)
          Keeps firing Matches until a halt is called.
 Agenda getAgenda()
          Returns a reference to this session's Agenda.
 Collection<AgendaEventListener> getAgendaEventListeners()
          Returns all event listeners.
 Calendars getCalendars()
           
 Map<String,Channel> getChannels()
           
 SessionEntryPoint getEntryPoint(String string)
          Returns the WorkingMemoryEntryPoint instance associated with the given name.
 String getEntryPointId()
          Returns the String Id of this entry point
 Collection<? extends SessionEntryPoint> getEntryPoints()
          Returns a collection of all available working memory entry points for this session.
 Environment getEnvironment()
           
 long getFactCount()
          Returns the total number of facts currently in this entry point
 FactHandle getFactHandle(Object o)
          Returns the fact handle associated with the given object.
<T extends FactHandle>
Collection<T>
getFactHandles()
          Returns all FactHandles from the current session.
<T extends FactHandle>
Collection<T>
getFactHandles(ObjectFilter of)
          Returns all FactHandles from the current session for which the facts are accepted by the given filter.
 Object getGlobal(String string)
           
 Globals getGlobals()
           
 int getId()
           
 KieBase getKieBase()
          Returns the KieBase reference from which this stateful session was created.
 KieSession getKsession()
           
 Object getObject(FactHandle fh)
          Returns the object associated with the given FactHandle.
 Collection<Object> getObjects()
           Returns all facts from the current session as a Collection.
 Collection<Object> getObjects(ObjectFilter of)
          Returns all facts from the current session that are accepted by the given ObjectFilter.
 Collection<ProcessEventListener> getProcessEventListeners()
          Returns all event listeners.
 ProcessInstance getProcessInstance(long l)
          Returns the process instance with the given id.
 ProcessInstance getProcessInstance(long l, boolean b)
          Returns the process instance with the given id.
 Collection<ProcessInstance> getProcessInstances()
          Returns a collection of currently active process instances.
 QueryResults getQueryResults(String string, Object... os)
          Retrieve the QueryResults of the specified query and arguments
<T extends SessionClock>
T
getSessionClock()
          Returns the session clock instance assigned to this session
 KieSessionConfiguration getSessionConfiguration()
           
 Collection<WorkingMemoryEventListener> getWorkingMemoryEventListeners()
          Returns all event listeners.
 WorkItemManager getWorkItemManager()
          Returns the WorkItemManager related to this session.
 void halt()
          Request the engine to stop firing rules.
 FactHandle insert(Object o)
          Inserts a new fact into this entry point
 LiveQuery openLiveQuery(String string, Object[] os, ViewChangedEventListener vl)
           
 void registerChannel(String string, Channel chnl)
           
 void removeEventListener(AgendaEventListener al)
          Remove an event listener.
 void removeEventListener(ProcessEventListener pl)
          Remove a process event listener.
 void removeEventListener(WorkingMemoryEventListener wl)
          Remove an event listener.
 void retract(FactHandle fh)
          Retracts the fact for which the given FactHandle was assigned.
 void setGlobal(String string, Object o)
          Sets a global value on the internal collection
 void setKsession(org.kie.runtime.StatefulKnowledgeSession ksession)
           
 void signalEvent(String string, Object o)
          Signals the engine that an event has occurred.
 void signalEvent(String string, Object o, long l)
          Signals the process instance that an event has occurred.
 ProcessInstance startProcess(String string)
          Start a new process instance.
 ProcessInstance startProcess(String string, Map<String,Object> map)
          Start a new process instance.
 ProcessInstance startProcessInstance(long l)
          Starts the given process instance (which was created by using createProcesInstance but not yet started).
 void unregisterChannel(String string)
           
 void update(FactHandle fh, Object o)
          Updates the fact for which the given FactHandle was assigned with the new fact set as the second parameter in this method.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StatefulKnowledgeSessionDelegate

public StatefulKnowledgeSessionDelegate(String name,
                                        KieSession ksession,
                                        SessionManager sessionManager)
Method Detail

getKsession

public KieSession getKsession()

setKsession

public void setKsession(org.kie.runtime.StatefulKnowledgeSession ksession)

getId

public int getId()
Specified by:
getId in interface KieSession

dispose

public void dispose()
Description copied from interface: KieSession
Releases all the current session resources, setting up the session for garbage collection. This method must always be called after finishing using the session, or the engine will not free the memory used by the session.

Specified by:
dispose in interface KieSession

getSessionClock

public <T extends SessionClock> T getSessionClock()
Description copied from interface: KieRuntime
Returns the session clock instance assigned to this session

Specified by:
getSessionClock in interface KieRuntime
Returns:

setGlobal

public void setGlobal(String string,
                      Object o)
Description copied from interface: KieRuntime
Sets a global value on the internal collection

Specified by:
setGlobal in interface KieRuntime
Parameters:
string - the global identifier
o - the value assigned to the global identifier

getGlobal

public Object getGlobal(String string)
Specified by:
getGlobal in interface KieRuntime

getGlobals

public Globals getGlobals()
Specified by:
getGlobals in interface KieRuntime

getCalendars

public Calendars getCalendars()
Specified by:
getCalendars in interface KieRuntime

getEnvironment

public Environment getEnvironment()
Specified by:
getEnvironment in interface KieRuntime

getKieBase

public KieBase getKieBase()
Description copied from interface: KieRuntime
Returns the KieBase reference from which this stateful session was created.

Specified by:
getKieBase in interface KieRuntime

registerChannel

public void registerChannel(String string,
                            Channel chnl)
Specified by:
registerChannel in interface KieRuntime

unregisterChannel

public void unregisterChannel(String string)
Specified by:
unregisterChannel in interface KieRuntime

getChannels

public Map<String,Channel> getChannels()
Specified by:
getChannels in interface KieRuntime

getSessionConfiguration

public KieSessionConfiguration getSessionConfiguration()
Specified by:
getSessionConfiguration in interface KieRuntime

halt

public void halt()
Description copied from interface: Session

Request the engine to stop firing rules. If the engine is currently firing a rule, it will finish executing this rule's consequence before stopping.

This method will not remove active Matches from the Agenda. In case the application later wants to continue firing rules from the point where it stopped, it should just call org.kie.runtime.StatefulKnowledgeSession.fireAllRules() or org.kie.runtime.StatefulKnowledgeSession.fireUntilHalt() again.

Specified by:
halt in interface Session

getAgenda

public Agenda getAgenda()
Description copied from interface: Session
Returns a reference to this session's Agenda.

Specified by:
getAgenda in interface Session
Returns:

getEntryPoint

public SessionEntryPoint getEntryPoint(String string)
Description copied from interface: Session
Returns the WorkingMemoryEntryPoint instance associated with the given name.

Specified by:
getEntryPoint in interface Session
Returns:

getEntryPoints

public Collection<? extends SessionEntryPoint> getEntryPoints()
Description copied from interface: Session
Returns a collection of all available working memory entry points for this session.

Specified by:
getEntryPoints in interface Session
Returns:
the collection of all available entry points for this session

getQueryResults

public QueryResults getQueryResults(String string,
                                    Object... os)
Description copied from interface: Session
Retrieve the QueryResults of the specified query and arguments

Specified by:
getQueryResults in interface Session
Parameters:
string - The name of the query.
os - The arguments used for the query
Returns:
The QueryResults of the specified query. If the query does not exist or no results match the query it is empty.

openLiveQuery

public LiveQuery openLiveQuery(String string,
                               Object[] os,
                               ViewChangedEventListener vl)
Specified by:
openLiveQuery in interface Session

addEventListener

public void addEventListener(ProcessEventListener pl)
Description copied from interface: ProcessEventManager
Add a process event listener.

Specified by:
addEventListener in interface ProcessEventManager
Parameters:
pl - the listener to add.

removeEventListener

public void removeEventListener(ProcessEventListener pl)
Description copied from interface: ProcessEventManager
Remove a process event listener.

Specified by:
removeEventListener in interface ProcessEventManager
Parameters:
pl - the listener to remove

getProcessEventListeners

public Collection<ProcessEventListener> getProcessEventListeners()
Description copied from interface: ProcessEventManager
Returns all event listeners.

Specified by:
getProcessEventListeners in interface ProcessEventManager
Returns:
listeners the listeners

addEventListener

public void addEventListener(WorkingMemoryEventListener wl)
Description copied from interface: WorkingMemoryEventManager
Add an event listener.

Specified by:
addEventListener in interface WorkingMemoryEventManager
Parameters:
wl - The listener to add.

removeEventListener

public void removeEventListener(WorkingMemoryEventListener wl)
Description copied from interface: WorkingMemoryEventManager
Remove an event listener.

Specified by:
removeEventListener in interface WorkingMemoryEventManager
Parameters:
wl - The listener to remove.

getWorkingMemoryEventListeners

public Collection<WorkingMemoryEventListener> getWorkingMemoryEventListeners()
Description copied from interface: WorkingMemoryEventManager
Returns all event listeners.

Specified by:
getWorkingMemoryEventListeners in interface WorkingMemoryEventManager
Returns:
listeners The listeners.

addEventListener

public void addEventListener(AgendaEventListener al)
Description copied from interface: WorkingMemoryEventManager
Add an event listener.

Specified by:
addEventListener in interface WorkingMemoryEventManager
Parameters:
al - The listener to add.

removeEventListener

public void removeEventListener(AgendaEventListener al)
Description copied from interface: WorkingMemoryEventManager
Remove an event listener.

Specified by:
removeEventListener in interface WorkingMemoryEventManager
Parameters:
al - The listener to remove.

getAgendaEventListeners

public Collection<AgendaEventListener> getAgendaEventListeners()
Description copied from interface: WorkingMemoryEventManager
Returns all event listeners.

Specified by:
getAgendaEventListeners in interface WorkingMemoryEventManager
Returns:
listeners The listeners.

execute

public <T> T execute(Command<T> cmnd)
Description copied from interface: CommandExecutor
Execute the command and return a ExecutionResults for the results of the Command.

Specified by:
execute in interface CommandExecutor
Returns:

startProcess

public ProcessInstance startProcess(String string)
Description copied from interface: ProcessRuntime
Start a new process instance. The process (definition) that should be used is referenced by the given process id.

Specified by:
startProcess in interface ProcessRuntime
Parameters:
string - The id of the process that should be started
Returns:
the ProcessInstance that represents the instance of the process that was started

startProcess

public ProcessInstance startProcess(String string,
                                    Map<String,Object> map)
Description copied from interface: ProcessRuntime
Start a new process instance. The process (definition) that should be used is referenced by the given process id. Parameters can be passed to the process instance (as name-value pairs), and these will be set as variables of the process instance.

Specified by:
startProcess in interface ProcessRuntime
Parameters:
string - the id of the process that should be started
map - the process variables that should be set when starting the process instance
Returns:
the ProcessInstance that represents the instance of the process that was started

createProcessInstance

public ProcessInstance createProcessInstance(String string,
                                             Map<String,Object> map)
Description copied from interface: ProcessRuntime
Creates a new process instance (but does not yet start it). The process (definition) that should be used is referenced by the given process id. Parameters can be passed to the process instance (as name-value pairs), and these will be set as variables of the process instance. You should only use this method if you need a reference to the process instance before actually starting it. Otherwise, use startProcess.

Specified by:
createProcessInstance in interface ProcessRuntime
Parameters:
string - the id of the process that should be started
map - the process variables that should be set when creating the process instance
Returns:
the ProcessInstance that represents the instance of the process that was created (but not yet started)

startProcessInstance

public ProcessInstance startProcessInstance(long l)
Description copied from interface: ProcessRuntime
Starts the given process instance (which was created by using createProcesInstance but not yet started). This method can only be called once for each process instance. You should only use this method if you need a reference to the process instance before actually starting it. Otherwise, use startProcess.

Specified by:
startProcessInstance in interface ProcessRuntime
Parameters:
l - the id of the process instance that needs to be started
Returns:
the ProcessInstance that represents the instance of the process that was started

signalEvent

public void signalEvent(String string,
                        Object o)
Description copied from interface: ProcessRuntime
Signals the engine that an event has occurred. The type parameter defines which type of event and the event parameter can contain additional information related to the event. All process instances that are listening to this type of (external) event will be notified. For performance reasons, this type of event signaling should only be used if one process instance should be able to notify other process instances. For internal event within one process instance, use the signalEvent method that also include the processInstanceId of the process instance in question.

Specified by:
signalEvent in interface ProcessRuntime
Parameters:
string - the type of event
o - the data associated with this event

signalEvent

public void signalEvent(String string,
                        Object o,
                        long l)
Description copied from interface: ProcessRuntime
Signals the process instance that an event has occurred. The type parameter defines which type of event and the event parameter can contain additional information related to the event. All node instances inside the given process instance that are listening to this type of (internal) event will be notified. Note that the event will only be processed inside the given process instance. All other process instances waiting for this type of event will not be notified.

Specified by:
signalEvent in interface ProcessRuntime
Parameters:
string - the type of event
o - the data associated with this event
l - the id of the process instance that should be signaled

getProcessInstances

public Collection<ProcessInstance> getProcessInstances()
Description copied from interface: ProcessRuntime
Returns a collection of currently active process instances. Note that only process instances that are currently loaded and active inside the engine will be returned. When using persistence, it is likely not all running process instances will be loaded as their state will be stored persistently. It is recommended not to use this method to collect information about the state of your process instances but to use a history log for that purpose.

Specified by:
getProcessInstances in interface ProcessRuntime
Returns:
a collection of process instances currently active in the session

getProcessInstance

public ProcessInstance getProcessInstance(long l)
Description copied from interface: ProcessRuntime
Returns the process instance with the given id. Note that only active process instances will be returned. If a process instance has been completed already, this method will return null.

Specified by:
getProcessInstance in interface ProcessRuntime
Returns:
the process instance with the given id or null if it cannot be found

getProcessInstance

public ProcessInstance getProcessInstance(long l,
                                          boolean b)
Description copied from interface: ProcessRuntime
Returns the process instance with the given id. Note that only active process instances will be returned. If a process instance has been completed already, this method will return null.

Specified by:
getProcessInstance in interface ProcessRuntime
b - if this is true and when using persistence, this process instance will not be tracked and updated by the engine
Returns:
the process instance with the given id or null if it cannot be found

abortProcessInstance

public void abortProcessInstance(long l)
Description copied from interface: ProcessRuntime
Aborts the process instance with the given id. If the process instance has been completed (or aborted), or the process instance cannot be found, this method will throw an IllegalArgumentException.

Specified by:
abortProcessInstance in interface ProcessRuntime

getWorkItemManager

public WorkItemManager getWorkItemManager()
Description copied from interface: ProcessRuntime
Returns the WorkItemManager related to this session. This can be used to register new WorkItemHandlers or to complete (or abort) WorkItems.

Specified by:
getWorkItemManager in interface ProcessRuntime
Returns:
the WorkItemManager related to this session

getEntryPointId

public String getEntryPointId()
Description copied from interface: SessionEntryPoint
Returns the String Id of this entry point

Specified by:
getEntryPointId in interface SessionEntryPoint
Returns:

insert

public FactHandle insert(Object o)
Description copied from interface: SessionEntryPoint
Inserts a new fact into this entry point

Specified by:
insert in interface SessionEntryPoint
Parameters:
o - the fact to be inserted
Returns:
the fact handle created for the given fact

retract

public void retract(FactHandle fh)
Description copied from interface: SessionEntryPoint
Retracts the fact for which the given FactHandle was assigned.

Specified by:
retract in interface SessionEntryPoint
Parameters:
fh - the handle whose fact is to be retracted.

delete

public void delete(FactHandle fh)
Description copied from interface: SessionEntryPoint
Retracts the fact for which the given FactHandle was assigned.

Specified by:
delete in interface SessionEntryPoint
Parameters:
fh - the handle whose fact is to be retracted.

update

public void update(FactHandle fh,
                   Object o)
Description copied from interface: SessionEntryPoint
Updates the fact for which the given FactHandle was assigned with the new fact set as the second parameter in this method.

Specified by:
update in interface SessionEntryPoint
Parameters:
fh - the FactHandle for the fact to be updated.
o - the new value for the fact being updated.

getFactHandle

public FactHandle getFactHandle(Object o)
Description copied from interface: SessionEntryPoint
Returns the fact handle associated with the given object. It is important to note that this method behaves in accordance with the configured assert behaviour for this knowledge base (either IDENTITY or EQUALITY).

Specified by:
getFactHandle in interface SessionEntryPoint
Parameters:
o - the fact for which the fact handle will be returned.
Returns:
the fact handle for the given object, or null in case no fact handle was found for the given object.
See Also:
KnowledgeBaseConfiguration

getObject

public Object getObject(FactHandle fh)
Description copied from interface: SessionEntryPoint
Returns the object associated with the given FactHandle.

Specified by:
getObject in interface SessionEntryPoint
Returns:

getObjects

public Collection<Object> getObjects()
Description copied from interface: SessionEntryPoint

Returns all facts from the current session as a Collection.

This class is not a general-purpose Collection implementation! While this class implements the Collection interface, it intentionally violates Collection general contract, which mandates the use of the equals method when comparing objects.

Instead the approach used when comparing objects with the contains(Object) method is dependent on the WorkingMemory configuration, where it can be configured for Identity or for Equality.

Specified by:
getObjects in interface SessionEntryPoint
Returns:

getObjects

public Collection<Object> getObjects(ObjectFilter of)
Description copied from interface: SessionEntryPoint
Returns all facts from the current session that are accepted by the given ObjectFilter.

Specified by:
getObjects in interface SessionEntryPoint
Parameters:
of - the filter to be applied to the returned collection of facts.
Returns:

getFactHandles

public <T extends FactHandle> Collection<T> getFactHandles()
Description copied from interface: SessionEntryPoint
Returns all FactHandles from the current session.

Specified by:
getFactHandles in interface SessionEntryPoint
Returns:

getFactHandles

public <T extends FactHandle> Collection<T> getFactHandles(ObjectFilter of)
Description copied from interface: SessionEntryPoint
Returns all FactHandles from the current session for which the facts are accepted by the given filter.

Specified by:
getFactHandles in interface SessionEntryPoint
Parameters:
of - the filter to be applied to the returned collection of FactHandles.
Returns:

getFactCount

public long getFactCount()
Description copied from interface: SessionEntryPoint
Returns the total number of facts currently in this entry point

Specified by:
getFactCount in interface SessionEntryPoint
Returns:

fireAllRules

public int fireAllRules()
Description copied from interface: StatefulRuleSession
Fire all Matches on the Agenda.

Specified by:
fireAllRules in interface StatefulRuleSession
Returns:
returns the number of rules fired

fireAllRules

public int fireAllRules(int i)
Description copied from interface: StatefulRuleSession
Fire Matches on the Agenda up to the given maximum number of Matches, before returning the control to the application. In case the application wants to continue firing the rules later, from the point where it stopped, it just needs to call fireAllRules() again.

Specified by:
fireAllRules in interface StatefulRuleSession
Parameters:
i - the maximum number of rules that should be fired
Returns:
returns the number of rules fired

fireAllRules

public int fireAllRules(AgendaFilter af)
Description copied from interface: StatefulRuleSession
Fire all Matches on the Agenda

Specified by:
fireAllRules in interface StatefulRuleSession
Parameters:
af - filters the Matches that may fire
Returns:
returns the number of rules fired

fireAllRules

public int fireAllRules(AgendaFilter af,
                        int i)
Description copied from interface: StatefulRuleSession
Fire all Matches on the Agenda

Specified by:
fireAllRules in interface StatefulRuleSession
Parameters:
af - filters the Matches that may fire
i - the maximum number of rules that should be fired
Returns:
returns the number of rules fired

fireUntilHalt

public void fireUntilHalt()
Description copied from interface: StatefulRuleSession
Keeps firing Matches until a halt is called. If in a given moment, there is no Match to fire, it will wait for an Match to be added to an active agenda group or rule flow group. This blocks the thread until halt is called.

Specified by:
fireUntilHalt in interface StatefulRuleSession

fireUntilHalt

public void fireUntilHalt(AgendaFilter af)
Description copied from interface: StatefulRuleSession
Keeps firing Matches until a halt is called. If in a given moment, there is no Match to fire, it will wait for an Match to be added to an active agenda group or rule flow group. This blocks the thread until halt is called.

Specified by:
fireUntilHalt in interface StatefulRuleSession
Parameters:
af - filters the Matches that may fire

jBPM distribution 6.0.0.Alpha9

Copyright © 2001-2013 JBoss by Red Hat. All Rights Reserved.