Expose registerInProcessServer method of device gRPC service
Change-Id: Ib10d4e7776f469750552ade4b4618b3e917065fb
diff --git a/incubator/protobuf/services/nb/src/main/java/org/onosproject/incubator/protobuf/services/nb/GrpcNbDeviceService.java b/incubator/protobuf/services/nb/src/main/java/org/onosproject/incubator/protobuf/services/nb/GrpcNbDeviceService.java
index 4ca0e03..e898df4 100644
--- a/incubator/protobuf/services/nb/src/main/java/org/onosproject/incubator/protobuf/services/nb/GrpcNbDeviceService.java
+++ b/incubator/protobuf/services/nb/src/main/java/org/onosproject/incubator/protobuf/services/nb/GrpcNbDeviceService.java
@@ -17,6 +17,7 @@
import com.google.common.annotations.Beta;
+import io.grpc.BindableService;
import io.grpc.stub.StreamObserver;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
@@ -35,8 +36,10 @@
import org.onosproject.net.PortNumber;
import org.onosproject.net.device.DeviceService;
import org.onosproject.incubator.protobuf.models.GrpcNbDeviceServiceUtil;
+import org.slf4j.Logger;
import static org.onosproject.grpc.nb.net.device.DeviceServiceNb.*;
+import static org.slf4j.LoggerFactory.getLogger;
/**
@@ -48,6 +51,8 @@
@Component(immediate = true)
public class GrpcNbDeviceService {
+ private final Logger log = getLogger(getClass());
+
private static DeviceServiceNbServerInternal instance = null;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
@@ -58,21 +63,27 @@
@Activate
public void activate() {
- //TODO this should contact the registry service and register an instance
- // of this service
registry.register(getInnerInstance());
+ log.info("Started.");
}
@Deactivate
public void deactivate() {
registry.unregister(getInnerInstance());
+ log.info("Stopped");
}
- public DeviceServiceNbServerInternal getInnerInstance() {
- if (instance == null) {
- instance = new DeviceServiceNbServerInternal();
- }
- return instance;
+ /**
+ * Register Device Service, Used for unit testing purposes.
+ *
+ * @return An instance of binding Device service
+ */
+ public InProcessServer<BindableService> registerInProcessServer() {
+ InProcessServer<BindableService> inprocessServer =
+ new InProcessServer(GrpcNbDeviceService.DeviceServiceNbServerInternal.class);
+ inprocessServer.addServiceToBind(getInnerInstance());
+
+ return inprocessServer;
}
private final class DeviceServiceNbServerInternal extends DeviceServiceImplBase {
@@ -367,4 +378,11 @@
responseObserver.onCompleted();
}
}
+
+ private DeviceServiceNbServerInternal getInnerInstance() {
+ if (instance == null) {
+ instance = new DeviceServiceNbServerInternal();
+ }
+ return instance;
+ }
}
\ No newline at end of file