Source code: com/synaptics/elvis/ElvisCommStatus.java
1 /*
2 * The contents of this file are subject to the Mozilla Public License Version
3 * 1.1 (the "License"); you may not use this file except in compliance with the
4 * License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
5 *
6 * Software distributed under the License is distributed on an "AS IS" basis,
7 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
8 * the specific language governing rights and limitations under the License.
9 *
10 * The Original Code is com.synaptics.elvis code.
11 *
12 * The Initial Developers of the Original Code are Synaptics, Inc. and Christopher Heiny.
13 * Portions created by Synaptics, Inc. and Christopher Heiny are
14 * Copyright (C) 2002 Synaptics, Inc. and Christopher Heiny. All Rights Reserved.
15 *
16 * Contributor(s):
17 * Christopher Heiny <cheiny@synaptics.com>
18 */
19
20 package com.synaptics.elvis;
21
22 /** ElvisCommStatus implements an enumeration of the various statuses than an
23 * ElvisComm may have. See the individual statuses for details of what they do.
24 * <P>
25 * ElvisCommStatus is private to the elvis package, and should never be put in a
26 * position to be directly seen by clients. However, each status has a string
27 * associated with it that is more or less descriptive of the status. It is quite
28 * practical to pass this String to Elvis clients.
29 * <P>
30 * ElvisCommStatus implements the <CODE>typesafe enum</code> design pattern, as described
31 * in Joshua Bloch's <I>Effective Java</i>.
32 *
33 * @author cheiny
34 * @version $Id: ElvisCommStatus.java,v 1.1 2002/05/09 07:17:17 clheiny Exp $
35 */
36
37 final class ElvisCommStatus {
38
39 /** We keep a list of valid statuses here for checking.
40 */
41 private static java.util.Hashtable knownStatus = new java.util.Hashtable();
42
43 /** Indicates that we are the One True Elvis, and are waiting for a request.
44 */
45 public static final ElvisCommStatus OK = new ElvisCommStatus("listening");
46
47 /** Indicates that we are the One True Elvis, and are handling a request.
48 */
49 public static final ElvisCommStatus PROCESSING = new ElvisCommStatus("performing");
50
51 /** Are in the process of locking the authentication information file.
52 */
53 public static final ElvisCommStatus LOCKING = new ElvisCommStatus("acquiring file lock");
54
55 /** This instance has been created but not started. You must call @link #start() to do that.
56 */
57 public static final ElvisCommStatus NEW = new ElvisCommStatus("uninitialized");
58
59 /** We are looking to see if another Elvis might exist on this machine.
60 */
61 public static final ElvisCommStatus CHECKING = new ElvisCommStatus("looking for another Elvis");
62
63 /** There might be another Elvis, and we are trying to contact him.
64 */
65 public static final ElvisCommStatus CONNECTING = new ElvisCommStatus("trying to contact an existing instance");
66
67 /** We failed miserably in setting up the listener. The fans might as well go home.
68 */
69 public static final ElvisCommStatus FAILED = new ElvisCommStatus("failed");
70
71 /** We timed out waiting for the other Elvis to respond to us.
72 */
73 public static final ElvisCommStatus TIMEOUT = new ElvisCommStatus("timeout waiting for response");
74
75 /** The other Elvis did not send a reasonable response.
76 */
77 public static final ElvisCommStatus NO_RESPONSE = new ElvisCommStatus("no response");
78
79 /** There is another Elvis, he responded correctly, so we will be asking him to
80 * handle all performance requests.
81 */
82 public static final ElvisCommStatus NOT_THE_KING = new ElvisCommStatus("we are not Elvis");
83
84 /** This is the string associated with this status. We initialize it to <CODE>"ERROR"</code> just in case
85 * something strange happens.
86 */
87 String name = "ERROR";
88
89 /** Creates new ElvisCommStatus */
90 private ElvisCommStatus(String name) {
91 this.name = name;
92 knownStatus.put ( name, this );
93 }
94
95 /** Get the String associated with the status.
96 * @return A (hopefully) descriptive String.
97 */
98 public String toString() {
99 return name;
100 }
101
102 /** @return <CODE>true</code> if this string corresponds to a known status, <CODE>false</code>
103 * otherwise.
104 */
105 public static final boolean valid ( String name ) {
106 return knownStatus.containsKey(name);
107 }
108
109 }