BUG-8327: deprecate sal.core.api.model.SchemaService
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / messages / DataExists.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.controller.cluster.datastore.messages;
10
11 import com.google.common.base.Preconditions;
12 import com.google.common.util.concurrent.CheckedFuture;
13 import com.google.common.util.concurrent.SettableFuture;
14 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
15 import org.opendaylight.controller.sal.core.spi.data.DOMStoreReadTransaction;
16 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
17
18 public class DataExists extends AbstractRead<Boolean> {
19     private static final long serialVersionUID = 1L;
20
21     public DataExists() {
22     }
23
24     public DataExists(final YangInstanceIdentifier path, final short version) {
25         super(path, version);
26     }
27
28     @Override
29     public CheckedFuture<Boolean, ReadFailedException> apply(DOMStoreReadTransaction readDelegate) {
30         return readDelegate.exists(getPath());
31     }
32
33     @Override
34     public void processResponse(Object response, SettableFuture<Boolean> returnFuture) {
35         if (DataExistsReply.isSerializedType(response)) {
36             returnFuture.set(Boolean.valueOf(DataExistsReply.fromSerializable(response).exists()));
37         } else {
38             returnFuture.setException(new ReadFailedException("Invalid response checking exists for path "
39                     + getPath()));
40         }
41     }
42
43     @Override
44     protected AbstractRead<Boolean> newInstance(short withVersion) {
45         return new DataExists(getPath(), withVersion);
46     }
47
48     public static DataExists fromSerializable(final Object serializable) {
49         Preconditions.checkArgument(serializable instanceof DataExists);
50         return (DataExists)serializable;
51     }
52
53     public static boolean isSerializedType(Object message) {
54         return message instanceof DataExists;
55     }
56 }