Removing @ServerEndpoint caching, its just getting in the way

This commit is contained in:
Joakim Erdfelt 2013-09-06 12:28:33 -07:00
parent 9008210c2e
commit 714bbf943a
2 changed files with 47 additions and 48 deletions

View File

@ -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<Class<?>, 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<ServerEndpoint,ServerEndpointConfig> scanner = new AnnotatedEndpointScanner<>(ametadata);
metadata = ametadata;
scanner.scan();
}
else if (Endpoint.class.isAssignableFrom(endpoint))
{
// extends Endpoint
@SuppressWarnings("unchecked")
Class<? extends Endpoint> eendpoint = (Class<? extends Endpoint>)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<ServerEndpoint, ServerEndpointConfig> scanner = new AnnotatedEndpointScanner<>(ametadata);
metadata = ametadata;
scanner.scan();
}
else if (Endpoint.class.isAssignableFrom(endpoint))
{
// extends Endpoint
@SuppressWarnings("unchecked")
Class<? extends Endpoint> eendpoint = (Class<? extends Endpoint>)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

View File

@ -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();
}
}