当前位置: 首页>>代码示例>>Java>>正文


Java StatefulKnowledgeSession.insert方法代码示例

本文整理汇总了Java中org.kie.internal.runtime.StatefulKnowledgeSession.insert方法的典型用法代码示例。如果您正苦于以下问题:Java StatefulKnowledgeSession.insert方法的具体用法?Java StatefulKnowledgeSession.insert怎么用?Java StatefulKnowledgeSession.insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.kie.internal.runtime.StatefulKnowledgeSession的用法示例。


在下文中一共展示了StatefulKnowledgeSession.insert方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testFactHandleMarshall

import org.kie.internal.runtime.StatefulKnowledgeSession; //导入方法依赖的package包/类
@Test
public void testFactHandleMarshall() throws JAXBException {
    JAXBContext jaxbContext = getJaxbContext();

    KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
    StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();

    FactHandle fh1 = ksession.insert(new Person("darth", 105));

    Marshaller marshaller = jaxbContext.createMarshaller();
    marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    marshaller.marshal(fh1, baos);

    assertXMLEqual("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n<fact-handle external-form=\"" + fh1.toExternalForm() + "\"/>",
                   new String(baos.toByteArray()));

    Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
    FactHandle fh2 = (FactHandle)unmarshaller.unmarshal(new StringReader(baos.toString()));
    assertEquals(fh1, fh2);
}
 
开发者ID:jboss-integration,项目名称:fuse-bxms-integ,代码行数:22,代码来源:JaxbTest.java

示例2: insertSessionConfigItems

import org.kie.internal.runtime.StatefulKnowledgeSession; //导入方法依赖的package包/类
/**
 * Inserts standard configuration items into a Drools session.
 * 
 * @param session The session into which to insert the configuration items.
 */
protected void insertSessionConfigItems( final StatefulKnowledgeSession session )
{
	session.insert( new DroolsSession( session ) );
	
	if( LoggingConfiguration.LOGGING_ON )
	{
		session.insert( new LoggingConfiguration() );
	}
	
	if( LoggingConfiguration.EVENT_LOGGING_ON )
	{
		session.addEventListener( generateEventLoggingListener() );
	}
}
 
开发者ID:viridian1138,项目名称:SimpleAlgebra_V2,代码行数:20,代码来源:Elem.java

示例3: main

import org.kie.internal.runtime.StatefulKnowledgeSession; //导入方法依赖的package包/类
public static void main(String[] args) {
	//rule,rule2可以放在数据库中,有个唯一code和他们对于,代码要执行规则的时候,根据code从数据库获取出来就OK了,这样自己开发的规则管理系统那边对数据库里的规则进行维护就行了
	String rule = "package com.neo.drools\r\n";
	rule += "import com.neo.drools.model.Message;\r\n";
	rule += "rule \"rule1\"\r\n";
	rule += "\twhen\r\n";
	rule += "Message( status == 1, myMessage : msg )";
	rule += "\tthen\r\n";
	rule += "\t\tSystem.out.println( 1+\":\"+myMessage );\r\n";
	rule += "end\r\n";


	String rule2 = "package com.neo.drools\r\n";
	rule += "import com.neo.drools.model.Message;\r\n";

	rule += "rule \"rule2\"\r\n";
	rule += "\twhen\r\n";
	rule += "Message( status == 2, myMessage : msg )";
	rule += "\tthen\r\n";
	rule += "\t\tSystem.out.println( 2+\":\"+myMessage );\r\n";
	rule += "end\r\n";


	StatefulKnowledgeSession kSession = null;
	try {


		KnowledgeBuilder kb = KnowledgeBuilderFactory.newKnowledgeBuilder();
		//装入规则,可以装入多个
		kb.add(ResourceFactory.newByteArrayResource(rule.getBytes("utf-8")), ResourceType.DRL);
		kb.add(ResourceFactory.newByteArrayResource(rule2.getBytes("utf-8")), ResourceType.DRL);

		KnowledgeBuilderErrors errors = kb.getErrors();
		for (KnowledgeBuilderError error : errors) {
			System.out.println(error);
		}
		KnowledgeBase kBase = KnowledgeBaseFactory.newKnowledgeBase();
		kBase.addKnowledgePackages(kb.getKnowledgePackages());

		kSession = kBase.newStatefulKnowledgeSession();


		Message message1 = new Message();
		message1.setStatus(1);
		message1.setMsg("hello world!");

		Message message2 = new Message();
		message2.setStatus(2);
		message2.setMsg("hi world!");

		kSession.insert(message1);
		kSession.insert(message2);
		kSession.fireAllRules();

	} catch (UnsupportedEncodingException e) {
		e.printStackTrace();
	} finally {
		if (kSession != null)
			kSession.dispose();
	}

}
 
开发者ID:ityouknow,项目名称:drools-examples,代码行数:63,代码来源:DdLoadTest.java

