View Javadoc

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  /**
22   * Basic WebSocket Listener interface for incoming WebSocket events.
23   */
24  public interface WebSocketListener
25  {
26      /**
27       * A WebSocket binary frame has been received.
28       * 
29       * @param payload
30       *            the raw payload array received
31       * @param offset
32       *            the offset in the payload array where the data starts
33       * @param len
34       *            the length of bytes in the payload
35       */
36      void onWebSocketBinary(byte payload[], int offset, int len);
37  
38      /**
39       * A Close Event was received.
40       * <p>
41       * The underlying {@link WebSocketConnection} will be considered closed at this point.
42       * 
43       * @param statusCode
44       *            the close status code. (See {@link StatusCode})
45       * @param reason
46       *            the optional reason for the close.
47       */
48      void onWebSocketClose(int statusCode, String reason);
49  
50      /**
51       * A WebSocket {@link Session} has connected successfully and is ready to be used.
52       * <p>
53       * Note: It is a good idea to track this session as a field in your object so that you can write messages back via the {@link RemoteEndpoint}
54       * 
55       * @param session
56       *            the websocket session.
57       */
58      void onWebSocketConnect(Session session);
59  
60      /**
61       * A WebSocket exception has occurred.
62       * <p>
63       * This is a way for the internal implementation to notify of exceptions occured during the processing of websocket.
64       * <p>
65       * Usually this occurs from bad / malformed incoming packets. (example: bad UTF8 data, frames that are too big, violations of the spec)
66       * <p>
67       * This will result in the {@link Session} being closed by the implementing side.
68       * 
69       * @param error
70       *            the error that occurred.
71       */
72      void onWebSocketError(Throwable cause);
73  
74      /**
75       * A WebSocket Text frame was received.
76       * 
77       * @param message
78       */
79      void onWebSocketText(String message);
80  }