2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.controller.cluster.datastore.messages;
11 import com.google.common.util.concurrent.CheckedFuture;
12 import com.google.common.util.concurrent.SettableFuture;
13 import org.opendaylight.controller.cluster.datastore.DataStoreVersions;
14 import org.opendaylight.controller.cluster.datastore.util.InstanceIdentifierUtils;
15 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
16 import org.opendaylight.controller.protobuff.messages.transaction.ShardTransactionMessages;
17 import org.opendaylight.controller.sal.core.spi.data.DOMStoreReadTransaction;
18 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
20 public class DataExists extends AbstractRead<Boolean> {
21 private static final long serialVersionUID = 1L;
26 public DataExists(final YangInstanceIdentifier path, final short version) {
31 public Object toSerializable() {
32 if(getVersion() >= DataStoreVersions.BORON_VERSION) {
35 return ShardTransactionMessages.DataExists.newBuilder().setInstanceIdentifierPathArguments(
36 InstanceIdentifierUtils.toSerializable(getPath())).build();
41 public CheckedFuture<Boolean, ReadFailedException> apply(DOMStoreReadTransaction readDelegate) {
42 return readDelegate.exists(getPath());
46 public void processResponse(Object response, SettableFuture<Boolean> returnFuture) {
47 if(DataExistsReply.isSerializedType(response)) {
48 returnFuture.set(Boolean.valueOf(DataExistsReply.fromSerializable(response).exists()));
50 returnFuture.setException(new ReadFailedException("Invalid response checking exists for path " + getPath()));
55 protected AbstractRead<Boolean> newInstance(short withVersion) {
56 return new DataExists(getPath(), withVersion);
59 public static DataExists fromSerializable(final Object serializable){
60 if(serializable instanceof DataExists) {
61 return (DataExists)serializable;
63 ShardTransactionMessages.DataExists o = (ShardTransactionMessages.DataExists) serializable;
64 return new DataExists(InstanceIdentifierUtils.fromSerializable(o.getInstanceIdentifierPathArguments()),
65 DataStoreVersions.LITHIUM_VERSION);
69 public static boolean isSerializedType(Object message) {
70 return message instanceof DataExists || message instanceof ShardTransactionMessages.DataExists;