|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.sun.grizzly.filter.CustomProtocolClient
public class CustomProtocolClient
Out of the box TCP/TLS Client for using CustomProtocol Comunictaion Layer. An usage example would be:
CustomProtocolClient client = new CustomProtocolClient();
client.start();
client.connect(new InetSocketAddress("localhost", 8087));
With start()
a DefaultProtocolChain
is build which
listens and forwards Read Events to the CustomProtocol Layer. The read bytes get internally parsed to
Messages. If the Message is an Message Reply the bytes get tranfered to the
RemoteInputStream
the client is waiting on.
If the Message is an server broadcast the bytes are handed of as an java.io.InputStream) to
{@link CustomProtocolClient#service(java.io.InputStream, java.io.OutputStream)}. Therefore
a user should override {@link CustomProtocolClient#service(java.io.InputStream, java.io.OutputStream)}
to process any broadcast messages.
Constructor Summary | |
---|---|
CustomProtocolClient()
|
|
CustomProtocolClient(SSLConfig sslConfig)
Configures Client to use TLS |
Method Summary | |
---|---|
void |
addProtocolFilter(ProtocolFilter protocolFilter)
Adds a Filter before the CustomProtocol Filters will execute. |
void |
addProtocolFilter(ProtocolFilter protocolFilter,
boolean beforeParser)
Users can add addtional ProtocolFilters to the Reading Chain. |
RemoteCall |
callRemote()
Sends data to server. |
void |
connect(InetSocketAddress address)
Connects to an Server. |
void |
connect(InetSocketAddress address,
InetSocketAddress proxy,
String userAgent,
String userName,
String pass)
Used to build up a connection to a server over an proxy. |
OutputStream |
getOutputStream()
|
boolean |
isGzip()
If bytes send to server are gzipped |
void |
onMessageError(String errorMsg)
Gets called if some protocol sepecific error happens. |
void |
service(InputStream inputStream,
OutputStream outputStream)
An User should override service(java.io.InputStream, java.io.OutputStream)
to process bytes that are send from an Server. |
void |
setBytesArrivedListener(BytesTrafficListener bytesArrivedListener)
|
void |
setGzip(boolean gzip)
If bytes send to server should be gzipped |
void |
setIoExceptionHandler(IOExceptionHandler ioExceptionHandler)
|
void |
setSession(int session)
Every message send to an server can have a session id attached so that server can keep track of its clients. |
void |
setThreadSizes(int minWorkerThreads,
int maxWorkerThreads)
Set up the Grizzly Worker Threads. |
void |
start()
Setups Grizzly Controller and Components and starts Grizzly. |
void |
stop()
Stops the Grizzly Framework |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public CustomProtocolClient()
public CustomProtocolClient(SSLConfig sslConfig)
sslConfig
- if null no TLS will be configuredMethod Detail |
---|
public boolean isGzip()
public void setGzip(boolean gzip)
gzip
- true if they shouldpublic void setBytesArrivedListener(BytesTrafficListener bytesArrivedListener)
public void setThreadSizes(int minWorkerThreads, int maxWorkerThreads)
minWorkerThreads
- min count of grizzly workersmaxWorkerThreads
- max count of grizzly workerspublic void addProtocolFilter(ProtocolFilter protocolFilter, boolean beforeParser)
protocolFilter
- Filter for chainbeforeParser
- before or afterpublic void addProtocolFilter(ProtocolFilter protocolFilter)
protocolFilter
- Filter for chainpublic void start() throws Exception
start
in interface Client
Exception
- Exceptionpublic void stop() throws Exception
stop
in interface Client
Exception
- Exceptionpublic void connect(InetSocketAddress address) throws IOException
start()
must have been called before.
connect
in interface Client
address
- host and port
IOException
- Exceptionpublic void connect(InetSocketAddress address, InetSocketAddress proxy, String userAgent, String userName, String pass) throws IOException
Client
Client.start()
must have been called before.
connect
in interface Client
address
- server addressproxy
- addressuserAgent
- proxy agent identifieruserName
- if proxy needs authentification (otherwise null)pass
- if proxy needs authentification (otherwise null)
IOException
public RemoteCall callRemote() throws IOException
callRemote
in interface Client
IOException
- expublic void setSession(int session)
session
- an idpublic OutputStream getOutputStream()
getOutputStream
in interface Client
public void service(InputStream inputStream, OutputStream outputStream)
service(java.io.InputStream, java.io.OutputStream)
to process bytes that are send from an Server.
service
in interface Client
inputStream
- bytes send from serveroutputStream
- reply to serverpublic void onMessageError(String errorMsg)
Client
onMessageError
in interface Client
public void setIoExceptionHandler(IOExceptionHandler ioExceptionHandler)
setIoExceptionHandler
in interface Client
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |