GeezerVison is showing github.com — Merge pull request #30 from normanmaurer/3.2 · netty/netty@ce1643c
File treeExpand file treeCollapse file tree Open diff view settings src/main/java/org/jboss/netty
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: src/main/java/org/jboss/netty/channel/ChannelEvent.java +4-1Lines changed: 4 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 71 | 71 | * <td>{@code "channelOpen"}</td> | 72 | 72 | * <td>{@link ChannelStateEvent}<br/>(state = {@link ChannelState#OPEN OPEN}, value = {@code true})</td> | 73 | 73 | * <td>a {@link Channel} is open, but not bound nor connected</td> | | 74 | + * <td><strong>Be aware that this event is fired from within the Boss-Thread so you should not execute any heavy operation in there as it will block the dispatching to other workers!</strong></td> | 74 | 75 | * </tr> | 75 | 76 | * <tr> | 76 | 77 | * <td>{@code "channelClosed"}</td> | | 80 | 81 | * <tr> | 81 | 82 | * <td>{@code "channelBound"}</td> | 82 | 83 | * <td>{@link ChannelStateEvent}<br/>(state = {@link ChannelState#BOUND BOUND}, value = {@link SocketAddress})</td> | 83 | | - * <td>a {@link Channel} is open and bound to a local address, but not connected</td> | | 84 | + * <td>a {@link Channel} is open and bound to a local address, but not connected.</td> | | 85 | + * <td><strong>Be aware that this event is fired from within the Boss-Thread so you should not execute any heavy operation in there as it will block the dispatching to other workers!</strong></td> | 84 | 86 | * </tr> | 85 | 87 | * <tr> | 86 | 88 | * <td>{@code "channelUnbound"}</td> | | 91 | 93 | * <td>{@code "channelConnected"}</td> | 92 | 94 | * <td>{@link ChannelStateEvent}<br/>(state = {@link ChannelState#CONNECTED CONNECTED}, value = {@link SocketAddress})</td> | 93 | 95 | * <td>a {@link Channel} is open, bound to a local address, and connected to a remote address</td> | | 96 | + * <td><strong>Be aware that this event is fired from within the Boss-Thread so you should not execute any heavy operation in there as it will block the dispatching to other workers!</strong></td> | 94 | 97 | * </tr> | 95 | 98 | * <tr> | 96 | 99 | * <td>{@code "writeComplete"}</td> | |
Collapse file Copy file name to clipboardExpand all lines: src/main/java/org/jboss/netty/channel/ChannelLocal.java +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -51,7 +51,7 @@ public ChannelLocal() { | 51 | 51 | * Returns the initial value of the variable. By default, it returns | 52 | 52 | * {@code null}. Override it to change the initial value. | 53 | 53 | */ | 54 | | - protected T initialValue(@SuppressWarnings("unused") Channel channel) { | | 54 | + protected T initialValue(Channel channel) { | 55 | 55 | return null; | 56 | 56 | } | 57 | 57 |
| |
Collapse file Copy file name to clipboardExpand all lines: src/main/java/org/jboss/netty/channel/SimpleChannelUpstreamHandler.java +9Lines changed: 9 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -150,6 +150,9 @@ public void exceptionCaught( | 150 | 150 |
| 151 | 151 | /** | 152 | 152 | * Invoked when a {@link Channel} is open, but not bound nor connected. | | 153 | + * <br/> | | 154 | + * | | 155 | + * <strong>Be aware that this event is fired from within the Boss-Thread so you should not execute any heavy operation in there as it will block the dispatching to other workers!</strong> | 153 | 156 | */ | 154 | 157 | public void channelOpen( | 155 | 158 | ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception { | @@ -159,6 +162,9 @@ public void channelOpen( | 159 | 162 | /** | 160 | 163 | * Invoked when a {@link Channel} is open and bound to a local address, | 161 | 164 | * but not connected. | | 165 | + * <br/> | | 166 | + * | | 167 | + * <strong>Be aware that this event is fired from within the Boss-Thread so you should not execute any heavy operation in there as it will block the dispatching to other workers!</strong> | 162 | 168 | */ | 163 | 169 | public void channelBound( | 164 | 170 | ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception { | @@ -168,6 +174,9 @@ public void channelBound( | 168 | 174 | /** | 169 | 175 | * Invoked when a {@link Channel} is open, bound to a local address, and | 170 | 176 | * connected to a remote address. | | 177 | + * <br/> | | 178 | + * | | 179 | + * <strong>Be aware that this event is fired from within the Boss-Thread so you should not execute any heavy operation in there as it will block the dispatching to other workers!</strong> | 171 | 180 | */ | 172 | 181 | public void channelConnected( | 173 | 182 | ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception { | |
Collapse file Copy file name to clipboardExpand all lines: src/main/java/org/jboss/netty/channel/socket/nio/NioAcceptedSocketChannel.java +3-2Lines changed: 3 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 15 | 15 | */ | 16 | 16 | package org.jboss.netty.channel.socket.nio; | 17 | 17 |
| 18 | | -import static org.jboss.netty.channel.Channels.*; | | 18 | +import static org.jboss.netty.channel.Channels.fireChannelBound; | | 19 | +import static org.jboss.netty.channel.Channels.fireChannelOpen; | 19 | 20 |
| 20 | 21 | import java.nio.channels.SocketChannel; | 21 | 22 |
| @@ -46,8 +47,8 @@ final class NioAcceptedSocketChannel extends NioSocketChannel { | 46 | 47 | this.bossThread = bossThread; | 47 | 48 |
| 48 | 49 | setConnected(); | | 50 | + | 49 | 51 | fireChannelOpen(this); | 50 | 52 | fireChannelBound(this, getLocalAddress()); | 51 | | - fireChannelConnected(this, getRemoteAddress()); | 52 | 53 | } | 53 | 54 | } |
Collapse file Copy file name to clipboardExpand all lines: src/main/java/org/jboss/netty/channel/socket/nio/NioSocketChannel.java -1Lines changed: 0 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 29 | 29 | import org.jboss.netty.channel.Channel; | 30 | 30 | import org.jboss.netty.channel.ChannelFactory; | 31 | 31 | import org.jboss.netty.channel.ChannelFuture; | 32 | | -import org.jboss.netty.channel.ChannelFutureListener; | 33 | 32 | import org.jboss.netty.channel.ChannelPipeline; | 34 | 33 | import org.jboss.netty.channel.ChannelSink; | 35 | 34 | import org.jboss.netty.channel.MessageEvent; | |
Collapse file Copy file name to clipboardExpand all lines: src/main/java/org/jboss/netty/channel/socket/nio/NioWorker.java +9-1Lines changed: 9 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -82,7 +82,7 @@ class NioWorker implements Runnable { | 82 | 82 |
| 83 | 83 | private final SocketReceiveBufferPool recvBufferPool = new SocketReceiveBufferPool(); | 84 | 84 | private final SocketSendBufferPool sendBufferPool = new SocketSendBufferPool(); | 85 | | - | | 85 | + | 86 | 86 | NioWorker(int bossId, int id, Executor executor) { | 87 | 87 | this.bossId = bossId; | 88 | 88 | this.id = id; | @@ -96,6 +96,7 @@ void register(NioSocketChannel channel, ChannelFuture future) { | 96 | 96 | Selector selector; | 97 | 97 |
| 98 | 98 | synchronized (startStopLock) { | | 99 | + | 99 | 100 | if (!started) { | 100 | 101 | // Open a selector if this worker didn't start yet. | 101 | 102 | try { | @@ -160,6 +161,7 @@ public void run() { | 160 | 161 | } | 161 | 162 |
| 162 | 163 | try { | | 164 | + | 163 | 165 | SelectorUtil.select(selector); | 164 | 166 |
| 165 | 167 | // 'wakenUp.compareAndSet(false, true)' is always evaluated | @@ -790,6 +792,12 @@ public void run() { | 790 | 792 | } | 791 | 793 | fireChannelConnected(channel, remoteAddress); | 792 | 794 | } | | 795 | + | | 796 | + // Handle the channelConnected in the worker thread | | 797 | + if (channel instanceof NioAcceptedSocketChannel) { | | 798 | + fireChannelConnected(channel, channel.getRemoteAddress()); | | 799 | + | | 800 | + } | 793 | 801 | } | 794 | 802 | } | 795 | 803 | } |
Collapse file Copy file name to clipboardExpand all lines: src/main/java/org/jboss/netty/channel/socket/nio/SocketSendBufferPool.java +2-1Lines changed: 2 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -288,7 +288,8 @@ public long transferTo(DatagramChannel ch, SocketAddress raddr) | 288 | 288 | } | 289 | 289 |
| 290 | 290 | public void release() { | 291 | | - // Unpooled. | | 291 | + // Make sure the FileRegion resource are released otherwise it may cause a FD leak or something similar | | 292 | + file.releaseExternalResources(); | 292 | 293 | } | 293 | 294 | } | 294 | 295 |
| |
Collapse file Copy file name to clipboardExpand all lines: src/main/java/org/jboss/netty/channel/socket/oio/OioAcceptedSocketChannel.java +3-3Lines changed: 3 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 15 | 15 | */ | 16 | 16 | package org.jboss.netty.channel.socket.oio; | 17 | 17 |
| 18 | | -import static org.jboss.netty.channel.Channels.*; | | 18 | +import static org.jboss.netty.channel.Channels.fireChannelBound; | | 19 | +import static org.jboss.netty.channel.Channels.fireChannelOpen; | 19 | 20 |
| 20 | 21 | import java.io.IOException; | 21 | 22 | import java.io.OutputStream; | @@ -60,10 +61,9 @@ class OioAcceptedSocketChannel extends OioSocketChannel { | 60 | 61 | } catch (IOException e) { | 61 | 62 | throw new ChannelException("Failed to obtain an OutputStream.", e); | 62 | 63 | } | 63 | | - | | 64 | + | 64 | 65 | fireChannelOpen(this); | 65 | 66 | fireChannelBound(this, getLocalAddress()); | 66 | | - fireChannelConnected(this, getRemoteAddress()); | 67 | 67 | } | 68 | 68 |
| 69 | 69 | @Override | |
Collapse file Copy file name to clipboardExpand all lines: src/main/java/org/jboss/netty/channel/socket/oio/OioWorker.java +39-4Lines changed: 39 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 20 | 20 | import java.io.OutputStream; | 21 | 21 | import java.io.PushbackInputStream; | 22 | 22 | import java.net.SocketException; | | 23 | +import java.nio.channels.Channels; | 23 | 24 | import java.nio.channels.ClosedChannelException; | | 25 | +import java.nio.channels.WritableByteChannel; | 24 | 26 | import java.util.regex.Pattern; | 25 | 27 |
| 26 | 28 | import org.jboss.netty.buffer.ChannelBuffer; | 27 | 29 | import org.jboss.netty.channel.Channel; | 28 | 30 | import org.jboss.netty.channel.ChannelFuture; | | 31 | +import org.jboss.netty.channel.FileRegion; | 29 | 32 |
| 30 | 33 | /** | 31 | 34 | * | @@ -50,7 +53,13 @@ public void run() { | 50 | 53 | channel.workerThread = Thread.currentThread(); | 51 | 54 | final PushbackInputStream in = channel.getInputStream(); | 52 | 55 |
| | 56 | + boolean fireConnected = channel instanceof OioAcceptedSocketChannel; | | 57 | + | 53 | 58 | while (channel.isOpen()) { | | 59 | + if (fireConnected) { | | 60 | + fireConnected = false; | | 61 | + fireChannelConnected(channel, channel.getRemoteAddress()); | | 62 | + } | 54 | 63 | synchronized (channel.interestOpsLock) { | 55 | 64 | while (!channel.isReadable()) { | 56 | 65 | try { | @@ -113,13 +122,39 @@ static void write( | 113 | 122 | } | 114 | 123 |
| 115 | 124 | try { | 116 | | - ChannelBuffer a = (ChannelBuffer) message; | 117 | | - int length = a.readableBytes(); | 118 | | - synchronized (out) { | 119 | | - a.getBytes(a.readerIndex(), out, length); | | 125 | + int length = 0; | | 126 | + | | 127 | + // Add support to write a FileRegion. This in fact will not give any performance gain but at least it not fail and | | 128 | + // we did the best to emulate it | | 129 | + if (message instanceof FileRegion) { | | 130 | + FileRegion fr = (FileRegion) message; | | 131 | + try { | | 132 | + synchronized (out) { | | 133 | + WritableByteChannel bchannel = Channels.newChannel(out); | | 134 | + | | 135 | + long i = 0; | | 136 | + while ((i = fr.transferTo(bchannel, length)) > 0) { | | 137 | + length += i; | | 138 | + if (length >= fr.getCount()) { | | 139 | + break; | | 140 | + } | | 141 | + } | | 142 | + } | | 143 | + } finally { | | 144 | + fr.releaseExternalResources(); | | 145 | + | | 146 | + } | | 147 | + } else { | | 148 | + ChannelBuffer a = (ChannelBuffer) message; | | 149 | + length = a.readableBytes(); | | 150 | + synchronized (out) { | | 151 | + a.getBytes(a.readerIndex(), out, length); | | 152 | + } | 120 | 153 | } | | 154 | + | 121 | 155 | fireWriteComplete(channel, length); | 122 | 156 | future.setSuccess(); | | 157 | + | 123 | 158 | } catch (Throwable t) { | 124 | 159 | // Convert 'SocketException: Socket closed' to | 125 | 160 | // ClosedChannelException. | |
Collapse file Copy file name to clipboardExpand all lines: src/main/java/org/jboss/netty/handler/ssl/SslHandler.java +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -370,7 +370,7 @@ public ChannelFuture handshake() { | 370 | 370 | * @deprecated Use {@link #handshake()} instead. | 371 | 371 | */ | 372 | 372 | @Deprecated | 373 | | - public ChannelFuture handshake(@SuppressWarnings("unused") Channel channel) { | | 373 | + public ChannelFuture handshake(Channel channel) { | 374 | 374 | return handshake(); | 375 | 375 | } | 376 | 376 |
| @@ -394,7 +394,7 @@ public ChannelFuture close() { | 394 | 394 | * @deprecated Use {@link #close()} instead. | 395 | 395 | */ | 396 | 396 | @Deprecated | 397 | | - public ChannelFuture close(@SuppressWarnings("unused") Channel channel) { | | 397 | + public ChannelFuture close(Channel channel) { | 398 | 398 | return close(); | 399 | 399 | } | 400 | 400 |
| |
|