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

org.drools.jsr94.rules.RuleRuntimeImpl Maven / Gradle / Ivy

There is a newer version: 7.2.0.Final
Show newest version
/*
 * Copyright 2005 Red Hat, Inc. and/or its affiliates.
 * 
 * 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.jsr94.rules;

import java.util.List;
import java.util.Map;

import javax.rules.RuleExecutionSetNotFoundException;
import javax.rules.RuleRuntime;
import javax.rules.RuleSession;
import javax.rules.RuleSessionCreateException;
import javax.rules.RuleSessionTypeUnsupportedException;

import org.drools.jsr94.rules.repository.RuleExecutionSetRepository;
import org.drools.jsr94.rules.repository.RuleExecutionSetRepositoryException;

/**
 * The Drools implementation of the RuleRuntime interface which
 * is the access point for runtime execution of RuleExecutionSets.
 * It provides methods to create RuleSession implementation as
 * well as methods to retrieve RuleExecutionSets that have been
 * previously registered using the RuleAdministrator. 

The * RuleRuntime should be accessed through the * RuleServiceProvider. An instance of the * RuleRuntime can be retrieved by calling:

* RuleServiceProvider ruleServiceProvider = * RuleServiceProvider.newInstance();
* RuleRuntime ruleRuntime = ruleServiceProvider.getRuleRuntime(); *
*

Note: the release method must be called on the RuleSession * to clean up all resources used by the RuleSession. * * @see RuleRuntime */ public class RuleRuntimeImpl implements RuleRuntime { private static final long serialVersionUID = 510l; private RuleExecutionSetRepository repository; /** * Create a new RuleRuntimeImpl. */ public RuleRuntimeImpl(final RuleExecutionSetRepository repository) { this.repository = repository; // no special initialization required } /** * Creates a RuleSession implementation using the supplied * Drools-specific rule execution set registration URI. * * @param uri * the URI for the RuleExecutionSet * @param properties * additional properties used to create the * RuleSession implementation. * @param ruleSessionType * the type of rule session to create. * * @throws RuleSessionTypeUnsupportedException * if the ruleSessionType is not supported by Drools or the * RuleExecutionSet * @throws RuleExecutionSetNotFoundException * if the URI could not be resolved into a * RuleExecutionSet * * @return The created RuleSession. */ public RuleSession createRuleSession(final String uri, final Map properties, final int ruleSessionType) throws RuleSessionTypeUnsupportedException, RuleSessionCreateException, RuleExecutionSetNotFoundException { if ( ruleSessionType == RuleRuntime.STATELESS_SESSION_TYPE ) { final StatelessRuleSessionImpl session = new StatelessRuleSessionImpl( uri, properties, this.repository ); return session; } else if ( ruleSessionType == RuleRuntime.STATEFUL_SESSION_TYPE ) { final StatefulRuleSessionImpl session = new StatefulRuleSessionImpl( uri, properties, this.repository ); return session; } throw new RuleSessionTypeUnsupportedException( "invalid session type: " + ruleSessionType ); } /** * Retrieves a List of the URIs that currently have * RuleExecutionSets associated with them. An empty list is * returned is there are no associations. * * @return a List of Strings (URIs) */ public List getRegistrations() { try { return this.repository.getRegistrations(); } catch (RuleExecutionSetRepositoryException e) { String s = "Error while retrieving list of registrations"; throw new RuntimeException(s, e); } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy