Permalink
Browse files

Fixed the possible duplication of tools/devices/exporters

  • Loading branch information...
1 parent 297e0b3 commit 89b66e1ed19fd0e16c57310527c2c4d42bd3f0ce @jawi committed Jun 29, 2012
Showing with 18 additions and 6 deletions.
  1. +18 −6 client/src/main/java/nl/lxtreme/ols/client/osgi/GenericBundleAdapter.java
@@ -40,6 +40,8 @@
private final String headerKey;
private volatile Bundle bundle; // = adapted bundle
+ private volatile DependencyManager manager; // injected
+ private volatile Component serviceComponent; // = added service
// CONSTRUCTORS
@@ -55,7 +57,18 @@ public GenericBundleAdapter( final Class<? extends TYPE> aClass, final String aH
// METHODS
/**
- * Called by Depdendency Manager upon initialization of this component.
+ * Called by Dependency Manager upon destruction of this component.
+ */
+ public void destroy( final Component aComponent ) throws Exception
+ {
+ if ( this.serviceComponent != null )
+ {
+ this.manager.remove( this.serviceComponent );
+ }
+ }
+
+ /**
+ * Called by Dependency Manager upon initialization of this component.
*/
public void init( final Component aComponent ) throws Exception
{
@@ -71,15 +84,14 @@ public void init( final Component aComponent ) throws Exception
Properties serviceProps = copyOlsProperties( bundleProps );
- DependencyManager dm = new DependencyManager( this.bundle.getBundleContext() );
- dm.add( dm.createComponent() //
+ this.serviceComponent = this.manager.createComponent() //
.setInterface( this.serviceClass.getName(), serviceProps ) //
.setImplementation( implClass ) //
- .add( dm.createServiceDependency() //
+ .add( this.manager.createServiceDependency() //
.setService( LogService.class ) //
.setRequired( false ) //
- ) //
- );
+ );
+ this.manager.add( this.serviceComponent );
}
/**

0 comments on commit 89b66e1

Please sign in to comment.