Re: RE: [rules-users] OSGI, classloading, and imports in KnowledgeBuilder

2009-07-08 Thread msully

Faron - I think I fixed my problem (and without the PackageBuilder stuff) but
I think I cheated :)

In my BundleListener, when I find a Bundle with an .rf file I want to
compile, I do this:
Create an instance of a new Classloader that first delegates class loading
to my BundleListener's Bundle, and if that fails, delegates to the .rf files
Bundle.  I pass this class loader in using a KnowledgeBuilderConfiguration.


BundleClassLoader bclassLoader = new
BundleClassLoader(bundleContext.getBundle(), bundle);
KnowledgeBuilderConfiguration conf = 

KnowledgeBuilderFactory.newKnowledgeBuilderConfiguration(null,
bclassLoader);
KnowledgeBuilder kbuilder =
KnowledgeBuilderFactory.newKnowledgeBuilder(conf);


The Classloader looks much like yours, but each overridden call looks like:


   protected Class findClass(final String name) throws
ClassNotFoundException {
try {
Class clazz =  primeBundle.loadClass(name);
return clazz;
} catch (ClassNotFoundException c) {
if (secondBundle != null) {
 Class clazz2 = secondBundle.loadClass(name);
 return clazz2;
} else {
logger.info("Second is null");
throw c;
}
}
}



Now only my bundles containing rules need to import the classes they need -
my bundle containing the 'FlowManager' that wraps the call to perform does
not.  It allows my core Flow bundle to be totally agnostic to the data
processed in it, while its clients, WorkItemHandlers and flow definition
bundles only import the classes they need.  Hopefully this is a lasting
solution - my Drools usage isn't very complex right now.

I imagine I'd have to get a little more complex if I were to use any
abilities where Drools had to create instances of my domain objects at
process time, but right now that is all handled by WorkItemHandlers that are
registered as services from their own bundles.

Mark - I'd love to help, but I'm just starting with Drools and OSGi right
now, so I'm not sure I know enough yet.

Mike
-- 
View this message in context: 
http://www.nabble.com/OSGI%2C-classloading%2C-and-imports-in-KnowledgeBuilder-tp24099671p24393091.html
Sent from the drools - user mailing list archive at Nabble.com.
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


RE: [rules-users] OSGI, classloading, and imports in KnowledgeBuilder

2009-06-19 Thread msully

Thanks - I started to try something like this, but I found that Drools
Package Builder was using its class classloader for the context - so I
started to override it but Eclipse isn't letting me import PackageBuilder
into my java class.

When I tried getting drools working in OSGI, I found that several different
jars had the same package. The only way I know to get OSGi to resolve this
is to make some of the jars fragments against the remaining one. But when I
do this, Eclipse lets me import-package the package I need to inherit from
in the manifest builder, but it doesn't let me do the import in the Java
editor.

Did you encounter the package issue with the jars? Is there a better way to
solve that?

Thanks,
mike
-- 
View this message in context: 
http://www.nabble.com/OSGI%2C-classloading%2C-and-imports-in-KnowledgeBuilder-tp24099671p24113108.html
Sent from the drools - user mailing list archive at Nabble.com.

___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] OSGI, classloading, and imports in KnowledgeBuilder

2009-06-18 Thread msully

Here's the ClassLoader that let's the import work:
org.springframework.osgi.util.BundleDelegatingClassLoader

OK, I realize this is starting to seem like a question for another board,
but I figured I'd put all the info here since I started here.

If I find the solution elsewhere, I'll share here.
-- 
View this message in context: 
http://www.nabble.com/OSGI%2C-classloading%2C-and-imports-in-KnowledgeBuilder-tp24099671p24099687.html
Sent from the drools - user mailing list archive at Nabble.com.

___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] OSGI, classloading, and imports in KnowledgeBuilder

2009-06-18 Thread msully

Update: The plot thickens.

Sometimes when I'm importing my domain class in the rulesflow, it works, and
sometimes it does not.

This seems to be tied to the class loader that happens to be in the current
thread context.  Sometimes it is
org.eclipse.core.runtime.internal.adaptor.ContextFinder and sometimes it is
another type.  I don't know what class the 'other type' is because it
overrides Object's toString()and I was just doing
getClassLoader().toString(). I've changed it to
getClassLoader().getClass().getName() so I can see what the real object is
if it happens again




