Skip to main content
summaryrefslogtreecommitdiffstats
blob: 05d815c4771f2f4740c147838ba66dd1d0ea1cbb (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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
//Copyright 2003-2005 Arthur van Hoff, Rick Blair
//Licensed under Apache License version 2.0
//Original license LGPL

package javax.jmdns.impl.constants;

/**
 * DNSState defines the possible states for services registered with JmDNS.
 *
 * @version %I%, %G%
 * @author Werner Randelshofer, Rick Blair, Pierre Frisch
 */
public enum DNSState
{

    /**
     *
     */
    PROBING_1("probing 1", StateClass.probing),
    /**
    *
    */
    PROBING_2("probing 2", StateClass.probing),
    /**
    *
    */
    PROBING_3("probing 3", StateClass.probing),
    /**
    *
    */
    ANNOUNCING_1("announcing 1", StateClass.announcing),
    /**
    *
    */
    ANNOUNCING_2("announcing 2", StateClass.announcing),
    /**
    *
    */
    ANNOUNCED("announced", StateClass.announced),
    /**
    *
    */
    CANCELING_1("canceling 1", StateClass.canceling),
    /**
    *
    */
    CANCELING_2("canceling 2", StateClass.canceling),
    /**
    *
    */
    CANCELING_3("canceling 3", StateClass.canceling),
    /**
    *
    */
    CANCELED("canceled", StateClass.canceled);

    private enum StateClass
    {
        probing, announcing, announced, canceling, canceled
    }

    // private static Logger logger = Logger.getLogger(DNSState.class.getName());

    private final String _name;

    private final StateClass _state;

    private DNSState(String name, StateClass state)
    {
        _name = name;
        _state = state;
    }

    @Override
    public final String toString()
    {
        return _name;
    }

    /**
     * Returns the next advanced state.<br/>
     * In general, this advances one step in the following sequence: PROBING_1, PROBING_2, PROBING_3, ANNOUNCING_1, ANNOUNCING_2, ANNOUNCED.<br/>
     * or CANCELING_1, CANCELING_2, CANCELING_3, CANCELED Does not advance for ANNOUNCED and CANCELED state.
     *
     * @return next state
     */
    public final DNSState advance()
    {
        switch (this)
        {
            case PROBING_1:
                return PROBING_2;
            case PROBING_2:
                return PROBING_3;
            case PROBING_3:
                return ANNOUNCING_1;
            case ANNOUNCING_1:
                return ANNOUNCING_2;
            case ANNOUNCING_2:
                return ANNOUNCED;
            case ANNOUNCED:
                return ANNOUNCED;
            case CANCELING_1:
                return CANCELING_2;
            case CANCELING_2:
                return CANCELING_3;
            case CANCELING_3:
                return CANCELED;
            case CANCELED:
                return CANCELED;
        }
        // This is just to keep the compiler happy as we have covered all cases before.
        return this;
    }

    /**
     * Returns to the next reverted state. All states except CANCELED revert to PROBING_1. Status CANCELED does not revert.
     *
     * @return reverted state
     */
    public final DNSState revert()
    {
        switch (this)
        {
            case PROBING_1:
            case PROBING_2:
            case PROBING_3:
            case ANNOUNCING_1:
            case ANNOUNCING_2:
            case ANNOUNCED:
                return PROBING_1;
            case CANCELING_1:
            case CANCELING_2:
            case CANCELING_3:
                return CANCELING_1;
            case CANCELED:
                return CANCELED;
        }
        // This is just to keep the compiler happy as we have covered all cases before.
        return this;
    }

    /**
     * Returns true, if this is a probing state.
     *
     * @return <code>true</code> if probing state, <code>false</code> otherwise
     */
    public final boolean isProbing()
    {
        return _state == StateClass.probing;
    }

    /**
     * Returns true, if this is an announcing state.
     *
     * @return <code>true</code> if announcing state, <code>false</code> otherwise
     */
    public final boolean isAnnouncing()
    {
        return _state == StateClass.announcing;
    }

    /**
     * Returns true, if this is an announced state.
     *
     * @return <code>true</code> if announced state, <code>false</code> otherwise
     */
    public final boolean isAnnounced()
    {
        return _state == StateClass.announced;
    }

    /**
     * Returns true, if this is a canceling state.
     *
     * @return <code>true</code> if canceling state, <code>false</code> otherwise
     */
    public final boolean isCanceling()
    {
        return _state == StateClass.canceling;
    }

    /**
     * Returns true, if this is a canceled state.
     *
     * @return <code>true</code> if canceled state, <code>false</code> otherwise
     */
    public final boolean isCanceled()
    {
        return _state == StateClass.canceled;
    }

}

Back to the top