diff --git a/jetty-websocket/javax-websocket-server-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/server/ServerContainer.java b/jetty-websocket/javax-websocket-server-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/server/ServerContainer.java index 45cfd12f32c..2e58bcf6377 100644 --- a/jetty-websocket/javax-websocket-server-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/server/ServerContainer.java +++ b/jetty-websocket/javax-websocket-server-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/server/ServerContainer.java @@ -18,8 +18,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; @@ -44,7 +42,6 @@ public class ServerContainer extends ClientContainer implements javax.websocket. private final MappedWebSocketCreator mappedCreator; private final WebSocketServerFactory webSocketServerFactory; - private final Map, ServerEndpointMetadata> endpointServerMetadataCache = new ConcurrentHashMap<>(); public ServerContainer(MappedWebSocketCreator creator, WebSocketServerFactory factory) { @@ -57,13 +54,6 @@ 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()); @@ -98,51 +88,46 @@ public class ServerContainer extends ClientContainer implements javax.websocket. @Override public void addEndpoint(ServerEndpointConfig config) throws DeploymentException { - LOG.debug("addEndpoint({})",config); + if (LOG.isDebugEnabled()) + { + LOG.debug("addEndpoint({}) path={} endpoint={}",config,config.getPath(),config.getEndpointClass()); + LOG.debug("Occurred from stack",new Throwable("stack")); + } ServerEndpointMetadata metadata = getServerEndpointMetadata(config.getEndpointClass(),config); addEndpoint(metadata); } - public ServerEndpointMetadata getServerEndpointMetadata(Class endpoint, ServerEndpointConfig config) throws DeploymentException + public ServerEndpointMetadata getServerEndpointMetadata(final Class endpoint, final ServerEndpointConfig config) throws DeploymentException { - synchronized (endpointServerMetadataCache) + ServerEndpointMetadata metadata = null; + + ServerEndpoint anno = endpoint.getAnnotation(ServerEndpoint.class); + if (anno != null) { - ServerEndpointMetadata metadata = endpointServerMetadataCache.get(endpoint); - if (metadata != null) - { - return metadata; - } - - ServerEndpoint anno = endpoint.getAnnotation(ServerEndpoint.class); - if (anno != null) - { - // Annotated takes precedence here - AnnotatedServerEndpointMetadata ametadata = new AnnotatedServerEndpointMetadata(endpoint,config); - AnnotatedEndpointScanner scanner = new AnnotatedEndpointScanner<>(ametadata); - metadata = ametadata; - scanner.scan(); - } - else if (Endpoint.class.isAssignableFrom(endpoint)) - { - // extends Endpoint - @SuppressWarnings("unchecked") - Class eendpoint = (Class)endpoint; - metadata = new SimpleServerEndpointMetadata(eendpoint,config); - } - else - { - StringBuilder err = new StringBuilder(); - err.append("Not a recognized websocket ["); - err.append(endpoint.getName()); - err.append("] does not extend @").append(ServerEndpoint.class.getName()); - err.append(" or extend from ").append(Endpoint.class.getName()); - throw new DeploymentException("Unable to identify as valid Endpoint: " + endpoint); - } - - endpointServerMetadataCache.put(endpoint,metadata); - - return metadata; + // Annotated takes precedence here + AnnotatedServerEndpointMetadata ametadata = new AnnotatedServerEndpointMetadata(endpoint,config); + AnnotatedEndpointScanner scanner = new AnnotatedEndpointScanner<>(ametadata); + metadata = ametadata; + scanner.scan(); } + else if (Endpoint.class.isAssignableFrom(endpoint)) + { + // extends Endpoint + @SuppressWarnings("unchecked") + Class eendpoint = (Class)endpoint; + metadata = new SimpleServerEndpointMetadata(eendpoint,config); + } + else + { + StringBuilder err = new StringBuilder(); + err.append("Not a recognized websocket ["); + err.append(endpoint.getName()); + err.append("] does not extend @").append(ServerEndpoint.class.getName()); + err.append(" or extend from ").append(Endpoint.class.getName()); + throw new DeploymentException("Unable to identify as valid Endpoint: " + endpoint); + } + + return metadata; } @Override diff --git a/jetty-websocket/javax-websocket-server-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/server/SimpleServerEndpointMetadata.java b/jetty-websocket/javax-websocket-server-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/server/SimpleServerEndpointMetadata.java index 5864268d7c6..ced82468cab 100644 --- a/jetty-websocket/javax-websocket-server-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/server/SimpleServerEndpointMetadata.java +++ b/jetty-websocket/javax-websocket-server-impl/src/main/java/org/eclipse/jetty/websocket/jsr356/server/SimpleServerEndpointMetadata.java @@ -49,4 +49,18 @@ public class SimpleServerEndpointMetadata extends SimpleEndpointMetadata impleme { return config.getPath(); } + + @Override + public String toString() + { + StringBuilder builder = new StringBuilder(); + builder.append("SimpleServerEndpointMetadata ["); + builder.append("config=").append(config.getClass().getName()); + builder.append(",path=").append(config.getPath()); + builder.append(",endpoint=").append(config.getEndpointClass()); + builder.append(",decoders=").append(config.getDecoders()); + builder.append(",encoders=").append(config.getEncoders()); + builder.append("]"); + return builder.toString(); + } }