I'll try to get the important parts :
in the server
public class QuoteFeedResponseHandler extends QuoteResponseHandler {
private static final Logger s_logger =
LoggerFactory.getLogger(QuoteFeedResponseHandler.class);
public void sendLastUpdateToClient(ClientConnectionHandler
clientConnectionHandler) {
if(f_lastQuoteUpdate==null){
return;
}
ByteBuffer writeBuffer = ByteBuffer.allocateDirect(1000);
writeBuffer.put(f_lastQuoteUpdate.toString().getBytes());
writeBuffer.flip();
if(s_logger.isDebugEnabled()){
s_logger.debug("SENDING LAST QUOTE UPDATE TO CLIENT ");
}
try {
if(clientConnectionHandler.getKey().isValid()){
clientConnectionHandler.getSelectorHandler().getAsyncQueueWriter().write(clientConnectionHandler.getKey(),
writeBuffer);
} else {
// le client n'est pas connecte
clientConnectionHandler.close();
}
} catch (IOException e) {
s_logger.warn("sendLastUpdateToClient", e);
// le client n'est pas connecte
clientConnectionHandler.close();
}
}
public void init(){
if(s_logger.isDebugEnabled()){
s_logger.debug("listening for incomming TCP Connections on port
: " + f_port);
}
try {
f_controller = new Controller();
TCPSelectorHandler tcpSelectorHandler = new
TCPSelectorHandler();
tcpSelectorHandler.setPort(f_port);
Pipeline pipeline = new DefaultPipeline();
pipeline.setMaxThreads(5);
f_controller.setPipeline(pipeline);
BaseSelectionKeyHandler selectionKeyHandler = new
BaseSelectionKeyHandler();
// to be notify when a client close the connection
selectionKeyHandler.setConnectionCloseHandler(new
ConnectionCloseHandler() {
public void locallyClosed(SelectionKey key) {
s_logger.debug(key + " is being locally cancelled");
f_quoteManager.getCacheManager().remove(key);
}
public void remotlyClosed(SelectionKey key) {
s_logger.debug(key + " is being remotly cancelled
(connection closed)");
f_quoteManager.getCacheManager().remove(key);
}
});
tcpSelectorHandler.setSelectionKeyHandler(selectionKeyHandler);
f_controller.addSelectorHandler(tcpSelectorHandler);
QuoteQueryProtocolFilter protocolParser = new
QuoteQueryProtocolFilter();
QuoteQueryManagerFilter quoteManagerFilter = new
QuoteQueryManagerFilter(f_quoteManager);
final ProtocolChain protocolChain = new DefaultProtocolChain();
protocolChain.addFilter(protocolParser);
protocolChain.addFilter(quoteManagerFilter);
((DefaultProtocolChain)
protocolChain).setContinuousExecution(true);
ProtocolChainInstanceHandler pciHandler = new
DefaultProtocolChainInstanceHandler() {
public boolean offer(ProtocolChain protocolChain) {
return false;
}
public ProtocolChain poll() {
return protocolChain;
}
};
f_controller.setProtocolChainInstanceHandler(pciHandler);
try {
f_controller.start();
} catch (IOException e) {
e.printStackTrace();
}
} catch (Exception e) {
f_quoteManager.exit(-10);
}
}
2008/12/1 Oleksiy Stashok <Oleksiy.Stashok_at_sun.com>
> Hi,
>
> can you pls. show the code? Seems there is async write preprocessor, which
> returns null.
>
> Thanks.
>
> WBR,
> Alexey.
>
>
> On Nov 28, 2008, at 20:30 , Survivant 00 wrote:
>
> I'm doing a a test with breakpoint. The client send requests to the
>> server and after few seconds the client close the connection.
>>
>> I receive this error in the console of my server.
>>
>> 2008-11-28 14:25:36 com.sun.grizzly.util.WorkerThreadImpl run
>> GRAVE: WorkerThreadImpl unexpected exception:
>> java.lang.NullPointerException
>> at sun.nio.ch.SocketChannelImpl.write(SocketChannelImpl.java:322)
>> at
>> com.sun.grizzly.async.TCPAsyncQueueWriter.doWrite(TCPAsyncQueueWriter.java:88)
>> at
>> com.sun.grizzly.async.AbstractAsyncQueueWriter.doWrite(AbstractAsyncQueueWriter.java:397)
>> at
>> com.sun.grizzly.async.AbstractAsyncQueueWriter.onWrite(AbstractAsyncQueueWriter.java:303)
>> at
>> com.sun.grizzly.async.AsyncQueueWriterContextTask.doCall(AsyncQueueWriterContextTask.java:86)
>> at
>> com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:56)
>> at
>> com.sun.grizzly.util.WorkerThreadImpl.processTask(WorkerThreadImpl.java:335)
>> at com.sun.grizzly.util.WorkerThreadImpl.run(WorkerThreadImpl.java:194)
>>
>>
>> There is a way to catch this exception ?
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_grizzly.dev.java.net
> For additional commands, e-mail: users-help_at_grizzly.dev.java.net
>
>