BUG-5280: add SimpleDataStoreClientBehavior
[controller.git] / opendaylight / md-sal / cds-access-client / src / main / java / org / opendaylight / controller / cluster / access / client / ClientActorBehavior.java
index e4b73b14f0c71f85bde3279522887a5b466700f8..97d312ce394a186ec4d9b4b311676218d2f21bc3 100644 (file)
@@ -16,6 +16,7 @@ import javax.annotation.Nullable;
 import javax.annotation.concurrent.GuardedBy;
 import org.opendaylight.controller.cluster.access.concepts.ClientIdentifier;
 import org.opendaylight.controller.cluster.access.concepts.FailureEnvelope;
 import javax.annotation.concurrent.GuardedBy;
 import org.opendaylight.controller.cluster.access.concepts.ClientIdentifier;
 import org.opendaylight.controller.cluster.access.concepts.FailureEnvelope;
+import org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier;
 import org.opendaylight.controller.cluster.access.concepts.RequestException;
 import org.opendaylight.controller.cluster.access.concepts.RequestFailure;
 import org.opendaylight.controller.cluster.access.concepts.ResponseEnvelope;
 import org.opendaylight.controller.cluster.access.concepts.RequestException;
 import org.opendaylight.controller.cluster.access.concepts.RequestFailure;
 import org.opendaylight.controller.cluster.access.concepts.ResponseEnvelope;
@@ -100,14 +101,19 @@ public abstract class ClientActorBehavior<T extends BackendInfo> extends
         return onCommand(command);
     }
 
         return onCommand(command);
     }
 
-    private void onResponse(final ResponseEnvelope<?> response) {
-        final WritableIdentifier id = response.getMessage().getTarget();
-
-        // FIXME: this will need to be updated for other Request/Response types to extract cookie
-        Preconditions.checkArgument(id instanceof TransactionIdentifier);
-        final TransactionIdentifier txId = (TransactionIdentifier) id;
+    private static long extractCookie(final WritableIdentifier id) {
+        if (id instanceof TransactionIdentifier) {
+            return ((TransactionIdentifier) id).getHistoryId().getCookie();
+        } else if (id instanceof LocalHistoryIdentifier) {
+            return ((LocalHistoryIdentifier) id).getCookie();
+        } else {
+            throw new IllegalArgumentException("Unhandled identifier " + id);
+        }
+    }
 
 
-        final AbstractClientConnection<T> connection = connections.get(txId.getHistoryId().getCookie());
+    private void onResponse(final ResponseEnvelope<?> response) {
+        final long cookie = extractCookie(response.getMessage().getTarget());
+        final AbstractClientConnection<T> connection = connections.get(cookie);
         if (connection != null) {
             connection.receiveResponse(response);
         } else {
         if (connection != null) {
             connection.receiveResponse(response);
         } else {