-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue #3730 - Cleaning up Scopes in WebSocketClient #4423
Merged
joakime
merged 7 commits into
jetty-9.4.x
from
jetty-9.4.x-3730-websocket-scope-cleanup
Dec 19, 2019
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
7d65183
Issue #3730 - Cleaning up Scopes in WebSocketClient
joakime 9da1820
Issue #3730 - Removing HttpContainerScope
joakime e02ef3e
Issue #3730 - Making new Constructor private
joakime bb79f3e
Issue #3730 - Collapsing now redundant private Constructor
joakime 9498859
Issue #3730 - Further updates from PR Review
joakime 26fde02
Issue #3730 - Updating invalid test assertion
joakime c2c2c56
Issue #3730 - EventDriverFactory and SessionFactory setters
joakime File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
119 changes: 119 additions & 0 deletions
119
...websocket-client/src/main/java/org/eclipse/jetty/websocket/client/HttpContainerScope.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
// | ||
// ======================================================================== | ||
// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd. | ||
// ------------------------------------------------------------------------ | ||
// All rights reserved. This program and the accompanying materials | ||
// are made available under the terms of the Eclipse Public License v1.0 | ||
// and Apache License v2.0 which accompanies this distribution. | ||
// | ||
// The Eclipse Public License is available at | ||
// http://www.eclipse.org/legal/epl-v10.html | ||
// | ||
// The Apache License v2.0 is available at | ||
// http://www.opensource.org/licenses/apache2.0.php | ||
// | ||
// You may elect to redistribute this code under either of these licenses. | ||
// ======================================================================== | ||
// | ||
|
||
package org.eclipse.jetty.websocket.client; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.concurrent.Executor; | ||
|
||
import org.eclipse.jetty.client.HttpClient; | ||
import org.eclipse.jetty.io.ByteBufferPool; | ||
import org.eclipse.jetty.util.DecoratedObjectFactory; | ||
import org.eclipse.jetty.util.component.ContainerLifeCycle; | ||
import org.eclipse.jetty.util.ssl.SslContextFactory; | ||
import org.eclipse.jetty.websocket.api.WebSocketPolicy; | ||
import org.eclipse.jetty.websocket.common.WebSocketSessionListener; | ||
import org.eclipse.jetty.websocket.common.scopes.WebSocketContainerScope; | ||
|
||
/** | ||
* A simple Scope that is focused around a HttpClient, DecoratedObjectFactory, and Client WebSocketPolicy. | ||
*/ | ||
public class HttpContainerScope extends ContainerLifeCycle implements WebSocketContainerScope | ||
{ | ||
private final HttpClient httpClient; | ||
private final DecoratedObjectFactory decoratedObjectFactory; | ||
private final WebSocketPolicy webSocketPolicy; | ||
private List<WebSocketSessionListener> sessionListeners = new ArrayList<>(); | ||
|
||
public HttpContainerScope(HttpClient httpClient) | ||
{ | ||
this(httpClient, new DecoratedObjectFactory()); | ||
} | ||
|
||
public HttpContainerScope(HttpClient httpClient, DecoratedObjectFactory decoratedObjectFactory) | ||
{ | ||
this.httpClient = Objects.requireNonNull(httpClient, "HttpClient"); | ||
this.decoratedObjectFactory = decoratedObjectFactory != null ? decoratedObjectFactory : new DecoratedObjectFactory(); | ||
this.webSocketPolicy = WebSocketPolicy.newClientPolicy(); | ||
} | ||
|
||
public HttpContainerScope(SslContextFactory sslContextFactory, Executor executor, ByteBufferPool bufferPool, DecoratedObjectFactory decoratedObjectFactory) | ||
{ | ||
this.httpClient = new HttpClient(sslContextFactory); | ||
this.httpClient.setExecutor(executor); | ||
this.httpClient.setByteBufferPool(bufferPool); | ||
this.decoratedObjectFactory = decoratedObjectFactory != null ? decoratedObjectFactory : new DecoratedObjectFactory(); | ||
this.webSocketPolicy = WebSocketPolicy.newClientPolicy(); | ||
} | ||
|
||
public HttpClient getHttpClient() | ||
{ | ||
return httpClient; | ||
} | ||
|
||
@Override | ||
public ByteBufferPool getBufferPool() | ||
{ | ||
return httpClient.getByteBufferPool(); | ||
} | ||
|
||
@Override | ||
public Executor getExecutor() | ||
{ | ||
return httpClient.getExecutor(); | ||
} | ||
|
||
@Override | ||
public DecoratedObjectFactory getObjectFactory() | ||
{ | ||
return decoratedObjectFactory; | ||
} | ||
|
||
@Override | ||
public WebSocketPolicy getPolicy() | ||
{ | ||
return webSocketPolicy; | ||
} | ||
|
||
@Override | ||
public SslContextFactory getSslContextFactory() | ||
{ | ||
return httpClient.getSslContextFactory(); | ||
} | ||
|
||
@Override | ||
public void addSessionListener(WebSocketSessionListener listener) | ||
{ | ||
this.sessionListeners.add(listener); | ||
} | ||
|
||
@Override | ||
public void removeSessionListener(WebSocketSessionListener listener) | ||
{ | ||
this.sessionListeners.remove(listener); | ||
} | ||
|
||
@Override | ||
public Collection<WebSocketSessionListener> getSessionListeners() | ||
{ | ||
return sessionListeners; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This call to add the
HttpClient
as a bean is repeated in every constructor, while it should only be in the newly introduced constructor.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, that's incorrect, there are 2 paths that have external clients.
Can't do that in the common constructor.