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  import org.eclipse.jetty.websocket.api.io.WebSocketBlockingConnection;
22  
23  /**
24   * Default implementation of the {@link WebSocketListener}.
25   * <p>
26   * Convenient abstract class to base standard WebSocket implementations off of.
27   */
28  public class WebSocketAdapter implements WebSocketListener
29  {
30      private WebSocketConnection connection;
31      private WebSocketBlockingConnection blocking;
32  
33      public WebSocketBlockingConnection getBlockingConnection()
34      {
35          return blocking;
36      }
37  
38      public WebSocketConnection getConnection()
39      {
40          return connection;
41      }
42  
43      public boolean isConnected()
44      {
45          return (connection != null) && (connection.isOpen());
46      }
47  
48      public boolean isNotConnected()
49      {
50          return (connection == null) || (!connection.isOpen());
51      }
52  
53      @Override
54      public void onWebSocketBinary(byte[] payload, int offset, int len)
55      {
56          /* do nothing */
57      }
58  
59      @Override
60      public void onWebSocketClose(int statusCode, String reason)
61      {
62          this.connection = null;
63      }
64  
65      @Override
66      public void onWebSocketConnect(WebSocketConnection connection)
67      {
68          this.connection = connection;
69          this.blocking = new WebSocketBlockingConnection(this.connection);
70      }
71  
72      @Override
73      public void onWebSocketException(WebSocketException error)
74      {
75          /* do nothing */
76      }
77  
78      @Override
79      public void onWebSocketText(String message)
80      {
81          /* do nothing */
82      }
83  }