Merge pull request #4026 from eclipse/jetty-9.4.x-4020-websocket-incompatibleclasschange

Fixes #4020 - Revert ExtensionFactory change to interface.
This commit is contained in:
Joakim Erdfelt 2019-08-28 12:37:44 -05:00 committed by GitHub
commit bf3638daa4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 199 additions and 13 deletions

View File

@ -18,22 +18,70 @@
package org.eclipse.jetty.websocket.api.extensions;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.ServiceLoader;
import java.util.Set;
public interface ExtensionFactory extends Iterable<Class<? extends Extension>>
/**
* The Factory for Extensions.
*
* @deprecated this class is removed from Jetty 10.0.0+
*/
@Deprecated
public abstract class ExtensionFactory implements Iterable<Class<? extends Extension>>
{
Map<String, Class<? extends Extension>> getAvailableExtensions();
private ServiceLoader<Extension> extensionLoader = ServiceLoader.load(Extension.class);
private Map<String, Class<? extends Extension>> availableExtensions;
Class<? extends Extension> getExtension(String name);
public ExtensionFactory()
{
availableExtensions = new HashMap<>();
for (Extension ext : extensionLoader)
{
if (ext != null)
{
availableExtensions.put(ext.getName(), ext.getClass());
}
}
}
Set<String> getExtensionNames();
public Map<String, Class<? extends Extension>> getAvailableExtensions()
{
return availableExtensions;
}
boolean isAvailable(String name);
public Class<? extends Extension> getExtension(String name)
{
return availableExtensions.get(name);
}
Extension newInstance(ExtensionConfig config);
public Set<String> getExtensionNames()
{
return availableExtensions.keySet();
}
void register(String name, Class<? extends Extension> extension);
public boolean isAvailable(String name)
{
return availableExtensions.containsKey(name);
}
void unregister(String name);
@Override
public Iterator<Class<? extends Extension>> iterator()
{
return availableExtensions.values().iterator();
}
public abstract Extension newInstance(ExtensionConfig config);
public void register(String name, Class<? extends Extension> extension)
{
availableExtensions.put(name, extension);
}
public void unregister(String name)
{
availableExtensions.remove(name);
}
}

View File

