minor structural updates with joakim's latest

This commit is contained in:
Jesse McConnell 2012-06-18 14:03:25 -05:00
parent 6679c9436e
commit b696915b29
6 changed files with 112 additions and 5 deletions

View File

@ -1,6 +1,26 @@
package org.eclipse.jetty.websocket.frames;
public class CloseFrame extends ControlFrame
{
import org.eclipse.jetty.websocket.frames.ControlFrameType;
public class CloseFrame extends ControlFrame
{
private final int pingId;
public CloseFrame(short version, int pingId)
{
super(version, ControlFrameType.CLOSE_FRAME, (byte)0);
this.pingId = pingId;
}
public int getPingId()
{
return pingId;
}
@Override
public String toString()
{
return String.format("%s ping=%d", super.toString(), getPingId());
}
}

View File

@ -1,6 +1,34 @@
package org.eclipse.jetty.websocket.frames;
import org.eclipse.jetty.websocket.frames.ControlFrameType;
public class ControlFrame extends BaseFrame
{
private final short _version;
private final ControlFrameType _type;
private final byte _flags; // check if needed
public ControlFrame( short version, ControlFrameType type, byte flags )
{
_version = version;
_type = type;
_flags = flags;
}
public short getVersion()
{
return _version;
}
public ControlFrameType getType()
{
return _type;
}
@Override
public String toString()
{
return String.format("%s frame v%s", getType(), getVersion());
}
}

View File

@ -1,6 +1,25 @@
package org.eclipse.jetty.websocket.frames;
import org.eclipse.jetty.websocket.frames.ControlFrameType;
public class PingFrame extends ControlFrame
{
private final int pingId;
public PingFrame(short version, int pingId)
{
super(version, ControlFrameType.PING_FRAME, (byte)0);
this.pingId = pingId;
}
public int getPingId()
{
return pingId;
}
@Override
public String toString()
{
return String.format("%s ping=%d", super.toString(), getPingId());
}
}

View File

@ -1,6 +1,25 @@
package org.eclipse.jetty.websocket.frames;
import org.eclipse.jetty.websocket.frames.ControlFrameType;
public class PongFrame extends ControlFrame
{
private final int pingId;
public PongFrame(short version, int pingId)
{
super(version, ControlFrameType.PONG_FRAME, (byte)0);
this.pingId = pingId;
}
public int getPingId()
{
return pingId;
}
@Override
public String toString()
{
return String.format("%s ping=%d", super.toString(), getPingId());
}
}

View File

@ -1,5 +1,11 @@
package org.eclipse.jetty.websocket.generator;
public class ControlFrameGenerator {
import java.nio.ByteBuffer;
import org.eclipse.jetty.websocket.frames.ControlFrame;
public abstract class ControlFrameGenerator
{
public abstract ByteBuffer generate(ControlFrame frame);
}

View File

@ -1,10 +1,13 @@
package org.eclipse.jetty.websocket.generator;
import java.nio.ByteBuffer;
import java.util.EnumMap;
import org.eclipse.jetty.io.ByteBufferPool;
import org.eclipse.jetty.websocket.frames.BaseFrame;
import org.eclipse.jetty.websocket.frames.ControlFrame;
import org.eclipse.jetty.websocket.frames.ControlFrameType;
import org.eclipse.jetty.websocket.frames.PingFrame;
import org.eclipse.jetty.websocket.generator.ControlFrameGenerator;
/**
@ -33,12 +36,24 @@ import org.eclipse.jetty.websocket.generator.ControlFrameGenerator;
*/
public class Generator {
private final EnumMap<ControlFrameType, BaseFrame> generators = new EnumMap<>(ControlFrameType.class);
private final EnumMap<ControlFrameType, ControlFrameGenerator> generators = new EnumMap<>(ControlFrameType.class);
public Generator(ByteBufferPool bufferPool) //, CompressionFactory.Compressor compressor)
{
HeadersBlockGenerator headerBlockGenerator = new HeadersBlockGenerator();
generators.put(ControlFrameType.BASE_FRAME, new BaseFrame());
generators.put(ControlFrameType.PING_FRAME, new PingFrameGenerator());
generators.put(ControlFrameType.PONG_FRAME, new PongFrameGenerator());
generators.put(ControlFrameType.CLOSE_FRAME, new CloseFrameGenerator());
}
public ByteBuffer control(ControlFrame frame)
{
ControlFrameGenerator generator = generators.get(frame.getType());
return generator.generate(frame);
}
}