summaryrefslogtreecommitdiffstats
path: root/logserver/src/main/java/com/yahoo/logserver/net/control/State.java
blob: 5d2a4f0fbd4b4dc978da62217ae425ad7cae5150 (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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.logserver.net.control;

import java.util.Map;
import java.util.HashMap;

/**
 * This value class represents the logging state of a component.
 * the valid states are:
 *
 * <UL>
 *  <LI> forward - store locally and send to log server
 *  <LI> store - store locally only
 *  <LI> noforward - do not send to logserver
 *  <LI> off - do not generate the message in the program
 * </UL>
 *
 * XXX This does not appear to be in use.
 */
public class State {
    private static final Map<String, State> nameToState = new HashMap<String, State>();

    public static final State FORWARD = new State("forward");
    public static final State NOFORWARD = new State("noforward");
    // public static final State STORE = new State("store");
    // public static final State OFF = new State("off");
    public static final State UNKNOWN = new State("unknown");

    private String name;

    /**
     * Typesafe enum.  Only able to instantiate self.
     * TODO: Rewrite to enum
     */
    private State () {}

    /**
     * Creates state with given name
     */
    private State (String name) {
        this.name = name;
        synchronized (State.class) {
            nameToState.put(name, this);
        }
    }

    public static State parse (String s) {
    	return nameToState.containsKey(s) ? nameToState.get(s) : UNKNOWN;
    }

    public String toString () {
        return name;
    }
}