msully wrote:
> 
> So I'm playing with Drools in Equinox OSGi, and so far it's behaving quite
> nicely - one bit of weirdness though.
> 
> What I'm trying to do:
> I have a bundle with a 'flow manager' that listens for instances of
> WorkItemHandler in the service broker (well, really my own subinterface
> that has a getName method).  It also listens for new bundles with a
> META-INF/drools directory with *.rf files in them, and parses the .rf
> files it finds there.
> 
> The Flow Manager is itself published as an OSGI Service with a 'perform'
> method.  It encapsulates all of its Drools calls within the perform method
> though - they aren't exposed to clients.
> 
> My test involves a simple start->work item->end workflow.
> 
> I pass in an instance of a class "Tablex" that can be saved to hibernate.
> I also pass in a String that has the table name, and an empty List to get
> the results.
> 
> My .rf file tries to import Tablex.  It declares the three values I
> mention above, and maps them to the work item in the work item definition.
> 
> 
>  
>   
> 
> ...
>   
>  name="org.drools.process.core.datatype.impl.type.ObjectDataType"
> className="my.pkg.Tablex"/>
> 
> ...
>  height="40" >
>   
>   
>   
>   
>   
>  
> 
> 
> 
> In my manifest for my .rf file and for the flow manager (where the parsing
> occurs) I Import-Package Tablex's package.
> 
> When my flow manager tries parsing the rule, it gives an error saying the
> the import failed. BUT, everything still works, and my WorkItemHandler
> works correctly (the WorkItemHandler imports Tablex itself, since it needs
> to manipulate it).
> 
> If I declare my Tablex variable as a java.util.Object in the ruleflow then
> I don't get the error and things also still work.
> 
> If I declare my Tablex as Tablex in the rule flow AND import it in the
> class that does the parsing (it's already 'OSGI' imported to the parsing
> bundle, but now I'm doing a plain old Java import on it) then everything
> works fine with no error message.
> 
> Kind of a hybrid question but I figured I'd start with the Drools folks.
> 
> Any ideas would be appreciated.
> 
> Thanks,
> Mike
> 

-- 
View this message in context: 
http://www.nabble.com/OSGI%2C-classloading%2C-and-imports-in-KnowledgeBuilder-tp24099671p24099685.html
Sent from the drools - user mailing list archive at Nabble.com.

___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


[rules-users] OSGI, classloading, and imports in KnowledgeBuilder

2009-06-18 Thread msully

So I'm playing with Drools in Equinox OSGi, and so far it's behaving quite
nicely - one bit of weirdness though.

What I'm trying to do:
I have a bundle with a 'flow manager' that listens for instances of
WorkItemHandler in the service broker (well, really my own subinterface that
has a getName method).  It also listens for new bundles with a
META-INF/drools directory with *.rf files in them, and parses the .rf files
it finds there.

The Flow Manager is itself published as an OSGI Service with a 'perform'
method.  It encapsulates all of its Drools calls within the perform method
though - they aren't exposed to clients.

My test involves a simple start->work item->end workflow.

I pass in an instance of a class "Tablex" that can be saved to hibernate. I
also pass in a String that has the table name, and an empty List to get the
results.

My .rf file tries to import Tablex.  It declares the three values I mention
above, and maps them to the work item in the work item definition.


 
  

...
  


...

  
  
  
  
  
 



In my manifest for my .rf file and for the flow manager (where the parsing
occurs) I Import-Package Tablex's package.

When my flow manager tries parsing the rule, it gives an error saying the
the import failed. BUT, everything still works, and my WorkItemHandler works
correctly (the WorkItemHandler imports Tablex itself, since it needs to
manipulate it).

If I declare my Tablex variable as a java.util.Object in the ruleflow then I
don't get the error and things also still work.

If I declare my Tablex as Tablex in the rule flow AND import it in the class
that does the parsing (it's already 'OSGI' imported to the parsing bundle,
but now I'm doing a plain old Java import on it) then everything works fine
with no error message.

Kind of a hybrid question but I figured I'd start with the Drools folks.

Any ideas would be appreciated.

Thanks,
Mike
-- 
View this message in context: 
http://www.nabble.com/OSGI%2C-classloading%2C-and-imports-in-KnowledgeBuilder-tp24099671p24099671.html
Sent from the drools - user mailing list archive at Nabble.com.

___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] Is work item configuration needed at run time? Can it be built programmatically?

2009-06-18 Thread msully

Thanks Kris - it did work as you described. Got another issue, which I'll
make another post on.

Thanks again,
Mike 

Kris Verlaenen wrote:
> 
> Mike,
> 
> The work item definitions file is only used in the graphical editor, to
> add custom nodes to the palette.  It is not used at compile or runtime,
> as the variable definitions etc. are all part of the work item itself. 
> So you probably don't need it in your environment.
> 
> Kris
> 
> Quoting msully :
> 
>> 
>> Hi folks,
>> 
>> I'm trying to use Drools Flow in a Spring DM environment.  I've
>> OSGified its
>> jars and things look promising.  The thing is, I want to use Work
>> Items for
>> my domain interface, and I want WorkItemHandler's to come from the
>> service
>> broker.  I can see how most of this would work, except for reading in
>> the
>> workDefinitions.conf for a new work item.  I've down a quick browse
>> through
>> the source code and I think it might be that I don't need the work
>> item
>> configuration file during run time, just for visual rule building. 
>> Anyone
>> know if that is true?
>> 
>> If it is needed, is there an API that I can introduce it into while
>> building
>> the session, the way I can introduce KnowledgePackages/rules files?
>> 
>> Thanks,
>> mike
>> -- 
>> View this message in context:
>>
> http://www.nabble.com/Is-work-item-configuration-needed-at-run-time---Can-it-be-built-programmatically--tp24079237p24079237.html
>> Sent from the drools - user mailing list archive at Nabble.com.
>> 
>> ___
>> rules-users mailing list
>> rules-users@lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/rules-users
>> 
> 
> 
> 
> 
> Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm
> ___
> rules-users mailing list
> rules-users@lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Is-work-item-configuration-needed-at-run-time---Can-it-be-built-programmatically--tp24079237p24099663.html
Sent from the drools - user mailing list archive at Nabble.com.

___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


[rules-users] Is work item configuration needed at run time? Can it be built programmatically?

2009-06-17 Thread msully

Hi folks,

I'm trying to use Drools Flow in a Spring DM environment.  I've OSGified its
jars and things look promising.  The thing is, I want to use Work Items for
my domain interface, and I want WorkItemHandler's to come from the service
broker.  I can see how most of this would work, except for reading in the
workDefinitions.conf for a new work item.  I've down a quick browse through
the source code and I think it might be that I don't need the work item
configuration file during run time, just for visual rule building.  Anyone
know if that is true?

If it is needed, is there an API that I can introduce it into while building
the session, the way I can introduce KnowledgePackages/rules files?

Thanks,
mike
-- 
View this message in context: 
http://www.nabble.com/Is-work-item-configuration-needed-at-run-time---Can-it-be-built-programmatically--tp24079237p24079237.html
Sent from the drools - user mailing list archive at Nabble.com.

___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users