示例4: performInserts

import org.kie.internal.runtime.StatefulKnowledgeSession; //导入方法依赖的package包/类
/**
 * Inserts this elem into a Drools ( <A href="http://drools.org">http://drools.org</A> ) session.
 * 
 * @param session The session in which to insert the elem.
 */
public void performInserts( StatefulKnowledgeSession session )
{
	if(elem != null ) elem.performInserts( session );
	session.insert( this );
}
 
开发者ID:viridian1138,项目名称:SimpleAlgebra_V2,代码行数:11,代码来源:SymbolicPlaceholder.java

示例5: processDaqHg

import org.kie.internal.runtime.StatefulKnowledgeSession; //导入方法依赖的package包/类
/**
 * Executes a DaqHg (Drools As a Query language for HyperGraphDB) query.
 * 
 * @param drlPath The path to the Drools query description.
 * @param context The context for the query execution.
 * @param resultHandler The handler for the query results.
 */
public void processDaqHg( String drlPath , 
		DaqHgContext<T> context , DaqHgResultHandler<T> resultHandler )
{
	OptimizerFactory.setDefaultOptimizer( OptimizerFactory.SAFE_REFLECTIVE );
	
	KnowledgeBuilder builder = KnowledgeBuilderFactory.newKnowledgeBuilder();
	
	builder.add( ResourceFactory.newClassPathResource( drlPath )  , 
			ResourceType.DRL );
	
	KnowledgeBase knowledgeBase = KnowledgeBaseFactory.newKnowledgeBase();
	knowledgeBase.addKnowledgePackages( builder.getKnowledgePackages() );
	
	StatefulKnowledgeSession session = knowledgeBase.newStatefulKnowledgeSession();
	
	context.setResultHandler( resultHandler );
	
	session.insert( context );
			
	session.fireAllRules();

	session.dispose();
	
}
 
开发者ID:viridian1138,项目名称:SimpleAlgebra_V2,代码行数:32,代码来源:DaqHg.java

示例6: testSort

import org.kie.internal.runtime.StatefulKnowledgeSession; //导入方法依赖的package包/类
/**
 * Verifies that Drools ( <A href="http://drools.org">http://drools.org</A> ) constructs a sorting algorithm from a set of heuristics.
 * Note: this is only intended to be notional, and one should use something different when efficient execution is desired.
 */
public void testSort()
{
	
	OptimizerFactory.setDefaultOptimizer( OptimizerFactory.SAFE_REFLECTIVE );
	
	KnowledgeBuilder builder = KnowledgeBuilderFactory.newKnowledgeBuilder();
	
	builder.add( ResourceFactory.newClassPathResource( "test_simplealgebra/sort_test/sort.drl" )  , 
			ResourceType.DRL );
	
	KnowledgeBase knowledgeBase = KnowledgeBaseFactory.newKnowledgeBase();
	knowledgeBase.addKnowledgePackages( builder.getKnowledgePackages() );
	
	StatefulKnowledgeSession session = knowledgeBase.newStatefulKnowledgeSession();
	
	session.insert( new DroolsSession( session ) );
	
	final Random rand = new Random( 65432 );
	
	SortNode<DoubleElem> currentSort = null;
	
	for( int count = 0 ; count < 10 ; count++ )
	{
		SortNode<DoubleElem> node = new SortNode<DoubleElem>( new DoubleElem( rand.nextDouble() ) , currentSort );
		currentSort = node;
		session.insert( node );
		session.insert( node.sortValue );
	}
	
	SortPlaceholder<DoubleElem> placeholder = new SortPlaceholder<DoubleElem>( currentSort );
	
	session.insert( placeholder );
			
	session.fireAllRules();

	session.dispose();
	
	SortNode<DoubleElem> prev = null;
	SortNode<DoubleElem> nxt = placeholder.getElem();
	
	while( nxt != null )
	{
		prev = nxt;
		nxt = prev.next;
		
		if( ( prev != null ) && ( nxt != null ) )
		{
			Assert.assertTrue( nxt.sortValue.compareTo( prev.sortValue ) >= 0 );
		}
		
	}
	
	
}
 
开发者ID:viridian1138,项目名称:SimpleAlgebra_V2,代码行数:59,代码来源:TestSort.java

示例7: performInserts

import org.kie.internal.runtime.StatefulKnowledgeSession; //导入方法依赖的package包/类
/**
 * Inserts this elem into a Drools ( <A href="http://drools.org">http://drools.org</A> ) session.
 * 
 * @param session The session in which to insert the elem.
 */
public void performInserts( StatefulKnowledgeSession session )
{
	session.insert( this );
}
 
开发者ID:viridian1138,项目名称:SimpleAlgebra_V2,代码行数:10,代码来源:Elem.java


注:本文中的org.kie.internal.runtime.StatefulKnowledgeSession.insert方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。