Fixed lifecycle management.
This commit is contained in:
parent
47a8809ec7
commit
ed95ffbfea
|
@ -27,7 +27,6 @@ import java.util.Set;
|
|||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
import javax.websocket.ClientEndpoint;
|
||||
import javax.websocket.ClientEndpointConfig;
|
||||
import javax.websocket.DeploymentException;
|
||||
|
@ -68,7 +67,7 @@ public class ClientContainer extends ContainerLifeCycle implements WebSocketCont
|
|||
/** Tracking for all declared Client endpoints */
|
||||
private final Map<Class<?>, EndpointMetadata> endpointClientMetadataCache;
|
||||
/** The jetty websocket client in use for this container */
|
||||
private WebSocketClient client;
|
||||
private final WebSocketClient client;
|
||||
|
||||
public ClientContainer()
|
||||
{
|
||||
|
@ -79,6 +78,26 @@ public class ClientContainer extends ContainerLifeCycle implements WebSocketCont
|
|||
EmptyClientEndpointConfig empty = new EmptyClientEndpointConfig();
|
||||
decoderFactory.init(empty);
|
||||
encoderFactory.init(empty);
|
||||
|
||||
client = new WebSocketClient();
|
||||
client.setEventDriverFactory(new JsrEventDriverFactory(client.getPolicy()));
|
||||
client.setSessionFactory(new JsrSessionFactory(this));
|
||||
addBean(client);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doStart() throws Exception
|
||||
{
|
||||
super.doStart();
|
||||
ShutdownThread.register(client);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doStop() throws Exception
|
||||
{
|
||||
endpointClientMetadataCache.clear();
|
||||
ShutdownThread.deregister(client);
|
||||
super.doStop();
|
||||
}
|
||||
|
||||
private Session connect(EndpointInstance instance, URI path) throws IOException
|
||||
|
@ -159,19 +178,6 @@ public class ClientContainer extends ContainerLifeCycle implements WebSocketCont
|
|||
return connect(instance,path);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doStart() throws Exception
|
||||
{
|
||||
client = new WebSocketClient();
|
||||
client.setEventDriverFactory(new JsrEventDriverFactory(client.getPolicy()));
|
||||
client.setSessionFactory(new JsrSessionFactory(this));
|
||||
addBean(client);
|
||||
|
||||
ShutdownThread.register(client);
|
||||
|
||||
super.doStart();
|
||||
}
|
||||
|
||||
public EndpointMetadata getClientEndpointMetadata(Class<?> endpoint)
|
||||
{
|
||||
EndpointMetadata metadata = null;
|
||||
|
@ -266,7 +272,7 @@ public class ClientContainer extends ContainerLifeCycle implements WebSocketCont
|
|||
|
||||
/**
|
||||
* Used in {@link Session#getOpenSessions()}
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Set<Session> getOpenSessions()
|
||||
|
|
|
@ -20,7 +20,6 @@ package org.eclipse.jetty.websocket.jsr356.server;
|
|||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import javax.websocket.DeploymentException;
|
||||
import javax.websocket.Endpoint;
|
||||
import javax.websocket.server.ServerEndpoint;
|
||||
|
@ -42,10 +41,10 @@ import org.eclipse.jetty.websocket.server.WebSocketServerFactory;
|
|||
public class ServerContainer extends ClientContainer implements javax.websocket.server.ServerContainer
|
||||
{
|
||||
private static final Logger LOG = Log.getLogger(ServerContainer.class);
|
||||
|
||||
|
||||
private final MappedWebSocketCreator mappedCreator;
|
||||
private final WebSocketServerFactory webSocketServerFactory;
|
||||
private Map<Class<?>, ServerEndpointMetadata> endpointServerMetadataCache = new ConcurrentHashMap<>();
|
||||
private final Map<Class<?>, ServerEndpointMetadata> endpointServerMetadataCache = new ConcurrentHashMap<>();
|
||||
|
||||
public ServerContainer(MappedWebSocketCreator creator, WebSocketServerFactory factory)
|
||||
{
|
||||
|
@ -58,6 +57,13 @@ public class ServerContainer extends ClientContainer implements javax.websocket.
|
|||
this.webSocketServerFactory.addSessionFactory(new JsrSessionFactory(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doStop() throws Exception
|
||||
{
|
||||
endpointServerMetadataCache.clear();
|
||||
super.doStop();
|
||||
}
|
||||
|
||||
public EndpointInstance newClientEndpointInstance(Object endpoint, ServerEndpointConfig config, String path)
|
||||
{
|
||||
EndpointMetadata metadata = getClientEndpointMetadata(endpoint.getClass());
|
||||
|
@ -189,7 +195,7 @@ public class ServerContainer extends ClientContainer implements javax.websocket.
|
|||
{
|
||||
// overall message limit (used in non-streaming)
|
||||
webSocketServerFactory.getPolicy().setMaxTextMessageSize(max);
|
||||
// incoming streaming buffer size
|
||||
// incoming streaming buffer size
|
||||
webSocketServerFactory.getPolicy().setMaxTextMessageBufferSize(max);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
package org.eclipse.jetty.websocket.server;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.servlet.Filter;
|
||||
import javax.servlet.FilterChain;
|
||||
import javax.servlet.FilterConfig;
|
||||
|
@ -49,8 +48,8 @@ public class WebSocketUpgradeFilter extends ContainerLifeCycle implements Filter
|
|||
{
|
||||
private static final Logger LOG = Log.getLogger(WebSocketUpgradeFilter.class);
|
||||
private final WebSocketServerFactory factory;
|
||||
private PathMappings<WebSocketCreator> pathmap = new PathMappings<>();
|
||||
|
||||
private final PathMappings<WebSocketCreator> pathmap = new PathMappings<>();
|
||||
|
||||
public WebSocketUpgradeFilter(WebSocketPolicy policy)
|
||||
{
|
||||
factory = new WebSocketServerFactory(policy);
|
||||
|
@ -67,8 +66,10 @@ public class WebSocketUpgradeFilter extends ContainerLifeCycle implements Filter
|
|||
public void destroy()
|
||||
{
|
||||
factory.cleanup();
|
||||
pathmap.getMappings().clear();
|
||||
super.destroy();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException
|
||||
{
|
||||
|
@ -124,7 +125,6 @@ public class WebSocketUpgradeFilter extends ContainerLifeCycle implements Filter
|
|||
|
||||
// not an Upgrade request
|
||||
chain.doFilter(request,response);
|
||||
return;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -158,7 +158,7 @@ public class WebSocketUpgradeFilter extends ContainerLifeCycle implements Filter
|
|||
try
|
||||
{
|
||||
WebSocketPolicy policy = factory.getPolicy();
|
||||
|
||||
|
||||
String max = config.getInitParameter("maxIdleTime");
|
||||
if (max != null)
|
||||
{
|
||||
|
@ -182,7 +182,7 @@ public class WebSocketUpgradeFilter extends ContainerLifeCycle implements Filter
|
|||
{
|
||||
policy.setInputBufferSize(Integer.parseInt(max));
|
||||
}
|
||||
|
||||
|
||||
factory.start();
|
||||
}
|
||||
catch (Exception x)
|
||||
|
|
Loading…
Reference in New Issue