1 //
2 // ========================================================================
3 // Copyright (c) 1995-2013 Mort Bay Consulting Pty. Ltd.
4 // ------------------------------------------------------------------------
5 // All rights reserved. This program and the accompanying materials
6 // are made available under the terms of the Eclipse Public License v1.0
7 // and Apache License v2.0 which accompanies this distribution.
8 //
9 // The Eclipse Public License is available at
10 // http://www.eclipse.org/legal/epl-v10.html
11 //
12 // The Apache License v2.0 is available at
13 // http://www.opensource.org/licenses/apache2.0.php
14 //
15 // You may elect to redistribute this code under either of these licenses.
16 // ========================================================================
17 //
18
19 package org.eclipse.jetty.websocket.api;
20
21 public class CloseStatus
22 {
23 private static final int MAX_CONTROL_PAYLOAD = 125;
24 private static final int MAX_REASON_PHRASE = MAX_CONTROL_PAYLOAD - 2;
25 private int code;
26 private String phrase;
27
28 /**
29 * Creates a reason for closing a web socket connection with the given code and reason phrase.
30 *
31 * @param closeCode
32 * the close code
33 * @param reasonPhrase
34 * the reason phrase
35 * @see StatusCode
36 */
37 public CloseStatus(int closeCode, String reasonPhrase)
38 {
39 this.code = closeCode;
40 this.phrase = reasonPhrase;
41 if (reasonPhrase.length() > MAX_REASON_PHRASE)
42 {
43 throw new IllegalArgumentException("Phrase exceeds maximum length of " + MAX_REASON_PHRASE);
44 }
45 }
46
47 public int getCode()
48 {
49 return code;
50 }
51
52 public String getPhrase()
53 {
54 return phrase;
55 }
56 }