X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=org.argeo.enterprise%2Fsrc%2Forg%2Fargeo%2Fosgi%2Futil%2FOsgiRegister.java;fp=org.argeo.enterprise%2Fsrc%2Forg%2Fargeo%2Fosgi%2Futil%2FOsgiRegister.java;h=0000000000000000000000000000000000000000;hb=9f729eeb8255a9d800ad2506735dda8cc215a135;hp=7132b7c3f05d82aa55e6d7c744c2b516e063e1d8;hpb=f9efbe5228615951dd8482a4582aa24e00c10ce5;p=lgpl%2Fargeo-commons.git diff --git a/org.argeo.enterprise/src/org/argeo/osgi/util/OsgiRegister.java b/org.argeo.enterprise/src/org/argeo/osgi/util/OsgiRegister.java deleted file mode 100644 index 7132b7c3f..000000000 --- a/org.argeo.enterprise/src/org/argeo/osgi/util/OsgiRegister.java +++ /dev/null @@ -1,60 +0,0 @@ -package org.argeo.osgi.util; - -import java.util.ArrayList; -import java.util.Hashtable; -import java.util.List; -import java.util.Map; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.Executor; -import java.util.concurrent.ForkJoinPool; - -import org.argeo.util.register.Register; -import org.argeo.util.register.Singleton; -import org.osgi.framework.BundleContext; -import org.osgi.framework.ServiceRegistration; - -public class OsgiRegister implements Register { - private final BundleContext bundleContext; - private Executor executor; - - private CompletableFuture shutdownStarting = new CompletableFuture(); - - public OsgiRegister(BundleContext bundleContext) { - this.bundleContext = bundleContext; - // TODO experiment with dedicated executors - this.executor = ForkJoinPool.commonPool(); - } - - @Override - public Singleton set(T obj, Class clss, Map attributes, Class... classes) { - CompletableFuture> srf = new CompletableFuture>(); - CompletableFuture postRegistration = CompletableFuture.supplyAsync(() -> { - List lst = new ArrayList<>(); - lst.add(clss.getName()); - for (Class c : classes) { - lst.add(c.getName()); - } - ServiceRegistration sr = bundleContext.registerService(lst.toArray(new String[lst.size()]), obj, - new Hashtable(attributes)); - srf.complete(sr); - return obj; - }, executor); - Singleton singleton = new Singleton(clss, postRegistration); - - shutdownStarting. // - thenCompose(singleton::prepareUnregistration). // - thenRunAsync(() -> { - try { - srf.get().unregister(); - } catch (InterruptedException | ExecutionException e) { - e.printStackTrace(); - } - }, executor); - return singleton; - } - - public void shutdown() { - shutdownStarting.complete(null); - } -}