Re: OSGi (Blueprint) fragment and host bundle notification

2011-09-07 Thread Mark Nuttall
Hi Matt,
A web search for osgi bundle tracker fragment yields this article:
http://java.dzone.com/articles/osgi-junit-test-extender-using. This uses a
BundleTrackerCustomizer,

bundleTracker = new BundleTracker(context, Bundle.RESOLVED, testExtender);
bundleTracker.open();

Which then tests to see if it's been given a fragment:

String fragment =
bundle.getHeaders().get(org.osgi.framework.Constants.FRAGMENT_HOST) + ;

 Thanks in advance!

You're welcome!

Regards,
Mark


On 6 September 2011 23:14, Matt Madhavan mattmadha...@gmail.com wrote:

 Hello,
 I would like to know when a new BluePrint fragment attaches it self to a
 host bundle will the host bundle be notified? I would like to do some work
 inside of the host bundle anytime a fragment attaches itself to a host.

 Any ideas?

 Thanks in advance!
 Matt Madhavan



RE: OSGi (Blueprint) fragment and host bundle notification

2011-09-07 Thread Timothy Ward

Hi,

From the original question I would say No, there is no way for a host bundle 
to receive a notification when a fragment attaches. Fragments only attach at 
resolution time, therefore the host bundle can never see the attachment 
because it is, by definition, not resolved yet!

What you can do is the following at startup (On OSGi 4.3):

  public void start(BundleContext ctx) throws BundleException {

Bundle hostBundle = ctx.getBundle();

BundleWiring wiring = hostBundle.adapt(BundleWiring.class);

CollectionBundleWire fragmentWires = wiring.
   getProvidedWires(BundleRevision.HOST_NAMESPACE);

for(BundleWire wire : fragmentWires) {
  Bundle fragment = wire.getRequirerWiring().getBundle();
  //Do some stuff with this fragment
}
  }

This will allow you to find out which fragments were wired to your bundle when 
it resolved.

Regards,

Tim

From: mnutt...@apache.org
Date: Wed, 7 Sep 2011 08:54:57 +0100
Subject: Re: OSGi (Blueprint) fragment and host bundle notification
To: user@aries.apache.org

Hi Matt, A web search for osgi bundle tracker fragment yields this article: 
http://java.dzone.com/articles/osgi-junit-test-extender-using. This uses a 
BundleTrackerCustomizer, 




bundleTracker = new BundleTracker(context, Bundle.RESOLVED, testExtender);

bundleTracker.open();


Which then tests to see if it's been given a fragment:
String fragment = 
bundle.getHeaders().get(org.osgi.framework.Constants.FRAGMENT_HOST) + ;


 Thanks in advance!
You're welcome!
Regards, Mark

On 6 September 2011 23:14, Matt Madhavan mattmadha...@gmail.com wrote:


Hello,I would like to know when a new BluePrint fragment attaches it self to a 
host bundle will the host bundle be notified? I would like to do some work 
inside of the host bundle anytime a fragment attaches itself to a host.



Any ideas?
Thanks in advance!Matt Madhavan

  

RE: Auditor and OSGi

2011-09-07 Thread Timothy Ward

Hi,

So the Aries JPA container uses the createContainerEntityManagerFactory method 
to build EMFs. This provides, amongst other things, a ClassLoader for the 
persistence unit. IMO JPA providers should use this to load config if it isn't 
found on their own classloader.

Regards,

Tim

Date: Tue, 6 Sep 2011 21:47:19 +0200
Subject: Re: Auditor and OSGi
From: be...@rodehav.com
To: user@aries.apache.org

Thanks for your reply Tim,
I agree, it seems like OpenJPA uses its own classloader to load my auditor 
implementation. That won't work of course. Is best practice for JPA providers 
to use the class loader for the bundle containing  the persistence.xml?

/Bengt

2011/9/6 Timothy Ward timothyjw...@apache.org






This sort of problem is usually caused by a JPA provider using the wrong 
classloader to try and find your class. If you import the 
se.digia.maia.common.auditlog.impl package into your persistence bundle *and* 
OpenJPA uses the Persistence Unit classloader (rather than its own) to load it 
then everything should work fine. Realistically they should try both their 
classloader and the persistence unit classloader in case the config property is 
for their own internals.


