summaryrefslogtreecommitdiffstats
path: root/src/main/java/com/thinkaurelius/titan/diskstorage/cassandra/CLevel.java
blob: f3b1ca86010c59452a156222a01af02afbf376ca (plain)
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package com.thinkaurelius.titan.diskstorage.cassandra;

import com.google.common.base.Preconditions;

/**
 * This enum unites different libraries' consistency level enums, streamlining
 * configuration and processing in {@link AbstractCassandraStoreManager}.
 *
 */
public enum CLevel implements CLevelInterface { // One ring to rule them all
    ANY,
    ONE,
    TWO,
    THREE,
    QUORUM,
    ALL,
    LOCAL_QUORUM,
    EACH_QUORUM;

    private final org.apache.cassandra.db.ConsistencyLevel db;
    private final org.apache.cassandra.thrift.ConsistencyLevel thrift;
    private final com.netflix.astyanax.model.ConsistencyLevel astyanax;

    private CLevel() {
        db = org.apache.cassandra.db.ConsistencyLevel.valueOf(toString());
        thrift = org.apache.cassandra.thrift.ConsistencyLevel.valueOf(toString());
        astyanax = com.netflix.astyanax.model.ConsistencyLevel.valueOf("CL_" + toString());
    }

    @Override
    public org.apache.cassandra.db.ConsistencyLevel getDB() {
        return db;
    }

    @Override
    public org.apache.cassandra.thrift.ConsistencyLevel getThrift() {
        return thrift;
    }

    @Override
    public com.netflix.astyanax.model.ConsistencyLevel getAstyanax() {
        return astyanax;
    }

    public static CLevel parse(String value) {
        Preconditions.checkArgument(value != null && !value.isEmpty());
        value = value.trim();
        if (value.equals("1")) return ONE;
        else if (value.equals("2")) return TWO;
        else if (value.equals("3")) return THREE;
        else {
            for (CLevel c : values()) {
                if (c.toString().equalsIgnoreCase(value) ||
                    ("CL_" + c.toString()).equalsIgnoreCase(value)) return c;
            }
        }
        throw new IllegalArgumentException("Unrecognized cassandra consistency level: " + value);
    }
}