$search
00001 // Copyright 2003-2005 Arthur van Hoff, Rick Blair 00002 // Licensed under Apache License version 2.0 00003 // Original license LGPL 00004 00005 package javax.jmdns.impl.constants; 00006 00012 public enum DNSState { 00013 00017 PROBING_1("probing 1", StateClass.probing), 00021 PROBING_2("probing 2", StateClass.probing), 00025 PROBING_3("probing 3", StateClass.probing), 00029 ANNOUNCING_1("announcing 1", StateClass.announcing), 00033 ANNOUNCING_2("announcing 2", StateClass.announcing), 00037 ANNOUNCED("announced", StateClass.announced), 00041 CANCELING_1("canceling 1", StateClass.canceling), 00045 CANCELING_2("canceling 2", StateClass.canceling), 00049 CANCELING_3("canceling 3", StateClass.canceling), 00053 CANCELED("canceled", StateClass.canceled), 00057 CLOSING("closing", StateClass.closing), 00061 CLOSED("closed", StateClass.closed); 00062 00063 private enum StateClass { 00064 probing, announcing, announced, canceling, canceled, closing, closed 00065 } 00066 00067 // private static Logger logger = Logger.getLogger(DNSState.class.getName()); 00068 00069 private final String _name; 00070 00071 private final StateClass _state; 00072 00073 private DNSState(String name, StateClass state) { 00074 _name = name; 00075 _state = state; 00076 } 00077 00078 @Override 00079 public final String toString() { 00080 return _name; 00081 } 00082 00090 public final DNSState advance() { 00091 switch (this) { 00092 case PROBING_1: 00093 return PROBING_2; 00094 case PROBING_2: 00095 return PROBING_3; 00096 case PROBING_3: 00097 return ANNOUNCING_1; 00098 case ANNOUNCING_1: 00099 return ANNOUNCING_2; 00100 case ANNOUNCING_2: 00101 return ANNOUNCED; 00102 case ANNOUNCED: 00103 return ANNOUNCED; 00104 case CANCELING_1: 00105 return CANCELING_2; 00106 case CANCELING_2: 00107 return CANCELING_3; 00108 case CANCELING_3: 00109 return CANCELED; 00110 case CANCELED: 00111 return CANCELED; 00112 case CLOSING: 00113 return CLOSED; 00114 case CLOSED: 00115 return CLOSED; 00116 default: 00117 // This is just to keep the compiler happy as we have covered all cases before. 00118 return this; 00119 } 00120 } 00121 00127 public final DNSState revert() { 00128 switch (this) { 00129 case PROBING_1: 00130 case PROBING_2: 00131 case PROBING_3: 00132 case ANNOUNCING_1: 00133 case ANNOUNCING_2: 00134 case ANNOUNCED: 00135 return PROBING_1; 00136 case CANCELING_1: 00137 case CANCELING_2: 00138 case CANCELING_3: 00139 return CANCELING_1; 00140 case CANCELED: 00141 return CANCELED; 00142 case CLOSING: 00143 return CLOSING; 00144 case CLOSED: 00145 return CLOSED; 00146 default: 00147 // This is just to keep the compiler happy as we have covered all cases before. 00148 return this; 00149 } 00150 } 00151 00157 public final boolean isProbing() { 00158 return _state == StateClass.probing; 00159 } 00160 00166 public final boolean isAnnouncing() { 00167 return _state == StateClass.announcing; 00168 } 00169 00175 public final boolean isAnnounced() { 00176 return _state == StateClass.announced; 00177 } 00178 00184 public final boolean isCanceling() { 00185 return _state == StateClass.canceling; 00186 } 00187 00193 public final boolean isCanceled() { 00194 return _state == StateClass.canceled; 00195 } 00196 00202 public final boolean isClosing() { 00203 return _state == StateClass.closing; 00204 } 00205 00211 public final boolean isClosed() { 00212 return _state == StateClass.closed; 00213 } 00214 00215 }