public abstract class WebSocketBase extends Object implements WebSocket
| Modifier and Type | Field and Description |
|---|---|
protected int |
bufferSize
The buffer size.
|
protected CountDownLatch |
closeLatch
The close latch.
|
protected int |
connectionReadTimeout
connection read timeout(second).
|
protected int |
connectionTimeout
connection timeout(second).
|
protected ByteBuffer |
downstreamBuffer
The downstream buffer.
|
protected InetSocketAddress |
endpointAddress
endpoint.
|
protected ExecutorService |
executorService
worker.
|
protected WebSocketHandler |
handler
websocket handler.
|
protected CountDownLatch |
handshakeLatch
The handshake latch.
|
protected URI |
location
The location.
|
protected String |
origin
The origin.
|
protected String |
path
the URL to which to connect.
|
protected WebSocketPipeline |
pipeline
The pipeline.
|
protected String[] |
protocols
subprotocol name array.
|
protected Proxy |
proxy
proxy.
|
protected boolean |
quit
quit flag.
|
protected HttpHeader |
requestHeader
The request header map.
|
protected HttpHeader |
responseHeader
The response header map.
|
protected int |
responseStatus
The response status.
|
protected Selector |
selector
The selector.
|
protected String[] |
serverProtocols
The server protocols.
|
protected SocketChannel |
socket
The socket.
|
protected SSLHandshake |
sslHandshake
The ssl handshake.
|
protected com.taobao.api.internal.toplink.embedded.websocket.impl.WebSocketBase.State |
state
The state.
|
protected ByteBuffer |
upstreamBuffer
The upstream buffer.
|
protected BlockingQueue<ByteBuffer> |
upstreamQueue
The upstream queue.
|
protected boolean |
useSsl
The use ssl.
|
| Constructor and Description |
|---|
WebSocketBase(String url,
Proxy proxy,
WebSocketHandler handler,
String... protocols)
Instantiates a new web socket base.
|
WebSocketBase(String url,
String origin,
Proxy proxy,
WebSocketHandler handler,
String... protocols)
Instantiates a new web socket base.
|
WebSocketBase(String url,
String origin,
WebSocketHandler handler,
String... protocols)
Instantiates a new web socket base.
|
WebSocketBase(String url,
WebSocketHandler handler,
String... protocols)
Instantiates a new web socket base.
|
| Modifier and Type | Method and Description |
|---|---|
protected static void |
addHeader(StringBuilder sb,
String key,
String value)
Adds the header.
|
void |
awaitClose()
await close
|
protected void |
awaitTermination(int timeout,
TimeUnit unit)
Await termination.
|
void |
close()
Close.
|
protected void |
closeWebSocket()
Close web socket.
|
void |
connect()
Connect.
|
abstract Frame |
createFrame(byte[] bytes)
Creates the frame.
|
Frame |
createFrame(ByteBuffer buffer)
Creates the frame.
|
Frame |
createFrame(Object obj)
Creates the frame.
|
abstract Frame |
createFrame(String str)
Creates the frame.
|
protected SocketChannel |
createSocket()
Creates the socket.
|
int |
getBufferSize()
Gets the buffer size.
|
int |
getConnectionReadTimeout()
Gets the connection read timeout.
|
int |
getConnectionTimeout()
Gets the connection timeout.
|
InetSocketAddress |
getEndpoint()
Gets the endpoint.
|
protected FrameParser |
getFrameParser()
Gets the frame parser.
|
protected Handshake |
getHandshake()
Gets the handshake.
|
URI |
getLocation()
Gets the location.
|
String |
getOrigin()
Gets the origin.
|
int |
getPacketDumpMode()
Gets the packet dump mode.
|
String |
getPath()
Gets the path.
|
String[] |
getProtocols()
Gets the protocols.
|
HttpHeader |
getRequestHeader()
Gets the request header.
|
HttpHeader |
getResponseHeader()
Gets the response header.
|
int |
getResponseStatus()
Gets the response status.
|
String[] |
getServerProtocols()
Gets the server protocols.
|
protected abstract int |
getWebSocketVersion()
Gets the web socket version.
|
protected void |
init(String url)
Inits the.
|
protected void |
initializePipeline()
Initialize pipeline.
|
protected void |
initializePipeline(WebSocketPipeline pipeline)
Initialize pipeline.
|
protected void |
initializeProperties()
Initialize properties.
|
boolean |
isBlockingMode()
Checks if is blocking mode.
|
boolean |
isConnected()
Checks if is connected.
|
protected static String |
join(String delim,
Collection<String> collections)
Join.
|
protected static String |
join(String delim,
int start,
int end,
String... strings)
Join.
|
protected static String |
join(String delim,
String... strings)
Join.
|
protected abstract FrameParser |
newFrameParserInstance()
New frame parser instance.
|
protected abstract Handshake |
newHandshakeInstance()
New handshake instance.
|
protected void |
processBuffer(ByteBuffer buffer)
Process buffer.
|
protected void |
read(SocketChannel socket,
ByteBuffer buffer)
Read.
|
void |
send(byte[] bytes)
Send.
|
void |
send(ByteBuffer buffer)
Send.
|
void |
send(Frame frame)
Send.
|
void |
send(Object obj)
Send.
|
void |
send(String str)
Send.
|
void |
setBlockingMode(boolean blockingMode)
Sets the blocking mode.
|
void |
setConnectionReadTimeout(int connectionReadTimeout)
Sets the connection read timeout.
|
void |
setConnectionTimeout(int connectionTimeout)
Sets the connection timeout.
|
void |
setOrigin(String origin)
Sets the origin.
|
void |
setPacketDumpMode(int packetDumpMode)
Sets the packet dump mode.
|
void |
setServerProtocols(String[] serverProtocols)
Sets the server protocols.
|
protected com.taobao.api.internal.toplink.embedded.websocket.impl.WebSocketBase.State |
state()
State.
|
protected com.taobao.api.internal.toplink.embedded.websocket.impl.WebSocketBase.State |
transitionTo(com.taobao.api.internal.toplink.embedded.websocket.impl.WebSocketBase.State to)
Transition to.
|
protected URI location
protected String path
protected boolean useSsl
protected SSLHandshake sslHandshake
protected InetSocketAddress endpointAddress
protected Proxy proxy
protected int connectionTimeout
protected int connectionReadTimeout
protected volatile boolean quit
protected String[] protocols
protected String[] serverProtocols
protected int bufferSize
protected ByteBuffer upstreamBuffer
protected ByteBuffer downstreamBuffer
protected String origin
protected BlockingQueue<ByteBuffer> upstreamQueue
protected WebSocketHandler handler
protected WebSocketPipeline pipeline
protected SocketChannel socket
protected Selector selector
protected HttpHeader responseHeader
protected HttpHeader requestHeader
protected int responseStatus
protected volatile com.taobao.api.internal.toplink.embedded.websocket.impl.WebSocketBase.State state
protected CountDownLatch closeLatch
protected CountDownLatch handshakeLatch
protected ExecutorService executorService
public WebSocketBase(String url, String origin, WebSocketHandler handler, String... protocols) throws WebSocketException
url - the urlhandler - the handlerprotocols - the protocolsWebSocketException - the web socket exceptionpublic WebSocketBase(String url, WebSocketHandler handler, String... protocols) throws WebSocketException
url - the urlhandler - the handlerprotocols - the protocolsWebSocketException - the web socket exceptionpublic WebSocketBase(String url, String origin, Proxy proxy, WebSocketHandler handler, String... protocols) throws WebSocketException
url - the urlorigin - the originproxy - the proxyhandler - the handlerprotocols - the protocolsWebSocketException - the web socket exceptionpublic WebSocketBase(String url, Proxy proxy, WebSocketHandler handler, String... protocols) throws WebSocketException
url - the urlproxy - the proxyhandler - the handlerprotocols - the protocolsWebSocketException - the web socket exceptionprotected void init(String url) throws WebSocketException
url - the urlWebSocketException - the web socket exceptionprotected void initializeProperties()
throws WebSocketException
WebSocketException - the web socket exceptionprotected void initializePipeline()
throws WebSocketException
WebSocketException - the web socket exceptionprotected void initializePipeline(WebSocketPipeline pipeline) throws WebSocketException
pipeline - the pipelineWebSocketException - the web socket exceptionpublic URI getLocation()
WebSocketgetLocation in interface WebSocketpublic void send(Frame frame) throws WebSocketException
WebSocketsend in interface WebSocketframe - the frameWebSocketException - the web socket exceptionpublic void send(Object obj) throws WebSocketException
obj - the objWebSocketException - the web socket exceptionpublic void send(ByteBuffer buffer) throws WebSocketException
WebSocketsend in interface WebSocketbuffer - the ByteBufferWebSocketException - the web socket exceptionpublic void send(byte[] bytes)
throws WebSocketException
WebSocketsend in interface WebSocketbytes - the bytesWebSocketException - the web socket exceptionpublic void send(String str) throws WebSocketException
WebSocketsend in interface WebSocketstr - the textWebSocketException - the web socket exceptionprotected com.taobao.api.internal.toplink.embedded.websocket.impl.WebSocketBase.State transitionTo(com.taobao.api.internal.toplink.embedded.websocket.impl.WebSocketBase.State to)
to - the toprotected com.taobao.api.internal.toplink.embedded.websocket.impl.WebSocketBase.State state()
protected void read(SocketChannel socket, ByteBuffer buffer) throws WebSocketException
socket - the socketbuffer - the bufferWebSocketException - the web socket exceptionprotected SocketChannel createSocket() throws IOException
IOException - Signals that an I/O exception has occurred.public void connect()
throws WebSocketException
WebSocketconnect in interface WebSocketWebSocketException - the web socket exceptionprotected void processBuffer(ByteBuffer buffer) throws WebSocketException
buffer - the bufferWebSocketException - the web socket exceptionpublic boolean isConnected()
WebSocketisConnected in interface WebSocketpublic void close()
WebSocketprotected void awaitTermination(int timeout,
TimeUnit unit)
throws InterruptedException
timeout - the timeoutunit - the unitInterruptedException - the interrupted exceptionpublic void awaitClose()
throws InterruptedException
WebSocketawaitClose in interface WebSocketInterruptedExceptionprotected void closeWebSocket()
throws WebSocketException
WebSocketException - the web socket exceptionpublic Frame createFrame(Object obj) throws WebSocketException
WebSocketcreateFrame in interface WebSocketobj - the objWebSocketException - the web socket exceptionpublic Frame createFrame(ByteBuffer buffer) throws WebSocketException
WebSocketcreateFrame in interface WebSocketbuffer - the ByteBufferWebSocketException - the web socket exceptionpublic abstract Frame createFrame(byte[] bytes) throws WebSocketException
WebSocketcreateFrame in interface WebSocketbytes - the byte arrayWebSocketException - the web socket exceptionpublic abstract Frame createFrame(String str) throws WebSocketException
WebSocketcreateFrame in interface WebSocketstr - the strWebSocketException - the web socket exceptionprotected static String join(String delim, Collection<String> collections)
delim - the delimcollections - the collectionsprotected static String join(String delim, String... strings)
delim - the delimstrings - the stringsprotected static String join(String delim, int start, int end, String... strings)
delim - the delimstart - the startend - the endstrings - the stringsprotected static void addHeader(StringBuilder sb, String key, String value)
sb - the sbkey - the keyvalue - the valueprotected abstract int getWebSocketVersion()
protected abstract Handshake newHandshakeInstance()
protected Handshake getHandshake()
protected abstract FrameParser newFrameParserInstance()
protected FrameParser getFrameParser()
public boolean isBlockingMode()
WebSocketisBlockingMode in interface WebSocketpublic void setBlockingMode(boolean blockingMode)
WebSocketsetBlockingMode in interface WebSocketblockingMode - the new blocking modepublic String[] getServerProtocols()
public void setServerProtocols(String[] serverProtocols)
serverProtocols - the new server protocolspublic String getPath()
public InetSocketAddress getEndpoint()
WebSocketgetEndpoint in interface WebSocketpublic String[] getProtocols()
public String getOrigin()
public HttpHeader getResponseHeader()
public HttpHeader getRequestHeader()
public int getResponseStatus()
public int getConnectionTimeout()
WebSocketgetConnectionTimeout in interface WebSocketpublic void setConnectionTimeout(int connectionTimeout)
WebSocketsetConnectionTimeout in interface WebSocketconnectionTimeout - the new connection timeoutpublic int getConnectionReadTimeout()
public void setConnectionReadTimeout(int connectionReadTimeout)
connectionReadTimeout - the new connection read timeoutpublic void setOrigin(String origin)
origin - the new originpublic int getBufferSize()
WebSocketgetBufferSize in interface WebSocketpublic int getPacketDumpMode()
public void setPacketDumpMode(int packetDumpMode)
packetDumpMode - the new packet dump modeCopyright © 2021. All rights reserved.