aboutsummaryrefslogtreecommitdiffstats
path: root/zkfacade/src/main/java/com/yahoo/vespa/curator/transaction/CuratorSetDataOperation.java
blob: 418cf45eb78593d5f0f5899a4b0d1b95fd77a8ac (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.curator.transaction;

import com.yahoo.path.Path;
import com.yahoo.vespa.curator.Curator;
import org.apache.curator.framework.api.transaction.CuratorTransaction;

/**
 * ZooKeeper setData operation.
 *
 * @author Ulf Lilleengen
 * @author bratseth
 */
class CuratorSetDataOperation implements CuratorOperation {

    private final String path;
    private final byte[] data;

    public CuratorSetDataOperation(String path, byte[] data) {
        this.path = path;
        this.data = data;
    }

    @Override
    public void check(Curator curator, TransactionChanges changes) {
        if ( ! curator.exists(Path.fromString(path)) && ! changes.create(path) )
            throw new IllegalStateException("Cannot perform " + this + ": Path does not exist");
    }

    @Override
    public CuratorTransaction and(CuratorTransaction transaction) throws Exception {
        return transaction.setData().forPath(path, data).and();
    }

    @Override
    public String toString() {
        return "SET " + path;
    }

}