* Javadoc

* Backported fixes applied to OioWorker
This commit is contained in:
Trustin Lee 2009-06-18 08:20:57 +00:00
parent 2b33c26e72
commit e1abd56c1d
8 changed files with 59 additions and 16 deletions

View File

@ -32,6 +32,7 @@ import org.jboss.netty.channel.ChannelFuture;
/**
* @author The Netty Project (netty-dev@lists.jboss.org)
* @author Andy Taylor (andy.taylor@jboss.org)
* @author Trustin Lee (tlee@redhat.com)
* @version $Rev$, $Date$
*/
final class HttpTunnelWorker implements Runnable {
@ -46,12 +47,12 @@ final class HttpTunnelWorker implements Runnable {
channel.workerThread = Thread.currentThread();
while (channel.isOpen()) {
synchronized (this) {
synchronized (channel.interestOpsLock) {
while (!channel.isReadable()) {
try {
// notify() is not called at all.
// close() and setInterestOps() calls Thread.interrupt()
this.wait();
channel.interestOpsLock.wait();
}
catch (InterruptedException e) {
if (!channel.isOpen()) {
@ -73,7 +74,11 @@ final class HttpTunnelWorker implements Runnable {
}
if (buf != null) {
fireMessageReceived(channel, ChannelBuffers.wrappedBuffer(buf));
fireMessageReceived(
channel,
ChannelBuffers.wrappedBuffer(
channel.getConfig().getBufferFactory().getDefaultOrder(),
buf));
}
}
@ -90,8 +95,10 @@ final class HttpTunnelWorker implements Runnable {
Object message) {
try {
channel.sendChunk((ChannelBuffer) message);
ChannelBuffer buf = (ChannelBuffer) message;
int writtenBytes = channel.sendChunk(buf);
future.setSuccess();
fireWriteComplete(channel, writtenBytes);
}
catch (Throwable t) {
future.setFailure(t);
@ -120,14 +127,17 @@ final class HttpTunnelWorker implements Runnable {
future.setSuccess();
if (changed) {
// Notify the worker so it stops or continues reading.
Thread currentThread = Thread.currentThread();
Thread workerThread = channel.workerThread;
if (workerThread != null && currentThread != workerThread) {
workerThread.interrupt();
synchronized (channel.interestOpsLock) {
channel.setInterestOpsNow(interestOps);
// Notify the worker so it stops or continues reading.
Thread currentThread = Thread.currentThread();
Thread workerThread = channel.workerThread;
if (workerThread != null && currentThread != workerThread) {
workerThread.interrupt();
}
}
channel.setInterestOpsNow(interestOps);
fireChannelInterestChanged(channel);
}
}

View File

@ -48,6 +48,7 @@ import org.jboss.netty.logging.InternalLoggerFactory;
*
* @author The Netty Project (netty-dev@lists.jboss.org)
* @author Andy Taylor (andy.taylor@jboss.org)
* @author Trustin Lee (tlee@redhat.com)
* @version $Rev$, $Date$
*/
@ChannelPipelineCoverage("one")

View File

@ -54,6 +54,7 @@ import org.jboss.netty.util.internal.LinkedTransferQueue;
/**
* @author The Netty Project (netty-dev@lists.jboss.org)
* @author Andy Taylor (andy.taylor@jboss.org)
* @author Trustin Lee (tlee@redhat.com)
* @version $Rev$, $Date$
*/
class HttpTunnelingClientSocketChannel extends AbstractChannel
@ -67,6 +68,7 @@ class HttpTunnelingClientSocketChannel extends AbstractChannel
volatile boolean awaitingInitialResponse = true;
private final Object writeLock = new Object();
final Object interestOpsLock = new Object();
volatile Thread workerThread;
@ -168,7 +170,7 @@ class HttpTunnelingClientSocketChannel extends AbstractChannel
channel.write(ChannelBuffers.copiedBuffer(msg, "ASCII"));
}
void sendChunk(ChannelBuffer a) {
int sendChunk(ChannelBuffer a) {
int size = a.readableBytes();
String hex = Integer.toHexString(size) + HttpTunnelingClientSocketPipelineSink.LINE_TERMINATOR;
@ -179,6 +181,8 @@ class HttpTunnelingClientSocketChannel extends AbstractChannel
ChannelBuffers.copiedBuffer(HttpTunnelingClientSocketPipelineSink.LINE_TERMINATOR, "ASCII")));
future.awaitUninterruptibly();
}
return size + hex.length() + HttpTunnelingClientSocketPipelineSink.LINE_TERMINATOR.length();
}
byte[] receiveChunk() {

View File

@ -33,6 +33,7 @@ import org.jboss.netty.util.internal.ExecutorUtil;
/**
* @author The Netty Project (netty-dev@lists.jboss.org)
* @author Andy Taylor (andy.taylor@jboss.org)
* @author Trustin Lee (tlee@redhat.com)
* @version $Rev$, $Date$
*/
public class HttpTunnelingClientSocketChannelFactory implements ClientSocketChannelFactory {

View File

@ -41,6 +41,7 @@ import org.jboss.netty.util.internal.IoWorkerRunnable;
/**
* @author The Netty Project (netty-dev@lists.jboss.org)
* @author Andy Taylor (andy.taylor@jboss.org)
* @author Trustin Lee (tlee@redhat.com)
* @version $Rev$, $Date$
*/
final class HttpTunnelingClientSocketPipelineSink extends AbstractChannelSink {

View File

@ -42,6 +42,7 @@ import org.jboss.netty.channel.MessageEvent;
*
* @author The Netty Project (netty-dev@lists.jboss.org)
* @author Andy Taylor (andy.taylor@jboss.org)
* @author Trustin Lee (tlee@redhat.com)
* @version $Rev$, $Date$
*/
public class HttpTunnelingServlet extends HttpServlet {

View File

@ -42,6 +42,7 @@ import org.jboss.netty.channel.local.LocalAddress;
*
* @author The Netty Project (netty-dev@lists.jboss.org)
* @author Andy Taylor (andy.taylor@jboss.org)
* @author Trustin Lee (tlee@redhat.com)
* @version $Rev$, $Date$
*/
public class HttpTunnelingSessionListener implements HttpSessionListener, ChannelHandler {
@ -69,11 +70,6 @@ public class HttpTunnelingSessionListener implements HttpSessionListener, Channe
}
}
/**
* @author The Netty Project (netty-dev@lists.jboss.org)
* @author Trustin Lee (tlee@redhat.com)
* @version $Rev$, $Date$
*/
private static final class HttpTunnelingChannelPipelineFactory implements ChannelPipelineFactory {
private final HttpTunnelingChannelHandler handler;

View File

@ -0,0 +1,29 @@
/*
* JBoss, Home of Professional Open Source
*
* Copyright 2008, Red Hat Middleware LLC, and individual contributors
* by the @author tags. See the COPYRIGHT.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
/**
* An HTTP-based client-side {@link org.jboss.netty.channel.socket.SocketChannel}
* and its corresponding server-side Servlet implementation that make your
* existing Netty application work in a firewalled network.
*/
package org.jboss.netty.channel.socket.http;