View Javadoc

1   //
2   //  ========================================================================
3   //  Copyright (c) 1995-2016 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.common.scopes;
20  
21  import java.util.concurrent.Executor;
22  
23  import org.eclipse.jetty.io.ByteBufferPool;
24  import org.eclipse.jetty.io.MappedByteBufferPool;
25  import org.eclipse.jetty.util.DecoratedObjectFactory;
26  import org.eclipse.jetty.util.component.ContainerLifeCycle;
27  import org.eclipse.jetty.util.ssl.SslContextFactory;
28  import org.eclipse.jetty.util.thread.QueuedThreadPool;
29  import org.eclipse.jetty.websocket.api.WebSocketPolicy;
30  import org.eclipse.jetty.websocket.common.WebSocketSession;
31  
32  public class SimpleContainerScope extends ContainerLifeCycle implements WebSocketContainerScope
33  {
34      private final ByteBufferPool bufferPool;
35      private final DecoratedObjectFactory objectFactory;
36      private final WebSocketPolicy policy;
37      private Executor executor;
38      private SslContextFactory sslContextFactory;
39  
40      public SimpleContainerScope(WebSocketPolicy policy)
41      {
42          this(policy,new MappedByteBufferPool(),new DecoratedObjectFactory());
43      }
44  
45      public SimpleContainerScope(WebSocketPolicy policy, ByteBufferPool bufferPool)
46      {
47          this(policy,bufferPool,new DecoratedObjectFactory());
48      }
49  
50      public SimpleContainerScope(WebSocketPolicy policy, ByteBufferPool bufferPool, DecoratedObjectFactory objectFactory)
51      {
52          this.policy = policy;
53          this.bufferPool = bufferPool;
54          this.objectFactory = objectFactory;
55  
56          QueuedThreadPool threadPool = new QueuedThreadPool();
57          String name = "WebSocketSimpleContainer@" + hashCode();
58          threadPool.setName(name);
59          threadPool.setDaemon(true);
60          this.executor = threadPool;
61      }
62  
63      @Override
64      protected void doStart() throws Exception
65      {
66          super.doStart();
67      }
68  
69      @Override
70      protected void doStop() throws Exception
71      {
72          super.doStop();
73      }
74  
75      @Override
76      public ByteBufferPool getBufferPool()
77      {
78          return this.bufferPool;
79      }
80  
81      @Override
82      public Executor getExecutor()
83      {
84          return this.executor;
85      }
86  
87      @Override
88      public DecoratedObjectFactory getObjectFactory()
89      {
90          return this.objectFactory;
91      }
92  
93      @Override
94      public WebSocketPolicy getPolicy()
95      {
96          return this.policy;
97      }
98  
99      @Override
100     public SslContextFactory getSslContextFactory()
101     {
102         return this.sslContextFactory;
103     }
104 
105     public void setSslContextFactory(SslContextFactory sslContextFactory)
106     {
107         this.sslContextFactory = sslContextFactory;
108     }
109 
110     @Override
111     public void onSessionOpened(WebSocketSession session)
112     {
113     }
114 
115     @Override
116     public void onSessionClosed(WebSocketSession session)
117     {
118     }
119 }