Remove unused classes
- ChannelPipelineFactory will be replaced with sometime else when I refactory the bootstrap package - FileRegion is going away. A user can deregister a channel and perform such operations by him/herself. If this turns out to be too difficult, I'll introduce a new 'sendfile' operation to the outbound handler.
This commit is contained in:
parent
1b5960a1a8
commit
0682421ce1
@ -1,42 +0,0 @@
|
||||
/*
|
||||
* Copyright 2011 The Netty Project
|
||||
*
|
||||
* The Netty Project licenses this file to you under the Apache License,
|
||||
* version 2.0 (the "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package io.netty.channel;
|
||||
|
||||
import io.netty.bootstrap.Bootstrap;
|
||||
import io.netty.bootstrap.ClientBootstrap;
|
||||
import io.netty.bootstrap.ConnectionlessBootstrap;
|
||||
|
||||
/**
|
||||
* Creates a new {@link ChannelPipeline} for a new {@link Channel}.
|
||||
* <p>
|
||||
* When a {@linkplain ServerChannel server-side channel} accepts a new incoming
|
||||
* connection, a new child channel is created for each newly accepted connection.
|
||||
* A new child channel uses a new {@link ChannelPipeline}, which is created by
|
||||
* the {@link ChannelPipelineFactory} specified in the server-side channel's
|
||||
* {@link ChannelConfig#getPipelineFactory() "pipelineFactory"} option.
|
||||
* <p>
|
||||
* Also, when a {@link ClientBootstrap} or {@link ConnectionlessBootstrap}
|
||||
* creates a new channel, it uses the {@link Bootstrap#getPipelineFactory() "pipelineFactory"}
|
||||
* property to create a new {@link ChannelPipeline} for each new channel.
|
||||
* @apiviz.has io.netty.channel.ChannelPipeline oneway - - creates
|
||||
*/
|
||||
public interface ChannelPipelineFactory {
|
||||
|
||||
/**
|
||||
* Returns a newly created {@link ChannelPipeline}.
|
||||
*/
|
||||
ChannelPipeline getPipeline() throws Exception;
|
||||
}
|
@ -1,99 +0,0 @@
|
||||
/*
|
||||
* Copyright 2011 The Netty Project
|
||||
*
|
||||
* The Netty Project licenses this file to you under the Apache License,
|
||||
* version 2.0 (the "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package io.netty.channel;
|
||||
|
||||
import java.net.SocketAddress;
|
||||
|
||||
/**
|
||||
* The current or future state of a {@link Channel}.
|
||||
* <p>
|
||||
* The state of a {@link Channel} is interpreted differently depending on the
|
||||
* {@linkplain ChannelStateEvent#getValue() value} of a {@link ChannelStateEvent}
|
||||
* and the direction of the event in a {@link ChannelPipeline}:
|
||||
*
|
||||
* <table border="1" cellspacing="0" cellpadding="6">
|
||||
* <tr>
|
||||
* <th>Direction</th><th>State</th><th>Value</th><th>Meaning</th>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>Upstream</td><td>{@link #OPEN}</td><td>{@code true}</td><td>The channel is open.</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>Upstream</td><td>{@link #OPEN}</td><td>{@code false}</td><td>The channel is closed.</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>Upstream</td><td>{@link #BOUND}</td><td>{@link SocketAddress}</td><td>The channel is bound to a local address.</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>Upstream</td><td>{@link #BOUND}</td><td>{@code null}</td><td>The channel is unbound to a local address.</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>Upstream</td><td>{@link #CONNECTED}</td><td>{@link SocketAddress}</td><td>The channel is connected to a remote address.</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>Upstream</td><td>{@link #CONNECTED}</td><td>{@code null}</td><td>The channel is disconnected from a remote address.</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>Upstream</td><td>{@link #INTEREST_OPS}</td><td>an integer</td><td>The channel interestOps has been changed.</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>Downstream</td><td>{@link #OPEN}</td><td>{@code true}</td><td>N/A</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>Downstream</td><td>{@link #OPEN}</td><td>{@code false}</td><td>Close the channel.</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>Downstream</td><td>{@link #BOUND}</td><td>{@link SocketAddress}</td><td>Bind the channel to the specified local address.</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>Downstream</td><td>{@link #BOUND}</td><td>{@code null}</td><td>Unbind the channel from the current local address.</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>Downstream</td><td>{@link #CONNECTED}</td><td>{@link SocketAddress}</td><td>Connect the channel to the specified remote address.</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>Downstream</td><td>{@link #CONNECTED}</td><td>{@code null}</td><td>Disconnect the channel from the current remote address.</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>Downstream</td><td>{@link #INTEREST_OPS}</td><td>an integer</td><td>Change the interestOps of the channel.</td>
|
||||
* </tr>
|
||||
* </table>
|
||||
* <p>
|
||||
* To see how an event is interpreted further, please refer to {@link ChannelEvent}.
|
||||
*/
|
||||
public enum ChannelState {
|
||||
/**
|
||||
* Represents a {@link Channel}'s {@link Channel#isOpen() open} property
|
||||
*/
|
||||
OPEN,
|
||||
|
||||
/**
|
||||
* Represents a {@link Channel}'s {@link Channel#isBound() bound} property
|
||||
*/
|
||||
BOUND,
|
||||
|
||||
/**
|
||||
* Represents a {@link Channel}'s {@link Channel#isConnected() connected}
|
||||
* property
|
||||
*/
|
||||
CONNECTED,
|
||||
|
||||
/**
|
||||
* Represents a {@link Channel}'s {@link Channel#getInterestOps() interestOps}
|
||||
* property
|
||||
*/
|
||||
INTEREST_OPS
|
||||
}
|
@ -1,89 +0,0 @@
|
||||
/*
|
||||
* Copyright 2011 The Netty Project
|
||||
*
|
||||
* The Netty Project licenses this file to you under the Apache License,
|
||||
* version 2.0 (the "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package io.netty.channel;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.channels.FileChannel;
|
||||
import java.nio.channels.WritableByteChannel;
|
||||
|
||||
import io.netty.logging.InternalLogger;
|
||||
import io.netty.logging.InternalLoggerFactory;
|
||||
|
||||
public class DefaultFileRegion implements FileRegion {
|
||||
|
||||
private static final InternalLogger logger = InternalLoggerFactory.getInstance(DefaultFileRegion.class);
|
||||
|
||||
private final FileChannel file;
|
||||
private final long position;
|
||||
private final long count;
|
||||
private final boolean releaseAfterTransfer;
|
||||
|
||||
/**
|
||||
* Calls {@link #DefaultFileRegion(FileChannel, long, long, boolean)}
|
||||
* with <code>true</code> as the last argument.
|
||||
*/
|
||||
public DefaultFileRegion(FileChannel file, long position, long count) {
|
||||
this(file, position, count, true);
|
||||
}
|
||||
|
||||
public DefaultFileRegion(FileChannel file, long position, long count, boolean releaseAfterTransfer) {
|
||||
this.file = file;
|
||||
this.position = position;
|
||||
this.count = count;
|
||||
this.releaseAfterTransfer = releaseAfterTransfer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getCount() {
|
||||
return count;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean releaseAfterTransfer() {
|
||||
return releaseAfterTransfer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long transferTo(WritableByteChannel target, long position) throws IOException {
|
||||
long count = this.count - position;
|
||||
if (count < 0 || position < 0) {
|
||||
throw new IllegalArgumentException(
|
||||
"position out of range: " + position +
|
||||
" (expected: 0 - " + (this.count - 1) + ")");
|
||||
}
|
||||
if (count == 0) {
|
||||
return 0L;
|
||||
}
|
||||
|
||||
return file.transferTo(this.position + position, count, target);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void releaseExternalResources() {
|
||||
try {
|
||||
file.close();
|
||||
} catch (IOException e) {
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn("Failed to close a file.", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,89 +0,0 @@
|
||||
/*
|
||||
* Copyright 2011 The Netty Project
|
||||
*
|
||||
* The Netty Project licenses this file to you under the Apache License,
|
||||
* version 2.0 (the "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at:
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package io.netty.channel;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.channels.FileChannel;
|
||||
import java.nio.channels.WritableByteChannel;
|
||||
|
||||
import io.netty.util.ExternalResourceReleasable;
|
||||
|
||||
/**
|
||||
* A region of a file that is sent via a {@link Channel} which supports
|
||||
* <a href="http://en.wikipedia.org/wiki/Zero-copy">zero-copy file transfer</a>.
|
||||
*
|
||||
* <h3>Upgrade your JDK / JRE</h3>
|
||||
*
|
||||
* {@link FileChannel#transferTo(long, long, WritableByteChannel)} has at least
|
||||
* four known bugs in the old versions of Sun JDK and perhaps its derived ones.
|
||||
* Please upgrade your JDK to 1.6.0_18 or later version if you are going to use
|
||||
* zero-copy file transfer.
|
||||
* <ul>
|
||||
* <li><a href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5103988">5103988</a>
|
||||
* - FileChannel.transferTo() should return -1 for EAGAIN instead throws IOException</li>
|
||||
* <li><a href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6253145">6253145</a>
|
||||
* - FileChannel.transferTo() on Linux fails when going beyond 2GB boundary</li>
|
||||
* <li><a href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6427312">6427312</a>
|
||||
* - FileChannel.transferTo() throws IOException "system call interrupted"</li>
|
||||
* <li><a href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6524172">6470086</a>
|
||||
* - FileChannel.transferTo(2147483647, 1, channel) causes "Value too large" exception</li>
|
||||
* </ul>
|
||||
*
|
||||
* <h3>Check your operating system and JDK / JRE</h3>
|
||||
*
|
||||
* If your operating system (or JDK / JRE) does not support zero-copy file
|
||||
* transfer, sending a file with {@link FileRegion} might fail or yield worse
|
||||
* performance. For example, sending a large file doesn't work well in Windows.
|
||||
*
|
||||
* <h3>Not all transports support it</h3>
|
||||
*
|
||||
* Currently, the NIO transport is the only transport that supports {@link FileRegion}.
|
||||
* Attempting to write a {@link FileRegion} to non-NIO {@link Channel} will trigger
|
||||
* a {@link ClassCastException} or a similar exception.
|
||||
*/
|
||||
public interface FileRegion extends ExternalResourceReleasable {
|
||||
|
||||
// FIXME Make sure all transports support writing a FileRegion
|
||||
// Even if zero copy cannot be achieved, all transports should emulate it.
|
||||
|
||||
/**
|
||||
* Returns the offset in the file where the transfer began.
|
||||
*/
|
||||
long getPosition();
|
||||
|
||||
/**
|
||||
* Returns the number of bytes to transfer.
|
||||
*/
|
||||
long getCount();
|
||||
|
||||
/**
|
||||
* Returns <code>true</code> if {@link #releaseExternalResources()} has to
|
||||
* be called after the transfer of this {@link FileRegion} is complete.
|
||||
*/
|
||||
boolean releaseAfterTransfer();
|
||||
|
||||
/**
|
||||
* Transfers the content of this file region to the specified channel.
|
||||
*
|
||||
* @param target the destination of the transfer
|
||||
* @param position the relative offset of the file where the transfer
|
||||
* begins from. For example, <tt>0</tt> will make the
|
||||
* transfer start from {@link #getPosition()}th byte and
|
||||
* <tt>{@link #getCount()} - 1</tt> will make the last
|
||||
* byte of the region transferred.
|
||||
*/
|
||||
long transferTo(WritableByteChannel target, long position) throws IOException;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user