fix: (vNet) class load issues for OSGi bundle.
Problem.
1. Inside incubator package, class loader can't search classes defined
in the other bundles such as onos-core
Solution
1. Added a method to return bundle context, and obtain class loader.
Change-Id: If5ee4cb1a5b9ef5ab7d7e3bbc70408ea8257baea
diff --git a/incubator/api/src/main/java/org/onosproject/incubator/net/virtual/event/AbstractVirtualListenerManager.java b/incubator/api/src/main/java/org/onosproject/incubator/net/virtual/event/AbstractVirtualListenerManager.java
index e87876c..866e845 100644
--- a/incubator/api/src/main/java/org/onosproject/incubator/net/virtual/event/AbstractVirtualListenerManager.java
+++ b/incubator/api/src/main/java/org/onosproject/incubator/net/virtual/event/AbstractVirtualListenerManager.java
@@ -29,9 +29,7 @@
*/
public abstract class AbstractVirtualListenerManager
<E extends Event, L extends EventListener<E>>
- implements ListenerService<E, L>, VnetService {
-
- private static final String NETWORK_NULL = "Network ID cannot be null";
+ implements ListenerService<E, L>, VnetService {
protected final NetworkId networkId;
protected final VirtualNetworkService manager;
@@ -39,29 +37,34 @@
protected EventDeliveryService eventDispatcher;
- VirtualListenerRegistryManager listenerManager =
+ private VirtualListenerRegistryManager listenerManager =
VirtualListenerRegistryManager.getInstance();
+ private Class<? extends Event> eventClass;
+
public AbstractVirtualListenerManager(VirtualNetworkService manager,
- NetworkId networkId) {
+ NetworkId networkId,
+ Class<? extends Event> eventClass) {
this.manager = manager;
this.networkId = networkId;
this.serviceDirectory = manager.getServiceDirectory();
+ this.eventClass = eventClass;
+
//Set default event delivery service by default
this.eventDispatcher = serviceDirectory.get(EventDeliveryService.class);
}
@Override
+ @SuppressWarnings("unchecked")
public void addListener(L listener) {
- listenerManager.getRegistry(networkId, getEventClass())
- .addListener(listener);
+ listenerManager.getRegistry(networkId, eventClass).addListener(listener);
}
@Override
+ @SuppressWarnings("unchecked")
public void removeListener(L listener) {
- listenerManager.getRegistry(networkId, getEventClass())
- .removeListener(listener);
+ listenerManager.getRegistry(networkId, eventClass).removeListener(listener);
}
/**
@@ -83,23 +86,4 @@
public NetworkId networkId() {
return this.networkId;
}
-
- /**
- * Returns the class type of parameter type.
- * More specifically, it returns the class type of event class.
- *
- * @return the class type of provider service of the service
- */
- public Class getEventClass() {
- String className = this.getClass().getGenericSuperclass().toString();
- String pramType = className.split("<")[1].split(",")[0];
-
- try {
- return Class.forName(pramType);
- } catch (ClassNotFoundException e) {
- e.printStackTrace();
- }
-
- return null;
- }
}
diff --git a/incubator/api/src/main/java/org/onosproject/incubator/net/virtual/event/VirtualListenerRegistryManager.java b/incubator/api/src/main/java/org/onosproject/incubator/net/virtual/event/VirtualListenerRegistryManager.java
index 9d01a00..252d466 100644
--- a/incubator/api/src/main/java/org/onosproject/incubator/net/virtual/event/VirtualListenerRegistryManager.java
+++ b/incubator/api/src/main/java/org/onosproject/incubator/net/virtual/event/VirtualListenerRegistryManager.java
@@ -72,8 +72,10 @@
ListenerRegistry listenerRegistry =
listenerMapByNetwork.get(networkId).get(originalEvent.getClass());
- listenerRegistry.process(originalEvent);
- lastStart = listenerRegistry;
+ if (listenerRegistry != null) {
+ listenerRegistry.process(originalEvent);
+ lastStart = listenerRegistry;
+ }
}
@Override
diff --git a/incubator/api/src/test/java/org/onosproject/incubator/net/virtual/event/AbstractVirtualListenerManagerTest.java b/incubator/api/src/test/java/org/onosproject/incubator/net/virtual/event/AbstractVirtualListenerManagerTest.java
index 23934b5..6614941 100644
--- a/incubator/api/src/test/java/org/onosproject/incubator/net/virtual/event/AbstractVirtualListenerManagerTest.java
+++ b/incubator/api/src/test/java/org/onosproject/incubator/net/virtual/event/AbstractVirtualListenerManagerTest.java
@@ -38,6 +38,7 @@
import org.onosproject.incubator.net.virtual.VirtualNetworkService;
import org.onosproject.incubator.net.virtual.VirtualPort;
import org.onosproject.net.DeviceId;
+import org.osgi.framework.BundleContext;
import java.util.ArrayList;
import java.util.List;
@@ -52,24 +53,22 @@
*/
public class AbstractVirtualListenerManagerTest {
- private VirtualNetworkService manager;
-
- TestEventDispatcher dispatcher = new TestEventDispatcher();
- VirtualListenerRegistryManager listenerRegistryManager =
+ private TestEventDispatcher dispatcher = new TestEventDispatcher();
+ private VirtualListenerRegistryManager listenerRegistryManager =
VirtualListenerRegistryManager.getInstance();
- PrickleManager prickleManager;
- PrickleListener prickleListener;
+ private PrickleManager prickleManager;
+ private PrickleListener prickleListener;
- GooManager gooManager;
- GooListener gooListener;
+ private GooManager gooManager;
+ private GooListener gooListener;
- BarManager barManager;
- BarListener barListener;
+ private BarManager barManager;
+ private BarListener barListener;
@Before
public void setUp() {
- manager = new TestVirtualNetworkManager();
+ VirtualNetworkService manager = new TestVirtualNetworkManager();
dispatcher.addSink(VirtualEvent.class, listenerRegistryManager);
@@ -153,25 +152,25 @@
private enum Type { FOO }
private static class Thing extends AbstractEvent<Type, String> {
- protected Thing(String subject) {
+ private Thing(String subject) {
super(Type.FOO, subject);
}
}
private static class Prickle extends Thing {
- protected Prickle(String subject) {
+ private Prickle(String subject) {
super(subject);
}
}
private static class Goo extends Thing {
- protected Goo(String subject) {
+ private Goo(String subject) {
super(subject);
}
}
private static class Bar extends Thing {
- protected Bar(String subject) {
+ private Bar(String subject) {
super(subject);
}
}
@@ -198,19 +197,19 @@
private class PrickleManager extends AbstractVirtualListenerManager<Prickle, PrickleListener> {
public PrickleManager(VirtualNetworkService service, NetworkId networkId) {
- super(service, networkId);
+ super(service, networkId, Prickle.class);
}
}
private class GooManager extends AbstractVirtualListenerManager<Goo, GooListener> {
public GooManager(VirtualNetworkService service, NetworkId networkId) {
- super(service, networkId);
+ super(service, networkId, Goo.class);
}
}
private class BarManager extends AbstractVirtualListenerManager<Bar, BarListener> {
public BarManager(VirtualNetworkService service, NetworkId networkId) {
- super(service, networkId);
+ super(service, networkId, Bar.class);
}
}
diff --git a/incubator/net/src/main/java/org/onosproject/incubator/net/virtual/impl/VirtualNetworkDeviceManager.java b/incubator/net/src/main/java/org/onosproject/incubator/net/virtual/impl/VirtualNetworkDeviceManager.java
index c529061..0f47a29 100644
--- a/incubator/net/src/main/java/org/onosproject/incubator/net/virtual/impl/VirtualNetworkDeviceManager.java
+++ b/incubator/net/src/main/java/org/onosproject/incubator/net/virtual/impl/VirtualNetworkDeviceManager.java
@@ -61,7 +61,7 @@
*/
public VirtualNetworkDeviceManager(VirtualNetworkService virtualNetworkManager,
NetworkId networkId) {
- super(virtualNetworkManager, networkId);
+ super(virtualNetworkManager, networkId, DeviceEvent.class);
manager.addListener(virtualNetworkListener);
}
diff --git a/incubator/net/src/main/java/org/onosproject/incubator/net/virtual/impl/VirtualNetworkFlowRuleManager.java b/incubator/net/src/main/java/org/onosproject/incubator/net/virtual/impl/VirtualNetworkFlowRuleManager.java
index f6c6e2b..0cbe131 100644
--- a/incubator/net/src/main/java/org/onosproject/incubator/net/virtual/impl/VirtualNetworkFlowRuleManager.java
+++ b/incubator/net/src/main/java/org/onosproject/incubator/net/virtual/impl/VirtualNetworkFlowRuleManager.java
@@ -112,7 +112,7 @@
*/
public VirtualNetworkFlowRuleManager(VirtualNetworkService virtualNetworkManager,
NetworkId networkId) {
- super(virtualNetworkManager, networkId);
+ super(virtualNetworkManager, networkId, FlowRuleEvent.class);
store = serviceDirectory.get(VirtualNetworkFlowRuleStore.class);
diff --git a/incubator/net/src/main/java/org/onosproject/incubator/net/virtual/impl/VirtualNetworkGroupManager.java b/incubator/net/src/main/java/org/onosproject/incubator/net/virtual/impl/VirtualNetworkGroupManager.java
index fee36bc..02fa2be 100644
--- a/incubator/net/src/main/java/org/onosproject/incubator/net/virtual/impl/VirtualNetworkGroupManager.java
+++ b/incubator/net/src/main/java/org/onosproject/incubator/net/virtual/impl/VirtualNetworkGroupManager.java
@@ -67,7 +67,7 @@
private boolean purgeOnDisconnection = false;
public VirtualNetworkGroupManager(VirtualNetworkService manager, NetworkId networkId) {
- super(manager, networkId);
+ super(manager, networkId, GroupEvent.class);
store = serviceDirectory.get(VirtualNetworkGroupStore.class);
deviceService = manager.get(networkId, DeviceService.class);
diff --git a/incubator/net/src/main/java/org/onosproject/incubator/net/virtual/impl/VirtualNetworkHostManager.java b/incubator/net/src/main/java/org/onosproject/incubator/net/virtual/impl/VirtualNetworkHostManager.java
index 216a76b..35f915b 100644
--- a/incubator/net/src/main/java/org/onosproject/incubator/net/virtual/impl/VirtualNetworkHostManager.java
+++ b/incubator/net/src/main/java/org/onosproject/incubator/net/virtual/impl/VirtualNetworkHostManager.java
@@ -57,7 +57,7 @@
*/
public VirtualNetworkHostManager(VirtualNetworkService virtualNetworkManager,
NetworkId networkId) {
- super(virtualNetworkManager, networkId);
+ super(virtualNetworkManager, networkId, HostEvent.class);
}
diff --git a/incubator/net/src/main/java/org/onosproject/incubator/net/virtual/impl/VirtualNetworkIntentManager.java b/incubator/net/src/main/java/org/onosproject/incubator/net/virtual/impl/VirtualNetworkIntentManager.java
index 4026cb5..41cd952 100644
--- a/incubator/net/src/main/java/org/onosproject/incubator/net/virtual/impl/VirtualNetworkIntentManager.java
+++ b/incubator/net/src/main/java/org/onosproject/incubator/net/virtual/impl/VirtualNetworkIntentManager.java
@@ -75,7 +75,7 @@
public VirtualNetworkIntentManager(VirtualNetworkService virtualNetworkManager,
NetworkId networkId) {
- super(virtualNetworkManager, networkId);
+ super(virtualNetworkManager, networkId, IntentEvent.class);
this.store = serviceDirectory.get(VirtualNetworkStore.class);
this.intentService = serviceDirectory.get(IntentService.class);
diff --git a/incubator/net/src/main/java/org/onosproject/incubator/net/virtual/impl/VirtualNetworkLinkManager.java b/incubator/net/src/main/java/org/onosproject/incubator/net/virtual/impl/VirtualNetworkLinkManager.java
index 3a93e3c..ed18f86 100644
--- a/incubator/net/src/main/java/org/onosproject/incubator/net/virtual/impl/VirtualNetworkLinkManager.java
+++ b/incubator/net/src/main/java/org/onosproject/incubator/net/virtual/impl/VirtualNetworkLinkManager.java
@@ -51,7 +51,7 @@
*/
public VirtualNetworkLinkManager(VirtualNetworkService virtualNetworkManager,
NetworkId networkId) {
- super(virtualNetworkManager, networkId);
+ super(virtualNetworkManager, networkId, LinkEvent.class);
}
@Override
diff --git a/incubator/net/src/main/java/org/onosproject/incubator/net/virtual/impl/VirtualNetworkManager.java b/incubator/net/src/main/java/org/onosproject/incubator/net/virtual/impl/VirtualNetworkManager.java
index 11a7990..ff3c696 100644
--- a/incubator/net/src/main/java/org/onosproject/incubator/net/virtual/impl/VirtualNetworkManager.java
+++ b/incubator/net/src/main/java/org/onosproject/incubator/net/virtual/impl/VirtualNetworkManager.java
@@ -142,10 +142,10 @@
@Activate
public void activate() {
- store.setDelegate(delegate);
eventDispatcher.addSink(VirtualNetworkEvent.class, listenerRegistry);
eventDispatcher.addSink(VirtualEvent.class,
VirtualListenerRegistryManager.getInstance());
+ store.setDelegate(delegate);
intentService.addListener(intentListener);
appId = coreService.registerApplication(VIRTUAL_NETWORK_APP_ID_STRING);
log.info("Started");
@@ -364,6 +364,7 @@
private final Map<ServiceKey, VnetService> networkServices = Maps.newConcurrentMap();
@Override
+ @SuppressWarnings("unchecked")
public <T> T get(NetworkId networkId, Class<T> serviceClass) {
checkNotNull(networkId, NETWORK_NULL);
ServiceKey serviceKey = networkServiceKey(networkId, serviceClass);
@@ -453,7 +454,7 @@
* @param networkId network identifier
* @param serviceClass service class
*/
- public ServiceKey(NetworkId networkId, Class serviceClass) {
+ ServiceKey(NetworkId networkId, Class serviceClass) {
checkNotNull(networkId, NETWORK_NULL);
this.networkId = networkId;
diff --git a/incubator/net/src/main/java/org/onosproject/incubator/net/virtual/impl/VirtualNetworkTopologyManager.java b/incubator/net/src/main/java/org/onosproject/incubator/net/virtual/impl/VirtualNetworkTopologyManager.java
index c55829d..c056b25 100644
--- a/incubator/net/src/main/java/org/onosproject/incubator/net/virtual/impl/VirtualNetworkTopologyManager.java
+++ b/incubator/net/src/main/java/org/onosproject/incubator/net/virtual/impl/VirtualNetworkTopologyManager.java
@@ -68,7 +68,7 @@
*/
public VirtualNetworkTopologyManager(VirtualNetworkService virtualNetworkManager,
NetworkId networkId) {
- super(virtualNetworkManager, networkId);
+ super(virtualNetworkManager, networkId, TopologyEvent.class);
}
@Override