View Javadoc

1   //
2   //  ========================================================================
3   //  Copyright (c) 1995-2014 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.server;
20  
21  import java.net.InetSocketAddress;
22  import java.util.concurrent.Executor;
23  import java.util.concurrent.atomic.AtomicBoolean;
24  
25  import org.eclipse.jetty.io.ByteBufferPool;
26  import org.eclipse.jetty.io.EndPoint;
27  import org.eclipse.jetty.util.thread.Scheduler;
28  import org.eclipse.jetty.websocket.api.WebSocketPolicy;
29  import org.eclipse.jetty.websocket.api.extensions.IncomingFrames;
30  import org.eclipse.jetty.websocket.common.io.AbstractWebSocketConnection;
31  
32  public class WebSocketServerConnection extends AbstractWebSocketConnection
33  {
34      private final AtomicBoolean opened = new AtomicBoolean(false);
35  
36      public WebSocketServerConnection(EndPoint endp, Executor executor, Scheduler scheduler, WebSocketPolicy policy, ByteBufferPool bufferPool)
37      {
38          super(endp,executor,scheduler,policy,bufferPool);
39          if (policy.getIdleTimeout() > 0)
40          {
41              endp.setIdleTimeout(policy.getIdleTimeout());
42          }
43      }
44  
45      @Override
46      public InetSocketAddress getLocalAddress()
47      {
48          return getEndPoint().getLocalAddress();
49      }
50  
51      @Override
52      public InetSocketAddress getRemoteAddress()
53      {
54          return getEndPoint().getRemoteAddress();
55      }
56  
57      @Override
58      public void onOpen()
59      {
60          boolean beenOpened = opened.getAndSet(true);
61          if (!beenOpened)
62          {
63              getSession().open();
64          }
65          super.onOpen();
66      }
67      
68      @Override
69      public void setNextIncomingFrames(IncomingFrames incoming)
70      {
71          getParser().setIncomingFramesHandler(incoming);
72      }
73  }