Hi again
John is right with following comment:
>
> In HttpResponseParserFilter you have a
> public boolean releaseBuffer() {
> savedBuffer = null;
> return true;
> }
>
> This leads to
> com.sun.grizzly.filter.ParserProtocolFilter.saveParser(SelectionKey
> key, ProtocolParser parser)
> which overwrites anything in the SelectionKey which is not under the
> control of WorkerThread.
>
> So in your Code you need something like:owever,
> CallbackHandler.onConnect() is called directly from main selector
> thread, which means we can not cast it to WorkerThread.
So I would suggest to not put much logic to the onConnect method, also
there is no much sense to call ProtocolChain from onConnect, because,
possibly at that point your channel is not ready neither for reading
nor writing. I would suggest to change your CallbackHandler impl. to
something like that:
package grizzly.http.client;
import java.util.HashMap;
import java.util.Map;
import com.sun.grizzly.CallbackHandler;
import com.sun.grizzly.Context;
import com.sun.grizzly.IOEvent;
import com.sun.grizzly.TCPConnectorHandler;
import com.sun.grizzly.Context.AttributeScope;
import com.sun.grizzly.util.AttributeHolder;
public class HttpCallback implements CallbackHandler<Context> {
public static final String ATTIB_CONNECTION = "connection";
private TCPConnectorHandler connectorHandler;
public HttpCallback(TCPConnectorHandler ch) {
connectorHandler = ch;
}
public void onConnect(IOEvent<Context> ioEvent) {
Context ctx = ioEvent.attachment();
connectorHandler.finishConnect(ctx.getSelectionKey());
ctx.getSelectorHandler().register(key,
SelectionKey.OP_READ | SelectionKey.OP_WRITE); // Depends on your
requirements you can choose just one interest
}
public void onRead(IOEvent<Context> ioEvent) {
callFilterChain(ioEvent.attachment());
}
public void onWrite(IOEvent<Context> ioEvent) {
callFilterChain(ioEvent.attachment());
}
private void callFilterChain(Context ctx) {
AttributeHolder ah =
ctx.getAttributeHolderByScope(AttributeScope.CONNECTION);
if (ah == null) {
ah=((WorkerThread)
Thread.currentThread()).getAttachment();
ctx.getSelectionKey().attach(ah);
}
ctx.getProtocolChain().execute(ctx);
}
}
Let me know if it works for you :))
Thanks.
WBR,
Alexey.
>
>
> Anyway with your code in a real situation you may also run into
> other problems,
> because your write("Get.Http..") will be called on any
> Selection.Key.OP_READ event
> Probably something you do not want...
>
> Many Greetings
> John
>
> --
> Der GMX SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen!
> Ideal für Modem und ISDN: http://www.gmx.net/de/go/smartsurfer
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_grizzly.dev.java.net
> For additional commands, e-mail: users-help_at_grizzly.dev.java.net
>