Merge pull request #4664 from eclipse/jetty-9.4.x-4650-RemoteEndpointFactory
Issue #4650 - do not use ServiceLoader every time a WSSession is started
This commit is contained in:
commit
a9ef2d0d74
|
@ -64,6 +64,7 @@ import org.eclipse.jetty.websocket.common.scopes.WebSocketSessionScope;
|
|||
public class WebSocketSession extends ContainerLifeCycle implements Session, RemoteEndpointFactory, WebSocketSessionScope, IncomingFrames, OutgoingFrames, Connection.Listener
|
||||
{
|
||||
private static final Logger LOG = Log.getLogger(WebSocketSession.class);
|
||||
private static final RemoteEndpointFactory defaultRemoteEndpointFactory;
|
||||
private final WebSocketContainerScope containerScope;
|
||||
private final URI requestURI;
|
||||
private final LogicalConnection connection;
|
||||
|
@ -71,9 +72,9 @@ public class WebSocketSession extends ContainerLifeCycle implements Session, Rem
|
|||
private final Executor executor;
|
||||
private final WebSocketPolicy policy;
|
||||
private final AtomicBoolean onCloseCalled = new AtomicBoolean(false);
|
||||
private final RemoteEndpointFactory remoteEndpointFactory;
|
||||
private ClassLoader classLoader;
|
||||
private ExtensionFactory extensionFactory;
|
||||
private RemoteEndpointFactory remoteEndpointFactory;
|
||||
private String protocolVersion;
|
||||
private Map<String, String[]> parameterMap = new HashMap<>();
|
||||
private RemoteEndpoint remote;
|
||||
|
@ -83,6 +84,15 @@ public class WebSocketSession extends ContainerLifeCycle implements Session, Rem
|
|||
private UpgradeResponse upgradeResponse;
|
||||
private CompletableFuture<Session> openFuture;
|
||||
|
||||
static
|
||||
{
|
||||
// Attempt to discover a RemoteEndpointFactory with the SerivceLoader.
|
||||
Iterator<RemoteEndpointFactory> iter = ServiceLoader.load(RemoteEndpointFactory.class).iterator();
|
||||
defaultRemoteEndpointFactory = iter.hasNext() ? iter.next() : null;
|
||||
if (LOG.isDebugEnabled())
|
||||
LOG.debug("Discovered default RemoteEndpointFactory: {}", defaultRemoteEndpointFactory);
|
||||
}
|
||||
|
||||
public WebSocketSession(WebSocketContainerScope containerScope, URI requestURI, EventDriver websocket, LogicalConnection connection)
|
||||
{
|
||||
Objects.requireNonNull(containerScope, "Container Scope cannot be null");
|
||||
|
@ -98,6 +108,10 @@ public class WebSocketSession extends ContainerLifeCycle implements Session, Rem
|
|||
this.incomingHandler = websocket;
|
||||
this.policy = websocket.getPolicy();
|
||||
|
||||
remoteEndpointFactory = (defaultRemoteEndpointFactory == null) ? this : defaultRemoteEndpointFactory;
|
||||
if (LOG.isDebugEnabled())
|
||||
LOG.debug("Using RemoteEndpointFactory: {}", remoteEndpointFactory);
|
||||
|
||||
this.connection.setSession(this);
|
||||
|
||||
addBean(this.connection);
|
||||
|
@ -168,16 +182,6 @@ public class WebSocketSession extends ContainerLifeCycle implements Session, Rem
|
|||
if (LOG.isDebugEnabled())
|
||||
LOG.debug("starting - {}", this);
|
||||
|
||||
Iterator<RemoteEndpointFactory> iter = ServiceLoader.load(RemoteEndpointFactory.class).iterator();
|
||||
if (iter.hasNext())
|
||||
remoteEndpointFactory = iter.next();
|
||||
|
||||
if (remoteEndpointFactory == null)
|
||||
remoteEndpointFactory = this;
|
||||
|
||||
if (LOG.isDebugEnabled())
|
||||
LOG.debug("Using RemoteEndpointFactory: {}", remoteEndpointFactory);
|
||||
|
||||
super.doStart();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue