WebSocket - breaking out unfinished MUX extension into its own module

This commit is contained in:
Joakim Erdfelt 2013-07-30 15:09:40 -07:00
parent b63a6047d3
commit 28b3ee8b13
55 changed files with 855 additions and 128 deletions

View File

@ -19,6 +19,7 @@
<module>websocket-client</module>
<module>websocket-server</module>
<module>websocket-servlet</module>
<module>websocket-mux-extension</module>
<module>javax-websocket-client-impl</module>
<module>javax-websocket-server-impl</module>
</modules>

View File

@ -0,0 +1,56 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<parent>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>websocket-parent</artifactId>
<version>9.1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>websocket-mux-extension</artifactId>
<name>Jetty :: Websocket :: Mux Extension</name>
<properties>
<bundle-symbolic-name>${project.groupId}.mux</bundle-symbolic-name>
</properties>
<dependencies>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>websocket-client</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>websocket-server</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.toolchain</groupId>
<artifactId>jetty-test-helper</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<id>tests-jar</id>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -16,7 +16,7 @@
// ========================================================================
//
package org.eclipse.jetty.websocket.common.extensions.mux;
package org.eclipse.jetty.websocket.mux;
import org.eclipse.jetty.websocket.api.WriteCallback;
import org.eclipse.jetty.websocket.api.extensions.Frame;

View File

@ -16,7 +16,7 @@
// ========================================================================
//
package org.eclipse.jetty.websocket.common.extensions.mux;
package org.eclipse.jetty.websocket.mux;
import java.net.InetSocketAddress;
import java.util.concurrent.Executor;

View File

@ -16,7 +16,7 @@
// ========================================================================
//
package org.eclipse.jetty.websocket.common.extensions.mux;
package org.eclipse.jetty.websocket.mux;
public interface MuxControlBlock
{

View File

@ -16,7 +16,7 @@
// ========================================================================
//
package org.eclipse.jetty.websocket.common.extensions.mux;
package org.eclipse.jetty.websocket.mux;
import org.eclipse.jetty.websocket.api.WebSocketException;

View File

@ -16,7 +16,7 @@
// ========================================================================
//
package org.eclipse.jetty.websocket.common.extensions.mux;
package org.eclipse.jetty.websocket.mux;
import java.io.IOException;
import java.nio.ByteBuffer;
@ -28,11 +28,11 @@ import org.eclipse.jetty.websocket.api.WriteCallback;
import org.eclipse.jetty.websocket.api.extensions.Frame;
import org.eclipse.jetty.websocket.api.extensions.OutgoingFrames;
import org.eclipse.jetty.websocket.common.WebSocketFrame;
import org.eclipse.jetty.websocket.common.extensions.mux.op.MuxAddChannelRequest;
import org.eclipse.jetty.websocket.common.extensions.mux.op.MuxAddChannelResponse;
import org.eclipse.jetty.websocket.common.extensions.mux.op.MuxDropChannel;
import org.eclipse.jetty.websocket.common.extensions.mux.op.MuxFlowControl;
import org.eclipse.jetty.websocket.common.extensions.mux.op.MuxNewChannelSlot;
import org.eclipse.jetty.websocket.mux.op.MuxAddChannelRequest;
import org.eclipse.jetty.websocket.mux.op.MuxAddChannelResponse;
import org.eclipse.jetty.websocket.mux.op.MuxDropChannel;
import org.eclipse.jetty.websocket.mux.op.MuxFlowControl;
import org.eclipse.jetty.websocket.mux.op.MuxNewChannelSlot;
/**
* Generate Mux frames destined for the physical connection.

View File

@ -16,7 +16,7 @@
// ========================================================================
//
package org.eclipse.jetty.websocket.common.extensions.mux;
package org.eclipse.jetty.websocket.mux;
public final class MuxOp
{

View File

@ -16,7 +16,7 @@
// ========================================================================
//
package org.eclipse.jetty.websocket.common.extensions.mux;
package org.eclipse.jetty.websocket.mux;
import java.nio.ByteBuffer;
@ -26,11 +26,11 @@ import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.websocket.api.extensions.Frame;
import org.eclipse.jetty.websocket.common.OpCode;
import org.eclipse.jetty.websocket.common.WebSocketFrame;
import org.eclipse.jetty.websocket.common.extensions.mux.op.MuxAddChannelRequest;
import org.eclipse.jetty.websocket.common.extensions.mux.op.MuxAddChannelResponse;
import org.eclipse.jetty.websocket.common.extensions.mux.op.MuxDropChannel;
import org.eclipse.jetty.websocket.common.extensions.mux.op.MuxFlowControl;
import org.eclipse.jetty.websocket.common.extensions.mux.op.MuxNewChannelSlot;
import org.eclipse.jetty.websocket.mux.op.MuxAddChannelRequest;
import org.eclipse.jetty.websocket.mux.op.MuxAddChannelResponse;
import org.eclipse.jetty.websocket.mux.op.MuxDropChannel;
import org.eclipse.jetty.websocket.mux.op.MuxFlowControl;
import org.eclipse.jetty.websocket.mux.op.MuxNewChannelSlot;
public class MuxParser
{

View File

@ -16,9 +16,9 @@
// ========================================================================
//
package org.eclipse.jetty.websocket.common.extensions.mux;
package org.eclipse.jetty.websocket.mux;
import org.eclipse.jetty.websocket.common.extensions.mux.op.MuxDropChannel;
import org.eclipse.jetty.websocket.mux.op.MuxDropChannel;
public class MuxPhysicalConnectionException extends MuxException
{

View File

@ -16,7 +16,7 @@
// ========================================================================
//
package org.eclipse.jetty.websocket.common.extensions.mux;
package org.eclipse.jetty.websocket.mux;
import java.nio.ByteBuffer;

View File

@ -16,7 +16,7 @@
// ========================================================================
//
package org.eclipse.jetty.websocket.common.extensions.mux;
package org.eclipse.jetty.websocket.mux;
import org.eclipse.jetty.websocket.api.UpgradeResponse;

View File

@ -16,7 +16,7 @@
// ========================================================================
//
package org.eclipse.jetty.websocket.common.extensions.mux;
package org.eclipse.jetty.websocket.mux;
import org.eclipse.jetty.websocket.common.OpCode;
import org.eclipse.jetty.websocket.common.WebSocketFrame;

View File

@ -16,7 +16,7 @@
// ========================================================================
//
package org.eclipse.jetty.websocket.common.extensions.mux;
package org.eclipse.jetty.websocket.mux;
import java.io.IOException;
import java.net.InetSocketAddress;
@ -38,13 +38,13 @@ import org.eclipse.jetty.websocket.api.extensions.IncomingFrames;
import org.eclipse.jetty.websocket.api.extensions.OutgoingFrames;
import org.eclipse.jetty.websocket.common.LogicalConnection;
import org.eclipse.jetty.websocket.common.WebSocketFrame;
import org.eclipse.jetty.websocket.common.extensions.mux.add.MuxAddClient;
import org.eclipse.jetty.websocket.common.extensions.mux.add.MuxAddServer;
import org.eclipse.jetty.websocket.common.extensions.mux.op.MuxAddChannelRequest;
import org.eclipse.jetty.websocket.common.extensions.mux.op.MuxAddChannelResponse;
import org.eclipse.jetty.websocket.common.extensions.mux.op.MuxDropChannel;
import org.eclipse.jetty.websocket.common.extensions.mux.op.MuxFlowControl;
import org.eclipse.jetty.websocket.common.extensions.mux.op.MuxNewChannelSlot;
import org.eclipse.jetty.websocket.mux.add.MuxAddClient;
import org.eclipse.jetty.websocket.mux.add.MuxAddServer;
import org.eclipse.jetty.websocket.mux.op.MuxAddChannelRequest;
import org.eclipse.jetty.websocket.mux.op.MuxAddChannelResponse;
import org.eclipse.jetty.websocket.mux.op.MuxDropChannel;
import org.eclipse.jetty.websocket.mux.op.MuxFlowControl;
import org.eclipse.jetty.websocket.mux.op.MuxNewChannelSlot;
/**
* Muxer responsible for managing sub-channels.

View File

@ -16,10 +16,10 @@
// ========================================================================
//
package org.eclipse.jetty.websocket.common.extensions.mux.add;
package org.eclipse.jetty.websocket.mux.add;
import org.eclipse.jetty.websocket.common.WebSocketSession;
import org.eclipse.jetty.websocket.common.extensions.mux.op.MuxAddChannelResponse;
import org.eclipse.jetty.websocket.mux.op.MuxAddChannelResponse;
/**
* Interface for Mux Client to handle receiving a AddChannelResponse

View File

@ -16,16 +16,16 @@
// ========================================================================
//
package org.eclipse.jetty.websocket.common.extensions.mux.add;
package org.eclipse.jetty.websocket.mux.add;
import java.io.IOException;
import org.eclipse.jetty.websocket.api.UpgradeRequest;
import org.eclipse.jetty.websocket.api.UpgradeResponse;
import org.eclipse.jetty.websocket.common.WebSocketSession;
import org.eclipse.jetty.websocket.common.extensions.mux.MuxChannel;
import org.eclipse.jetty.websocket.common.extensions.mux.MuxException;
import org.eclipse.jetty.websocket.common.extensions.mux.Muxer;
import org.eclipse.jetty.websocket.mux.MuxChannel;
import org.eclipse.jetty.websocket.mux.MuxException;
import org.eclipse.jetty.websocket.mux.Muxer;
/**
* Server interface, for dealing with incoming AddChannelRequest / AddChannelResponse flows.

View File

@ -19,5 +19,5 @@
/**
* Jetty WebSocket Common : MUX Extension Add Channel Handling [<em>Unstable Early Draft</em>]
*/
package org.eclipse.jetty.websocket.common.extensions.mux.add;
package org.eclipse.jetty.websocket.mux.add;

View File

@ -16,11 +16,11 @@
// ========================================================================
//
package org.eclipse.jetty.websocket.client.mux;
package org.eclipse.jetty.websocket.mux.client;
import org.eclipse.jetty.websocket.common.WebSocketSession;
import org.eclipse.jetty.websocket.common.extensions.mux.add.MuxAddClient;
import org.eclipse.jetty.websocket.common.extensions.mux.op.MuxAddChannelResponse;
import org.eclipse.jetty.websocket.mux.add.MuxAddClient;
import org.eclipse.jetty.websocket.mux.op.MuxAddChannelResponse;
public class MuxClientAddHandler implements MuxAddClient
{

View File

@ -16,10 +16,10 @@
// ========================================================================
//
package org.eclipse.jetty.websocket.client.mux;
package org.eclipse.jetty.websocket.mux.client;
import org.eclipse.jetty.websocket.common.extensions.mux.AbstractMuxExtension;
import org.eclipse.jetty.websocket.common.extensions.mux.Muxer;
import org.eclipse.jetty.websocket.mux.AbstractMuxExtension;
import org.eclipse.jetty.websocket.mux.Muxer;
public class MuxClientExtension extends AbstractMuxExtension
{

View File

@ -19,5 +19,5 @@
/**
* Jetty WebSocket Client : MUX Extension [<em>Unstable Early Draft</em>]
*/
package org.eclipse.jetty.websocket.client.mux;
package org.eclipse.jetty.websocket.mux.client;

View File

@ -16,14 +16,14 @@
// ========================================================================
//
package org.eclipse.jetty.websocket.common.extensions.mux.op;
package org.eclipse.jetty.websocket.mux.op;
import java.nio.ByteBuffer;
import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.util.StringUtil;
import org.eclipse.jetty.websocket.common.extensions.mux.MuxControlBlock;
import org.eclipse.jetty.websocket.common.extensions.mux.MuxOp;
import org.eclipse.jetty.websocket.mux.MuxControlBlock;
import org.eclipse.jetty.websocket.mux.MuxOp;
public class MuxAddChannelRequest implements MuxControlBlock
{

View File

@ -16,14 +16,14 @@
// ========================================================================
//
package org.eclipse.jetty.websocket.common.extensions.mux.op;
package org.eclipse.jetty.websocket.mux.op;
import java.nio.ByteBuffer;
import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.util.StringUtil;
import org.eclipse.jetty.websocket.common.extensions.mux.MuxControlBlock;
import org.eclipse.jetty.websocket.common.extensions.mux.MuxOp;
import org.eclipse.jetty.websocket.mux.MuxControlBlock;
import org.eclipse.jetty.websocket.mux.MuxOp;
public class MuxAddChannelResponse implements MuxControlBlock
{

View File

@ -16,14 +16,14 @@
// ========================================================================
//
package org.eclipse.jetty.websocket.common.extensions.mux.op;
package org.eclipse.jetty.websocket.mux.op;
import java.nio.ByteBuffer;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.jetty.websocket.common.extensions.mux.MuxControlBlock;
import org.eclipse.jetty.websocket.common.extensions.mux.MuxOp;
import org.eclipse.jetty.websocket.mux.MuxControlBlock;
import org.eclipse.jetty.websocket.mux.MuxOp;
public class MuxDropChannel implements MuxControlBlock
{

View File

@ -16,10 +16,10 @@
// ========================================================================
//
package org.eclipse.jetty.websocket.common.extensions.mux.op;
package org.eclipse.jetty.websocket.mux.op;
import org.eclipse.jetty.websocket.common.extensions.mux.MuxControlBlock;
import org.eclipse.jetty.websocket.common.extensions.mux.MuxOp;
import org.eclipse.jetty.websocket.mux.MuxControlBlock;
import org.eclipse.jetty.websocket.mux.MuxOp;
public class MuxFlowControl implements MuxControlBlock
{

View File

@ -16,10 +16,10 @@
// ========================================================================
//
package org.eclipse.jetty.websocket.common.extensions.mux.op;
package org.eclipse.jetty.websocket.mux.op;
import org.eclipse.jetty.websocket.common.extensions.mux.MuxControlBlock;
import org.eclipse.jetty.websocket.common.extensions.mux.MuxOp;
import org.eclipse.jetty.websocket.mux.MuxControlBlock;
import org.eclipse.jetty.websocket.mux.MuxOp;
public class MuxNewChannelSlot implements MuxControlBlock
{

View File

@ -19,5 +19,5 @@
/**
* Jetty WebSocket Common : MUX Extension OpCode Handling [<em>Unstable Early Draft</em>]
*/
package org.eclipse.jetty.websocket.common.extensions.mux.op;
package org.eclipse.jetty.websocket.mux.op;

View File

@ -19,5 +19,5 @@
/**
* Jetty WebSocket Common : MUX Extension Core [<em>Unstable Early Draft</em>]
*/
package org.eclipse.jetty.websocket.common.extensions.mux;
package org.eclipse.jetty.websocket.mux;

View File

@ -16,7 +16,7 @@
// ========================================================================
//
package org.eclipse.jetty.websocket.server.mux;
package org.eclipse.jetty.websocket.mux.server;
import java.nio.ByteBuffer;

View File

@ -16,7 +16,7 @@
// ========================================================================
//
package org.eclipse.jetty.websocket.server.mux;
package org.eclipse.jetty.websocket.mux.server;
import java.nio.ByteBuffer;

View File

@ -16,7 +16,7 @@
// ========================================================================
//
package org.eclipse.jetty.websocket.server.mux;
package org.eclipse.jetty.websocket.mux.server;
import java.io.IOException;
import java.nio.ByteBuffer;
@ -28,8 +28,8 @@ import org.eclipse.jetty.util.BlockingCallback;
import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.websocket.common.extensions.mux.MuxChannel;
import org.eclipse.jetty.websocket.common.extensions.mux.Muxer;
import org.eclipse.jetty.websocket.mux.MuxChannel;
import org.eclipse.jetty.websocket.mux.Muxer;
/**
* Take {@link ResponseInfo} objects and convert to bytes for response.

View File

@ -16,7 +16,7 @@
// ========================================================================
//
package org.eclipse.jetty.websocket.server.mux;
package org.eclipse.jetty.websocket.mux.server;
import java.io.IOException;
@ -30,10 +30,10 @@ import org.eclipse.jetty.server.HttpConfiguration;
import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.websocket.api.UpgradeRequest;
import org.eclipse.jetty.websocket.api.UpgradeResponse;
import org.eclipse.jetty.websocket.common.extensions.mux.MuxChannel;
import org.eclipse.jetty.websocket.common.extensions.mux.MuxException;
import org.eclipse.jetty.websocket.common.extensions.mux.Muxer;
import org.eclipse.jetty.websocket.common.extensions.mux.add.MuxAddServer;
import org.eclipse.jetty.websocket.mux.MuxChannel;
import org.eclipse.jetty.websocket.mux.MuxException;
import org.eclipse.jetty.websocket.mux.Muxer;
import org.eclipse.jetty.websocket.mux.add.MuxAddServer;
/**
* Handler for incoming MuxAddChannel requests.

View File

@ -16,10 +16,10 @@
// ========================================================================
//
package org.eclipse.jetty.websocket.server.mux;
package org.eclipse.jetty.websocket.mux.server;
import org.eclipse.jetty.websocket.common.extensions.mux.AbstractMuxExtension;
import org.eclipse.jetty.websocket.common.extensions.mux.Muxer;
import org.eclipse.jetty.websocket.mux.AbstractMuxExtension;
import org.eclipse.jetty.websocket.mux.Muxer;
public class MuxServerExtension extends AbstractMuxExtension
{

View File

@ -19,5 +19,5 @@
/**
* Jetty WebSocket Server : MUX Extension [<em>Unstable Early Draft</em>]
*/
package org.eclipse.jetty.websocket.server.mux;
package org.eclipse.jetty.websocket.mux.server;

View File

@ -0,0 +1 @@
org.eclipse.jetty.websocket.mux.client.MuxClientExtension

View File

@ -0,0 +1 @@
org.eclipse.jetty.websocket.mux.client.MuxServerExtension

View File

@ -0,0 +1,47 @@
//
// ========================================================================
// Copyright (c) 1995-2013 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 examples.echo;
import java.io.IOException;
import org.eclipse.jetty.websocket.api.WebSocketAdapter;
/**
* Example EchoSocket using Adapter.
*/
public class AdapterEchoSocket extends WebSocketAdapter
{
@Override
public void onWebSocketText(String message)
{
if (isConnected())
{
try
{
System.out.printf("Echoing back message [%s]%n",message);
// echo the message back
getRemote().sendString(message);
}
catch (IOException e)
{
e.printStackTrace(System.err);
}
}
}
}

View File

@ -16,11 +16,12 @@
// ========================================================================
//
package org.eclipse.jetty.websocket.common.extensions.mux;
package org.eclipse.jetty.websocket.mux;
import org.eclipse.jetty.websocket.api.WriteCallback;
import org.eclipse.jetty.websocket.api.extensions.Frame;
import org.eclipse.jetty.websocket.api.extensions.OutgoingFrames;
import org.eclipse.jetty.websocket.mux.MuxParser;
/**
* Helpful utility class to parse arbitrary mux events from a physical connection's OutgoingFrames.

View File

@ -16,7 +16,7 @@
// ========================================================================
//
package org.eclipse.jetty.websocket.common.extensions.mux;
package org.eclipse.jetty.websocket.mux;
import java.io.IOException;
@ -25,6 +25,8 @@ import org.eclipse.jetty.websocket.api.extensions.IncomingFrames;
import org.eclipse.jetty.websocket.api.extensions.OutgoingFrames;
import org.eclipse.jetty.websocket.common.WebSocketFrame;
import org.eclipse.jetty.websocket.common.io.FramePipes;
import org.eclipse.jetty.websocket.mux.MuxControlBlock;
import org.eclipse.jetty.websocket.mux.MuxGenerator;
/**
* Helpful utility class to send arbitrary mux events into a physical connection's IncomingFrames.

View File

@ -16,7 +16,7 @@
// ========================================================================
//
package org.eclipse.jetty.websocket.common.extensions.mux;
package org.eclipse.jetty.websocket.mux;
import static org.hamcrest.Matchers.*;
@ -25,15 +25,15 @@ import java.util.LinkedList;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.websocket.common.OpCode;
import org.eclipse.jetty.websocket.common.extensions.mux.MuxControlBlock;
import org.eclipse.jetty.websocket.common.extensions.mux.MuxException;
import org.eclipse.jetty.websocket.common.extensions.mux.MuxParser;
import org.eclipse.jetty.websocket.common.extensions.mux.MuxedFrame;
import org.eclipse.jetty.websocket.common.extensions.mux.op.MuxAddChannelRequest;
import org.eclipse.jetty.websocket.common.extensions.mux.op.MuxAddChannelResponse;
import org.eclipse.jetty.websocket.common.extensions.mux.op.MuxDropChannel;
import org.eclipse.jetty.websocket.common.extensions.mux.op.MuxFlowControl;
import org.eclipse.jetty.websocket.common.extensions.mux.op.MuxNewChannelSlot;
import org.eclipse.jetty.websocket.mux.MuxControlBlock;
import org.eclipse.jetty.websocket.mux.MuxException;
import org.eclipse.jetty.websocket.mux.MuxParser;
import org.eclipse.jetty.websocket.mux.MuxedFrame;
import org.eclipse.jetty.websocket.mux.op.MuxAddChannelRequest;
import org.eclipse.jetty.websocket.mux.op.MuxAddChannelResponse;
import org.eclipse.jetty.websocket.mux.op.MuxDropChannel;
import org.eclipse.jetty.websocket.mux.op.MuxFlowControl;
import org.eclipse.jetty.websocket.mux.op.MuxNewChannelSlot;
import org.junit.Assert;
public class MuxEventCapture implements MuxParser.Listener

View File

@ -16,7 +16,7 @@
// ========================================================================
//
package org.eclipse.jetty.websocket.common.extensions.mux;
package org.eclipse.jetty.websocket.mux;
import static org.hamcrest.Matchers.*;
@ -28,7 +28,7 @@ import java.util.Locale;
import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.util.TypeUtil;
import org.eclipse.jetty.websocket.common.extensions.mux.MuxGenerator;
import org.eclipse.jetty.websocket.mux.MuxGenerator;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;

View File

@ -16,7 +16,7 @@
// ========================================================================
//
package org.eclipse.jetty.websocket.common.extensions.mux;
package org.eclipse.jetty.websocket.mux;
import static org.hamcrest.Matchers.*;
@ -28,7 +28,7 @@ import java.util.Locale;
import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.util.TypeUtil;
import org.eclipse.jetty.websocket.common.extensions.mux.MuxGenerator;
import org.eclipse.jetty.websocket.mux.MuxGenerator;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;

View File

@ -16,7 +16,7 @@
// ========================================================================
//
package org.eclipse.jetty.websocket.common.extensions.mux;
package org.eclipse.jetty.websocket.mux;
import static org.hamcrest.Matchers.*;
@ -33,12 +33,12 @@ import org.eclipse.jetty.util.StringUtil;
import org.eclipse.jetty.util.TypeUtil;
import org.eclipse.jetty.websocket.api.WebSocketPolicy;
import org.eclipse.jetty.websocket.api.extensions.Frame;
import org.eclipse.jetty.websocket.common.IncomingFramesCapture;
import org.eclipse.jetty.websocket.common.OpCode;
import org.eclipse.jetty.websocket.common.Parser;
import org.eclipse.jetty.websocket.common.UnitParser;
import org.eclipse.jetty.websocket.common.WebSocketFrame;
import org.eclipse.jetty.websocket.common.extensions.AbstractExtension;
import org.eclipse.jetty.websocket.mux.helper.IncomingFramesCapture;
import org.eclipse.jetty.websocket.mux.helper.UnitParser;
import org.junit.Assert;
import org.junit.Test;

View File

@ -16,7 +16,7 @@
// ========================================================================
//
package org.eclipse.jetty.websocket.common.extensions.mux;
package org.eclipse.jetty.websocket.mux;
import static org.hamcrest.Matchers.*;
@ -26,8 +26,8 @@ import java.util.Collection;
import java.util.List;
import org.eclipse.jetty.util.TypeUtil;
import org.eclipse.jetty.websocket.common.extensions.mux.MuxException;
import org.eclipse.jetty.websocket.common.extensions.mux.MuxParser;
import org.eclipse.jetty.websocket.mux.MuxException;
import org.eclipse.jetty.websocket.mux.MuxParser;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;

View File

@ -16,7 +16,7 @@
// ========================================================================
//
package org.eclipse.jetty.websocket.common.extensions.mux;
package org.eclipse.jetty.websocket.mux;
import static org.hamcrest.Matchers.*;
@ -26,7 +26,7 @@ import java.util.Collection;
import java.util.List;
import org.eclipse.jetty.util.TypeUtil;
import org.eclipse.jetty.websocket.common.extensions.mux.MuxParser;
import org.eclipse.jetty.websocket.mux.MuxParser;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;

View File

@ -16,7 +16,7 @@
// ========================================================================
//
package org.eclipse.jetty.websocket.common.extensions.mux;
package org.eclipse.jetty.websocket.mux;
import static org.hamcrest.Matchers.*;
@ -26,8 +26,8 @@ import java.util.Collection;
import java.util.List;
import org.eclipse.jetty.util.TypeUtil;
import org.eclipse.jetty.websocket.common.extensions.mux.MuxException;
import org.eclipse.jetty.websocket.common.extensions.mux.MuxParser;
import org.eclipse.jetty.websocket.mux.MuxException;
import org.eclipse.jetty.websocket.mux.MuxParser;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;

View File

@ -16,7 +16,7 @@
// ========================================================================
//
package org.eclipse.jetty.websocket.common.extensions.mux;
package org.eclipse.jetty.websocket.mux;
import static org.hamcrest.Matchers.*;
@ -26,7 +26,7 @@ import java.util.Collection;
import java.util.List;
import org.eclipse.jetty.util.TypeUtil;
import org.eclipse.jetty.websocket.common.extensions.mux.MuxParser;
import org.eclipse.jetty.websocket.mux.MuxParser;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;

View File

@ -16,10 +16,11 @@
// ========================================================================
//
package org.eclipse.jetty.websocket.common.extensions.mux.add;
package org.eclipse.jetty.websocket.mux.add;
import org.eclipse.jetty.websocket.common.WebSocketSession;
import org.eclipse.jetty.websocket.common.extensions.mux.op.MuxAddChannelResponse;
import org.eclipse.jetty.websocket.mux.add.MuxAddClient;
import org.eclipse.jetty.websocket.mux.op.MuxAddChannelResponse;
public class DummyMuxAddClient implements MuxAddClient
{

View File

@ -16,7 +16,7 @@
// ========================================================================
//
package org.eclipse.jetty.websocket.common.extensions.mux.add;
package org.eclipse.jetty.websocket.mux.add;
import java.io.IOException;
@ -28,10 +28,11 @@ import org.eclipse.jetty.websocket.api.WebSocketPolicy;
import org.eclipse.jetty.websocket.common.WebSocketSession;
import org.eclipse.jetty.websocket.common.events.EventDriver;
import org.eclipse.jetty.websocket.common.events.EventDriverFactory;
import org.eclipse.jetty.websocket.common.extensions.mux.MuxChannel;
import org.eclipse.jetty.websocket.common.extensions.mux.MuxException;
import org.eclipse.jetty.websocket.common.extensions.mux.Muxer;
import org.eclipse.jetty.websocket.common.extensions.mux.op.MuxAddChannelResponse;
import org.eclipse.jetty.websocket.mux.MuxChannel;
import org.eclipse.jetty.websocket.mux.MuxException;
import org.eclipse.jetty.websocket.mux.Muxer;
import org.eclipse.jetty.websocket.mux.add.MuxAddServer;
import org.eclipse.jetty.websocket.mux.op.MuxAddChannelResponse;
import examples.echo.AdapterEchoSocket;

View File

@ -16,17 +16,17 @@
// ========================================================================
//
package org.eclipse.jetty.websocket.common.extensions.mux.add;
package org.eclipse.jetty.websocket.mux.add;
import org.eclipse.jetty.websocket.api.WebSocketPolicy;
import org.eclipse.jetty.websocket.common.extensions.mux.MuxChannel;
import org.eclipse.jetty.websocket.common.extensions.mux.MuxDecoder;
import org.eclipse.jetty.websocket.common.extensions.mux.MuxEncoder;
import org.eclipse.jetty.websocket.common.extensions.mux.MuxOp;
import org.eclipse.jetty.websocket.common.extensions.mux.Muxer;
import org.eclipse.jetty.websocket.common.extensions.mux.op.MuxAddChannelRequest;
import org.eclipse.jetty.websocket.common.extensions.mux.op.MuxAddChannelResponse;
import org.eclipse.jetty.websocket.common.io.LocalWebSocketConnection;
import org.eclipse.jetty.websocket.mux.MuxChannel;
import org.eclipse.jetty.websocket.mux.MuxDecoder;
import org.eclipse.jetty.websocket.mux.MuxEncoder;
import org.eclipse.jetty.websocket.mux.MuxOp;
import org.eclipse.jetty.websocket.mux.Muxer;
import org.eclipse.jetty.websocket.mux.helper.LocalWebSocketConnection;
import org.eclipse.jetty.websocket.mux.op.MuxAddChannelRequest;
import org.eclipse.jetty.websocket.mux.op.MuxAddChannelResponse;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;

View File

@ -16,20 +16,20 @@
// ========================================================================
//
package org.eclipse.jetty.websocket.common.extensions.mux.add;
package org.eclipse.jetty.websocket.mux.add;
import static org.hamcrest.Matchers.*;
import org.eclipse.jetty.websocket.api.WebSocketPolicy;
import org.eclipse.jetty.websocket.common.OpCode;
import org.eclipse.jetty.websocket.common.WebSocketFrame;
import org.eclipse.jetty.websocket.common.extensions.mux.MuxDecoder;
import org.eclipse.jetty.websocket.common.extensions.mux.MuxEncoder;
import org.eclipse.jetty.websocket.common.extensions.mux.MuxOp;
import org.eclipse.jetty.websocket.common.extensions.mux.Muxer;
import org.eclipse.jetty.websocket.common.extensions.mux.op.MuxAddChannelRequest;
import org.eclipse.jetty.websocket.common.extensions.mux.op.MuxAddChannelResponse;
import org.eclipse.jetty.websocket.common.io.LocalWebSocketConnection;
import org.eclipse.jetty.websocket.mux.MuxDecoder;
import org.eclipse.jetty.websocket.mux.MuxEncoder;
import org.eclipse.jetty.websocket.mux.MuxOp;
import org.eclipse.jetty.websocket.mux.Muxer;
import org.eclipse.jetty.websocket.mux.helper.LocalWebSocketConnection;
import org.eclipse.jetty.websocket.mux.op.MuxAddChannelRequest;
import org.eclipse.jetty.websocket.mux.op.MuxAddChannelResponse;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Rule;

View File

@ -0,0 +1,142 @@
//
// ========================================================================
// Copyright (c) 1995-2013 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.mux.helper;
import static org.hamcrest.Matchers.*;
import java.util.LinkedList;
import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.websocket.api.WebSocketException;
import org.eclipse.jetty.websocket.api.extensions.Frame;
import org.eclipse.jetty.websocket.api.extensions.IncomingFrames;
import org.eclipse.jetty.websocket.common.OpCode;
import org.eclipse.jetty.websocket.common.WebSocketFrame;
import org.junit.Assert;
public class IncomingFramesCapture implements IncomingFrames
{
private static final Logger LOG = Log.getLogger(IncomingFramesCapture.class);
private LinkedList<WebSocketFrame> frames = new LinkedList<>();
private LinkedList<Throwable> errors = new LinkedList<>();
public void assertErrorCount(int expectedCount)
{
Assert.assertThat("Captured error count",errors.size(),is(expectedCount));
}
public void assertFrameCount(int expectedCount)
{
Assert.assertThat("Captured frame count",frames.size(),is(expectedCount));
}
public void assertHasErrors(Class<? extends WebSocketException> errorType, int expectedCount)
{
Assert.assertThat(errorType.getSimpleName(),getErrorCount(errorType),is(expectedCount));
}
public void assertHasFrame(byte op)
{
Assert.assertThat(OpCode.name(op),getFrameCount(op),greaterThanOrEqualTo(1));
}
public void assertHasFrame(byte op, int expectedCount)
{
Assert.assertThat(OpCode.name(op),getFrameCount(op),is(expectedCount));
}
public void assertHasNoFrames()
{
Assert.assertThat("Has no frames",frames.size(),is(0));
}
public void assertNoErrors()
{
Assert.assertThat("Has no errors",errors.size(),is(0));
}
public void dump()
{
System.err.printf("Captured %d incoming frames%n",frames.size());
for (int i = 0; i < frames.size(); i++)
{
Frame frame = frames.get(i);
System.err.printf("[%3d] %s%n",i,frame);
System.err.printf(" %s%n",BufferUtil.toDetailString(frame.getPayload()));
}
}
public int getErrorCount(Class<? extends WebSocketException> errorType)
{
int count = 0;
for (Throwable error : errors)
{
if (errorType.isInstance(error))
{
count++;
}
}
return count;
}
public LinkedList<Throwable> getErrors()
{
return errors;
}
public int getFrameCount(byte op)
{
int count = 0;
for (WebSocketFrame frame : frames)
{
if (frame.getOpCode() == op)
{
count++;
}
}
return count;
}
public LinkedList<WebSocketFrame> getFrames()
{
return frames;
}
@Override
public void incomingError(Throwable e)
{
LOG.debug(e);
errors.add(e);
}
@Override
public void incomingFrame(Frame frame)
{
WebSocketFrame copy = new WebSocketFrame(frame);
frames.add(copy);
}
public int size()
{
return frames.size();
}
}

View File

@ -0,0 +1,250 @@
//
// ========================================================================
// Copyright (c) 1995-2013 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.mux.helper;
import java.net.InetSocketAddress;
import java.util.concurrent.Executor;
import org.eclipse.jetty.io.ByteBufferPool;
import org.eclipse.jetty.io.MappedByteBufferPool;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.util.thread.ExecutorThreadPool;
import org.eclipse.jetty.websocket.api.StatusCode;
import org.eclipse.jetty.websocket.api.SuspendToken;
import org.eclipse.jetty.websocket.api.WebSocketPolicy;
import org.eclipse.jetty.websocket.api.WriteCallback;
import org.eclipse.jetty.websocket.api.extensions.Frame;
import org.eclipse.jetty.websocket.api.extensions.IncomingFrames;
import org.eclipse.jetty.websocket.common.CloseInfo;
import org.eclipse.jetty.websocket.common.ConnectionState;
import org.eclipse.jetty.websocket.common.LogicalConnection;
import org.eclipse.jetty.websocket.common.WebSocketSession;
import org.eclipse.jetty.websocket.common.io.IOState;
import org.eclipse.jetty.websocket.common.io.IOState.ConnectionStateListener;
import org.junit.rules.TestName;
public class LocalWebSocketConnection implements LogicalConnection, IncomingFrames, ConnectionStateListener
{
private static final Logger LOG = Log.getLogger(LocalWebSocketConnection.class);
private final String id;
private final ByteBufferPool bufferPool;
private final Executor executor;
private WebSocketPolicy policy = WebSocketPolicy.newServerPolicy();
private IncomingFrames incoming;
private IOState ioState = new IOState();
public LocalWebSocketConnection()
{
this("anon");
}
public LocalWebSocketConnection(String id)
{
this.id = id;
this.bufferPool = new MappedByteBufferPool();
this.executor = new ExecutorThreadPool();
this.ioState.addListener(this);
}
public LocalWebSocketConnection(TestName testname)
{
this(testname.getMethodName());
}
@Override
public Executor getExecutor()
{
return executor;
}
@Override
public void close()
{
close(StatusCode.NORMAL,null);
}
@Override
public void close(int statusCode, String reason)
{
LOG.debug("close({}, {})",statusCode,reason);
CloseInfo close = new CloseInfo(statusCode,reason);
ioState.onCloseLocal(close);
}
public void connect()
{
LOG.debug("connect()");
ioState.onConnected();
}
@Override
public void disconnect()
{
LOG.debug("disconnect()");
}
@Override
public ByteBufferPool getBufferPool()
{
return this.bufferPool;
}
@Override
public long getIdleTimeout()
{
return 0;
}
public IncomingFrames getIncoming()
{
return incoming;
}
@Override
public IOState getIOState()
{
return ioState;
}
@Override
public InetSocketAddress getLocalAddress()
{
return null;
}
@Override
public long getMaxIdleTimeout()
{
return 0;
}
@Override
public WebSocketPolicy getPolicy()
{
return policy;
}
@Override
public InetSocketAddress getRemoteAddress()
{
return null;
}
@Override
public WebSocketSession getSession()
{
return null;
}
@Override
public void incomingError(Throwable e)
{
incoming.incomingError(e);
}
@Override
public void incomingFrame(Frame frame)
{
incoming.incomingFrame(frame);
}
@Override
public boolean isOpen()
{
return getIOState().isOpen();
}
@Override
public boolean isReading()
{
return false;
}
@Override
public void onConnectionStateChange(ConnectionState state)
{
LOG.debug("Connection State Change: {}",state);
switch (state)
{
case CLOSED:
this.disconnect();
break;
case CLOSING:
if (ioState.wasRemoteCloseInitiated())
{
// send response close frame
CloseInfo close = ioState.getCloseInfo();
LOG.debug("write close frame: {}",close);
ioState.onCloseLocal(close);
}
default:
break;
}
}
public void open()
{
LOG.debug("open()");
ioState.onOpened();
}
@Override
public void outgoingFrame(Frame frame, WriteCallback callback)
{
}
@Override
public void resume()
{
}
@Override
public void setMaxIdleTimeout(long ms)
{
}
@Override
public void setNextIncomingFrames(IncomingFrames incoming)
{
this.incoming = incoming;
}
public void setPolicy(WebSocketPolicy policy)
{
this.policy = policy;
}
@Override
public void setSession(WebSocketSession session)
{
}
@Override
public SuspendToken suspend()
{
return null;
}
@Override
public String toString()
{
return String.format("%s[%s]",LocalWebSocketConnection.class.getSimpleName(),id);
}
}

View File

@ -0,0 +1,50 @@
//
// ========================================================================
// Copyright (c) 1995-2013 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.mux.helper;
import java.net.URI;
import org.eclipse.jetty.websocket.common.WebSocketSession;
import org.eclipse.jetty.websocket.common.events.EventDriver;
import org.junit.rules.TestName;
public class LocalWebSocketSession extends WebSocketSession
{
private String id;
private OutgoingFramesCapture outgoingCapture;
public LocalWebSocketSession(TestName testname, EventDriver driver)
{
super(URI.create("ws://localhost/LocalWebSocketSesssion/" + testname.getMethodName()),driver,new LocalWebSocketConnection(testname));
this.id = testname.getMethodName();
outgoingCapture = new OutgoingFramesCapture();
setOutgoingHandler(outgoingCapture);
}
public OutgoingFramesCapture getOutgoingCapture()
{
return outgoingCapture;
}
@Override
public String toString()
{
return String.format("%s[%s]",LocalWebSocketSession.class.getSimpleName(),id);
}
}

View File

@ -0,0 +1,96 @@
//
// ========================================================================
// Copyright (c) 1995-2013 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.mux.helper;
import static org.hamcrest.Matchers.*;
import java.util.LinkedList;
import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.websocket.api.WriteCallback;
import org.eclipse.jetty.websocket.api.extensions.Frame;
import org.eclipse.jetty.websocket.api.extensions.OutgoingFrames;
import org.eclipse.jetty.websocket.common.OpCode;
import org.eclipse.jetty.websocket.common.WebSocketFrame;
import org.junit.Assert;
public class OutgoingFramesCapture implements OutgoingFrames
{
private LinkedList<WebSocketFrame> frames = new LinkedList<>();
public void assertFrameCount(int expectedCount)
{
Assert.assertThat("Captured frame count",frames.size(),is(expectedCount));
}
public void assertHasFrame(byte op)
{
Assert.assertThat(OpCode.name(op),getFrameCount(op),greaterThanOrEqualTo(1));
}
public void assertHasFrame(byte op, int expectedCount)
{
Assert.assertThat(OpCode.name(op),getFrameCount(op),is(expectedCount));
}
public void assertHasNoFrames()
{
Assert.assertThat("Has no frames",frames.size(),is(0));
}
public void dump()
{
System.out.printf("Captured %d outgoing writes%n",frames.size());
for (int i = 0; i < frames.size(); i++)
{
Frame frame = frames.get(i);
System.out.printf("[%3d] %s%n",i,frame);
System.out.printf(" %s%n",BufferUtil.toDetailString(frame.getPayload()));
}
}
public int getFrameCount(byte op)
{
int count = 0;
for (WebSocketFrame frame : frames)
{
if (frame.getOpCode() == op)
{
count++;
}
}
return count;
}
public LinkedList<WebSocketFrame> getFrames()
{
return frames;
}
@Override
public void outgoingFrame(Frame frame, WriteCallback callback)
{
WebSocketFrame copy = new WebSocketFrame(frame);
frames.add(copy);
if (callback != null)
{
callback.writeSuccess();
}
}
}

View File

@ -0,0 +1,78 @@
//
// ========================================================================
// Copyright (c) 1995-2013 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.mux.helper;
import java.nio.ByteBuffer;
import org.eclipse.jetty.io.ByteBufferPool;
import org.eclipse.jetty.io.MappedByteBufferPool;
import org.eclipse.jetty.util.log.StacklessLogging;
import org.eclipse.jetty.websocket.api.WebSocketPolicy;
import org.eclipse.jetty.websocket.common.Parser;
public class UnitParser extends Parser
{
public UnitParser()
{
this(WebSocketPolicy.newServerPolicy());
}
public UnitParser(ByteBufferPool bufferPool, WebSocketPolicy policy)
{
super(policy,bufferPool);
}
public UnitParser(WebSocketPolicy policy)
{
this(new MappedByteBufferPool(),policy);
}
private void parsePartial(ByteBuffer buf, int numBytes)
{
int len = Math.min(numBytes,buf.remaining());
byte arr[] = new byte[len];
buf.get(arr,0,len);
this.parse(ByteBuffer.wrap(arr));
}
/**
* Parse a buffer, but do so in a quiet fashion, squelching stacktraces if encountered.
* <p>
* Use if you know the parse will cause an exception and just don't wnat to make the test console all noisy.
*/
public void parseQuietly(ByteBuffer buf)
{
try (StacklessLogging supress = new StacklessLogging(Parser.class))
{
parse(buf);
}
catch (Exception ignore)
{
/* ignore */
}
}
public void parseSlowly(ByteBuffer buf, int segmentSize)
{
while (buf.remaining() > 0)
{
parsePartial(buf,segmentSize);
}
}
}