All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.drools.runtime.rule.WorkingMemoryEntryPoint Maven / Gradle / Ivy

There is a newer version: 5.1.1
Show newest version
/**
 * Copyright 2010 JBoss Inc
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.drools.runtime.rule;

import java.util.Collection;

import org.drools.KnowledgeBaseConfiguration;
import org.drools.runtime.ObjectFilter;

/**
 * 

An entry-point is an abstract channel through where facts are inserted into the engine.

*

Drools 5 supports multiple entry-points into a single StatefulKnowledgeBase: the * default, anonymous entry-point, as well as as many user declared entry points the application * requires.

* *

To get a reference to an entry point, just request the session:

*
 * StatefulKnowledgeSession session = kbase.newStatelessKnowledgeSession();
 * ...
 * WorkingMemoryEntryPoint entrypoint = session.getWorkingMemoryEntryPoint("my entry point");
 * 
*

Once a reference to an entry point is acquired, the application can insert, update and retract facts * to/from that entry-point as usual:

*
 * ...
 * FactHandle factHandle = entrypoint.insert( fact );
 * ...
 * entrypoint.update( factHandle, newFact );
 * ...
 * entrypoint.retract( factHandle );
 * ...
 * 
* */ public interface WorkingMemoryEntryPoint { /** * Returns the String Id of this entry point * * @return */ public String getEntryPointId(); /** * Inserts a new fact into this entry point * * @param object * the fact to be inserted * * @return the fact handle created for the given fact */ FactHandle insert(Object object); /** * Retracts the fact for which the given FactHandle was assigned. * * @param handle the handle whose fact is to be retracted. */ void retract(FactHandle handle); /** * Updates the fact for which the given FactHandle was assigned with the new * fact set as the second parameter in this method. * * @param handle the FactHandle for the fact to be updated. * * @param object the new value for the fact being updated. */ void update(FactHandle handle, Object object); /** * 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). * * @param object * the fact for which the fact handle will be returned. * * @return the fact handle for the given object, or null in case no fact handle was found for the * given object. * * @see KnowledgeBaseConfiguration */ FactHandle getFactHandle(Object object); /** * Returns the object associated with the given FactHandle. * * @param factHandle * @return */ Object getObject(FactHandle factHandle); /** *

* 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.

* * @return */ Collection< Object > getObjects(); /** * Returns all facts from the current session that are accepted by the given ObjectFilter. * * @param filter the filter to be applied to the returned collection of facts. * * @return */ Collection< Object > getObjects(ObjectFilter filter); /** * Returns all FactHandles from the current session. * * @return */ Collection< T > getFactHandles(); /** * Returns all FactHandles from the current session for which the facts are accepted by * the given filter. * * @param filter the filter to be applied to the returned collection of FactHandles. * * @return */ Collection< T > getFactHandles(ObjectFilter filter); /** * Returns the total number of facts currently in this entry point * * @return */ public long getFactCount(); }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy