[jboss-svn-commits] JBL Code SVN: r34383 - in labs/jbossrules/trunk/drools-docs/drools-docs-integration/src/main/docbook/en-US: Chapter-OSGI and 1 other directory.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Thu Jul 29 22:03:32 EDT 2010
Author: mark.proctor at jboss.com
Date: 2010-07-29 22:03:32 -0400 (Thu, 29 Jul 2010)
New Revision: 34383
Modified:
labs/jbossrules/trunk/drools-docs/drools-docs-integration/src/main/docbook/en-US/Chapter-Commands/Section-Commands/Section-InsertElementsCommand.xml
labs/jbossrules/trunk/drools-docs/drools-docs-integration/src/main/docbook/en-US/Chapter-Commands/Section-Commands/Section-InsertObjectCommand.xml
labs/jbossrules/trunk/drools-docs/drools-docs-integration/src/main/docbook/en-US/Chapter-OSGI/Chapter-OSGI.xml
Log:
-updated commands
-updated osgi docs
Modified: labs/jbossrules/trunk/drools-docs/drools-docs-integration/src/main/docbook/en-US/Chapter-Commands/Section-Commands/Section-InsertElementsCommand.xml
===================================================================
--- labs/jbossrules/trunk/drools-docs/drools-docs-integration/src/main/docbook/en-US/Chapter-Commands/Section-Commands/Section-InsertElementsCommand.xml 2010-07-30 02:00:34 UTC (rev 34382)
+++ labs/jbossrules/trunk/drools-docs/drools-docs-integration/src/main/docbook/en-US/Chapter-Commands/Section-Commands/Section-InsertElementsCommand.xml 2010-07-30 02:03:32 UTC (rev 34383)
@@ -1,9 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<section version="5.0"
xsi:schemaLocation="http://docbook.org/ns/docbook http://www.docbook.org/xml/5.0/xsd/docbook.xsd http://www.w3.org/1999/xlink http://www.docbook.org/xml/5.0/xsd/xlink.xsd"
- xml:base="../../" xmlns="http://docbook.org/ns/docbook" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xlink="http://www.w3.org/1999/xlink"
- xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:ns="http://docbook.org/ns/docbook">
+ xml:base="../../" xmlns="http://docbook.org/ns/docbook"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ xmlns:xlink="http://www.w3.org/1999/xlink"
+ xmlns:xi="http://www.w3.org/2001/XInclude"
+ xmlns:ns="http://docbook.org/ns/docbook">
<title>InsertElementsCommand</title>
<para></para>
@@ -59,6 +62,14 @@
<entry>false</entry>
</row>
+
+ <row>
+ <entry>entryPoint</entry>
+
+ <entry>Entrypoint for the insertion</entry>
+
+ <entry>false</entry>
+ </row>
</tbody>
</tgroup>
</table>
@@ -66,15 +77,18 @@
<listitem>
<para>Command creation</para>
- <programlisting role="JAVA">BatchExecutionCommand command = new BatchExecutionCommand();
-command.setLookup("ksession1");
-InsertElementsCommand insertElementsCommand = new InsertElementsCommand();
+
+ <programlisting role="JAVA">List<Command> cmds = ArrayList<Command>();
+
List<Object> objects = new ArrayList<Object>();
objects.add(new Person("john", 25));
objects.add(new Person("sarah", 35));
-insertElementsCommand.setObjects(objects);
-command.getCommands().add(insertElementsCommand);</programlisting>
+Command insertElementsCommand = CommandFactory.newInsertElements( objects );
+cmds.add( insertElementsCommand );
+
+BatchExecutionCommand command = CommandFactory.createBatchExecution(cmds, "ksession1" );</programlisting>
+
<para></para>
</listitem>
Modified: labs/jbossrules/trunk/drools-docs/drools-docs-integration/src/main/docbook/en-US/Chapter-Commands/Section-Commands/Section-InsertObjectCommand.xml
===================================================================
--- labs/jbossrules/trunk/drools-docs/drools-docs-integration/src/main/docbook/en-US/Chapter-Commands/Section-Commands/Section-InsertObjectCommand.xml 2010-07-30 02:00:34 UTC (rev 34382)
+++ labs/jbossrules/trunk/drools-docs/drools-docs-integration/src/main/docbook/en-US/Chapter-Commands/Section-Commands/Section-InsertObjectCommand.xml 2010-07-30 02:03:32 UTC (rev 34383)
@@ -1,9 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<section version="5.0"
xsi:schemaLocation="http://docbook.org/ns/docbook http://www.docbook.org/xml/5.0/xsd/docbook.xsd http://www.w3.org/1999/xlink http://www.docbook.org/xml/5.0/xsd/xlink.xsd"
- xml:base="../../" xmlns="http://docbook.org/ns/docbook" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xlink="http://www.w3.org/1999/xlink"
- xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:ns="http://docbook.org/ns/docbook">
+ xml:base="../../" xmlns="http://docbook.org/ns/docbook"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ xmlns:xlink="http://www.w3.org/1999/xlink"
+ xmlns:xi="http://www.w3.org/2001/XInclude"
+ xmlns:ns="http://docbook.org/ns/docbook">
<title>InsertObjectCommand</title>
<para></para>
@@ -58,6 +61,14 @@
<entry>false</entry>
</row>
+
+ <row>
+ <entry>entryPoint</entry>
+
+ <entry>Entrypoint for the insertion</entry>
+
+ <entry>false</entry>
+ </row>
</tbody>
</tgroup>
</table>
@@ -65,13 +76,15 @@
<listitem>
<para>Command creation</para>
- <programlisting role="JAVA">BatchExecutionCommand command = new BatchExecutionCommand();
-command.setLookup("ksession1");
-InsertObjectCommand insertObjectCommand = new InsertObjectCommand(new Person("john", 25));
-insertObjectCommand.setOutIdentifier("john");
-insertObjectCommand.setReturnObject(false);
-command.getCommands().add(insertObjectCommand);</programlisting>
+ <programlisting role="JAVA">List<Command> cmds = ArrayList<Command>();
+
+Command insertObjectCommand = CommandFactory.newInsert(new Person("john", 25), "john", false, null);
+cmds.add( insertObjectCommand );
+
+BatchExecutionCommand command = CommandFactory.createBatchExecution(cmds, "ksession1" );
+</programlisting>
+
<para></para>
</listitem>
@@ -83,7 +96,7 @@
<para>XStream</para>
<programlisting><batch-execution lookup="ksession1">
- <insert out-identifier="john" return-object="false">
+ <insert out-identifier="john" entry-point="my stream" return-object="false">
<org.drools.test.Person>
<name>john</name>
<age>25</age>
@@ -97,7 +110,7 @@
<listitem>
<para>JSON</para>
- <programlisting>{"batch-execution":{"lookup":"ksession1","commands":{"insert":{"out-identifier":"john","return-object":false,"object":{"org.drools.test.Person":{"name":"john","age":25}}}}}}
+ <programlisting>{"batch-execution":{"lookup":"ksession1","commands":{"insert":{"entry-point":"my stream", "out-identifier":"john","return-object":false,"object":{"org.drools.test.Person":{"name":"john","age":25}}}}}}
</programlisting>
<para></para>
@@ -108,7 +121,7 @@
<programlisting><?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<batch-execution lookup="ksession1">
- <insert out-identifier="john">
+ <insert out-identifier="john" entry-point="my stream" >
<object xsi:type="person" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<age>25</age>
<name>john</name>
Modified: labs/jbossrules/trunk/drools-docs/drools-docs-integration/src/main/docbook/en-US/Chapter-OSGI/Chapter-OSGI.xml
===================================================================
--- labs/jbossrules/trunk/drools-docs/drools-docs-integration/src/main/docbook/en-US/Chapter-OSGI/Chapter-OSGI.xml 2010-07-30 02:00:34 UTC (rev 34382)
+++ labs/jbossrules/trunk/drools-docs/drools-docs-integration/src/main/docbook/en-US/Chapter-OSGI/Chapter-OSGI.xml 2010-07-30 02:03:32 UTC (rev 34383)
@@ -1,11 +1,177 @@
<?xml version="1.0" encoding="UTF-8"?>
<chapter version="5.0"
xsi:schemaLocation="http://docbook.org/ns/docbook http://www.docbook.org/xml/5.0/xsd/docbook.xsd http://www.w3.org/1999/xlink http://www.docbook.org/xml/5.0/xsd/xlink.xsd"
- xml:base="../" xmlns="http://docbook.org/ns/docbook" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xlink="http://www.w3.org/1999/xlink"
- xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:ns="http://docbook.org/ns/docbook">
+ xml:base="../" xmlns="http://docbook.org/ns/docbook"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ xmlns:xlink="http://www.w3.org/1999/xlink"
+ xmlns:xi="http://www.w3.org/2001/XInclude"
+ xmlns:ns="http://docbook.org/ns/docbook">
<title>OSGi Integration</title>
- <para>TODO</para>
+ <para>OSGi is a dynamic module system for declarative services. So what does
+ that mean? Each jar in OSGi is called a bundle and has it's own Classloader.
+ Each bundle specifies the packages it exports (makes publicly available) and
+ which packages it imports (external dependencies). OSGi will use this
+ information to wire the classloaders of different bundles together; the key
+ distinction is you don't specify what bundle you depend on, or have a single
+ monolithic classpath, instead you specify your package import and version
+ and OSGi attempts to satisfy this from available bundles.</para>
+ <para>It also supports side by side versioning, so you can have multiple
+ versions of a bundle installed and it'll wire up the correct one. Further to
+ this Bundles can register services for other bundles to use. These services
+ need initialisation, which can cause ordering problems - how do you make
+ sure you don't consume a service before its registered? OSGi has a number of
+ features to help with service composition and ordering. The two main ones
+ are the programmatic ServiceTracker and the xml based Declarative Services.
+ There are also other projects that help with this; Spring DM, iPOJO,
+ Gravity.</para>
+
+ <para>Each of the Drools factories is now also available as a FactoryService
+ interface. You can either have OSGi inject those into a pojo, or retrieve
+ them yourself from OSGi.</para>
+
+ <para>The following modules should work with OSGi;</para>
+
+ <itemizedlist>
+ <listitem>
+ <para>drools-api</para>
+ </listitem>
+
+ <listitem>
+ <para>drools-core</para>
+ </listitem>
+
+ <listitem>
+ <para>drools-compiler</para>
+ </listitem>
+
+ <listitem>
+ <para>drools-templates</para>
+ </listitem>
+
+ <listitem>
+ <para>drools-decisiontables</para>
+ </listitem>
+
+ <listitem>
+ <para>drools-bpmn2 (no persistence)</para>
+ </listitem>
+ </itemizedlist>
+
+ <para>The following Services can be located as OSGi Bundles</para>
+
+ <itemizedlist>
+ <listitem>
+ <para>KnowledgeBuilderFactoryService</para>
+ </listitem>
+
+ <listitem>
+ <para>KnowledgeBaseFactoryService</para>
+ </listitem>
+
+ <listitem>
+ <para>ResourceFactroryService</para>
+ </listitem>
+ </itemizedlist>
+
+ <para> I'll cover injection here. The below example injects the
+ KnowledgeBuilderFacotryService, KnowledgeBaseFactoryService and
+ ResourecFactoryService into the TestComponent pojo.</para>
+
+ <example>
+ <title>Osgi Declarative Services</title>
+
+ <programlisting><scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0">
+<implementation class="testosgi.TestComponent"/>
+
+<reference bind="setKnowledgeBaseFactoryService"
+ unbind="unsetKnowledgeBaseFactoryService"
+ interface="org.drools.KnowledgeBaseFactoryService"
+ />
+
+<reference bind="setResourceFactoryService"
+ unbind="unsetResourceFactoryService"
+ interface="org.drools.io.ResourceFactoryService"
+ />
+
+<reference bind="setKnowledgeBuilderFactoryService"
+ unbind="unsetKnowledgeBuilderFactoryService"
+ interface="org.drools.builder.KnowledgeBuilderFactoryService"
+ target="(org.drools.compiler.DecisionTableProvider=true)" />
+</scr:component></programlisting>
+ </example>
+
+ <para>The TestComponent will only be activated when all of the referenced
+ services are available and injected into the pojo. You'll also notice the
+ "target" attribute for the KnowledgeBuilderFactoryService. The reason for
+ this is that OSGi DS has no built in way to declaratively say which optional
+ services must be present to satisfy your component. As a work around I made
+ any Drools service that has optional services set a property if/when the
+ optional service is available. Filters can then be applied, via the target
+ attribute, to make sure the Service is in a desired state before consuming
+ it. And that is pretty much it :)</para>
+
+ <example>
+ <title>Basic Rule Compilation</title>
+
+ <programlisting>ServiceReference serviceRef = bundleContext.getServiceReference( ServiceRegistry.class.getName() );
+ServiceRegistry registry = (ServiceRegistry) bundleContext.getService( serviceRef );
+
+KnowledgeBuilderFactoryService knowledgeBuilderFactoryService = registry.get( KnowledgeBuilderFactoryService.class );
+
+KnowledgeBaseFactoryService knowledgeBaseFactoryService = registry.get( KnowledgeBaseFactoryService.class );
+ResourceFactoryService resourceFactoryService = registry.get( ResourceFactoryService.class );
+
+KnowledgeBuilderConfiguration kbConf = knowledgeBuilderFactoryService.newKnowledgeBuilderConfiguration( null,
+ getClass().getClassLoader() );
+
+KnowledgeBuilder kbuilder = knowledgeBuilderFactoryService.newKnowledgeBuilder( kbConf );
+ResourceFactoryService resource = resourceFactoryService;
+kbuilder.add( resource.newByteArrayResource( string.getBytes() ),
+ ResourceType.DRL );
+
+if ( kbuilder.hasErrors() ) {
+ System.out.println( kbuilder.getErrors() );
+ throw new RuntimeException( kbuilder.getErrors().toString() );
+}
+
+KnowledgeBaseConfiguration kbaseConf = knowledgeBaseFactoryService.newKnowledgeBaseConfiguration( null,
+ getClass().getClassLoader() );
+
+KnowledgeBase kbase = knowledgeBaseFactoryService.newKnowledgeBase( kbaseConf );
+kbase.addKnowledgePackages( kbuilder.getKnowledgePackages() );
+StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
+</programlisting>
+ </example>
+
+ <example>
+ <title>Decision Table Example</title>
+
+ <programlisting>ServiceReference serviceRef = bundleContext.getServiceReference( ServiceRegistry.class.getName() );
+ServiceRegistry registry = (ServiceRegistry) bundleContext.getService( serviceRef );
+
+KnowledgeBuilderFactoryService knowledgeBuilderFactoryService = registry.get( KnowledgeBuilderFactoryService.class );
+KnowledgeBaseFactoryService knowledgeBaseFactoryService = registry.get( KnowledgeBaseFactoryService.class );
+ResourceFactoryService resourceFactoryService = registry.get( ResourceFactoryService.class );
+
+KnowledgeBaseConfiguration kbaseConf = knowledgeBaseFactoryService.newKnowledgeBaseConfiguration( null,
+ getClass().getClassLoader() );
+
+KnowledgeBuilderConfiguration kbConf = knowledgeBuilderFactoryService.newKnowledgeBuilderConfiguration( null,
+ getClass().getClassLoader() );
+KnowledgeBuilder kbuilder = knowledgeBuilderFactoryService.newKnowledgeBuilder( kbConf );
+kbuilder.add( resourceFactoryService.newClassPathResource( "changeset1Test.xml",
+ Dummy.class ),
+ ResourceType.CHANGE_SET );
+
+kbaseConf = knowledgeBaseFactoryService.newKnowledgeBaseConfiguration( null,
+ getClass().getClassLoader() );
+KnowledgeBase kbase = knowledgeBaseFactoryService.newKnowledgeBase( kbaseConf );
+kbase.addKnowledgePackages( kbuilder.getKnowledgePackages() );
+
+StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
+</programlisting>
+ </example>
</chapter>
More information about the jboss-svn-commits
mailing list