Unfortunately there is a limit to how much Aries can shield JPA providers from 
OSGi classloading!

Regards,

Tim



Date: Mon, 5 Sep 2011 23:01:07 +0200
Subject: Auditor and OSGi

From: be...@rodehav.com
To: user@aries.apache.org

I posted the following mail on OpenJPA's mailing list but got no answer. I'm 
posting it on the Aries mailing list as well since I suspect that this may 
rather depend on the JPA container in Aries than on OpenJPA itself.




/Bengt


Hello everyone,






After a long discussion about audit logging on this mailing list, Pinaki 
developed an audit logging facility that he describes on:






http://openjpa.208410.n2.nabble.com/OpenJPA-Audit-Facility-tc6722915.html






It provides very interesting functionality and I've tried it in simple JUnit 
scenarios using RESOURCE_LOCAL and it seems to work fine. However, my 
production environment nowadays is OSGi using Karaf+Felix. I use Aries for 
transaction support and also for it's JPA support. In that environment, OpenJPA 
doesn't seem to be able to find my auditor implementation 
(se.digia.maia.common.auditlog.impl.MaiaAuditor) that I specify in my 
persistence.xml.






Has anyone else tried OpenJPA's new audit log facility? How can I make OpenJPA 
find classes specified in the persistence.xml? I have double-checked that the 
se.digia.maia.common.auditlog.impl is exported from my implementing bundle.












I get the following exception:







ERROR: Bundle org.apache.aries.jpa.container [21] EventDispatcher: Error during 
dispatch. (openjpa-2.2.0-SNAPSHOT-runknown fatal user error 
org.apache.openjpa.persistence.ArgumentException: Could not invoke the static 
newInstance method on the named factory class 
org.apache.openjpa.jdbc.kernel.JDBCBrokerFactory.)






openjpa-2.2.0-SNAPSHOT-runknown fatal user error 
org.apache.openjpa.persistence.ArgumentException: Could not invoke the static 
newInstance method on the named factory class 
org.apache.openjpa.jdbc.kernel.JDBCBrokerFactory.






at 
org.apache.openjpa.kernel.Bootstrap.newBrokerFactory(Bootstrap.java:76)
at 
org.apache.openjpa.persistence.PersistenceProviderImpl.getBrokerFactory(PersistenceProviderImpl.java:147)






at 
org.apache.openjpa.persistence.PersistenceProviderImpl.createContainerEntityManagerFactory(PersistenceProviderImpl.java:185)
at 
org.apache.openjpa.persistence.PersistenceProviderImpl.createContainerEntityManagerFactory(PersistenceProviderImpl.java:62)






at 
org.apache.aries.jpa.container.impl.EntityManagerFactoryManager.createEntityManagerFactories(EntityManagerFactoryManager.java:263)
at 
org.apache.aries.jpa.container.impl.EntityManagerFactoryManager.bundleStateChange(EntityManagerFactoryManager.java:153)






at 
org.apache.aries.jpa.container.impl.PersistenceBundleManager.modifiedBundle(PersistenceBundleManager.java:283)
at 
org.osgi.util.tracker.BundleTracker$Tracked.customizerModified(BundleTracker.java:453)






at org.osgi.util.tracker.AbstractTracked.track(AbstractTracked.java:237)
at 
org.osgi.util.tracker.BundleTracker$Tracked.bundleChanged(BundleTracker.java:413)






at 
org.apache.felix.framework.util.EventDispatcher.invokeBundleListenerCallback(EventDispatcher.java:807)
at 
org.apache.felix.framework.util.EventDispatcher.fireEventImmediately(EventDispatcher.java:729)






at 
org.apache.felix.framework.util.EventDispatcher.fireBundleEvent(EventDispatcher.java:610)
at org.apache.felix.framework.Felix.fireBundleEvent(Felix.java:3879)






at org.apache.felix.framework.Felix.access$800(Felix.java:79)
at 
org.apache.felix.framework.Felix$StatefulResolver.fireResolvedEvents(Felix.java:4491)






at