I want to know how to fix my problem. here the context.
I have parserProtocol that will parse the buffer and the next Filter will
receive a valid String.
the String is my command to do.
so in MyProtocolFilter I'll have that :
String query = (String) context.removeAttribute(ProtocolParser.MESSAGE);
after that I'll launch the process to do
like : if(query.equals("sample1")){ sample1Command.process();}
sample1Command.process will create a CommandRequest and a CommandResponse,
and send this request to a 3th party (could be anything). The 3th party
will process the request and send back the response by the
CommandResponse.handleResponse(response);
and the CommandResponse.handleResponse(..) will send this response to the
client.
here a sequence.
client -> message to the server
server :
MyQueryProtocolFilter (parse the queries)
MyProtocolFilter ->
create a Command
send the query to the 3th party ->
3th : send back the response <-
reponsehandler.handle(..) : send back the response to the
client<-
I don't want to block the threadpool when waiting for the response from the
3th party.
(I think I can use a SuspendableFilter right ? )
and the other thing.. how to send to response to the client ?
Should I have to pass the context to the Command ?
without Grizzly, I was keeping the SocketChannel, and the response send the
response to the client using that..
but with grizzly, not sure if I had the best idea ? any comments ?
I tought of using that in the CommandResponse
void handleResponse(String response){
// Depending on protocol perform echo
SelectableChannel channel = context.getSelectionKey().channel();
try {
ByteBuffer writeBuffer =
ByteBuffer.allocateDirect(response.length());
writeBuffer.put(response.getBytes());
writeBuffer.flip();
if (context.getProtocol() == Controller.Protocol.TCP) { // TCP
case
OutputWriter.flushChannel(channel, writeBuffer);
}
} catch (IOException ex) {
throw ex;
}
}