Skip to content

Commit

Permalink
Draft for [connect] allow registration of FrameworkUtilHelper directly
Browse files Browse the repository at this point in the history
  • Loading branch information
laeubi committed Jul 27, 2022
1 parent 4b397a2 commit 7b737e4
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.eclipse.osgi.launch.EquinoxFactory
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@
package org.eclipse.osgi.launch;

import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import org.osgi.framework.Bundle;
import org.osgi.framework.connect.ConnectFramework;
import org.osgi.framework.connect.ConnectFrameworkFactory;
import org.osgi.framework.connect.FrameworkUtilHelper;
import org.osgi.framework.connect.ModuleConnector;
import org.osgi.framework.launch.Framework;
import org.osgi.framework.launch.FrameworkFactory;
Expand All @@ -23,15 +29,40 @@
* The framework factory implementation for the Equinox framework.
* @since 3.5
*/
public class EquinoxFactory implements FrameworkFactory, ConnectFrameworkFactory {
public class EquinoxFactory implements FrameworkFactory, ConnectFrameworkFactory, FrameworkUtilHelper {

static final Set<FrameworkUtilHelper> connectHelpers = ConcurrentHashMap.newKeySet();

@Override
public Framework newFramework(Map<String, String> configuration) {
return newFramework(configuration, null);
return new Equinox(configuration);
}

@Override
public Framework newFramework(Map<String, String> configuration, ModuleConnector moduleConnector) {
return new Equinox(configuration, moduleConnector);
public ConnectFramework newFramework(Map<String, String> configuration, ModuleConnector moduleConnector) {
return new EquinoxConnect(configuration, moduleConnector);
}

@Override
public Optional<Bundle> getBundle(Class<?> classFromBundle) {
return connectHelpers.stream().flatMap(helper -> helper.getBundle(classFromBundle).stream()).findFirst();
}

private static final class EquinoxConnect extends Equinox implements ConnectFramework {

public EquinoxConnect(Map<String, String> configuration, ModuleConnector moduleConnector) {
super(configuration, moduleConnector);
}

@Override
public void addFrameworkUtilHelper(FrameworkUtilHelper helper) {
connectHelpers.add(helper);
}

@Override
public void removeFrameworkUtilHelper(FrameworkUtilHelper helper) {
connectHelpers.remove(helper);
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.osgi.framework.connect;

import org.osgi.framework.launch.Framework;

/**
* A framework created by a {@link ConnectFrameworkFactory} ... this is non
* standard extension
*/
public interface ConnectFramework extends Framework {

/**
* adds a {@link FrameworkUtilHelper} via this {@link ConnectFramework}
*
* @param helper
*/
void addFrameworkUtilHelper(FrameworkUtilHelper helper);

/**
* removes a {@link FrameworkUtilHelper} via this {@link ConnectFramework}
*
* @param helper
*/
void removeFrameworkUtilHelper(FrameworkUtilHelper helper);

}
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,6 @@ public interface ConnectFrameworkFactory {
* supports permissions.
* @see ModuleConnector
*/
Framework newFramework(Map<String,String> configuration,
ConnectFramework newFramework(Map<String, String> configuration,
ModuleConnector moduleConnector);
}

0 comments on commit 7b737e4

Please sign in to comment.