View Javadoc

1   //========================================================================
2   //Copyright 2011-2012 Mort Bay Consulting Pty. Ltd.
3   //------------------------------------------------------------------------
4   //All rights reserved. This program and the accompanying materials
5   //are made available under the terms of the Eclipse Public License v1.0
6   //and Apache License v2.0 which accompanies this distribution.
7   //The Eclipse Public License is available at
8   //http://www.eclipse.org/legal/epl-v10.html
9   //The Apache License v2.0 is available at
10  //http://www.opensource.org/licenses/apache2.0.php
11  //You may elect to redistribute this code under either of these licenses.
12  //========================================================================
13  
14  package org.eclipse.jetty.spdy.api;
15  
16  import java.util.HashMap;
17  import java.util.Map;
18  
19  /**
20   * <p>An enumeration of session statuses.</p>
21   */
22  public enum SessionStatus
23  {
24      /**
25       * <p>The session status indicating no errors</p>
26       */
27      OK(0),
28      /**
29       * <p>The session status indicating a protocol error</p>
30       */
31      PROTOCOL_ERROR(1);
32  
33      /**
34       * @param code the session status code
35       * @return a {@link SessionStatus} from the given code,
36       * or null if no status exists
37       */
38      public static SessionStatus from(int code)
39      {
40          return Codes.codes.get(code);
41      }
42  
43      private final int code;
44  
45      private SessionStatus(int code)
46      {
47          this.code = code;
48          Codes.codes.put(code, this);
49      }
50  
51      /**
52       * @return the code of this {@link SessionStatus}
53       */
54      public int getCode()
55      {
56          return code;
57      }
58  
59      private static class Codes
60      {
61          private static final Map<Integer, SessionStatus> codes = new HashMap<>();
62      }
63  }