Convert sal-netconf-connector to OSGi DS
[netconf.git] / netconf / sal-netconf-connector / src / main / java / org / opendaylight / netconf / sal / connect / netconf / DeviceActionFactoryImpl.java
index a15b00a6ecb472439c77ee77f4fb988d4eed030b..73077849cba91ddd0dca9213a983af21711f86a0 100644 (file)
@@ -5,15 +5,16 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.netconf.sal.connect.netconf;
 
-import com.google.common.base.Preconditions;
+import static java.util.Objects.requireNonNull;
+
 import com.google.common.collect.ClassToInstanceMap;
 import com.google.common.collect.ImmutableClassToInstanceMap;
-import com.google.common.util.concurrent.FluentFuture;
+import com.google.common.util.concurrent.Futures;
+import com.google.common.util.concurrent.ListenableFuture;
 import com.google.common.util.concurrent.MoreExecutors;
-import org.eclipse.jdt.annotation.NonNull;
+import javax.inject.Singleton;
 import org.opendaylight.mdsal.dom.api.DOMActionResult;
 import org.opendaylight.mdsal.dom.api.DOMActionService;
 import org.opendaylight.mdsal.dom.api.DOMActionServiceExtension;
@@ -26,6 +27,7 @@ import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.osgi.service.component.annotations.Component;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -35,8 +37,9 @@ import org.slf4j.LoggerFactory;
  * transforms replied NETCONF message  to action result, and using {@link RemoteDeviceCommunicator} that is responsible
  * for sending of built RPCs to NETCONF client.
  */
+@Singleton
+@Component(immediate = true, property = "type=default")
 public class DeviceActionFactoryImpl implements DeviceActionFactory {
-
     private static final Logger LOG = LoggerFactory.getLogger(DeviceActionFactoryImpl.class);
 
     @Override
@@ -45,16 +48,16 @@ public class DeviceActionFactoryImpl implements DeviceActionFactory {
 
         return new DOMActionService() {
             @Override
-            public FluentFuture<? extends DOMActionResult> invokeAction(final SchemaPath schemaPath,
+            public ListenableFuture<? extends DOMActionResult> invokeAction(final SchemaPath schemaPath,
                     final DOMDataTreeIdentifier dataTreeIdentifier, final ContainerNode input) {
-                Preconditions.checkNotNull(schemaPath);
-                Preconditions.checkNotNull(dataTreeIdentifier);
-                Preconditions.checkNotNull(input);
+                requireNonNull(schemaPath);
+                requireNonNull(dataTreeIdentifier);
+                requireNonNull(input);
 
-                final FluentFuture<RpcResult<NetconfMessage>> actionResultFuture = listener.sendRequest(
+                final ListenableFuture<RpcResult<NetconfMessage>> actionResultFuture = listener.sendRequest(
                         messageTransformer.toActionRequest(schemaPath, dataTreeIdentifier, input), input.getNodeType());
 
-                return actionResultFuture.transform(netconfMessageRpcResult -> {
+                return Futures.transform(actionResultFuture, netconfMessageRpcResult -> {
                     if (netconfMessageRpcResult != null) {
                         return messageTransformer.toActionResult(schemaPath, netconfMessageRpcResult.getResult());
                     } else {
@@ -66,7 +69,7 @@ public class DeviceActionFactoryImpl implements DeviceActionFactory {
             }
 
             @Override
-            public @NonNull ClassToInstanceMap<DOMActionServiceExtension> getExtensions() {
+            public ClassToInstanceMap<DOMActionServiceExtension> getExtensions() {
                 return ImmutableClassToInstanceMap.of();
             }
         };