Polish in EndpointRegistration

This commit is contained in:
Rossen Stoyanchev
2013-04-05 09:48:11 -04:00
parent 6cf17449fa
commit 41153efd03
2 changed files with 46 additions and 43 deletions

View File

@@ -101,9 +101,8 @@ public abstract class AbstractEndpointConnectionManager implements ApplicationCo
}
/**
* Set whether to auto-connect to the {@link #setDefaultUri(URI) default URI} after
* this endpoint connection factory has been initialized and the Spring context has
* been refreshed.
* Set whether to auto-connect to the remote endpoint after this connection manager
* has been initialized and the Spring context has been refreshed.
* <p>Default is "false".
*/
public void setAutoStartup(boolean autoStartup) {
@@ -112,17 +111,17 @@ public abstract class AbstractEndpointConnectionManager implements ApplicationCo
/**
* Return the value for the 'autoStartup' property. If "true", this endpoint
* connection factory will connect to the {@link #setDefaultUri(URI) default URI} upon
* a ContextRefreshedEvent.
* connection manager will connect to the remote endpoint upon a
* ContextRefreshedEvent.
*/
public boolean isAutoStartup() {
return this.autoStartup;
}
/**
* Specify the phase in which this endpoint connection factory should be
* auto-connected and closed. The startup order proceeds from lowest to highest, and
* the shutdown order is the reverse of that. By default this value is
* Specify the phase in which a connection should be established to the remote
* endpoint and subsequently closed. The startup order proceeds from lowest to
* highest, and the shutdown order is the reverse of that. By default this value is
* Integer.MAX_VALUE meaning that this endpoint connection factory connects as late as
* possible and is closed as soon as possible.
*/

View File

@@ -17,7 +17,6 @@
package org.springframework.websocket.server.endpoint;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -37,6 +36,7 @@ import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.web.context.ContextLoader;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.websocket.endpoint.StandardWebSocketHandlerAdapter;
/**
@@ -60,16 +60,20 @@ public class EndpointRegistration implements ServerEndpointConfig, BeanFactoryAw
private final Object endpointBean;
private List<Class<? extends Encoder>> encoders;
private List<Class<? extends Decoder>> decoders;
private List<String> subprotocols = new ArrayList<String>();
private List<Extension> extensions = new ArrayList<Extension>();
private Map<String, Object> userProperties = new HashMap<String, Object>();
private final Map<String, Object> userProperties = new HashMap<String, Object>();
private Configurator configurator = new Configurator() {};
private BeanFactory beanFactory;
private final Configurator configurator = new Configurator() {};
/**
* Class constructor with the {@code javax.webscoket.Endpoint} class.
@@ -138,18 +142,13 @@ public class EndpointRegistration implements ServerEndpointConfig, BeanFactoryAw
return (Endpoint) bean;
}
@Override
public List<String> getSubprotocols() {
return this.subprotocols;
}
public void setSubprotocols(List<String> subprotocols) {
this.subprotocols = subprotocols;
}
@Override
public List<Extension> getExtensions() {
return this.extensions;
public List<String> getSubprotocols() {
return this.subprotocols;
}
public void setExtensions(List<Extension> extensions) {
@@ -157,23 +156,37 @@ public class EndpointRegistration implements ServerEndpointConfig, BeanFactoryAw
this.extensions = extensions;
}
@Override
public List<Extension> getExtensions() {
return this.extensions;
}
public void setUserProperties(Map<String, Object> userProperties) {
this.userProperties.clear();
this.userProperties.putAll(userProperties);
}
@Override
public Map<String, Object> getUserProperties() {
return this.userProperties;
}
public void setUserProperties(Map<String, Object> userProperties) {
this.userProperties = userProperties;
public void setEncoders(List<Class<? extends Encoder>> encoders) {
this.encoders = encoders;
}
@Override
public List<Class<? extends Encoder>> getEncoders() {
return Collections.emptyList();
return this.encoders;
}
public void setDecoders(List<Class<? extends Decoder>> decoders) {
this.decoders = decoders;
}
@Override
public List<Class<? extends Decoder>> getDecoders() {
return Collections.emptyList();
return this.decoders;
}
@Override
@@ -181,6 +194,13 @@ public class EndpointRegistration implements ServerEndpointConfig, BeanFactoryAw
this.beanFactory = beanFactory;
}
/**
* The {@link Configurator#getEndpointInstance(Class)} method is always ignored.
*/
public void setConfigurator(Configurator configurator) {
this.configurator = configurator;
}
@Override
public Configurator getConfigurator() {
return new Configurator() {
@@ -191,37 +211,21 @@ public class EndpointRegistration implements ServerEndpointConfig, BeanFactoryAw
}
@Override
public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) {
EndpointRegistration.this.modifyHandshake(request, response);
EndpointRegistration.this.configurator.modifyHandshake(sec, request, response);
}
@Override
public boolean checkOrigin(String originHeaderValue) {
return EndpointRegistration.this.checkOrigin(originHeaderValue);
return EndpointRegistration.this.configurator.checkOrigin(originHeaderValue);
}
@Override
public String getNegotiatedSubprotocol(List<String> supported, List<String> requested) {
return EndpointRegistration.this.selectSubProtocol(requested);
return EndpointRegistration.this.configurator.getNegotiatedSubprotocol(supported, requested);
}
@Override
public List<Extension> getNegotiatedExtensions(List<Extension> installed, List<Extension> requested) {
return EndpointRegistration.this.selectExtensions(requested);
return EndpointRegistration.this.configurator.getNegotiatedExtensions(installed, requested);
}
};
}
protected void modifyHandshake(HandshakeRequest request, HandshakeResponse response) {
this.configurator.modifyHandshake(this, request, response);
}
protected boolean checkOrigin(String originHeaderValue) {
return this.configurator.checkOrigin(originHeaderValue);
}
protected String selectSubProtocol(List<String> requested) {
return this.configurator.getNegotiatedSubprotocol(getSubprotocols(), requested);
}
protected List<Extension> selectExtensions(List<Extension> requested) {
return this.configurator.getNegotiatedExtensions(getExtensions(), requested);
}
}