@ -18,6 +18,7 @@
package org.eclipse.jetty.websocket.common.extensions;
import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
@ -27,6 +28,8 @@ import java.util.zip.Deflater;
import org.eclipse.jetty.util.StringUtil;
import org.eclipse.jetty.util.component.ContainerLifeCycle;
import org.eclipse.jetty.util.component.Dumpable;
import org.eclipse.jetty.util.component.LifeCycle;
import org.eclipse.jetty.util.compression.CompressionPool;
import org.eclipse.jetty.util.compression.DeflaterPool;
import org.eclipse.jetty.util.compression.InflaterPool;
@ -37,8 +40,9 @@ import org.eclipse.jetty.websocket.api.extensions.ExtensionFactory;
import org.eclipse.jetty.websocket.common.extensions.compress.CompressExtension;
import org.eclipse.jetty.websocket.common.scopes.WebSocketContainerScope;
public class WebSocketExtensionFactory extends ContainerLifeCycle implements ExtensionFactory
public class WebSocketExtensionFactory extends ExtensionFactory implements LifeCycle, Dumpable
{
private ContainerLifeCycle containerLifeCycle;
private WebSocketContainerScope container;
private ServiceLoader<Extension> extensionLoader = ServiceLoader.load(Extension.class);
private Map<String, Class<? extends Extension>> availableExtensions;
@ -47,16 +51,24 @@ public class WebSocketExtensionFactory extends ContainerLifeCycle implements Ext
public WebSocketExtensionFactory(WebSocketContainerScope container)
{
containerLifeCycle = new ContainerLifeCycle()
{
@Override
public String toString()
{
return String.format("%s@%x{%s}", WebSocketExtensionFactory.class.getSimpleName(), hashCode(), containerLifeCycle.getState());
}
};
availableExtensions = new HashMap<>();
for (Extension ext : extensionLoader)
{
if (ext != null)
availableExtensions.put(ext.getName(),ext.getClass());
availableExtensions.put(ext.getName(), ext.getClass());
}
this.container = container;
addBean(inflaterPool);
addBean(deflaterPool);
containerLifeCycle.addBean(inflaterPool);
containerLifeCycle.addBean(deflaterPool);
}
@Override
@ -130,7 +142,7 @@ public class WebSocketExtensionFactory extends ContainerLifeCycle implements Ext
@Override
public void register(String name, Class<? extends Extension> extension)
{
availableExtensions.put(name,extension);
availableExtensions.put(name, extension);
}
@Override
@ -144,4 +156,90 @@ public class WebSocketExtensionFactory extends ContainerLifeCycle implements Ext
{
return availableExtensions.values().iterator();
}
/* --- All of the below ugliness due to not being able to break API compatibility with ExtensionFactory --- */
@Override
public void start() throws Exception
{
containerLifeCycle.start();
}
@Override
public void stop() throws Exception
{
containerLifeCycle.stop();
}
@Override
public boolean isRunning()
{
return containerLifeCycle.isRunning();
}
@Override
public boolean isStarted()
{
return containerLifeCycle.isStarted();
}
@Override
public boolean isStarting()
{
return containerLifeCycle.isStarting();
}
@Override
public boolean isStopping()
{
return containerLifeCycle.isStopping();
}
@Override
public boolean isStopped()
{
return containerLifeCycle.isStopped();
}
@Override
public boolean isFailed()
{
return containerLifeCycle.isFailed();
}
@Override
public void addLifeCycleListener(Listener listener)
{
containerLifeCycle.addLifeCycleListener(listener);
}
@Override
public void removeLifeCycleListener(Listener listener)
{
containerLifeCycle.removeLifeCycleListener(listener);
}
@Override
public String dump()
{
return containerLifeCycle.dump();
}
@Override
public String dumpSelf()
{
return containerLifeCycle.dumpSelf();
}
@Override
public void dump(Appendable out, String indent) throws IOException
{
containerLifeCycle.dump(out, indent);
}
@Override
public String toString()
{
return containerLifeCycle.toString();
}
}

View File

@ -107,6 +107,12 @@
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-jmx</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.toolchain</groupId>
<artifactId>jetty-test-helper</artifactId>

View File

@ -29,6 +29,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.Executor;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
@ -450,6 +451,13 @@ public class WebSocketServerFactory extends ContainerLifeCycle implements WebSoc
return eventDriverFactory;
}
@Override
public Set<String> getAvailableExtensionNames()
{
return Collections.unmodifiableSet(extensionFactory.getExtensionNames());
}
@Deprecated
@Override
public ExtensionFactory getExtensionFactory()
{

View File

@ -20,12 +20,14 @@ package org.eclipse.jetty.websocket.server.browser;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.lang.management.ManagementFactory;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.jetty.jmx.MBeanContainer;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.server.handler.ResourceHandler;
@ -131,10 +133,17 @@ public class BrowserDebugTool implements WebSocketCreator
public void prepare(int port) throws IOException, URISyntaxException
{
server = new Server();
// Setup JMX
MBeanContainer mbContainer = new MBeanContainer(ManagementFactory.getPlatformMBeanServer());
server.addBean(mbContainer, true);
// Setup Connector
connector = new ServerConnector(server);
connector.setPort(port);
server.addConnector(connector);
// Setup WebSocket
WebSocketHandler wsHandler = new WebSocketHandler()
{
@Override

View File

@ -21,6 +21,7 @@ package org.eclipse.jetty.websocket.servlet;
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.Set;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@ -66,8 +67,24 @@ public interface WebSocketServletFactory
void stop() throws Exception;
/**
* Get the set of available Extensions by registered name.
*
* @return the set of available extensions by registered name.
*/
Set<String> getAvailableExtensionNames();
WebSocketCreator getCreator();
/**
* Get the registered extensions for this WebSocket factory.
*
* @return the ExtensionFactory
* @see #getAvailableExtensionNames()
* @deprecated this class is removed from Jetty 10.0.0+. To remove specific extensions
* from negotiation use {@link WebSocketCreator} to remove then during handshake.
*/
@Deprecated
ExtensionFactory getExtensionFactory();
/**