├── .gitignore ├── LICENSE.txt ├── api ├── pom.xml └── src │ ├── main │ ├── java │ │ ├── java │ │ │ └── nio │ │ │ │ └── channels │ │ │ │ └── FileChannel.java │ │ ├── org │ │ │ └── xnio │ │ │ │ ├── AbstractConvertingIoFuture.java │ │ │ │ ├── AbstractIoFuture.java │ │ │ │ ├── AutomaticReference.java │ │ │ │ ├── Bits.java │ │ │ │ ├── BrokenPipeException.java │ │ │ │ ├── BufferAllocator.java │ │ │ │ ├── Buffers.java │ │ │ │ ├── ByteBufferSlicePool.java │ │ │ │ ├── ByteString.java │ │ │ │ ├── Cancellable.java │ │ │ │ ├── ChainedChannelListener.java │ │ │ │ ├── ChannelDestination.java │ │ │ │ ├── ChannelExceptionHandler.java │ │ │ │ ├── ChannelListener.java │ │ │ │ ├── ChannelListeners.java │ │ │ │ ├── ChannelPipe.java │ │ │ │ ├── ChannelSource.java │ │ │ │ ├── ClosedWorkerException.java │ │ │ │ ├── Closer.java │ │ │ │ ├── CompressionType.java │ │ │ │ ├── Connection.java │ │ │ │ ├── DelegatingChannelListener.java │ │ │ │ ├── FailedIoFuture.java │ │ │ │ ├── FileAccess.java │ │ │ │ ├── FileChangeCallback.java │ │ │ │ ├── FileChangeEvent.java │ │ │ │ ├── FileSystemWatcher.java │ │ │ │ ├── FinishedIoFuture.java │ │ │ │ ├── FutureResult.java │ │ │ │ ├── IoFuture.java │ │ │ │ ├── IoUtils.java │ │ │ │ ├── LocalSocketAddress.java │ │ │ │ ├── MessageConnection.java │ │ │ │ ├── ObjectProperties.java │ │ │ │ ├── Option.java │ │ │ │ ├── OptionMap.java │ │ │ │ ├── Options.java │ │ │ │ ├── PollingFileSystemWatcher.java │ │ │ │ ├── Pool.java │ │ │ │ ├── Pooled.java │ │ │ │ ├── Property.java │ │ │ │ ├── ReadPropertyAction.java │ │ │ │ ├── Result.java │ │ │ │ ├── Sequence.java │ │ │ │ ├── SequenceOption.java │ │ │ │ ├── SingleOption.java │ │ │ │ ├── SslClientAuthMode.java │ │ │ │ ├── StreamConnection.java │ │ │ │ ├── TranslatingResult.java │ │ │ │ ├── TypeOption.java │ │ │ │ ├── TypeSequenceOption.java │ │ │ │ ├── Version.java │ │ │ │ ├── Xnio.java │ │ │ │ ├── XnioExecutor.java │ │ │ │ ├── XnioFileChannel.java │ │ │ │ ├── XnioIoFactory.java │ │ │ │ ├── XnioIoThread.java │ │ │ │ ├── XnioProvider.java │ │ │ │ ├── XnioWorker.java │ │ │ │ ├── _private │ │ │ │ └── Messages.java │ │ │ │ ├── channels │ │ │ │ ├── AcceptListenerSettable.java │ │ │ │ ├── AcceptingChannel.java │ │ │ │ ├── AssembledChannel.java │ │ │ │ ├── AssembledConnectedChannel.java │ │ │ │ ├── AssembledConnectedMessageChannel.java │ │ │ │ ├── AssembledConnectedSslStreamChannel.java │ │ │ │ ├── AssembledConnectedStreamChannel.java │ │ │ │ ├── AssembledMessageChannel.java │ │ │ │ ├── AssembledSslChannel.java │ │ │ │ ├── AssembledStreamChannel.java │ │ │ │ ├── BlockingByteChannel.java │ │ │ │ ├── BlockingReadableByteChannel.java │ │ │ │ ├── BlockingWritableByteChannel.java │ │ │ │ ├── BoundChannel.java │ │ │ │ ├── BoundMultipointMessageChannel.java │ │ │ │ ├── ByteChannel.java │ │ │ │ ├── ChannelFactory.java │ │ │ │ ├── Channels.java │ │ │ │ ├── CloseListenerSettable.java │ │ │ │ ├── CloseableChannel.java │ │ │ │ ├── ConcurrentStreamChannelAccessException.java │ │ │ │ ├── Configurable.java │ │ │ │ ├── ConnectedChannel.java │ │ │ │ ├── ConnectedMessageChannel.java │ │ │ │ ├── ConnectedSslStreamChannel.java │ │ │ │ ├── ConnectedStreamChannel.java │ │ │ │ ├── EmptyStreamSourceChannel.java │ │ │ │ ├── FixedLengthOverflowException.java │ │ │ │ ├── FixedLengthStreamSinkChannel.java │ │ │ │ ├── FixedLengthStreamSourceChannel.java │ │ │ │ ├── FixedLengthUnderflowException.java │ │ │ │ ├── FramedMessageChannel.java │ │ │ │ ├── MessageChannel.java │ │ │ │ ├── MulticastMessageChannel.java │ │ │ │ ├── MultipointMessageChannel.java │ │ │ │ ├── NullStreamSinkChannel.java │ │ │ │ ├── ProtectedWrappedChannel.java │ │ │ │ ├── PushBackStreamChannel.java │ │ │ │ ├── ReadListenerSettable.java │ │ │ │ ├── ReadTimeoutException.java │ │ │ │ ├── ReadableMessageChannel.java │ │ │ │ ├── ReadableMultipointMessageChannel.java │ │ │ │ ├── SimpleAcceptingChannel.java │ │ │ │ ├── SocketAddressBuffer.java │ │ │ │ ├── SplitStreamSinkChannel.java │ │ │ │ ├── SplitStreamSourceChannel.java │ │ │ │ ├── SslChannel.java │ │ │ │ ├── StreamChannel.java │ │ │ │ ├── StreamSinkChannel.java │ │ │ │ ├── StreamSourceChannel.java │ │ │ │ ├── SuspendableAcceptChannel.java │ │ │ │ ├── SuspendableChannel.java │ │ │ │ ├── SuspendableReadChannel.java │ │ │ │ ├── SuspendableWriteChannel.java │ │ │ │ ├── TranslatingSuspendableChannel.java │ │ │ │ ├── UnsupportedOptionException.java │ │ │ │ ├── WrappedChannel.java │ │ │ │ ├── WritableMessageChannel.java │ │ │ │ ├── WritableMultipointMessageChannel.java │ │ │ │ ├── WriteListenerSettable.java │ │ │ │ ├── WriteTimeoutException.java │ │ │ │ └── package-info.java │ │ │ │ ├── conduits │ │ │ │ ├── AbstractConduit.java │ │ │ │ ├── AbstractMessageSinkConduit.java │ │ │ │ ├── AbstractMessageSourceConduit.java │ │ │ │ ├── AbstractSinkConduit.java │ │ │ │ ├── AbstractSourceConduit.java │ │ │ │ ├── AbstractStreamSinkConduit.java │ │ │ │ ├── AbstractStreamSourceConduit.java │ │ │ │ ├── AbstractSynchronizedConduit.java │ │ │ │ ├── AbstractSynchronizedSinkConduit.java │ │ │ │ ├── AbstractSynchronizedSourceConduit.java │ │ │ │ ├── BlockingStreamSinkConduit.java │ │ │ │ ├── BlockingStreamSourceConduit.java │ │ │ │ ├── BufferedStreamSinkConduit.java │ │ │ │ ├── BufferedStreamSourceConduit.java │ │ │ │ ├── Conduit.java │ │ │ │ ├── ConduitReadableByteChannel.java │ │ │ │ ├── ConduitReadableMessageChannel.java │ │ │ │ ├── ConduitStreamSinkChannel.java │ │ │ │ ├── ConduitStreamSourceChannel.java │ │ │ │ ├── ConduitWritableByteChannel.java │ │ │ │ ├── ConduitWritableMessageChannel.java │ │ │ │ ├── Conduits.java │ │ │ │ ├── DeflatingStreamSinkConduit.java │ │ │ │ ├── EmptyStreamSourceConduit.java │ │ │ │ ├── FixedLengthStreamSinkConduit.java │ │ │ │ ├── FixedLengthStreamSourceConduit.java │ │ │ │ ├── FramingMessageSinkConduit.java │ │ │ │ ├── FramingMessageSourceConduit.java │ │ │ │ ├── InflatingStreamSourceConduit.java │ │ │ │ ├── MessageSinkConduit.java │ │ │ │ ├── MessageSourceConduit.java │ │ │ │ ├── MessageStreamSinkConduit.java │ │ │ │ ├── MessageStreamSourceConduit.java │ │ │ │ ├── NullStreamSinkConduit.java │ │ │ │ ├── PushBackStreamSourceConduit.java │ │ │ │ ├── ReadReadyHandler.java │ │ │ │ ├── SinkConduit.java │ │ │ │ ├── SourceConduit.java │ │ │ │ ├── StreamSinkChannelWrappingConduit.java │ │ │ │ ├── StreamSinkConduit.java │ │ │ │ ├── StreamSourceChannelWrappingConduit.java │ │ │ │ ├── StreamSourceConduit.java │ │ │ │ ├── SynchronizedMessageSinkConduit.java │ │ │ │ ├── SynchronizedMessageSourceConduit.java │ │ │ │ ├── SynchronizedStreamSinkConduit.java │ │ │ │ ├── SynchronizedStreamSourceConduit.java │ │ │ │ ├── TerminateHandler.java │ │ │ │ ├── WriteReadyHandler.java │ │ │ │ └── package-info.java │ │ │ │ ├── http │ │ │ │ ├── HandshakeChecker.java │ │ │ │ ├── HttpUpgrade.java │ │ │ │ ├── HttpUpgradeParser.java │ │ │ │ └── RedirectException.java │ │ │ │ ├── management │ │ │ │ ├── XnioProviderMXBean.java │ │ │ │ ├── XnioServerMXBean.java │ │ │ │ └── XnioWorkerMXBean.java │ │ │ │ ├── package-info.java │ │ │ │ ├── sasl │ │ │ │ ├── SaslQop.java │ │ │ │ ├── SaslStrength.java │ │ │ │ ├── SaslUnwrappingConduit.java │ │ │ │ ├── SaslUtils.java │ │ │ │ ├── SaslWrapper.java │ │ │ │ ├── SaslWrappingConduit.java │ │ │ │ └── package-info.java │ │ │ │ ├── ssl │ │ │ │ ├── AbstractAcceptingSslChannel.java │ │ │ │ ├── JsseAcceptingSslStreamConnection.java │ │ │ │ ├── JsseSslConduitEngine.java │ │ │ │ ├── JsseSslStreamConnection.java │ │ │ │ ├── JsseSslStreamSinkConduit.java │ │ │ │ ├── JsseSslStreamSourceConduit.java │ │ │ │ ├── JsseSslUtils.java │ │ │ │ ├── JsseXnioSsl.java │ │ │ │ ├── SslConnection.java │ │ │ │ ├── XnioSsl.java │ │ │ │ └── package-info.java │ │ │ │ └── streams │ │ │ │ ├── BufferPipeInputStream.java │ │ │ │ ├── BufferPipeOutputStream.java │ │ │ │ ├── BufferedChannelInputStream.java │ │ │ │ ├── ChannelInputStream.java │ │ │ │ ├── ChannelOutputStream.java │ │ │ │ ├── LimitedInputStream.java │ │ │ │ ├── LimitedOutputStream.java │ │ │ │ ├── Pipe.java │ │ │ │ ├── ReaderInputStream.java │ │ │ │ ├── Streams.java │ │ │ │ ├── WriterOutputStream.java │ │ │ │ └── package-info.java │ │ └── overview.html │ └── resources │ │ └── org │ │ └── xnio │ │ └── Version.properties │ └── test │ ├── java │ ├── java │ │ └── nio │ │ │ └── channels │ │ │ └── FileChannel.java │ └── org │ │ └── xnio │ │ ├── AbstractConvertingIoFutureTestCase.java │ │ ├── AbstractIoFutureTestCase.java │ │ ├── AssertReadWrite.java │ │ ├── BitsTestCase.java │ │ ├── BuffersTestCase.java │ │ ├── ByteStringTestCase.java │ │ ├── ChannelListenersTestCase.java │ │ ├── CloserTestCase.java │ │ ├── FailedIoFutureTestCase.java │ │ ├── FileSystemWatcherTestCase.java │ │ ├── FinishedIoFutureTestCase.java │ │ ├── FutureResultTestCase.java │ │ ├── IoUtilsTestCase.java │ │ ├── LocalSocketAddressTestCase.java │ │ ├── OptionMapTestCase.java │ │ ├── OptionTestCase.java │ │ ├── OptionsTestCase.java │ │ ├── PropertyTestCase.java │ │ ├── SequenceTestCase.java │ │ ├── XnioFileChannelTestCase.java │ │ ├── XnioTestCase.java │ │ ├── XnioWorkerTestCase.java │ │ ├── channels │ │ ├── AbstractBlockingReadableByteChannelTest.java │ │ ├── AbstractBlockingWritableByteChannelTest.java │ │ ├── BlockingByteChannelReadTestCase.java │ │ ├── BlockingByteChannelWriteTestCase.java │ │ ├── BlockingReadableByteChannelTestCase.java │ │ ├── BlockingWritableByteChannelTestCase.java │ │ ├── ChannelsTestCase.java │ │ ├── EmptyStreamSourceChannelTestCase.java │ │ ├── FramedMessageChannelTestCase.java │ │ ├── PushBackStreamChannelTestCase.java │ │ └── SocketAddressBufferTestCase.java │ │ ├── http │ │ └── HttpParserTestCase.java │ │ ├── mock │ │ ├── AcceptingChannelMock.java │ │ ├── ConduitMock.java │ │ ├── ConnectedStreamChannelMock.java │ │ ├── MessageChannelMock.java │ │ ├── MessageConnectionMock.java │ │ ├── Mock.java │ │ ├── MulticastMessageChannelMock.java │ │ ├── StreamConnectionMock.java │ │ ├── XnioIoThreadMock.java │ │ ├── XnioMock.java │ │ └── XnioWorkerMock.java │ │ ├── racecondition │ │ ├── CloseReadingSslChannelTestCase.java │ │ ├── CloseWritingSslChannelTestCase.java │ │ ├── ResumeReadsOnHandlingReadableChannelTestCase.java │ │ ├── ResumeWritesOnHandlingWritableChannelTestCase.java │ │ ├── SetReadListenerOnHandlingReadableChannelTestCase.java │ │ ├── SetReadReadyOnHandlingReadableChannelTestCase.java │ │ ├── SetReadRequiresWriteOnWritingSslChannelTestCase.java │ │ ├── SetWriteListenerOnHandlingWritableChannelTestCase.java │ │ ├── SetWriteReadyOnHandlingWritableChannelTestCase.java │ │ └── SetWriteRequiresReadOnReadingSslChannelTestCase.java │ │ ├── ssl │ │ ├── AbstractConnectedSslStreamChannelTest.java │ │ ├── AbstractSslConnectionTest.java │ │ ├── AbstractSslTest.java │ │ ├── ChannelDelegationTestCase.java │ │ ├── ConnectedSslStreamChannelBufferOverflowTestCase.java │ │ ├── ConnectedSslStreamChannelReadTestCase.java │ │ ├── ConnectedSslStreamChannelReadWriteTestCase.java │ │ ├── ConnectedSslStreamChannelWriteTestCase.java │ │ ├── JsseSslStreamConnectionBufferOverflowTestCase.java │ │ ├── JsseSslStreamConnectionTestCase.java │ │ ├── JsseSslStreamSinkConduitTestCase.java │ │ ├── JsseSslStreamSourceConduitTestCase.java │ │ ├── JsseXnioSslTestCase.java │ │ ├── SslStreamConnectionValidationTestCase.java │ │ ├── StartTLSChannelTestCase.java │ │ ├── StartTLSConnectionTestCase.java │ │ └── mock │ │ │ ├── SSLContextMock.java │ │ │ └── SSLEngineMock.java │ │ └── streams │ │ ├── AbstractChannelInputStreamTest.java │ │ ├── AbstractChannelStreamTest.java │ │ ├── BufferPipeInputStreamTestCase.java │ │ ├── BufferPipeOutputStreamTestCase.java │ │ ├── BufferedChannelInputStreamTestCase.java │ │ ├── ChannelInputStreamTestCase.java │ │ ├── ChannelOutputStreamTestCase.java │ │ ├── LimitedInputStreamTestCase.java │ │ ├── LimitedOutputStreamTestCase.java │ │ ├── PipeTestCase.java │ │ ├── ReaderInputStreamTestCase.java │ │ ├── StreamsTestCase.java │ │ └── WriterOutputStreamTestCase.java │ └── resources │ ├── META-INF │ └── services │ │ └── org.xnio.XnioProvider │ ├── keystore.jks │ ├── org │ └── xnio │ │ └── racecondition │ │ ├── CloseReadingSslChannelTestCase.btm │ │ ├── CloseWritingSslChannelTestCase.btm │ │ ├── ResumeReadsOnHandlingReadableChannelTestCase.btm │ │ ├── ResumeWritesOnHandlingWritableChannelTestCase.btm │ │ ├── SetReadListenerOnHandlingReadableChannelTestCase.btm │ │ ├── SetReadReadyOnHandlingReadableChannelTestCase.btm │ │ ├── SetReadRequiresWriteOnWritingSslChannelTestCase.btm │ │ ├── SetWriteListenerOnHandlingWritableChannelTestCase.btm │ │ ├── SetWriteReadyOnHandlingWritableChannelTestCase.btm │ │ └── SetWriteRequiresReadOnReadingSslChannelTestCase.btm │ └── security.policy ├── nio-impl ├── pom.xml └── src │ ├── main │ ├── java │ │ └── org │ │ │ └── xnio │ │ │ └── nio │ │ │ ├── AbstractNioChannel.java │ │ │ ├── AbstractNioStreamConnection.java │ │ │ ├── Log.java │ │ │ ├── NioHandle.java │ │ │ ├── NioPipeSinkConduit.java │ │ │ ├── NioPipeSourceConduit.java │ │ │ ├── NioPipeStreamConnection.java │ │ │ ├── NioSocketConduit.java │ │ │ ├── NioSocketStreamConnection.java │ │ │ ├── NioTcpServer.java │ │ │ ├── NioTcpServerHandle.java │ │ │ ├── NioUdpChannel.java │ │ │ ├── NioUdpChannelHandle.java │ │ │ ├── NioXnio.java │ │ │ ├── NioXnioProvider.java │ │ │ ├── NioXnioWorker.java │ │ │ ├── SelectorUtils.java │ │ │ ├── Version.java │ │ │ ├── WatchServiceFileSystemWatcher.java │ │ │ └── WorkerThread.java │ └── resources │ │ ├── META-INF │ │ └── services │ │ │ └── org.xnio.XnioProvider │ │ └── org │ │ └── xnio │ │ └── nio │ │ └── Version.properties │ └── test │ ├── java │ └── org │ │ └── xnio │ │ └── nio │ │ └── test │ │ ├── AbstractNioChannelPipeTest.java │ │ ├── AbstractNioStreamChannelTest.java │ │ ├── AbstractNioTcpTest.java │ │ ├── AbstractStreamSinkSourceChannelTest.java │ │ ├── CatchingChannelListener.java │ │ ├── ConnectionOptionSetupTestCase.java │ │ ├── FileSystemWatcherTestCase.java │ │ ├── FullDuplexChannelPipeTestCase.java │ │ ├── HalfDuplexChannelPipeTestCase.java │ │ ├── IllegalConnectionTestCase.java │ │ ├── MultiThreadedNioSslTcpChannelTestCase.java │ │ ├── MultiThreadedNioSslTcpConnectionTestCase.java │ │ ├── MultiThreadedNioStartTLSTcpChannelTestCase.java │ │ ├── MultiThreadedNioStartTLSTcpConnectionTestCase.java │ │ ├── MultiThreadedNioTcpChannelTestCase.java │ │ ├── MultiThreadedNioTcpConnectionTestCase.java │ │ ├── NioFullDuplexChannelPipeTestCase.java │ │ ├── NioHalfDuplexChannelPipeTestCase.java │ │ ├── NioSslTcpChannelTestCase.java │ │ ├── NioSslTcpConnectionTestCase.java │ │ ├── NioStartTLSTcpChannelTestCase.java │ │ ├── NioStartTLSTcpConnectionTestCase.java │ │ ├── NioTcpChannelTestCase.java │ │ ├── NioTcpConnectionTestCase.java │ │ ├── NioUdpTestCase.java │ │ ├── OptionHelper.java │ │ ├── TcpChannelTestCase.java │ │ ├── TcpConnectionTestCase.java │ │ ├── TcpServerTest.java │ │ ├── TestChannelListener.java │ │ ├── UdpChannelTestCase.java │ │ ├── XnioWorkerTestCase.java │ │ └── racecondition │ │ └── NullHelper.java │ └── resources │ ├── keystore.jks │ ├── logging.properties │ └── org │ └── xnio │ └── nio │ └── test │ └── racecondition │ ├── SetConnFullDuringAwaitTestCase │ └── UnsetConnFullDuringAwaitTestCase └── pom.xml /.gitignore: -------------------------------------------------------------------------------- 1 | .project 2 | .classpath 3 | .settings 4 | *.iml 5 | target 6 | .idea 7 | *.ipr 8 | *~ 9 | out 10 | -------------------------------------------------------------------------------- /api/src/main/java/org/xnio/BrokenPipeException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * 4 | * Copyright 2012 Red Hat, Inc. and/or its affiliates, and individual 5 | * contributors as indicated by the @author tags. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | 20 | package org.xnio; 21 | 22 | import java.io.IOException; 23 | 24 | /** 25 | * An exception that signifies that a pipe, stream, or channel was closed from the read side while the write side was 26 | * still writing. 27 | * 28 | * @author David M. Lloyd 29 | */ 30 | public class BrokenPipeException extends IOException { 31 | 32 | /** 33 | * Constructs a {@code BrokenPipeException} with no detail message. The cause is not initialized, and may 34 | * subsequently be initialized by a call to {@link #initCause(Throwable) initCause}. 35 | */ 36 | public BrokenPipeException() { 37 | } 38 | 39 | /** 40 | * Constructs a {@code BrokenPipeException} with the specified detail message. The cause is not initialized, and may 41 | * subsequently be initialized by a call to {@link #initCause(Throwable) initCause}. 42 | * 43 | * @param msg the detail message 44 | */ 45 | public BrokenPipeException(final String msg) { 46 | super(msg); 47 | } 48 | 49 | /** 50 | * Constructs a {@code BrokenPipeException} with the specified cause. The detail message is set to: 51 | *
(cause == null ? null : cause.toString())
52 | * (which typically contains the class and detail message of {@code cause}). 53 | * 54 | * @param cause the cause (which is saved for later retrieval by the {@link #getCause()} method) 55 | */ 56 | public BrokenPipeException(final Throwable cause) { 57 | super(cause); 58 | } 59 | 60 | /** 61 | * Constructs a {@code BrokenPipeException} with the specified detail message and cause. 62 | * 63 | * @param msg the detail message 64 | * @param cause the cause (which is saved for later retrieval by the {@link #getCause()} method) 65 | */ 66 | public BrokenPipeException(final String msg, final Throwable cause) { 67 | super(msg, cause); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /api/src/main/java/org/xnio/BufferAllocator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * 4 | * Copyright 2011 Red Hat, Inc. and/or its affiliates, and individual 5 | * contributors as indicated by the @author tags. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | 20 | package org.xnio; 21 | 22 | import java.nio.Buffer; 23 | import java.nio.ByteBuffer; 24 | 25 | /** 26 | * A simple allocator for buffers. 27 | * 28 | * @param the buffer type 29 | * 30 | * @author David M. Lloyd 31 | */ 32 | public interface BufferAllocator { 33 | 34 | /** 35 | * Allocate a buffer of the given size. 36 | * 37 | * @param size the size 38 | * @return the buffer 39 | * @throws IllegalArgumentException if the given buffer size is less than zero 40 | */ 41 | B allocate(int size) throws IllegalArgumentException; 42 | 43 | /** 44 | * A simple allocator for heap-array-backed byte buffers. 45 | */ 46 | BufferAllocator BYTE_BUFFER_ALLOCATOR = new BufferAllocator() { 47 | public ByteBuffer allocate(final int size) { 48 | return ByteBuffer.allocate(size); 49 | } 50 | }; 51 | 52 | /** 53 | * A simple allocator for direct byte buffers. 54 | */ 55 | BufferAllocator DIRECT_BYTE_BUFFER_ALLOCATOR = new BufferAllocator() { 56 | public ByteBuffer allocate(final int size) { 57 | return ByteBuffer.allocateDirect(size); 58 | } 59 | }; 60 | } 61 | -------------------------------------------------------------------------------- /api/src/main/java/org/xnio/Cancellable.java: -------------------------------------------------------------------------------- 1 | 2 | package org.xnio; 3 | 4 | /** 5 | * An operation which may be cancelled. 6 | */ 7 | public interface Cancellable { 8 | 9 | /** 10 | * Cancel an operation. The actual cancel may be synchronous or asynchronous. 11 | * 12 | * @return this instance 13 | */ 14 | Cancellable cancel(); 15 | } 16 | -------------------------------------------------------------------------------- /api/src/main/java/org/xnio/ChainedChannelListener.java: -------------------------------------------------------------------------------- 1 | 2 | package org.xnio; 3 | 4 | import java.nio.channels.Channel; 5 | 6 | /** 7 | * A channel listener that chains calls to a number of other channel listeners. 8 | * 9 | * @author David M. Lloyd 10 | */ 11 | public final class ChainedChannelListener implements ChannelListener { 12 | private final ChannelListener[] listeners; 13 | 14 | /** 15 | * Construct a new instance. The given array will be copied. 16 | * 17 | * @param listeners the listeners to chain to 18 | */ 19 | public ChainedChannelListener(final ChannelListener... listeners) { 20 | this.listeners = listeners.clone(); 21 | } 22 | 23 | public void handleEvent(final T channel) { 24 | for (ChannelListener listener : listeners) { 25 | ChannelListeners.invokeChannelListener(channel, listener); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /api/src/main/java/org/xnio/ChannelDestination.java: -------------------------------------------------------------------------------- 1 | 2 | package org.xnio; 3 | 4 | import java.nio.channels.Channel; 5 | import org.xnio.channels.BoundChannel; 6 | 7 | /** 8 | * A channel destination. This is the inverse of {@code ChannelSource}; it is used to accept a single connection from a remote 9 | * peer. 10 | * 11 | * @param the channel type 12 | * 13 | * @since 1.2 14 | */ 15 | public interface ChannelDestination { 16 | /** 17 | * Accept a connection. The bind listener will be called when the channel is bound; the open listener will be called 18 | * when the connection is accepted. It is not guaranteed that the open listener will be called after the bind listener. 19 | * 20 | * @param openListener the listener which will be notified when the channel is open, or {@code null} for none 21 | * @param bindListener the listener which will be notified when the channel is bound locally, or {@code null} for none 22 | * @return the future connection 23 | */ 24 | IoFuture accept(ChannelListener openListener, ChannelListener bindListener); 25 | } 26 | -------------------------------------------------------------------------------- /api/src/main/java/org/xnio/ChannelExceptionHandler.java: -------------------------------------------------------------------------------- 1 | 2 | package org.xnio; 3 | 4 | import java.io.IOException; 5 | import java.nio.channels.Channel; 6 | import java.util.EventListener; 7 | 8 | /** 9 | * An exception handler for utility channel listeners. 10 | * 11 | * @author David M. Lloyd 12 | */ 13 | public interface ChannelExceptionHandler extends EventListener { 14 | 15 | /** 16 | * Handle an exception on the channel. 17 | * 18 | * @param channel the channel 19 | * @param exception the exception 20 | */ 21 | void handleException(T channel, IOException exception); 22 | } 23 | -------------------------------------------------------------------------------- /api/src/main/java/org/xnio/ChannelPipe.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * 4 | * Copyright 2012 Red Hat, Inc. and/or its affiliates, and individual 5 | * contributors as indicated by the @author tags. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | 20 | package org.xnio; 21 | 22 | import org.xnio.channels.CloseableChannel; 23 | 24 | /** 25 | * A one-way pipe. 26 | * 27 | * @author David M. Lloyd 28 | */ 29 | public final class ChannelPipe { 30 | private final L leftSide; 31 | private final R rightSide; 32 | 33 | /** 34 | * Construct a new instance. 35 | * 36 | * @param leftSide the pipe left side 37 | * @param rightSide the pipe right side 38 | */ 39 | public ChannelPipe(final L leftSide, final R rightSide) { 40 | this.rightSide = rightSide; 41 | this.leftSide = leftSide; 42 | } 43 | 44 | /** 45 | * Get the pipe source. 46 | * 47 | * @return the pipe source 48 | */ 49 | public L getLeftSide() { 50 | return leftSide; 51 | } 52 | 53 | /** 54 | * Get the pipe sink. 55 | * 56 | * @return the pipe sink 57 | */ 58 | public R getRightSide() { 59 | return rightSide; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /api/src/main/java/org/xnio/ChannelSource.java: -------------------------------------------------------------------------------- 1 | 2 | package org.xnio; 3 | 4 | import java.nio.channels.Channel; 5 | 6 | /** 7 | * A channel source. Instances of this interface are used to create a channel and associate it with a listener. Example 8 | * uses are to establish a TCP connection (as a client), open a serial port, etc. 9 | * 10 | * @param the type of channel 11 | */ 12 | public interface ChannelSource { 13 | 14 | /** 15 | * Open a channel. 16 | * 17 | * @param openListener the listener which will be notified when the channel is open 18 | * @return the future result of this operation 19 | */ 20 | IoFuture open(ChannelListener openListener); 21 | } 22 | -------------------------------------------------------------------------------- /api/src/main/java/org/xnio/ClosedWorkerException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * 4 | * Copyright 2011 Red Hat, Inc. and/or its affiliates, and individual 5 | * contributors as indicated by the @author tags. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | 20 | package org.xnio; 21 | 22 | import java.io.IOException; 23 | 24 | /** 25 | * A channel open was attempted on a closed worker. 26 | * 27 | * @author David M. Lloyd 28 | */ 29 | public class ClosedWorkerException extends IOException { 30 | 31 | /** 32 | * Constructs a {@code ClosedWorkerException} with no detail message. The cause is not initialized, and may 33 | * subsequently be initialized by a call to {@link #initCause(Throwable) initCause}. 34 | */ 35 | public ClosedWorkerException() { 36 | } 37 | 38 | /** 39 | * Constructs a {@code ClosedWorkerException} with the specified detail message. The cause is not initialized, and 40 | * may subsequently be initialized by a call to {@link #initCause(Throwable) initCause}. 41 | * 42 | * @param msg the detail message 43 | */ 44 | public ClosedWorkerException(final String msg) { 45 | super(msg); 46 | } 47 | 48 | /** 49 | * Constructs a {@code ClosedWorkerException} with the specified cause. The detail message is set to: 50 | *
(cause == null ? null : cause.toString())
51 | * (which typically contains the class and detail message of {@code cause}). 52 | * 53 | * @param cause the cause (which is saved for later retrieval by the {@link #getCause()} method) 54 | */ 55 | public ClosedWorkerException(final Throwable cause) { 56 | super(cause); 57 | } 58 | 59 | /** 60 | * Constructs a {@code ClosedWorkerException} with the specified detail message and cause. 61 | * 62 | * @param msg the detail message 63 | * @param cause the cause (which is saved for later retrieval by the {@link #getCause()} method) 64 | */ 65 | public ClosedWorkerException(final String msg, final Throwable cause) { 66 | super(msg, cause); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /api/src/main/java/org/xnio/Closer.java: -------------------------------------------------------------------------------- 1 | 2 | package org.xnio; 3 | 4 | import java.io.Closeable; 5 | 6 | /** 7 | * A {@code Runnable} that closes some resource. 8 | * 9 | * @apiviz.exclude 10 | */ 11 | public final class Closer implements Runnable { 12 | private final Closeable resource; 13 | 14 | public Closer(final Closeable resource) { 15 | this.resource = resource; 16 | } 17 | 18 | public void run() { 19 | IoUtils.safeClose(resource); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /api/src/main/java/org/xnio/CompressionType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * 4 | * Copyright 2012 Red Hat, Inc. and/or its affiliates. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.xnio; 20 | 21 | /** 22 | * Supported compression types. 23 | * 24 | * @author David M. Lloyd 25 | */ 26 | public enum CompressionType { 27 | /** 28 | * ZLIB compatible compression. 29 | */ 30 | DEFLATE, 31 | /** 32 | * GZIP compatible compression. 33 | */ 34 | GZIP, 35 | ; 36 | } 37 | -------------------------------------------------------------------------------- /api/src/main/java/org/xnio/DelegatingChannelListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * 4 | * Copyright 2012 Red Hat, Inc. and/or its affiliates, and individual 5 | * contributors as indicated by the @author tags. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | 20 | package org.xnio; 21 | 22 | import java.nio.channels.Channel; 23 | 24 | /** 25 | * A base class for a channel listener which performs an action and then calls a delegate listener. 26 | * 27 | * @author David M. Lloyd 28 | */ 29 | public abstract class DelegatingChannelListener implements ChannelListener { 30 | private final ChannelListener next; 31 | 32 | /** 33 | * Construct a new instance. The next listener must be for the same type as, or a supertype of, the channel 34 | * type handleable by this listener. 35 | * 36 | * @param next the next listener 37 | */ 38 | protected DelegatingChannelListener(final ChannelListener next) { 39 | this.next = next; 40 | } 41 | 42 | /** 43 | * Call the next listener. Does not throw exceptions. 44 | * 45 | * @param channel the channel to pass to the next listener 46 | */ 47 | protected void callNext(T channel) { 48 | ChannelListeners.invokeChannelListener(channel, next); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /api/src/main/java/org/xnio/FailedIoFuture.java: -------------------------------------------------------------------------------- 1 | 2 | package org.xnio; 3 | 4 | import java.io.IOException; 5 | 6 | /** 7 | * An implementation of {@link IoFuture} that represents an immediately-failed operation. 8 | * 9 | * @param the type of result that this operation produces 10 | */ 11 | public class FailedIoFuture extends AbstractIoFuture { 12 | /** 13 | * Create an instance. 14 | * 15 | * @param e the failure cause 16 | */ 17 | public FailedIoFuture(IOException e) { 18 | setException(e); 19 | } 20 | 21 | /** 22 | * Cancel the operation. Since this operation is always complete, this is a no-op. 23 | * 24 | * @return this instance 25 | */ 26 | public IoFuture cancel() { 27 | return this; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /api/src/main/java/org/xnio/FileAccess.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * 4 | * Copyright 2013 Red Hat, Inc. and/or its affiliates. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.xnio; 20 | 21 | /** 22 | * Possible file access modes. 23 | * 24 | * @author David M. Lloyd 25 | */ 26 | public enum FileAccess { 27 | READ_ONLY(true, false), 28 | READ_WRITE(true, true), 29 | WRITE_ONLY(false, true), 30 | ; 31 | private final boolean read; 32 | private final boolean write; 33 | 34 | private FileAccess(final boolean read, final boolean write) { 35 | this.read = read; 36 | this.write = write; 37 | } 38 | 39 | boolean isRead() { 40 | return read; 41 | } 42 | 43 | boolean isWrite() { 44 | return write; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /api/src/main/java/org/xnio/FileChangeCallback.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * 4 | * Copyright 2013 Red Hat, Inc. and/or its affiliates. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.xnio; 20 | 21 | import java.util.Collection; 22 | 23 | /** 24 | * Callback for file system change events 25 | * 26 | * @see FileSystemWatcher 27 | * @author Stuart Douglas 28 | */ 29 | public interface FileChangeCallback { 30 | 31 | /** 32 | * Method that is invoked when file system changes are detected. 33 | * 34 | * @param changes the file system changes 35 | */ 36 | void handleChanges(final Collection changes); 37 | 38 | } 39 | -------------------------------------------------------------------------------- /api/src/main/java/org/xnio/FileChangeEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * 4 | * Copyright 2013 Red Hat, Inc. and/or its affiliates. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.xnio; 20 | 21 | import java.io.File; 22 | 23 | /** 24 | * The event object that is fired when a file system change is detected. 25 | * 26 | * @see FileSystemWatcher 27 | * 28 | * @author Stuart Douglas 29 | */ 30 | public class FileChangeEvent { 31 | 32 | private final File file; 33 | private final Type type; 34 | 35 | /** 36 | * Construct a new instance. 37 | * 38 | * @param file the file which is being watched 39 | * @param type the type of event that was encountered 40 | */ 41 | public FileChangeEvent(File file, Type type) { 42 | this.file = file; 43 | this.type = type; 44 | } 45 | 46 | /** 47 | * Get the file which was being watched. 48 | * 49 | * @return the file which was being watched 50 | */ 51 | public File getFile() { 52 | return file; 53 | } 54 | 55 | /** 56 | * Get the type of event. 57 | * 58 | * @return the type of event 59 | */ 60 | public Type getType() { 61 | return type; 62 | } 63 | 64 | /** 65 | * Watched file event types. More may be added in the future. 66 | */ 67 | public static enum Type { 68 | /** 69 | * A file was added in a directory. 70 | */ 71 | ADDED, 72 | /** 73 | * A file was removed from a directory. 74 | */ 75 | REMOVED, 76 | /** 77 | * A file was modified in a directory. 78 | */ 79 | MODIFIED, 80 | } 81 | 82 | } 83 | -------------------------------------------------------------------------------- /api/src/main/java/org/xnio/FileSystemWatcher.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * 4 | * Copyright 2013 Red Hat, Inc. and/or its affiliates. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.xnio; 20 | 21 | import java.io.Closeable; 22 | import java.io.File; 23 | 24 | /** 25 | * File system watcher service. This watcher can be used to receive notifications about a specific path. 26 | * 27 | * @author Stuart Douglas 28 | */ 29 | public interface FileSystemWatcher extends Closeable { 30 | 31 | /** 32 | * Watch the given path recursively, and invoke the callback when a change is made. 33 | * 34 | * @param file The path to watch 35 | * @param callback The callback 36 | */ 37 | public void watchPath(final File file, final FileChangeCallback callback); 38 | 39 | /** 40 | * Stop watching a path. 41 | * 42 | * @param file the path 43 | * @param callback the callback 44 | */ 45 | public void unwatchPath(final File file, final FileChangeCallback callback); 46 | } 47 | -------------------------------------------------------------------------------- /api/src/main/java/org/xnio/FinishedIoFuture.java: -------------------------------------------------------------------------------- 1 | 2 | package org.xnio; 3 | 4 | import java.io.IOException; 5 | import java.util.concurrent.CancellationException; 6 | import java.util.concurrent.TimeUnit; 7 | 8 | import static org.xnio.IoFuture.Status.DONE; 9 | 10 | /** 11 | * An implementation of {@link IoFuture} that represents an immediately-successful operation. 12 | * 13 | * @param the type of result that this operation produces 14 | */ 15 | public class FinishedIoFuture implements IoFuture { 16 | 17 | private final T result; 18 | 19 | /** 20 | * Create an instance. 21 | * 22 | * @param result the operation result 23 | */ 24 | public FinishedIoFuture(T result) { 25 | this.result = result; 26 | } 27 | 28 | /** 29 | * Cancel the operation. Since this operation is always complete, this is a no-op. 30 | * 31 | * @return this instance 32 | */ 33 | public IoFuture cancel() { 34 | return this; 35 | } 36 | 37 | @Override 38 | public Status getStatus() { 39 | return DONE; 40 | } 41 | 42 | @Override 43 | public Status await() { 44 | return DONE; 45 | } 46 | 47 | @Override 48 | public Status await(final long time, final TimeUnit timeUnit) { 49 | return DONE; 50 | } 51 | 52 | @Override 53 | public Status awaitInterruptibly() throws InterruptedException { 54 | return DONE; 55 | } 56 | 57 | @Override 58 | public Status awaitInterruptibly(final long time, final TimeUnit timeUnit) throws InterruptedException { 59 | return DONE; 60 | } 61 | 62 | @Override 63 | public T get() throws IOException, CancellationException { 64 | return result; 65 | } 66 | 67 | @Override 68 | public T getInterruptibly() throws IOException, InterruptedException, CancellationException { 69 | return result; 70 | } 71 | 72 | @Override 73 | public IOException getException() throws IllegalStateException { 74 | throw new IllegalStateException(); 75 | } 76 | 77 | @Override 78 | public IoFuture addNotifier(final Notifier notifier, final A attachment) { 79 | notifier.notify(this, attachment); 80 | return this; 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /api/src/main/java/org/xnio/LocalSocketAddress.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * 4 | * Copyright 2010 Red Hat, Inc. and/or its affiliates, and individual 5 | * contributors as indicated by the @author tags. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | 20 | package org.xnio; 21 | 22 | import java.net.SocketAddress; 23 | 24 | import static org.xnio._private.Messages.msg; 25 | 26 | /** 27 | * A socket address which is a local (UNIX domain) socket. 28 | * 29 | * @author David M. Lloyd 30 | */ 31 | public final class LocalSocketAddress extends SocketAddress { 32 | 33 | private static final long serialVersionUID = -596342428809783686L; 34 | 35 | private final String name; 36 | 37 | /** 38 | * Construct a new instance. 39 | * 40 | * @param name the name of this socket address 41 | */ 42 | public LocalSocketAddress(final String name) { 43 | if (name == null) { 44 | throw msg.nullParameter("name"); 45 | } 46 | this.name = name; 47 | } 48 | 49 | /** 50 | * Get the name (filesystem path) of this local socket address. 51 | * 52 | * @return the name 53 | */ 54 | public String getName() { 55 | return name; 56 | } 57 | 58 | /** 59 | * Get the string representation of this socket address (its name). 60 | * 61 | * @return the string representation 62 | */ 63 | public String toString() { 64 | return getName(); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /api/src/main/java/org/xnio/Pool.java: -------------------------------------------------------------------------------- 1 | 2 | package org.xnio; 3 | 4 | /** 5 | * A generic pooled resource manager. 6 | * 7 | * @param the resource type 8 | * 9 | * @apiviz.landmark 10 | */ 11 | public interface Pool { 12 | 13 | /** 14 | * Allocate a resource from the pool. 15 | * 16 | * @return the resource 17 | */ 18 | Pooled allocate(); 19 | } 20 | -------------------------------------------------------------------------------- /api/src/main/java/org/xnio/Pooled.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * 4 | * Copyright 2010 Red Hat, Inc. and/or its affiliates, and individual 5 | * contributors as indicated by the @author tags. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | 20 | package org.xnio; 21 | 22 | /** 23 | * A resource which is pooled. 24 | * 25 | * @param the pooled resource type 26 | * @author David M. Lloyd 27 | */ 28 | public interface Pooled extends AutoCloseable { 29 | 30 | /** 31 | * Discard this resource. Any backing resources corresponding to this pooled resource will be rendered unavailable 32 | * until the pooled resource has been garbage-collected. 33 | */ 34 | void discard(); 35 | 36 | /** 37 | * Free this resource for immediate re-use. The resource must not be accessed again after 38 | * calling this method; if it is possible that an instance is still in use, you must call {@link #discard()} instead. 39 | */ 40 | void free(); 41 | 42 | /** 43 | * Get the pooled resource. 44 | * 45 | * @return the pooled resource 46 | * @throws IllegalStateException if the resource has been freed or discarded already 47 | */ 48 | T getResource() throws IllegalStateException; 49 | 50 | /** 51 | * Delegates to {@link #free()}. 52 | */ 53 | void close(); 54 | } 55 | -------------------------------------------------------------------------------- /api/src/main/java/org/xnio/ReadPropertyAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * 4 | * Copyright 2012 Red Hat, Inc. and/or its affiliates. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.xnio; 20 | 21 | import java.security.PrivilegedAction; 22 | 23 | /** 24 | * A simple property-read privileged action. 25 | * 26 | * @author David M. Lloyd 27 | */ 28 | public final class ReadPropertyAction implements PrivilegedAction { 29 | private final String propertyName; 30 | private final String defaultValue; 31 | 32 | /** 33 | * Construct a new instance. 34 | * 35 | * @param propertyName the property name 36 | * @param defaultValue the default value 37 | */ 38 | public ReadPropertyAction(final String propertyName, final String defaultValue) { 39 | this.propertyName = propertyName; 40 | this.defaultValue = defaultValue; 41 | } 42 | 43 | /** 44 | * Run the action. 45 | * 46 | * @return the property or default value 47 | */ 48 | public String run() { 49 | return System.getProperty(propertyName, defaultValue); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /api/src/main/java/org/xnio/Result.java: -------------------------------------------------------------------------------- 1 | 2 | package org.xnio; 3 | 4 | import java.io.IOException; 5 | 6 | /** 7 | * A handler for the result of an operation. May be used to populate an {@link IoFuture}. 8 | */ 9 | public interface Result { 10 | 11 | /** 12 | * Set the result for this operation. Any threads blocking on this instance will be unblocked. 13 | * 14 | * @param result the result to set 15 | * 16 | * @return {@code false} if the operation was already completed, {@code true} otherwise 17 | */ 18 | boolean setResult(T result); 19 | 20 | /** 21 | * Set the exception for this operation. Any threads blocking on this instance will be unblocked. 22 | * 23 | * @param exception the exception to set 24 | * 25 | * @return {@code false} if the operation was already completed, {@code true} otherwise 26 | */ 27 | boolean setException(IOException exception); 28 | 29 | /** 30 | * Acknowledge the cancellation of this operation. 31 | * 32 | * @return {@code false} if the operation was already completed, {@code true} otherwise 33 | */ 34 | boolean setCancelled(); 35 | } 36 | -------------------------------------------------------------------------------- /api/src/main/java/org/xnio/SequenceOption.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * 4 | * Copyright 2011 Red Hat, Inc. and/or its affiliates, and individual 5 | * contributors as indicated by the @author tags. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | 20 | package org.xnio; 21 | 22 | import java.util.ArrayList; 23 | import java.util.Collection; 24 | import java.util.List; 25 | 26 | import static org.xnio._private.Messages.msg; 27 | 28 | /** 29 | * @author David M. Lloyd 30 | */ 31 | final class SequenceOption extends Option> { 32 | 33 | private static final long serialVersionUID = -4328676629293125136L; 34 | 35 | private final transient Class elementType; 36 | private final transient ValueParser parser; 37 | 38 | SequenceOption(final Class declClass, final String name, final Class elementType) { 39 | super(declClass, name); 40 | if (elementType == null) { 41 | throw msg.nullParameter("elementType"); 42 | } 43 | this.elementType = elementType; 44 | parser = Option.getParser(elementType); 45 | } 46 | 47 | public Sequence cast(final Object o) { 48 | if (o == null) { 49 | return null; 50 | } else if (o instanceof Sequence) { 51 | return ((Sequence)o).cast(elementType); 52 | } else if (o instanceof Object[]){ 53 | return Sequence.of((Object[])o).cast(elementType); 54 | } else if (o instanceof Collection) { 55 | return Sequence.of((Collection)o).cast(elementType); 56 | } else { 57 | throw new ClassCastException("Not a sequence"); 58 | } 59 | } 60 | 61 | public Sequence parseValue(final String string, final ClassLoader classLoader) throws IllegalArgumentException { 62 | final List list = new ArrayList(); 63 | if (string.isEmpty()) { 64 | return Sequence.empty(); 65 | } 66 | for (String value : string.split(",")) { 67 | list.add(parser.parseValue(value, classLoader)); 68 | } 69 | return Sequence.of(list); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /api/src/main/java/org/xnio/SingleOption.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * 4 | * Copyright 2011 Red Hat, Inc. and/or its affiliates, and individual 5 | * contributors as indicated by the @author tags. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | 20 | package org.xnio; 21 | 22 | import static org.xnio._private.Messages.msg; 23 | 24 | /** 25 | * @author David M. Lloyd 26 | */ 27 | final class SingleOption extends Option { 28 | 29 | private static final long serialVersionUID = 2449094406108952764L; 30 | 31 | private final transient Class type; 32 | private final transient ValueParser parser; 33 | 34 | SingleOption(final Class declClass, final String name, final Class type) { 35 | super(declClass, name); 36 | if (type == null) { 37 | throw msg.nullParameter("type"); 38 | } 39 | this.type = type; 40 | parser = Option.getParser(type); 41 | } 42 | 43 | public T cast(final Object o) { 44 | return type.cast(o); 45 | } 46 | 47 | public T parseValue(final String string, final ClassLoader classLoader) throws IllegalArgumentException { 48 | return parser.parseValue(string, classLoader); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /api/src/main/java/org/xnio/SslClientAuthMode.java: -------------------------------------------------------------------------------- 1 | 2 | package org.xnio; 3 | 4 | /** 5 | * The desired SSL client authentication mode for SSL channels in server mode. 6 | */ 7 | public enum SslClientAuthMode { 8 | 9 | /** 10 | * SSL client authentication is not requested. 11 | */ 12 | NOT_REQUESTED, 13 | /** 14 | * SSL client authentication is requested but not required. 15 | */ 16 | REQUESTED, 17 | /** 18 | * SSL client authentication is required. 19 | */ 20 | REQUIRED, 21 | } 22 | -------------------------------------------------------------------------------- /api/src/main/java/org/xnio/TranslatingResult.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * 4 | * Copyright 2009 Red Hat, Inc. and/or its affiliates. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.xnio; 20 | 21 | import java.io.IOException; 22 | 23 | /** 24 | * Abstract base class for {@code Result}s which translate from one type to another. 25 | * 26 | * @param the result type to accept 27 | * @param the result type to pass to the delegate 28 | */ 29 | public abstract class TranslatingResult implements Result { 30 | private final Result output; 31 | 32 | protected TranslatingResult(final Result output) { 33 | this.output = output; 34 | } 35 | 36 | public boolean setException(final IOException exception) { 37 | return output.setException(exception); 38 | } 39 | 40 | public boolean setCancelled() { 41 | return output.setCancelled(); 42 | } 43 | 44 | public boolean setResult(final T result) { 45 | try { 46 | return output.setResult(translate(result)); 47 | } catch (IOException e) { 48 | return output.setException(e); 49 | } 50 | } 51 | 52 | protected abstract O translate(T input) throws IOException; 53 | } 54 | -------------------------------------------------------------------------------- /api/src/main/java/org/xnio/TypeOption.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * 4 | * Copyright 2011 Red Hat, Inc. and/or its affiliates, and individual 5 | * contributors as indicated by the @author tags. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | 20 | package org.xnio; 21 | 22 | import static org.xnio._private.Messages.msg; 23 | 24 | /** 25 | * @author David M. Lloyd 26 | */ 27 | final class TypeOption extends Option> { 28 | 29 | private static final long serialVersionUID = 2449094406108952764L; 30 | 31 | private final transient Class type; 32 | private final transient ValueParser> parser; 33 | 34 | TypeOption(final Class declClass, final String name, final Class type) { 35 | super(declClass, name); 36 | if (type == null) { 37 | throw msg.nullParameter("type"); 38 | } 39 | this.type = type; 40 | parser = Option.getClassParser(type); 41 | } 42 | 43 | public Class cast(final Object o) { 44 | return ((Class) o).asSubclass(type); 45 | } 46 | 47 | public Class parseValue(final String string, final ClassLoader classLoader) throws IllegalArgumentException { 48 | return (Class) parser.parseValue(string, classLoader); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /api/src/main/java/org/xnio/XnioProvider.java: -------------------------------------------------------------------------------- 1 | 2 | package org.xnio; 3 | 4 | /** 5 | * An XNIO provider, used by the service loader discovery mechanism. 6 | * 7 | * @author David M. Lloyd 8 | */ 9 | public interface XnioProvider { 10 | 11 | /** 12 | * Get the XNIO instance for this provider. 13 | * 14 | * @return the XNIO instance 15 | */ 16 | Xnio getInstance(); 17 | 18 | /** 19 | * Get the provider name. 20 | * 21 | * @return the name 22 | */ 23 | String getName(); 24 | } 25 | -------------------------------------------------------------------------------- /api/src/main/java/org/xnio/channels/AcceptListenerSettable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * 4 | * Copyright 2013 Red Hat, Inc. and/or its affiliates. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.xnio.channels; 20 | 21 | import java.nio.channels.Channel; 22 | import org.xnio.ChannelListener; 23 | 24 | /** 25 | * An object which supports directly setting the accept listener may implement this interface. 26 | * 27 | * @author David M. Lloyd 28 | */ 29 | public interface AcceptListenerSettable { 30 | /** 31 | * Get the accept listener. 32 | * 33 | * @return the accept listener 34 | */ 35 | ChannelListener getAcceptListener(); 36 | 37 | /** 38 | * Set the accept listener. 39 | * 40 | * @param listener the accept listener 41 | */ 42 | void setAcceptListener(ChannelListener listener); 43 | 44 | /** 45 | * A channel listener setter implementation which delegates to the appropriate setter method. 46 | * 47 | * @param the channel type 48 | */ 49 | class Setter implements ChannelListener.Setter { 50 | private final AcceptListenerSettable settable; 51 | 52 | /** 53 | * Construct a new instance. 54 | * 55 | * @param settable the settable to delegate to 56 | */ 57 | public Setter(final AcceptListenerSettable settable) { 58 | this.settable = settable; 59 | } 60 | 61 | public void set(final ChannelListener listener) { 62 | settable.setAcceptListener(listener); 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /api/src/main/java/org/xnio/channels/AcceptingChannel.java: -------------------------------------------------------------------------------- 1 | 2 | package org.xnio.channels; 3 | 4 | import java.io.IOException; 5 | import org.xnio.ChannelListener; 6 | 7 | /** 8 | * A channel which can accept inbound connections from remote endpoints. 9 | * 10 | * @author David M. Lloyd 11 | * @param the channel type 12 | */ 13 | public interface AcceptingChannel extends BoundChannel, SimpleAcceptingChannel { 14 | 15 | /** {@inheritDoc} */ 16 | C accept() throws IOException; 17 | 18 | /** {@inheritDoc} */ 19 | ChannelListener.Setter> getAcceptSetter(); 20 | 21 | /** {@inheritDoc} */ 22 | ChannelListener.Setter> getCloseSetter(); 23 | } 24 | -------------------------------------------------------------------------------- /api/src/main/java/org/xnio/channels/AssembledConnectedChannel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * 4 | * Copyright 2012 Red Hat, Inc. and/or its affiliates, and individual 5 | * contributors as indicated by the @author tags. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | 20 | package org.xnio.channels; 21 | 22 | import static org.xnio._private.Messages.msg; 23 | 24 | import java.net.SocketAddress; 25 | import org.xnio.ChannelListener; 26 | 27 | /** 28 | * A closeable, connected view over a read and write side of a suspendable channel, at least one of which is connected. 29 | * 30 | * @author David M. Lloyd 31 | */ 32 | public class AssembledConnectedChannel extends AssembledChannel implements ConnectedChannel { 33 | private final ConnectedChannel connection; 34 | 35 | /** 36 | * Construct a new instance. At least one of the channels must be an instance of {@link ConnectedChannel}. 37 | * 38 | * @param readChannel the read channel 39 | * @param writeChannel the write channel 40 | */ 41 | public AssembledConnectedChannel(final SuspendableReadChannel readChannel, final SuspendableWriteChannel writeChannel) { 42 | super(readChannel, writeChannel); 43 | ConnectedChannel ch = Channels.unwrap(ConnectedChannel.class, readChannel); 44 | if (ch == null) ch = Channels.unwrap(ConnectedChannel.class, writeChannel); 45 | if (ch == null) throw msg.oneChannelMustBeConnection(); 46 | connection = ch; 47 | } 48 | 49 | @SuppressWarnings("unchecked") 50 | public ChannelListener.Setter getCloseSetter() { 51 | return (ChannelListener.Setter) super.getCloseSetter(); 52 | } 53 | 54 | public SocketAddress getPeerAddress() { 55 | return connection.getPeerAddress(); 56 | } 57 | 58 | public A getPeerAddress(final Class type) { 59 | return connection.getPeerAddress(type); 60 | } 61 | 62 | public SocketAddress getLocalAddress() { 63 | return connection.getLocalAddress(); 64 | } 65 | 66 | public A getLocalAddress(final Class type) { 67 | return connection.getLocalAddress(type); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /api/src/main/java/org/xnio/channels/AssembledSslChannel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * 4 | * Copyright 2012 Red Hat, Inc. and/or its affiliates, and individual 5 | * contributors as indicated by the @author tags. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | 20 | package org.xnio.channels; 21 | 22 | import static org.xnio._private.Messages.msg; 23 | 24 | import java.io.IOException; 25 | import org.xnio.ChannelListener; 26 | import org.xnio.ChannelListeners; 27 | 28 | import javax.net.ssl.SSLSession; 29 | 30 | /** 31 | * An assembled SSL channel. 32 | * 33 | * @author David M. Lloyd 34 | */ 35 | public class AssembledSslChannel extends AssembledConnectedChannel implements SslChannel { 36 | 37 | private final SslChannel sslChannel; 38 | 39 | private final ChannelListener.Setter handshakeSetter; 40 | 41 | /** 42 | * Construct a new instance. At least one side must be an SSL channel. 43 | * 44 | * @param readChannel the read channel 45 | * @param writeChannel the write channel 46 | */ 47 | public AssembledSslChannel(final SuspendableReadChannel readChannel, final SuspendableWriteChannel writeChannel) { 48 | super(readChannel, writeChannel); 49 | if (readChannel instanceof SslChannel) { 50 | sslChannel = (SslChannel) readChannel; 51 | } else if (writeChannel instanceof SslChannel) { 52 | sslChannel = (SslChannel) writeChannel; 53 | } else { 54 | throw msg.oneChannelMustBeSSL(); 55 | } 56 | handshakeSetter = ChannelListeners.getDelegatingSetter(sslChannel.getHandshakeSetter(), this); 57 | } 58 | 59 | public void startHandshake() throws IOException { 60 | sslChannel.startHandshake(); 61 | } 62 | 63 | public SSLSession getSslSession() { 64 | return sslChannel.getSslSession(); 65 | } 66 | 67 | public ChannelListener.Setter getHandshakeSetter() { 68 | return handshakeSetter; 69 | } 70 | 71 | @SuppressWarnings("unchecked") 72 | public ChannelListener.Setter getCloseSetter() { 73 | return (ChannelListener.Setter) super.getCloseSetter(); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /api/src/main/java/org/xnio/channels/BoundChannel.java: -------------------------------------------------------------------------------- 1 | 2 | package org.xnio.channels; 3 | 4 | import java.net.SocketAddress; 5 | import org.xnio.ChannelListener; 6 | 7 | /** 8 | * A channel that is bound to a local address. 9 | */ 10 | public interface BoundChannel extends CloseableChannel { 11 | /** 12 | * Get the local address that this channel is bound to. 13 | * 14 | * @return the local address 15 | */ 16 | SocketAddress getLocalAddress(); 17 | 18 | /** 19 | * Get the local address of a given type, or {@code null} if the address is not of that 20 | * type. 21 | * 22 | * @param type the address type class 23 | * @param the address type 24 | * @return the local address, or {@code null} if unknown 25 | */ 26 | A getLocalAddress(Class type); 27 | 28 | /** {@inheritDoc} */ 29 | ChannelListener.Setter getCloseSetter(); 30 | } 31 | -------------------------------------------------------------------------------- /api/src/main/java/org/xnio/channels/BoundMultipointMessageChannel.java: -------------------------------------------------------------------------------- 1 | 2 | package org.xnio.channels; 3 | 4 | import org.xnio.ChannelListener; 5 | 6 | /** 7 | * A multipoint datagram channel. A multipoint datagram channel is a bound multipoint message channel. 8 | */ 9 | public interface BoundMultipointMessageChannel extends MultipointMessageChannel, BoundChannel { 10 | 11 | /** {@inheritDoc} */ 12 | ChannelListener.Setter getReadSetter(); 13 | 14 | /** {@inheritDoc} */ 15 | ChannelListener.Setter getCloseSetter(); 16 | 17 | /** {@inheritDoc} */ 18 | ChannelListener.Setter getWriteSetter(); 19 | } 20 | -------------------------------------------------------------------------------- /api/src/main/java/org/xnio/channels/ByteChannel.java: -------------------------------------------------------------------------------- 1 | 2 | package org.xnio.channels; 3 | 4 | import java.nio.channels.GatheringByteChannel; 5 | import java.nio.channels.ScatteringByteChannel; 6 | 7 | /** 8 | * An extension of a simple NIO {@link java.nio.channels.ByteChannel} which includes scatter/gather operations. 9 | * 10 | * @author David M. Lloyd 11 | */ 12 | public interface ByteChannel extends java.nio.channels.ByteChannel, GatheringByteChannel, ScatteringByteChannel { 13 | } 14 | -------------------------------------------------------------------------------- /api/src/main/java/org/xnio/channels/ChannelFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * 4 | * Copyright 2012 Red Hat, Inc. and/or its affiliates. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.xnio.channels; 20 | 21 | import java.nio.channels.Channel; 22 | 23 | /** 24 | * A generalized channel factory type. 25 | * 26 | * @author David M. Lloyd 27 | */ 28 | public interface ChannelFactory { 29 | 30 | /** 31 | * Create the channel instance. 32 | * 33 | * @return the channel instance 34 | */ 35 | C create(); 36 | } 37 | -------------------------------------------------------------------------------- /api/src/main/java/org/xnio/channels/CloseListenerSettable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * 4 | * Copyright 2013 Red Hat, Inc. and/or its affiliates. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.xnio.channels; 20 | 21 | import java.nio.channels.Channel; 22 | import org.xnio.ChannelListener; 23 | 24 | /** 25 | * An object which supports directly setting the close listener may implement this interface. 26 | * 27 | * @author David M. Lloyd 28 | */ 29 | public interface CloseListenerSettable { 30 | /** 31 | * Set the close listener. 32 | * 33 | * @param listener the close listener 34 | */ 35 | void setCloseListener(ChannelListener listener); 36 | 37 | /** 38 | * Get the close listener. 39 | * 40 | * @return the close listener 41 | */ 42 | ChannelListener getCloseListener(); 43 | 44 | /** 45 | * A channel listener setter implementation which delegates to the appropriate setter method. 46 | * 47 | * @param the channel type 48 | */ 49 | class Setter implements ChannelListener.Setter { 50 | private final CloseListenerSettable settable; 51 | 52 | /** 53 | * Construct a new instance. 54 | * 55 | * @param settable the settable to delegate to 56 | */ 57 | public Setter(final CloseListenerSettable settable) { 58 | this.settable = settable; 59 | } 60 | 61 | public void set(final ChannelListener listener) { 62 | settable.setCloseListener(listener); 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /api/src/main/java/org/xnio/channels/CloseableChannel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * 4 | * Copyright 2009 Red Hat, Inc. and/or its affiliates. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.xnio.channels; 20 | 21 | import java.io.IOException; 22 | import java.nio.channels.InterruptibleChannel; 23 | import org.xnio.ChannelListener; 24 | import org.xnio.XnioIoThread; 25 | import org.xnio.XnioWorker; 26 | 27 | /** 28 | * A channel which is closeable. A listener may be registered which is triggered (only once) on channel close. 29 | * 30 | * @since 2.0 31 | */ 32 | public interface CloseableChannel extends InterruptibleChannel, Configurable { 33 | /** 34 | * Get the setter which can be used to change the close listener for this channel. If the channel is already 35 | * closed, then the listener will not be called. 36 | * 37 | * @return the setter 38 | */ 39 | ChannelListener.Setter getCloseSetter(); 40 | 41 | /** 42 | * Get the worker for this channel. 43 | * 44 | * @return the worker 45 | */ 46 | XnioWorker getWorker(); 47 | 48 | /** 49 | * Get the I/O thread associated with this channel. 50 | * 51 | * @return the I/O thread associated with this channel 52 | */ 53 | XnioIoThread getIoThread(); 54 | 55 | /** 56 | * Close this channel. When a channel is closed, its close listener is invoked. Invoking this method 57 | * more than once has no additional effect. 58 | * 59 | * @throws IOException if the close failed 60 | */ 61 | void close() throws IOException; 62 | } 63 | -------------------------------------------------------------------------------- /api/src/main/java/org/xnio/channels/Configurable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * 4 | * Copyright 2008 Red Hat, Inc. and/or its affiliates. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.xnio.channels; 20 | 21 | import java.io.IOException; 22 | import org.xnio.Option; 23 | 24 | /** 25 | * A channel that has parameters that may be configured while the channel is open. 26 | * 27 | * @apiviz.exclude 28 | */ 29 | public interface Configurable { 30 | 31 | /** 32 | * Determine whether an option is supported on this channel. 33 | * 34 | * @param option the option 35 | * @return {@code true} if it is supported 36 | */ 37 | boolean supportsOption(Option option); 38 | 39 | /** 40 | * Get the value of a channel option. 41 | * 42 | * @param the type of the option value 43 | * @param option the option to get 44 | * @return the value of the option, or {@code null} if it is not set 45 | * @throws IOException if an I/O error occurred when reading the option 46 | */ 47 | T getOption(Option option) throws IOException; 48 | 49 | /** 50 | * Set an option for this channel. Unsupported options are ignored. 51 | * 52 | * @param the type of the option value 53 | * @param option the option to set 54 | * @param value the value of the option to set 55 | * @return the previous option value, if any 56 | * @throws IllegalArgumentException if the value is not acceptable for this option 57 | * @throws IOException if an I/O error occurred when modifying the option 58 | */ 59 | T setOption(Option option, T value) throws IllegalArgumentException, IOException; 60 | 61 | /** 62 | * An empty configurable instance. 63 | */ 64 | Configurable EMPTY = new Configurable() { 65 | public boolean supportsOption(final Option option) { 66 | return false; 67 | } 68 | 69 | public T getOption(final Option option) throws IOException { 70 | return null; 71 | } 72 | 73 | public T setOption(final Option option, final T value) throws IllegalArgumentException, IOException { 74 | return null; 75 | } 76 | }; 77 | } 78 | -------------------------------------------------------------------------------- /api/src/main/java/org/xnio/channels/ConnectedChannel.java: -------------------------------------------------------------------------------- 1 | 2 | package org.xnio.channels; 3 | 4 | import java.net.SocketAddress; 5 | import org.xnio.ChannelListener; 6 | 7 | /** 8 | * A channel that has a local and peer endpoint address. 9 | */ 10 | public interface ConnectedChannel extends BoundChannel { 11 | /** 12 | * Get the peer address of this channel. 13 | * 14 | * @return the peer address 15 | */ 16 | SocketAddress getPeerAddress(); 17 | 18 | /** 19 | * Get the peer address of a given type, or {@code null} if the address is not of that 20 | * type. 21 | * 22 | * @param type the address type class 23 | * @return the peer address, or {@code null} if unknown 24 | */ 25 | A getPeerAddress(Class type); 26 | 27 | /** {@inheritDoc} */ 28 | ChannelListener.Setter getCloseSetter(); 29 | } 30 | -------------------------------------------------------------------------------- /api/src/main/java/org/xnio/channels/ConnectedMessageChannel.java: -------------------------------------------------------------------------------- 1 | 2 | package org.xnio.channels; 3 | 4 | import org.xnio.ChannelListener; 5 | 6 | /** 7 | * A channel that sends and receives messages to a connected peer. 8 | */ 9 | public interface ConnectedMessageChannel extends MessageChannel, ConnectedChannel { 10 | 11 | /** {@inheritDoc} */ 12 | ChannelListener.Setter getReadSetter(); 13 | 14 | /** {@inheritDoc} */ 15 | ChannelListener.Setter getCloseSetter(); 16 | 17 | /** {@inheritDoc} */ 18 | ChannelListener.Setter getWriteSetter(); 19 | } 20 | -------------------------------------------------------------------------------- /api/src/main/java/org/xnio/channels/ConnectedSslStreamChannel.java: -------------------------------------------------------------------------------- 1 | 2 | package org.xnio.channels; 3 | 4 | import org.xnio.ChannelListener; 5 | 6 | /** 7 | * A TLS-encapsulated connected stream channel. 8 | */ 9 | public interface ConnectedSslStreamChannel extends ConnectedStreamChannel, SslChannel { 10 | 11 | /** {@inheritDoc} */ 12 | ChannelListener.Setter getReadSetter(); 13 | 14 | /** {@inheritDoc} */ 15 | ChannelListener.Setter getWriteSetter(); 16 | 17 | /** {@inheritDoc} */ 18 | ChannelListener.Setter getCloseSetter(); 19 | } 20 | -------------------------------------------------------------------------------- /api/src/main/java/org/xnio/channels/ConnectedStreamChannel.java: -------------------------------------------------------------------------------- 1 | 2 | package org.xnio.channels; 3 | 4 | import org.xnio.ChannelListener; 5 | 6 | /** 7 | * A stream channel that is a connection between a local and remote endpoint. 8 | */ 9 | public interface ConnectedStreamChannel extends StreamChannel, ConnectedChannel { 10 | 11 | /** {@inheritDoc} */ 12 | ChannelListener.Setter getReadSetter(); 13 | 14 | /** {@inheritDoc} */ 15 | ChannelListener.Setter getWriteSetter(); 16 | 17 | /** {@inheritDoc} */ 18 | ChannelListener.Setter getCloseSetter(); 19 | } 20 | -------------------------------------------------------------------------------- /api/src/main/java/org/xnio/channels/FixedLengthOverflowException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2012 Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.xnio.channels; 20 | 21 | import java.io.IOException; 22 | 23 | /** 24 | * Exception thrown when a fixed-length write channel is written beyond its full length. 25 | * 26 | * @author David M. Lloyd 27 | */ 28 | public class FixedLengthOverflowException extends IOException { 29 | 30 | private static final long serialVersionUID = 475540863890698430L; 31 | 32 | /** 33 | * Constructs a {@code FixedLengthOverflowException} with no detail message. The cause is not initialized, and may 34 | * subsequently be initialized by a call to {@link #initCause(Throwable) initCause}. 35 | */ 36 | public FixedLengthOverflowException() { 37 | } 38 | 39 | /** 40 | * Constructs a {@code FixedLengthOverflowException} with the specified detail message. The cause is not 41 | * initialized, and may subsequently be initialized by a call to {@link #initCause(Throwable) initCause}. 42 | * 43 | * @param msg the detail message 44 | */ 45 | public FixedLengthOverflowException(final String msg) { 46 | super(msg); 47 | } 48 | 49 | /** 50 | * Constructs a {@code FixedLengthOverflowException} with the specified cause. The detail message is set to: 51 | *
(cause == null ? null : cause.toString())
52 | * (which typically contains the class and detail message of {@code cause}). 53 | * 54 | * @param cause the cause (which is saved for later retrieval by the {@link #getCause()} method) 55 | */ 56 | public FixedLengthOverflowException(final Throwable cause) { 57 | super(cause); 58 | } 59 | 60 | /** 61 | * Constructs a {@code FixedLengthOverflowException} with the specified detail message and cause. 62 | * 63 | * @param msg the detail message 64 | * @param cause the cause (which is saved for later retrieval by the {@link #getCause()} method) 65 | */ 66 | public FixedLengthOverflowException(final String msg, final Throwable cause) { 67 | super(msg, cause); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /api/src/main/java/org/xnio/channels/FixedLengthUnderflowException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2012 Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.xnio.channels; 20 | 21 | import java.io.IOException; 22 | 23 | /** 24 | * Exception thrown when a fixed-length write channel is not written to its full length. 25 | * 26 | * @author David M. Lloyd 27 | */ 28 | public class FixedLengthUnderflowException extends IOException { 29 | 30 | private static final long serialVersionUID = 7294784996964683484L; 31 | 32 | /** 33 | * Constructs a {@code UnfinishedWriteException} with no detail message. The cause is not initialized, and may 34 | * subsequently be initialized by a call to {@link #initCause(Throwable) initCause}. 35 | */ 36 | public FixedLengthUnderflowException() { 37 | } 38 | 39 | /** 40 | * Constructs a {@code UnfinishedWriteException} with the specified detail message. The cause is not initialized, 41 | * and may subsequently be initialized by a call to {@link #initCause(Throwable) initCause}. 42 | * 43 | * @param msg the detail message 44 | */ 45 | public FixedLengthUnderflowException(final String msg) { 46 | super(msg); 47 | } 48 | 49 | /** 50 | * Constructs a {@code UnfinishedWriteException} with the specified cause. The detail message is set to: 51 | *
(cause == null ? null : cause.toString())
52 | * (which typically contains the class and detail message of {@code cause}). 53 | * 54 | * @param cause the cause (which is saved for later retrieval by the {@link #getCause()} method) 55 | */ 56 | public FixedLengthUnderflowException(final Throwable cause) { 57 | super(cause); 58 | } 59 | 60 | /** 61 | * Constructs a {@code UnfinishedWriteException} with the specified detail message and cause. 62 | * 63 | * @param msg the detail message 64 | * @param cause the cause (which is saved for later retrieval by the {@link #getCause()} method) 65 | */ 66 | public FixedLengthUnderflowException(final String msg, final Throwable cause) { 67 | super(msg, cause); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /api/src/main/java/org/xnio/channels/MessageChannel.java: -------------------------------------------------------------------------------- 1 | 2 | package org.xnio.channels; 3 | 4 | import org.xnio.ChannelListener; 5 | 6 | /** 7 | * A channel that sends and receives whole messages. 8 | */ 9 | public interface MessageChannel extends ReadableMessageChannel, WritableMessageChannel, SuspendableChannel { 10 | 11 | /** {@inheritDoc} */ 12 | ChannelListener.Setter getReadSetter(); 13 | 14 | /** {@inheritDoc} */ 15 | ChannelListener.Setter getCloseSetter(); 16 | 17 | /** {@inheritDoc} */ 18 | ChannelListener.Setter getWriteSetter(); 19 | } 20 | -------------------------------------------------------------------------------- /api/src/main/java/org/xnio/channels/MultipointMessageChannel.java: -------------------------------------------------------------------------------- 1 | 2 | package org.xnio.channels; 3 | 4 | import org.xnio.ChannelListener; 5 | 6 | /** 7 | * A point-to-multipoint message channel. This type of channel is capable of sending to and receiving from multiple 8 | * peer endpoints; as such, the incoming and outgoing messages are each associated with a peer address. 9 | */ 10 | public interface MultipointMessageChannel extends ReadableMultipointMessageChannel, WritableMultipointMessageChannel, SuspendableChannel { 11 | 12 | /** {@inheritDoc} */ 13 | ChannelListener.Setter getReadSetter(); 14 | 15 | /** {@inheritDoc} */ 16 | ChannelListener.Setter getCloseSetter(); 17 | 18 | /** {@inheritDoc} */ 19 | ChannelListener.Setter getWriteSetter(); 20 | } 21 | -------------------------------------------------------------------------------- /api/src/main/java/org/xnio/channels/ProtectedWrappedChannel.java: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * JBoss, Home of Professional Open Source 4 | * 5 | * Copyright 2012 Red Hat, Inc. and/or its affiliates. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | 20 | package org.xnio.channels; 21 | 22 | import java.nio.channels.Channel; 23 | 24 | /** 25 | * A protected, wrapped channel. A guard object is required to gain access to the underlying channel. 26 | * 27 | * @param the wrapped channel type 28 | * @author David M. Lloyd 29 | */ 30 | public interface ProtectedWrappedChannel { 31 | 32 | /** 33 | * Get the channel which is wrapped by this object, or {@code null} if the guard is invalid. 34 | * 35 | * @param guard the guard object 36 | * @return the wrapped channel 37 | */ 38 | C getChannel(Object guard); 39 | } 40 | -------------------------------------------------------------------------------- /api/src/main/java/org/xnio/channels/ReadListenerSettable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * 4 | * Copyright 2013 Red Hat, Inc. and/or its affiliates. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.xnio.channels; 20 | 21 | import java.nio.channels.Channel; 22 | import org.xnio.ChannelListener; 23 | 24 | /** 25 | * An object which supports directly setting the read listener may implement this interface. 26 | * 27 | * @author David M. Lloyd 28 | */ 29 | public interface ReadListenerSettable { 30 | /** 31 | * Set the read listener. 32 | * 33 | * @param listener the read listener 34 | */ 35 | void setReadListener(ChannelListener listener); 36 | 37 | /** 38 | * Get the read listener. 39 | * 40 | * @return the read listener 41 | */ 42 | ChannelListener getReadListener(); 43 | 44 | /** 45 | * A channel listener setter implementation which delegates to the appropriate setter method. 46 | * 47 | * @param the channel type 48 | */ 49 | class Setter implements ChannelListener.Setter { 50 | private final ReadListenerSettable settable; 51 | 52 | /** 53 | * Construct a new instance. 54 | * 55 | * @param settable the settable to delegate to 56 | */ 57 | public Setter(final ReadListenerSettable settable) { 58 | this.settable = settable; 59 | } 60 | 61 | public void set(final ChannelListener listener) { 62 | settable.setReadListener(listener); 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /api/src/main/java/org/xnio/channels/ReadTimeoutException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * 4 | * Copyright 2010 Red Hat, Inc. and/or its affiliates. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.xnio.channels; 20 | 21 | import java.io.InterruptedIOException; 22 | 23 | /** 24 | * Thrown when a blocking read operation times out. 25 | */ 26 | public class ReadTimeoutException extends InterruptedIOException { 27 | 28 | private static final long serialVersionUID = 2058056832934733469L; 29 | 30 | /** 31 | * Constructs a {@code ReadTimeoutException} with no detail message. The cause is not initialized, and may subsequently 32 | * be initialized by a call to {@link #initCause(Throwable) initCause}. 33 | */ 34 | public ReadTimeoutException() { 35 | } 36 | 37 | /** 38 | * Constructs a {@code ReadTimeoutException} with the specified detail message. The cause is not initialized, and may 39 | * subsequently be initialized by a call to {@link #initCause(Throwable) initCause}. 40 | * 41 | * @param msg the detail message 42 | */ 43 | public ReadTimeoutException(final String msg) { 44 | super(msg); 45 | } 46 | 47 | /** 48 | * Constructs a {@code ReadTimeoutException} with the specified cause. The detail message is set to: 49 | *
(cause == null ? null : cause.toString())
50 | * (which typically contains the class and detail message of {@code cause}). 51 | * 52 | * @param cause the cause (which is saved for later retrieval by the {@link #getCause()} method) 53 | */ 54 | public ReadTimeoutException(final Throwable cause) { 55 | initCause(cause); 56 | } 57 | 58 | /** 59 | * Constructs a {@code ReadTimeoutException} with the specified detail message and cause. 60 | * 61 | * @param msg the detail message 62 | * @param cause the cause (which is saved for later retrieval by the {@link #getCause()} method) 63 | */ 64 | public ReadTimeoutException(final String msg, final Throwable cause) { 65 | super(msg); 66 | initCause(cause); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /api/src/main/java/org/xnio/channels/ReadableMessageChannel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * 4 | * Copyright 2008 Red Hat, Inc. and/or its affiliates. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.xnio.channels; 20 | 21 | import java.io.IOException; 22 | import java.nio.ByteBuffer; 23 | import org.xnio.ChannelListener; 24 | 25 | /** 26 | * A channel that can receive messages. Such a channel receives whole messages only. 27 | */ 28 | public interface ReadableMessageChannel extends SuspendableReadChannel, Configurable { 29 | /** 30 | * Receive a message. 31 | * 32 | * @param buffer the buffer that will hold the message 33 | * @return the size of the received message, 0 if no message is available, and -1 if the message channel has reached an end-of-file condition 34 | * @throws IOException if an I/O error occurs 35 | */ 36 | int receive(ByteBuffer buffer) throws IOException; 37 | 38 | /** 39 | * Receive a message. 40 | * 41 | * @param buffers the buffers that will hold the message 42 | * @return the size of the received message, 0 if no message is available, and -1 if the message channel has reached an end-of-file condition 43 | * @throws IOException if an I/O error occurs 44 | */ 45 | long receive(ByteBuffer[] buffers) throws IOException; 46 | 47 | /** 48 | * Receive a message. 49 | * 50 | * @param buffers the buffers that will hold the message 51 | * @param offs the offset into the array of buffers of the first buffer to read into 52 | * @param len the number of buffers to fill 53 | * @return the size of the received message, 0 if no message is available, and -1 if the message channel has reached an end-of-file condition 54 | * @throws IOException if an I/O error occurs 55 | */ 56 | long receive(ByteBuffer[] buffers, int offs, int len) throws IOException; 57 | 58 | /** {@inheritDoc} */ 59 | ChannelListener.Setter getReadSetter(); 60 | 61 | /** {@inheritDoc} */ 62 | ChannelListener.Setter getCloseSetter(); 63 | } 64 | -------------------------------------------------------------------------------- /api/src/main/java/org/xnio/channels/SimpleAcceptingChannel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * 4 | * Copyright 2011 Red Hat, Inc. and/or its affiliates, and individual 5 | * contributors as indicated by the @author tags. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | 20 | package org.xnio.channels; 21 | 22 | import java.io.IOException; 23 | import org.xnio.ChannelListener; 24 | 25 | /** 26 | * A channel which can accept connections. 27 | * 28 | * @param the channel type 29 | * 30 | * @author David M. Lloyd 31 | */ 32 | public interface SimpleAcceptingChannel extends SuspendableAcceptChannel { 33 | 34 | /** 35 | * Attempt to accept a connection. 36 | * 37 | * @return the new connection, or {@code null} if none is available 38 | * @throws IOException if an I/O error occurs 39 | */ 40 | C accept() throws IOException; 41 | 42 | /** {@inheritDoc} */ 43 | ChannelListener.Setter> getAcceptSetter(); 44 | 45 | /** {@inheritDoc} */ 46 | ChannelListener.Setter> getCloseSetter(); 47 | } 48 | -------------------------------------------------------------------------------- /api/src/main/java/org/xnio/channels/SslChannel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * 4 | * Copyright 2009 Red Hat, Inc. and/or its affiliates. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.xnio.channels; 20 | 21 | import java.io.IOException; 22 | 23 | import javax.net.ssl.SSLSession; 24 | 25 | import org.xnio.ChannelListener; 26 | 27 | /** 28 | * A channel which can use SSL/TLS to negotiate a security layer. 29 | */ 30 | public interface SslChannel extends ConnectedChannel { 31 | 32 | /** 33 | * Start or restart the SSL/TLS handshake. To force a complete SSL/TLS session renegotiation, the current 34 | * session should be invalidated prior to calling this method. This method is not needed for the initial handshake 35 | * as sending or receiving over the channel will automatically initiate it. 36 | * 37 | * @throws IOException if an I/O error occurs 38 | */ 39 | void startHandshake() throws IOException; 40 | 41 | /** 42 | * Get the current {@code SSLSession} for this channel. 43 | * 44 | * @return the current {@code SSLSession} 45 | */ 46 | SSLSession getSslSession(); 47 | 48 | /** {@inheritDoc} */ 49 | ChannelListener.Setter getCloseSetter(); 50 | 51 | /** 52 | * Get the setter which can be used to change the handshake listener for this channel. 53 | * 54 | * @return the setter 55 | */ 56 | ChannelListener.Setter getHandshakeSetter(); 57 | } 58 | -------------------------------------------------------------------------------- /api/src/main/java/org/xnio/channels/StreamChannel.java: -------------------------------------------------------------------------------- 1 | 2 | package org.xnio.channels; 3 | 4 | import org.xnio.ChannelListener; 5 | 6 | /** 7 | * A stream channel. This type of channel represents a stream of bytes flowing in two directions. 8 | * 9 | * @apiviz.landmark 10 | */ 11 | public interface StreamChannel extends SuspendableChannel, StreamSinkChannel, StreamSourceChannel, ByteChannel { 12 | 13 | /** {@inheritDoc} */ 14 | ChannelListener.Setter getReadSetter(); 15 | 16 | /** {@inheritDoc} */ 17 | ChannelListener.Setter getWriteSetter(); 18 | 19 | /** {@inheritDoc} */ 20 | ChannelListener.Setter getCloseSetter(); 21 | } 22 | -------------------------------------------------------------------------------- /api/src/main/java/org/xnio/channels/SuspendableChannel.java: -------------------------------------------------------------------------------- 1 | 2 | package org.xnio.channels; 3 | 4 | import org.xnio.ChannelListener; 5 | 6 | /** 7 | * A suspendable bidirectional channel. 8 | */ 9 | public interface SuspendableChannel extends CloseableChannel, SuspendableReadChannel, SuspendableWriteChannel { 10 | 11 | /** {@inheritDoc} */ 12 | ChannelListener.Setter getCloseSetter(); 13 | 14 | /** {@inheritDoc} */ 15 | ChannelListener.Setter getReadSetter(); 16 | 17 | /** {@inheritDoc} */ 18 | ChannelListener.Setter getWriteSetter(); 19 | } 20 | -------------------------------------------------------------------------------- /api/src/main/java/org/xnio/channels/UnsupportedOptionException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * 4 | * Copyright 2008 Red Hat, Inc. and/or its affiliates. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.xnio.channels; 20 | 21 | /** 22 | * An exception that is thrown when an invalid option is specified for a {@link Configurable}. 23 | * 24 | * @apiviz.exclude 25 | */ 26 | public class UnsupportedOptionException extends IllegalArgumentException { 27 | private static final long serialVersionUID = 250195510855241708L; 28 | 29 | /** 30 | * Construct a {@code UnsupportedOptionException} instance. 31 | */ 32 | public UnsupportedOptionException() { 33 | } 34 | 35 | /** 36 | * Construct a {@code UnsupportedOptionException} instance with the given message. 37 | * 38 | * @param message the message 39 | */ 40 | public UnsupportedOptionException(final String message) { 41 | super(message); 42 | } 43 | 44 | /** 45 | * Construct a {@code UnsupportedOptionException} instance with the given message and cause. 46 | * 47 | * @param message the message 48 | * @param cause the cause 49 | */ 50 | public UnsupportedOptionException(final String message, final Throwable cause) { 51 | super(message, cause); 52 | } 53 | 54 | /** 55 | * Construct a {@code UnsupportedOptionException} instance with the given cause. 56 | * 57 | * @param cause the cause 58 | */ 59 | public UnsupportedOptionException(final Throwable cause) { 60 | super(cause); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /api/src/main/java/org/xnio/channels/WrappedChannel.java: -------------------------------------------------------------------------------- 1 | 2 | package org.xnio.channels; 3 | 4 | import java.nio.channels.Channel; 5 | 6 | /** 7 | * A wrapped channel. 8 | * 9 | * @param the wrapped channel type 10 | * @author David M. Lloyd 11 | */ 12 | public interface WrappedChannel { 13 | 14 | /** 15 | * Get the channel which is wrapped by this object. 16 | * 17 | * @return the wrapped channel 18 | */ 19 | C getChannel(); 20 | } 21 | -------------------------------------------------------------------------------- /api/src/main/java/org/xnio/channels/WritableMultipointMessageChannel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * 4 | * Copyright 2008 Red Hat, Inc. and/or its affiliates. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.xnio.channels; 20 | 21 | import java.net.SocketAddress; 22 | import java.nio.ByteBuffer; 23 | import java.io.IOException; 24 | import org.xnio.ChannelListener; 25 | 26 | /** 27 | * The writable side of a multipoint message channel. 28 | * 29 | * @see MultipointMessageChannel 30 | */ 31 | public interface WritableMultipointMessageChannel extends SuspendableWriteChannel { 32 | 33 | /** 34 | * Send a buffer to a destination. 35 | * 36 | * @param target the destination 37 | * @param buffer the data to send 38 | * @return {@code true} if the message was sent, or {@code false} if the channel is not currently writable 39 | * @throws IOException if an I/O error occurs 40 | */ 41 | boolean sendTo(SocketAddress target, ByteBuffer buffer) throws IOException; 42 | 43 | /** 44 | * Send a message with data from multiple buffers to a destination. 45 | * 46 | * @param target the destination 47 | * @param buffers the data to send 48 | * @return {@code true} if the message was sent, or {@code false} if the channel is not currently writable 49 | * @throws IOException if an I/O error occurs 50 | */ 51 | boolean sendTo(SocketAddress target, ByteBuffer[] buffers) throws IOException; 52 | 53 | /** 54 | * Send a message with data from multiple buffers to a destination. 55 | * 56 | * @param target the destination 57 | * @param buffers the data to send 58 | * @param offset the offset into the {@code buffers} array 59 | * @param length the number of buffers to read from 60 | * @return {@code true} if the message was sent, or {@code false} if the channel is not currently writable 61 | * @throws IOException if an I/O error occurs 62 | */ 63 | boolean sendTo(SocketAddress target, ByteBuffer[] buffers, int offset, int length) throws IOException; 64 | 65 | /** {@inheritDoc} */ 66 | ChannelListener.Setter getWriteSetter(); 67 | 68 | /** {@inheritDoc} */ 69 | ChannelListener.Setter getCloseSetter(); 70 | } 71 | -------------------------------------------------------------------------------- /api/src/main/java/org/xnio/channels/WriteListenerSettable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * 4 | * Copyright 2013 Red Hat, Inc. and/or its affiliates. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.xnio.channels; 20 | 21 | import java.nio.channels.Channel; 22 | import org.xnio.ChannelListener; 23 | 24 | /** 25 | * An object which supports directly setting the write listener may implement this interface. 26 | * 27 | * @author David M. Lloyd 28 | */ 29 | public interface WriteListenerSettable { 30 | /** 31 | * Set the write listener. 32 | * 33 | * @param listener the write listener 34 | */ 35 | void setWriteListener(ChannelListener listener); 36 | 37 | /** 38 | * Get the write listener. 39 | * 40 | * @return the write listener 41 | */ 42 | ChannelListener getWriteListener(); 43 | 44 | /** 45 | * A channel listener setter implementation which delegates to the appropriate setter method. 46 | * 47 | * @param the channel type 48 | */ 49 | class Setter implements ChannelListener.Setter { 50 | private final WriteListenerSettable settable; 51 | 52 | /** 53 | * Construct a new instance. 54 | * 55 | * @param settable the settable to delegate to 56 | */ 57 | public Setter(final WriteListenerSettable settable) { 58 | this.settable = settable; 59 | } 60 | 61 | public void set(final ChannelListener listener) { 62 | settable.setWriteListener(listener); 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /api/src/main/java/org/xnio/channels/WriteTimeoutException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * 4 | * Copyright 2010 Red Hat, Inc. and/or its affiliates. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.xnio.channels; 20 | 21 | import java.io.InterruptedIOException; 22 | 23 | /** 24 | * Thrown when a blocking write operation times out. 25 | */ 26 | public class WriteTimeoutException extends InterruptedIOException { 27 | 28 | private static final long serialVersionUID = 2058056832934733469L; 29 | 30 | /** 31 | * Constructs a {@code WriteTimeoutException} with no detail message. The cause is not initialized, and may subsequently 32 | * be initialized by a call to {@link #initCause(Throwable) initCause}. 33 | */ 34 | public WriteTimeoutException() { 35 | } 36 | 37 | /** 38 | * Constructs a {@code WriteTimeoutException} with the specified detail message. The cause is not initialized, and may 39 | * subsequently be initialized by a call to {@link #initCause(Throwable) initCause}. 40 | * 41 | * @param msg the detail message 42 | */ 43 | public WriteTimeoutException(final String msg) { 44 | super(msg); 45 | } 46 | 47 | /** 48 | * Constructs a {@code WriteTimeoutException} with the specified cause. The detail message is set to: 49 | *
(cause == null ? null : cause.toString())
50 | * (which typically contains the class and detail message of {@code cause}). 51 | * 52 | * @param cause the cause (which is saved for later retrieval by the {@link #getCause()} method) 53 | */ 54 | public WriteTimeoutException(final Throwable cause) { 55 | initCause(cause); 56 | } 57 | 58 | /** 59 | * Constructs a {@code WriteTimeoutException} with the specified detail message and cause. 60 | * 61 | * @param msg the detail message 62 | * @param cause the cause (which is saved for later retrieval by the {@link #getCause()} method) 63 | */ 64 | public WriteTimeoutException(final String msg, final Throwable cause) { 65 | super(msg); 66 | initCause(cause); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /api/src/main/java/org/xnio/channels/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * The core XNIO channel API. 3 | */ 4 | package org.xnio.channels; 5 | -------------------------------------------------------------------------------- /api/src/main/java/org/xnio/conduits/AbstractConduit.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * 4 | * Copyright 2013 Red Hat, Inc. and/or its affiliates. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.xnio.conduits; 20 | 21 | import static org.xnio._private.Messages.msg; 22 | 23 | import org.xnio.XnioWorker; 24 | 25 | /** 26 | * An abstract base class for filtering conduits. 27 | * 28 | * @author David M. Lloyd 29 | */ 30 | public abstract class AbstractConduit implements Conduit { 31 | 32 | /** 33 | * The delegate conduit. 34 | */ 35 | protected final D next; 36 | 37 | /** 38 | * Construct a new instance. 39 | * 40 | * @param next the delegate conduit to set 41 | */ 42 | protected AbstractConduit(final D next) { 43 | if (next == null) { 44 | throw msg.nullParameter("next"); 45 | } 46 | this.next = next; 47 | } 48 | 49 | public XnioWorker getWorker() { 50 | return next.getWorker(); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /api/src/main/java/org/xnio/conduits/AbstractMessageSinkConduit.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * 4 | * Copyright 2013 Red Hat, Inc. and/or its affiliates. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.xnio.conduits; 20 | 21 | import java.io.IOException; 22 | import java.nio.ByteBuffer; 23 | 24 | /** 25 | * An abstract base class for filtering message sink conduits. 26 | * 27 | * @author David M. Lloyd 28 | */ 29 | public abstract class AbstractMessageSinkConduit extends AbstractSinkConduit implements MessageSinkConduit { 30 | 31 | /** 32 | * Construct a new instance. 33 | * 34 | * @param next the delegate conduit to set 35 | */ 36 | protected AbstractMessageSinkConduit(final D next) { 37 | super(next); 38 | } 39 | 40 | public boolean send(final ByteBuffer src) throws IOException { 41 | return next.send(src); 42 | } 43 | 44 | public boolean send(final ByteBuffer[] srcs, final int offs, final int len) throws IOException { 45 | return next.send(srcs, offs, len); 46 | } 47 | 48 | @Override 49 | public boolean sendFinal(ByteBuffer[] srcs, int offs, int len) throws IOException { 50 | return next.sendFinal(srcs, offs, len); 51 | } 52 | 53 | @Override 54 | public boolean sendFinal(ByteBuffer src) throws IOException { 55 | return next.sendFinal(src); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /api/src/main/java/org/xnio/conduits/AbstractMessageSourceConduit.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * 4 | * Copyright 2013 Red Hat, Inc. and/or its affiliates. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.xnio.conduits; 20 | 21 | import java.io.IOException; 22 | import java.nio.ByteBuffer; 23 | 24 | /** 25 | * An abstract base class for filtering message source conduits. 26 | * 27 | * @author David M. Lloyd 28 | */ 29 | public abstract class AbstractMessageSourceConduit extends AbstractSourceConduit implements MessageSourceConduit { 30 | 31 | /** 32 | * Construct a new instance. 33 | * 34 | * @param next the delegate conduit to set 35 | */ 36 | protected AbstractMessageSourceConduit(final D next) { 37 | super(next); 38 | } 39 | 40 | public int receive(final ByteBuffer dst) throws IOException { 41 | return next.receive(dst); 42 | } 43 | 44 | public long receive(final ByteBuffer[] dsts, final int offs, final int len) throws IOException { 45 | return next.receive(dsts, offs, len); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /api/src/main/java/org/xnio/conduits/AbstractSinkConduit.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * 4 | * Copyright 2013 Red Hat, Inc. and/or its affiliates. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.xnio.conduits; 20 | 21 | import java.io.IOException; 22 | import java.util.concurrent.TimeUnit; 23 | import org.xnio.XnioIoThread; 24 | 25 | /** 26 | * An abstract base class for filtering output conduits. 27 | * 28 | * @author David M. Lloyd 29 | */ 30 | public abstract class AbstractSinkConduit extends AbstractConduit implements SinkConduit { 31 | 32 | /** 33 | * Construct a new instance. 34 | * 35 | * @param next the delegate conduit to set 36 | */ 37 | protected AbstractSinkConduit(final D next) { 38 | super(next); 39 | } 40 | 41 | public void terminateWrites() throws IOException { 42 | next.terminateWrites(); 43 | } 44 | 45 | public boolean isWriteShutdown() { 46 | return next.isWriteShutdown(); 47 | } 48 | 49 | public void resumeWrites() { 50 | next.resumeWrites(); 51 | } 52 | 53 | public void suspendWrites() { 54 | next.suspendWrites(); 55 | } 56 | 57 | public void wakeupWrites() { 58 | next.wakeupWrites(); 59 | } 60 | 61 | public boolean isWriteResumed() { 62 | return next.isWriteResumed(); 63 | } 64 | 65 | public void awaitWritable() throws IOException { 66 | next.awaitWritable(); 67 | } 68 | 69 | public void awaitWritable(final long time, final TimeUnit timeUnit) throws IOException { 70 | next.awaitWritable(time, timeUnit); 71 | } 72 | 73 | public XnioIoThread getWriteThread() { 74 | return next.getWriteThread(); 75 | } 76 | 77 | public void setWriteReadyHandler(final WriteReadyHandler handler) { 78 | next.setWriteReadyHandler(handler); 79 | } 80 | 81 | public void truncateWrites() throws IOException { 82 | next.truncateWrites(); 83 | } 84 | 85 | public boolean flush() throws IOException { 86 | return next.flush(); 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /api/src/main/java/org/xnio/conduits/AbstractSourceConduit.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * 4 | * Copyright 2013 Red Hat, Inc. and/or its affiliates. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.xnio.conduits; 20 | 21 | import java.io.IOException; 22 | import java.util.concurrent.TimeUnit; 23 | import org.xnio.XnioIoThread; 24 | 25 | /** 26 | * An abstract base class for filtering source conduits. 27 | * 28 | * @author David M. Lloyd 29 | */ 30 | public abstract class AbstractSourceConduit extends AbstractConduit implements SourceConduit { 31 | 32 | /** 33 | * Construct a new instance. 34 | * 35 | * @param next the delegate conduit to set 36 | */ 37 | protected AbstractSourceConduit(final D next) { 38 | super(next); 39 | } 40 | 41 | public void terminateReads() throws IOException { 42 | next.terminateReads(); 43 | } 44 | 45 | public boolean isReadShutdown() { 46 | return next.isReadShutdown(); 47 | } 48 | 49 | public void resumeReads() { 50 | next.resumeReads(); 51 | } 52 | 53 | public void suspendReads() { 54 | next.suspendReads(); 55 | } 56 | 57 | public void wakeupReads() { 58 | next.wakeupReads(); 59 | } 60 | 61 | public boolean isReadResumed() { 62 | return next.isReadResumed(); 63 | } 64 | 65 | public void awaitReadable() throws IOException { 66 | next.awaitReadable(); 67 | } 68 | 69 | public void awaitReadable(final long time, final TimeUnit timeUnit) throws IOException { 70 | next.awaitReadable(time, timeUnit); 71 | } 72 | 73 | public XnioIoThread getReadThread() { 74 | return next.getReadThread(); 75 | } 76 | 77 | public void setReadReadyHandler(final ReadReadyHandler handler) { 78 | next.setReadReadyHandler(handler); 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /api/src/main/java/org/xnio/conduits/AbstractStreamSinkConduit.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * 4 | * Copyright 2013 Red Hat, Inc. and/or its affiliates. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.xnio.conduits; 20 | 21 | import java.io.IOException; 22 | import java.nio.ByteBuffer; 23 | import java.nio.channels.FileChannel; 24 | import org.xnio.channels.StreamSourceChannel; 25 | 26 | /** 27 | * An abstract base class for filtering stream sink conduits. 28 | * 29 | * @author David M. Lloyd 30 | */ 31 | public abstract class AbstractStreamSinkConduit extends AbstractSinkConduit implements StreamSinkConduit { 32 | 33 | /** 34 | * Construct a new instance. 35 | * 36 | * @param next the delegate conduit to set 37 | */ 38 | protected AbstractStreamSinkConduit(final D next) { 39 | super(next); 40 | } 41 | 42 | public long transferFrom(final FileChannel src, final long position, final long count) throws IOException { 43 | return next.transferFrom(src, position, count); 44 | } 45 | 46 | public long transferFrom(final StreamSourceChannel source, final long count, final ByteBuffer throughBuffer) throws IOException { 47 | return next.transferFrom(source, count, throughBuffer); 48 | } 49 | 50 | public int write(final ByteBuffer src) throws IOException { 51 | return next.write(src); 52 | } 53 | 54 | public long write(final ByteBuffer[] srcs, final int offs, final int len) throws IOException { 55 | return next.write(srcs, offs, len); 56 | } 57 | 58 | @Override 59 | public int writeFinal(ByteBuffer src) throws IOException { 60 | return next.writeFinal(src); 61 | } 62 | 63 | @Override 64 | public long writeFinal(ByteBuffer[] srcs, int offset, int length) throws IOException { 65 | return next.writeFinal(srcs, offset, length); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /api/src/main/java/org/xnio/conduits/AbstractStreamSourceConduit.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * 4 | * Copyright 2013 Red Hat, Inc. and/or its affiliates. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.xnio.conduits; 20 | 21 | import java.io.IOException; 22 | import java.nio.ByteBuffer; 23 | import java.nio.channels.FileChannel; 24 | import org.xnio.channels.StreamSinkChannel; 25 | 26 | /** 27 | * An abstract base class for filtering stream source conduits. 28 | * 29 | * @author David M. Lloyd 30 | */ 31 | public abstract class AbstractStreamSourceConduit extends AbstractSourceConduit implements StreamSourceConduit { 32 | 33 | /** 34 | * Construct a new instance. 35 | * 36 | * @param next the delegate conduit to set 37 | */ 38 | protected AbstractStreamSourceConduit(final D next) { 39 | super(next); 40 | } 41 | 42 | public long transferTo(final long position, final long count, final FileChannel target) throws IOException { 43 | return next.transferTo(position, count, target); 44 | } 45 | 46 | public long transferTo(final long count, final ByteBuffer throughBuffer, final StreamSinkChannel target) throws IOException { 47 | return next.transferTo(count, throughBuffer, target); 48 | } 49 | 50 | public int read(final ByteBuffer dst) throws IOException { 51 | return next.read(dst); 52 | } 53 | 54 | public long read(final ByteBuffer[] dsts, final int offs, final int len) throws IOException { 55 | return next.read(dsts, offs, len); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /api/src/main/java/org/xnio/conduits/AbstractSynchronizedConduit.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * 4 | * Copyright 2013 Red Hat, Inc. and/or its affiliates. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.xnio.conduits; 20 | 21 | /** 22 | * An abstract synchronized conduit. All conduit operations are wrapped in synchronization blocks for simplified 23 | * thread safety. 24 | * 25 | * @author David M. Lloyd 26 | */ 27 | public abstract class AbstractSynchronizedConduit extends AbstractConduit { 28 | protected final Object lock; 29 | 30 | /** 31 | * Construct a new instance. A new lock object is created. 32 | * 33 | * @param next the next conduit in the chain 34 | */ 35 | protected AbstractSynchronizedConduit(final D next) { 36 | this(next, new Object()); 37 | } 38 | 39 | /** 40 | * Construct a new instance. 41 | * 42 | * @param next the next conduit in the chain 43 | * @param lock the lock object to use 44 | */ 45 | protected AbstractSynchronizedConduit(final D next, final Object lock) { 46 | super(next); 47 | this.lock = lock; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /api/src/main/java/org/xnio/conduits/Conduit.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * 4 | * Copyright 2013 Red Hat, Inc. and/or its affiliates. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.xnio.conduits; 20 | 21 | import org.xnio.XnioWorker; 22 | 23 | /** 24 | * A conduit, or stage which data transfer is processed by or provided by. 25 | * 26 | * @author David M. Lloyd 27 | */ 28 | public interface Conduit { 29 | 30 | /** 31 | * Get the XNIO worker associated with this conduit. 32 | * 33 | * @return the XNIO worker associated with this conduit 34 | */ 35 | XnioWorker getWorker(); 36 | } 37 | -------------------------------------------------------------------------------- /api/src/main/java/org/xnio/conduits/ConduitReadableByteChannel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * 4 | * Copyright 2013 Red Hat, Inc. and/or its affiliates. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.xnio.conduits; 20 | 21 | import java.io.IOException; 22 | import java.nio.ByteBuffer; 23 | import java.nio.channels.ReadableByteChannel; 24 | 25 | /** 26 | * A byte channel which wraps a conduit. 27 | * 28 | * @author David M. Lloyd 29 | */ 30 | public final class ConduitReadableByteChannel implements ReadableByteChannel { 31 | 32 | private StreamSourceConduit conduit; 33 | 34 | /** 35 | * Construct a new instance. 36 | * 37 | * @param conduit the conduit to delegate to 38 | */ 39 | public ConduitReadableByteChannel(final StreamSourceConduit conduit) { 40 | this.conduit = conduit; 41 | } 42 | 43 | public int read(final ByteBuffer dst) throws IOException { 44 | return conduit.read(dst); 45 | } 46 | 47 | public boolean isOpen() { 48 | return ! conduit.isReadShutdown(); 49 | } 50 | 51 | public void close() throws IOException { 52 | conduit.terminateReads(); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /api/src/main/java/org/xnio/conduits/ConduitWritableByteChannel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * 4 | * Copyright 2013 Red Hat, Inc. and/or its affiliates. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.xnio.conduits; 20 | 21 | import java.io.IOException; 22 | import java.nio.ByteBuffer; 23 | import java.nio.channels.WritableByteChannel; 24 | 25 | /** 26 | * A byte channel which wraps a conduit. 27 | * 28 | * @author David M. Lloyd 29 | */ 30 | public final class ConduitWritableByteChannel implements WritableByteChannel { 31 | 32 | private StreamSinkConduit conduit; 33 | 34 | /** 35 | * Construct a new instance. 36 | * 37 | * @param conduit the conduit to delegate to 38 | */ 39 | public ConduitWritableByteChannel(final StreamSinkConduit conduit) { 40 | this.conduit = conduit; 41 | } 42 | 43 | public int write(final ByteBuffer src) throws IOException { 44 | return conduit.write(src); 45 | } 46 | 47 | public boolean isOpen() { 48 | return ! conduit.isWriteShutdown(); 49 | } 50 | 51 | public void close() throws IOException { 52 | conduit.truncateWrites(); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /api/src/main/java/org/xnio/conduits/MessageSourceConduit.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * 4 | * Copyright 2013 Red Hat, Inc. and/or its affiliates. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.xnio.conduits; 20 | 21 | import java.io.IOException; 22 | import java.nio.ByteBuffer; 23 | 24 | /** 25 | * A message source conduit. 26 | * 27 | * @author David M. Lloyd 28 | */ 29 | public interface MessageSourceConduit extends SourceConduit { 30 | 31 | /** 32 | * Receive a message. 33 | * 34 | * @param buffer the buffer that will hold the message 35 | * @return the size of the received message, 0 if no message is available, and -1 if the message channel has reached an end-of-file condition 36 | * @throws IOException if an I/O error occurs 37 | */ 38 | int receive(ByteBuffer dst) throws IOException; 39 | 40 | /** 41 | * Receive a message. 42 | * 43 | * @param buffers the buffers that will hold the message 44 | * @param offs the offset into the array of buffers of the first buffer to read into 45 | * @param len the number of buffers to fill 46 | * @return the size of the received message, 0 if no message is available, and -1 if the message channel has reached an end-of-file condition 47 | * @throws IOException if an I/O error occurs 48 | */ 49 | long receive(ByteBuffer[] dsts, int offs, int len) throws IOException; 50 | } 51 | -------------------------------------------------------------------------------- /api/src/main/java/org/xnio/conduits/MessageStreamSinkConduit.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * 4 | * Copyright 2013 Red Hat, Inc. and/or its affiliates. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.xnio.conduits; 20 | 21 | import java.io.IOException; 22 | import java.nio.ByteBuffer; 23 | import java.nio.channels.FileChannel; 24 | import org.xnio.Buffers; 25 | import org.xnio.channels.StreamSourceChannel; 26 | 27 | /** 28 | * A stream sink conduit which wraps each write into a single message. 29 | * 30 | * @author David M. Lloyd 31 | */ 32 | public final class MessageStreamSinkConduit extends AbstractSinkConduit implements StreamSinkConduit { 33 | 34 | /** 35 | * Construct a new instance. 36 | * 37 | * @param next the delegate conduit to set 38 | */ 39 | public MessageStreamSinkConduit(final MessageSinkConduit next) { 40 | super(next); 41 | } 42 | 43 | public long transferFrom(final FileChannel src, final long position, final long count) throws IOException { 44 | return src.transferTo(position, count, new ConduitWritableByteChannel(this)); 45 | } 46 | 47 | public long transferFrom(final StreamSourceChannel source, final long count, final ByteBuffer throughBuffer) throws IOException { 48 | return Conduits.transfer(source, count, throughBuffer, this); 49 | } 50 | 51 | public int write(final ByteBuffer src) throws IOException { 52 | final int remaining = src.remaining(); 53 | return next.send(src) ? remaining : 0; 54 | } 55 | 56 | public long write(final ByteBuffer[] srcs, final int offs, final int len) throws IOException { 57 | final long remaining = Buffers.remaining(srcs, offs, len); 58 | return next.send(srcs, offs, len) ? remaining : 0L; 59 | } 60 | 61 | @Override 62 | public int writeFinal(ByteBuffer src) throws IOException { 63 | return Conduits.writeFinalBasic(this, src); 64 | } 65 | 66 | @Override 67 | public long writeFinal(ByteBuffer[] srcs, int offset, int length) throws IOException { 68 | return Conduits.writeFinalBasic(this, srcs, offset, length); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /api/src/main/java/org/xnio/conduits/MessageStreamSourceConduit.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * 4 | * Copyright 2013 Red Hat, Inc. and/or its affiliates. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.xnio.conduits; 20 | 21 | import java.io.IOException; 22 | import java.nio.ByteBuffer; 23 | import java.nio.channels.FileChannel; 24 | import org.xnio.channels.StreamSinkChannel; 25 | 26 | /** 27 | * A stream source conduit which reads stream data from messages. The receive buffer should always be as large as 28 | * the largest possible incoming message, or larger, to avoid data loss. 29 | * 30 | * @author David M. Lloyd 31 | */ 32 | public final class MessageStreamSourceConduit extends AbstractSourceConduit implements StreamSourceConduit { 33 | 34 | /** 35 | * Construct a new instance. 36 | * 37 | * @param next the delegate conduit to set 38 | */ 39 | public MessageStreamSourceConduit(final MessageSourceConduit next) { 40 | super(next); 41 | } 42 | 43 | public long transferTo(final long position, final long count, final FileChannel target) throws IOException { 44 | return target.transferFrom(new ConduitReadableByteChannel(this), position, count); 45 | } 46 | 47 | public long transferTo(final long count, final ByteBuffer throughBuffer, final StreamSinkChannel target) throws IOException { 48 | return Conduits.transfer(this, count, throughBuffer, target); 49 | } 50 | 51 | public int read(final ByteBuffer dst) throws IOException { 52 | return next.receive(dst); 53 | } 54 | 55 | public long read(final ByteBuffer[] dsts, final int offs, final int len) throws IOException { 56 | return next.receive(dsts, offs, len); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /api/src/main/java/org/xnio/conduits/SynchronizedMessageSinkConduit.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * 4 | * Copyright 2013 Red Hat, Inc. and/or its affiliates. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.xnio.conduits; 20 | 21 | import java.io.IOException; 22 | import java.nio.ByteBuffer; 23 | 24 | /** 25 | * A synchronized message sink conduit. All conduit operations are wrapped in synchronization blocks for simplified 26 | * thread safety. 27 | * 28 | * @author David M. Lloyd 29 | */ 30 | public final class SynchronizedMessageSinkConduit extends AbstractSynchronizedSinkConduit implements MessageSinkConduit { 31 | 32 | /** 33 | * Construct a new instance. A new lock object is created. 34 | * 35 | * @param next the next conduit in the chain 36 | */ 37 | public SynchronizedMessageSinkConduit(final MessageSinkConduit next) { 38 | super(next); 39 | } 40 | 41 | /** 42 | * Construct a new instance. 43 | * 44 | * @param next the next conduit in the chain 45 | * @param lock the lock object to use 46 | */ 47 | public SynchronizedMessageSinkConduit(final MessageSinkConduit next, final Object lock) { 48 | super(next, lock); 49 | } 50 | 51 | public boolean send(final ByteBuffer src) throws IOException { 52 | synchronized (lock) { 53 | return next.send(src); 54 | } 55 | } 56 | 57 | public boolean send(final ByteBuffer[] srcs, final int offs, final int len) throws IOException { 58 | synchronized (lock) { 59 | return next.send(srcs, offs, len); 60 | } 61 | } 62 | 63 | public boolean sendFinal(final ByteBuffer src) throws IOException { 64 | synchronized (lock) { 65 | return next.sendFinal(src); 66 | } 67 | } 68 | 69 | public boolean sendFinal(final ByteBuffer[] srcs, final int offs, final int len) throws IOException { 70 | synchronized (lock) { 71 | return next.sendFinal(srcs, offs, len); 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /api/src/main/java/org/xnio/conduits/SynchronizedMessageSourceConduit.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * 4 | * Copyright 2013 Red Hat, Inc. and/or its affiliates. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.xnio.conduits; 20 | 21 | import java.io.IOException; 22 | import java.nio.ByteBuffer; 23 | 24 | /** 25 | * A synchronized message source conduit. All conduit operations are wrapped in synchronization blocks for simplified 26 | * thread safety. 27 | * 28 | * @author David M. Lloyd 29 | */ 30 | public final class SynchronizedMessageSourceConduit extends AbstractSynchronizedSourceConduit implements MessageSourceConduit { 31 | 32 | /** 33 | * Construct a new instance. A new lock object is created. 34 | * 35 | * @param next the next conduit in the chain 36 | */ 37 | public SynchronizedMessageSourceConduit(final MessageSourceConduit next) { 38 | super(next); 39 | } 40 | 41 | /** 42 | * Construct a new instance. 43 | * 44 | * @param next the next conduit in the chain 45 | * @param lock the lock object to use 46 | */ 47 | public SynchronizedMessageSourceConduit(final MessageSourceConduit next, final Object lock) { 48 | super(next, lock); 49 | } 50 | 51 | public int receive(final ByteBuffer dst) throws IOException { 52 | synchronized (lock) { 53 | return next.receive(dst); 54 | } 55 | } 56 | 57 | public long receive(final ByteBuffer[] dsts, final int offs, final int len) throws IOException { 58 | synchronized (lock) { 59 | return next.receive(dsts, offs, len); 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /api/src/main/java/org/xnio/conduits/SynchronizedStreamSourceConduit.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * 4 | * Copyright 2013 Red Hat, Inc. and/or its affiliates. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.xnio.conduits; 20 | 21 | import java.io.IOException; 22 | import java.nio.ByteBuffer; 23 | import java.nio.channels.FileChannel; 24 | 25 | import org.xnio.channels.StreamSinkChannel; 26 | 27 | /** 28 | * A synchronized stream source conduit. All conduit operations are wrapped in synchronization blocks for simplified 29 | * thread safety. 30 | * 31 | * @author David M. Lloyd 32 | */ 33 | public final class SynchronizedStreamSourceConduit extends AbstractSynchronizedSourceConduit implements StreamSourceConduit { 34 | 35 | /** 36 | * Construct a new instance. A new lock object is created. 37 | * 38 | * @param next the next conduit in the chain 39 | */ 40 | public SynchronizedStreamSourceConduit(final StreamSourceConduit next) { 41 | super(next); 42 | } 43 | 44 | /** 45 | * Construct a new instance. 46 | * 47 | * @param next the next conduit in the chain 48 | * @param lock the lock object to use 49 | */ 50 | public SynchronizedStreamSourceConduit(final StreamSourceConduit next, final Object lock) { 51 | super(next, lock); 52 | } 53 | 54 | public long transferTo(final long position, final long count, final FileChannel target) throws IOException { 55 | synchronized (lock) { 56 | return next.transferTo(position, count, target); 57 | } 58 | } 59 | 60 | public long transferTo(final long count, final ByteBuffer throughBuffer, final StreamSinkChannel target) throws IOException { 61 | synchronized (lock) { 62 | return next.transferTo(count, throughBuffer, target); 63 | } 64 | } 65 | 66 | public int read(final ByteBuffer dst) throws IOException { 67 | synchronized (lock) { 68 | return next.read(dst); 69 | } 70 | } 71 | 72 | public long read(final ByteBuffer[] dsts, final int offs, final int len) throws IOException { 73 | synchronized (lock) { 74 | return next.read(dsts, offs, len); 75 | } 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /api/src/main/java/org/xnio/conduits/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * 4 | * Copyright 2013 Red Hat, Inc. and/or its affiliates. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | /** 20 | * The XNIO conduit SPI. Conduits represent the underlying transport and filtering mechanism of 21 | * point-to-point message- and stream-oriented channels. 22 | */ 23 | package org.xnio.conduits; 24 | -------------------------------------------------------------------------------- /api/src/main/java/org/xnio/http/HandshakeChecker.java: -------------------------------------------------------------------------------- 1 | package org.xnio.http; 2 | 3 | import java.io.IOException; 4 | import java.util.Map; 5 | 6 | /** 7 | * A class that can decide if a HTTP upgrade handshake is valid. If not it should 8 | * throw an {@link java.io.IOException} 9 | */ 10 | public interface HandshakeChecker { 11 | 12 | /** 13 | * Checks a handshake, and throws an exception if it is invalid 14 | * 15 | * @param headers The response headers, keyed by lowercase name 16 | * @throws java.io.IOException If the handshake is not valid 17 | */ 18 | void checkHandshake(final Map headers) throws IOException; 19 | } 20 | -------------------------------------------------------------------------------- /api/src/main/java/org/xnio/management/XnioProviderMXBean.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * 4 | * Copyright 2013 Red Hat, Inc. and/or its affiliates. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.xnio.management; 20 | 21 | /** 22 | * The MXBean interface for XNIO providers. 23 | * 24 | * @author David M. Lloyd 25 | */ 26 | public interface XnioProviderMXBean { 27 | 28 | /** 29 | * Get the provider name. 30 | * 31 | * @return the provider name 32 | */ 33 | String getName(); 34 | 35 | /** 36 | * Get the provider version string. 37 | * 38 | * @return the provider version string 39 | */ 40 | String getVersion(); 41 | } 42 | -------------------------------------------------------------------------------- /api/src/main/java/org/xnio/management/XnioServerMXBean.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * 4 | * Copyright 2013 Red Hat, Inc. and/or its affiliates. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.xnio.management; 20 | 21 | /** 22 | * @author David M. Lloyd 23 | */ 24 | public interface XnioServerMXBean { 25 | /** 26 | * Get the name of the provider. 27 | * 28 | * @return the name of the provider 29 | */ 30 | String getProviderName(); 31 | 32 | /** 33 | * Get the worker's name. 34 | * 35 | * @return the worker's name 36 | */ 37 | String getWorkerName(); 38 | 39 | /** 40 | * Get the bind address. The address is converted into a readable string form. 41 | * 42 | * @return the bind address 43 | */ 44 | String getBindAddress(); 45 | 46 | /** 47 | * Get an estimate of the current connection count. 48 | * 49 | * @return an estimate of the current connection count 50 | */ 51 | int getConnectionCount(); 52 | 53 | /** 54 | * Get the connection limit high-water mark. If the connection count hits this number, no new connections 55 | * will be accepted until the count drops below the low-water mark. 56 | * 57 | * @return the connection limit high-water mark 58 | */ 59 | int getConnectionLimitHighWater(); 60 | 61 | /** 62 | * Get the connection limit low-water mark. If the connection count has previously hit the high water mark, 63 | * once it drops back down below this count, connections will be accepted again. 64 | * 65 | * @return the connection limit low-water mark 66 | */ 67 | int getConnectionLimitLowWater(); 68 | } 69 | -------------------------------------------------------------------------------- /api/src/main/java/org/xnio/management/XnioWorkerMXBean.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * 4 | * Copyright 2013 Red Hat, Inc. and/or its affiliates. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.xnio.management; 20 | 21 | /** 22 | * @author David M. Lloyd 23 | */ 24 | public interface XnioWorkerMXBean { 25 | 26 | /** 27 | * Get the name of the provider. 28 | * 29 | * @return the name of the provider 30 | */ 31 | String getProviderName(); 32 | 33 | /** 34 | * Get the worker's name. 35 | * 36 | * @return the worker's name 37 | */ 38 | String getName(); 39 | 40 | /** 41 | * Determine whether shutdown has been requested for this worker. 42 | * 43 | * @return {@code true} if shutdown was requested, {@code false} otherwise 44 | */ 45 | boolean isShutdownRequested(); 46 | 47 | /** 48 | * Get the core worker thread pool size. 49 | * 50 | * @return the core worker pool size 51 | */ 52 | int getCoreWorkerPoolSize(); 53 | 54 | /** 55 | * Get the maximum worker thread pool size. 56 | * 57 | * @return the maximum worker pool size 58 | */ 59 | int getMaxWorkerPoolSize(); 60 | 61 | /** 62 | * Get the I/O thread count. 63 | * 64 | * @return the I/O thread count 65 | */ 66 | int getIoThreadCount(); 67 | 68 | /** 69 | * Get an estimate of the number of tasks in the worker queue. 70 | * 71 | * @return the task count estimate 72 | */ 73 | int getWorkerQueueSize(); 74 | } 75 | -------------------------------------------------------------------------------- /api/src/main/java/org/xnio/package-info.java: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * The main API package for XNIO. 4 | *

5 | * In addition to interfaces that are used and implemented by users of XNIO, this package contains several utility 6 | * classes which, while not required to write an XNIO application, simplify boilerplate tasks associated with low-level 7 | * I/O operations. 8 | */ 9 | 10 | package org.xnio; 11 | -------------------------------------------------------------------------------- /api/src/main/java/org/xnio/sasl/SaslQop.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * 4 | * Copyright 2009 Red Hat, Inc. and/or its affiliates. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.xnio.sasl; 20 | 21 | import static org.xnio._private.Messages.msg; 22 | 23 | import javax.security.sasl.Sasl; 24 | 25 | /** 26 | * The SASL quality-of-protection value. 27 | * 28 | * @see Sasl#QOP 29 | */ 30 | public enum SaslQop { 31 | 32 | /** 33 | * A QOP value specifying authentication only. 34 | */ 35 | AUTH("auth"), 36 | /** 37 | * A QOP value specifying authentication plus integrity protection. 38 | */ 39 | AUTH_INT("auth-int"), 40 | /** 41 | * A QOP value specifying authentication plus integrity and confidentiality protection. 42 | */ 43 | AUTH_CONF("auth-conf"), 44 | ; 45 | 46 | private final String s; 47 | 48 | SaslQop(String s) { 49 | this.s = s; 50 | } 51 | 52 | /** 53 | * Get the SASL QOP level for the given string. 54 | * 55 | * @param name the QOP level 56 | * @return the QOP value 57 | */ 58 | public static SaslQop fromString(String name) { 59 | if ("auth".equals(name)) { 60 | return AUTH; 61 | } else if ("auth-int".equals(name)) { 62 | return AUTH_INT; 63 | } else if ("auth-conf".equals(name)) { 64 | return AUTH_CONF; 65 | } else { 66 | throw msg.invalidQop(name); 67 | } 68 | } 69 | 70 | /** 71 | * Get the string representation of this SASL QOP value. 72 | * 73 | * @return the string representation 74 | */ 75 | public String getString() { 76 | return s; 77 | } 78 | 79 | /** 80 | * Get the human-readable string representation of this SASL QOP value. 81 | * 82 | * @return the string representation 83 | */ 84 | public String toString() { 85 | return s; 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /api/src/main/java/org/xnio/sasl/SaslStrength.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * 4 | * Copyright 2009 Red Hat, Inc. and/or its affiliates. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.xnio.sasl; 20 | 21 | /** 22 | * The SASL cipher strength value. 23 | * 24 | * @see javax.security.sasl.Sasl#STRENGTH 25 | */ 26 | public enum SaslStrength { 27 | 28 | /** 29 | * Specify low cipher strength. 30 | */ 31 | LOW, 32 | /** 33 | * Specify medium cipher strength. 34 | */ 35 | MEDIUM, 36 | /** 37 | * Specify high cipher strength. 38 | */ 39 | HIGH, 40 | } 41 | -------------------------------------------------------------------------------- /api/src/main/java/org/xnio/sasl/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Utility classes for using SASL mechanisms atop NIO or XNIO APIs. 3 | */ 4 | package org.xnio.sasl; 5 | -------------------------------------------------------------------------------- /api/src/main/java/org/xnio/ssl/JsseAcceptingSslStreamConnection.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * 4 | * Copyright 2013 Red Hat, Inc. and/or its affiliates. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.xnio.ssl; 20 | 21 | import java.nio.ByteBuffer; 22 | 23 | import javax.net.ssl.SSLContext; 24 | import javax.net.ssl.SSLEngine; 25 | 26 | import org.xnio.OptionMap; 27 | import org.xnio.Pool; 28 | import org.xnio.StreamConnection; 29 | import org.xnio.channels.AcceptingChannel; 30 | 31 | /** 32 | * Accepting channel for StreamConnections with SSL. 33 | * 34 | * @author Flavia Rainone 35 | * 36 | */ 37 | final class JsseAcceptingSslStreamConnection extends AbstractAcceptingSslChannel { 38 | 39 | JsseAcceptingSslStreamConnection(final SSLContext sslContext, final AcceptingChannel tcpServer, final OptionMap optionMap, final Pool socketBufferPool, final Pool applicationBufferPool, final boolean startTls) { 40 | super(sslContext, tcpServer, optionMap, socketBufferPool, applicationBufferPool, startTls); 41 | } 42 | 43 | @Override 44 | public SslConnection accept(StreamConnection tcpConnection, SSLEngine engine) { 45 | return new JsseSslStreamConnection(tcpConnection, engine, socketBufferPool, applicationBufferPool, startTls); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /api/src/main/java/org/xnio/ssl/SslConnection.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * 4 | * Copyright 2013 Red Hat, Inc. and/or its affiliates. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package org.xnio.ssl; 19 | 20 | import java.io.IOException; 21 | 22 | import javax.net.ssl.SSLSession; 23 | 24 | import org.xnio.ChannelListener; 25 | import org.xnio.Options; 26 | import org.xnio.StreamConnection; 27 | import org.xnio.XnioIoThread; 28 | import org.xnio.channels.SslChannel; 29 | 30 | /** 31 | * A stream connection which can use SSL/TLS to negotiate a security layer. 32 | * 33 | * @author Flavia Rainone 34 | * 35 | */ 36 | public abstract class SslConnection extends StreamConnection implements SslChannel { 37 | 38 | /** 39 | * Construct a new instance. 40 | * 41 | * @param thread the I/O thread of this connection 42 | */ 43 | protected SslConnection(XnioIoThread thread) { 44 | super(thread); 45 | } 46 | 47 | /** 48 | * Start or restart the SSL/TLS handshake. To force a complete SSL/TLS session renegotiation, the current session 49 | * should be invalidated prior to calling this method. This method is not needed for the initial handshake unless 50 | * the {@link Options#SSL_STARTTLS} option is set as sending or receiving over the channel will automatically 51 | * initiate it. This method must not be called while a read or write operation is taking place. 52 | * 53 | * @throws IOException if an I/O error occurs 54 | */ 55 | public abstract void startHandshake() throws IOException; 56 | 57 | /** 58 | * Get the current {@code SSLSession} for this channel. 59 | * 60 | * @return the current {@code SSLSession} 61 | */ 62 | public abstract SSLSession getSslSession(); 63 | 64 | /** 65 | * Get the setter which can be used to change the handshake listener for this channel. 66 | * 67 | * @return the setter 68 | */ 69 | public abstract ChannelListener.Setter getHandshakeSetter(); 70 | 71 | /** {@inheritDoc} */ 72 | @SuppressWarnings("unchecked") 73 | @Override 74 | public ChannelListener.Setter getCloseSetter() { 75 | return (ChannelListener.Setter) super.getCloseSetter(); 76 | } 77 | } -------------------------------------------------------------------------------- /api/src/main/java/org/xnio/ssl/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Utility classes for using and implementing SSL within XNIO providers. 3 | */ 4 | package org.xnio.ssl; 5 | -------------------------------------------------------------------------------- /api/src/main/java/org/xnio/streams/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Utility classes for creating streams which use XNIO channels. 3 | */ 4 | package org.xnio.streams; 5 | -------------------------------------------------------------------------------- /api/src/main/java/overview.html: -------------------------------------------------------------------------------- 1 | An advanced non-blocking I/O API designed for utility and scalability. XNIO is based on the NIO concept of channels 2 | and buffers, and adds a channel-ready callback layer. In addition there are many utility classes and methods for 3 | performing zero-copy operations, buffer management, blocking I/O, SSL, and more. -------------------------------------------------------------------------------- /api/src/main/resources/org/xnio/Version.properties: -------------------------------------------------------------------------------- 1 | version=${project.version} 2 | jarName=${project.artifactId} 3 | -------------------------------------------------------------------------------- /api/src/test/java/org/xnio/CloserTestCase.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * 4 | * Copyright 2012 Red Hat, Inc. and/or its affiliates, and individual 5 | * contributors as indicated by the @author tags. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | 20 | package org.xnio; 21 | 22 | import static org.junit.Assert.assertFalse; 23 | import static org.junit.Assert.assertNull; 24 | import static org.junit.Assert.assertTrue; 25 | 26 | import org.junit.Test; 27 | import org.xnio.mock.ConnectedStreamChannelMock; 28 | 29 | /** 30 | * Test for {@link Closer}. 31 | * 32 | * @author Flavia Rainone 33 | * 34 | */ 35 | public class CloserTestCase { 36 | 37 | @Test 38 | public void close() { 39 | final ConnectedStreamChannelMock channel = new ConnectedStreamChannelMock(); 40 | final Closer closer = new Closer(channel); 41 | assertTrue(channel.isOpen()); 42 | closer.run(); 43 | assertFalse(channel.isOpen()); 44 | } 45 | 46 | @Test 47 | public void closeNullChannel() { 48 | final Closer closer = new Closer(null); 49 | NullPointerException notExpected = null; 50 | try { 51 | closer.run(); 52 | } catch (NullPointerException e) { 53 | notExpected = e; 54 | } 55 | assertNull(notExpected); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /api/src/test/java/org/xnio/LocalSocketAddressTestCase.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * 4 | * Copyright 2012 Red Hat, Inc. and/or its affiliates, and individual 5 | * contributors as indicated by the @author tags. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | 20 | package org.xnio; 21 | 22 | import static org.junit.Assert.assertEquals; 23 | import static org.junit.Assert.assertNotNull; 24 | import static org.junit.Assert.assertTrue; 25 | 26 | import org.junit.Test; 27 | 28 | /** 29 | * Test for {@link LocalSocketAddress}. 30 | * 31 | * @author Flavia Rainone 32 | * 33 | */ 34 | public class LocalSocketAddressTestCase { 35 | @Test 36 | public void test1() { 37 | final LocalSocketAddress socketAddress = new LocalSocketAddress("name"); 38 | assertEquals("name", socketAddress.getName()); 39 | assertTrue(socketAddress.toString().contains("name")); 40 | } 41 | 42 | @Test 43 | public void test2() { 44 | final LocalSocketAddress socketAddress = new LocalSocketAddress("address"); 45 | assertEquals("address", socketAddress.getName()); 46 | assertTrue(socketAddress.toString().contains("address")); 47 | } 48 | 49 | @Test 50 | public void testNull() { 51 | IllegalArgumentException expected = null; 52 | try { 53 | new LocalSocketAddress(null); 54 | } catch (IllegalArgumentException e) { 55 | expected = e; 56 | } 57 | assertNotNull(expected); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /api/src/test/java/org/xnio/channels/BlockingByteChannelReadTestCase.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * 4 | * Copyright 2012 Red Hat, Inc. and/or its affiliates, and individual 5 | * contributors as indicated by the @author tags. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | 20 | package org.xnio.channels; 21 | 22 | import java.util.concurrent.TimeUnit; 23 | 24 | import org.xnio.mock.ConnectedStreamChannelMock; 25 | 26 | /** 27 | * Test for {@link BlockingByteChannel} read-related operations. 28 | * 29 | * @author Flavia Rainone 30 | * 31 | */ 32 | public class BlockingByteChannelReadTestCase extends AbstractBlockingReadableByteChannelTest { 33 | @Override 34 | protected BlockingByteChannel createBlockingReadableByteChannel(ConnectedStreamChannelMock channelMock) { 35 | return new BlockingByteChannel(channelMock); 36 | } 37 | 38 | @Override 39 | protected BlockingByteChannel createBlockingReadableByteChannel(ConnectedStreamChannelMock channelMock, long timeout, 40 | TimeUnit timeoutUnit) { 41 | return new BlockingByteChannel(channelMock, timeout, timeoutUnit); 42 | } 43 | 44 | @Override 45 | protected BlockingByteChannel createBlockingReadableByteChannel(ConnectedStreamChannelMock channelMock, long readTimeout, 46 | TimeUnit readTimeoutUnit, long writeTimeout, TimeUnit writeTimeoutUnit) { 47 | return new BlockingByteChannel(channelMock, readTimeout, readTimeoutUnit, writeTimeout, writeTimeoutUnit); 48 | } 49 | 50 | @Override 51 | protected void setReadTimeout(BlockingByteChannel channel, long readTimeout, TimeUnit readTimeoutUnit) { 52 | channel.setReadTimeout(readTimeout, readTimeoutUnit); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /api/src/test/java/org/xnio/channels/BlockingByteChannelWriteTestCase.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * 4 | * Copyright 2012 Red Hat, Inc. and/or its affiliates, and individual 5 | * contributors as indicated by the @author tags. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | 20 | package org.xnio.channels; 21 | 22 | import java.util.concurrent.TimeUnit; 23 | 24 | import org.xnio.mock.ConnectedStreamChannelMock; 25 | 26 | /** 27 | * Test for {@link BlockingByteChannel} write-related operations. 28 | * 29 | * @author Flavia Rainone 30 | */ 31 | public class BlockingByteChannelWriteTestCase extends AbstractBlockingWritableByteChannelTest { 32 | 33 | @Override 34 | protected BlockingByteChannel createBlockingWritableByteChannel(ConnectedStreamChannelMock channelMock) { 35 | return new BlockingByteChannel(channelMock); 36 | } 37 | 38 | @Override 39 | protected BlockingByteChannel createBlockingWritableByteChannel(ConnectedStreamChannelMock channelMock, long timeout, 40 | TimeUnit timeoutUnit) { 41 | return new BlockingByteChannel(channelMock, timeout, timeoutUnit); 42 | } 43 | 44 | @Override 45 | protected BlockingByteChannel createBlockingWritableByteChannel(ConnectedStreamChannelMock channelMock, long readTimeout, 46 | TimeUnit readTimeoutUnit, long writeTimeout, TimeUnit writeTimeoutUnit) { 47 | return new BlockingByteChannel(channelMock, readTimeout, readTimeoutUnit, writeTimeout, writeTimeoutUnit); 48 | } 49 | 50 | @Override 51 | protected void setWriteTimeout(BlockingByteChannel channel, long writeTimeout, TimeUnit writeTimeoutUnit) { 52 | channel.setWriteTimeout(writeTimeout, writeTimeoutUnit); 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /api/src/test/java/org/xnio/channels/BlockingReadableByteChannelTestCase.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * 4 | * Copyright 2012 Red Hat, Inc. and/or its affiliates, and individual 5 | * contributors as indicated by the @author tags. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | 20 | package org.xnio.channels; 21 | 22 | import java.util.concurrent.TimeUnit; 23 | 24 | import org.xnio.mock.ConnectedStreamChannelMock; 25 | 26 | /** 27 | * Test for {@link BlockingReadableByteChannel}. 28 | * 29 | * @author Flavia Rainone 30 | * 31 | */ 32 | public class BlockingReadableByteChannelTestCase extends AbstractBlockingReadableByteChannelTest { 33 | 34 | @Override 35 | protected BlockingReadableByteChannel createBlockingReadableByteChannel(ConnectedStreamChannelMock channelMock) { 36 | return new BlockingReadableByteChannel(channelMock); 37 | } 38 | 39 | @Override 40 | protected BlockingReadableByteChannel createBlockingReadableByteChannel(ConnectedStreamChannelMock channelMock, long timeout, 41 | TimeUnit timeoutUnit) { 42 | return new BlockingReadableByteChannel(channelMock, timeout, timeoutUnit); 43 | } 44 | 45 | @Override 46 | protected BlockingReadableByteChannel createBlockingReadableByteChannel(ConnectedStreamChannelMock channelMock, long readTimeout, 47 | TimeUnit readTimeoutUnit, long writeTimeout, TimeUnit writeTimeoutUnit) { 48 | return new BlockingReadableByteChannel(channelMock, readTimeout, readTimeoutUnit); 49 | } 50 | 51 | @Override 52 | protected void setReadTimeout(BlockingReadableByteChannel blockingChannel, long readTimeout, TimeUnit readTimeoutUnit) { 53 | blockingChannel.setReadTimeout(readTimeout, readTimeoutUnit); 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /api/src/test/java/org/xnio/channels/BlockingWritableByteChannelTestCase.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * 4 | * Copyright 2012 Red Hat, Inc. and/or its affiliates, and individual 5 | * contributors as indicated by the @author tags. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | 20 | package org.xnio.channels; 21 | 22 | import java.util.concurrent.TimeUnit; 23 | 24 | import org.xnio.mock.ConnectedStreamChannelMock; 25 | 26 | /** 27 | * Test for {@link BlockingWritableByteChannel}. 28 | * 29 | * @author Flavia Rainone 30 | */ 31 | public class BlockingWritableByteChannelTestCase extends AbstractBlockingWritableByteChannelTest { 32 | 33 | @Override 34 | protected BlockingWritableByteChannel createBlockingWritableByteChannel(ConnectedStreamChannelMock channelMock) { 35 | return new BlockingWritableByteChannel(channelMock); 36 | } 37 | 38 | @Override 39 | protected BlockingWritableByteChannel createBlockingWritableByteChannel(ConnectedStreamChannelMock channelMock, long timeout, 40 | TimeUnit timeoutUnit) { 41 | return new BlockingWritableByteChannel(channelMock, timeout, timeoutUnit); 42 | } 43 | 44 | @Override 45 | protected BlockingWritableByteChannel createBlockingWritableByteChannel(ConnectedStreamChannelMock channelMock, long readTimeout, 46 | TimeUnit readTimeoutUnit, long writeTimeout, TimeUnit writeTimeoutUnit) { 47 | return new BlockingWritableByteChannel(channelMock, writeTimeout, writeTimeoutUnit); 48 | } 49 | 50 | @Override 51 | protected void setWriteTimeout(BlockingWritableByteChannel channel, long writeTimeout, TimeUnit writeTimeoutUnit) { 52 | channel.setWriteTimeout(writeTimeout, writeTimeoutUnit); 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /api/src/test/java/org/xnio/mock/Mock.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * 4 | * Copyright 2013 Red Hat, Inc. and/or its affiliates. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package org.xnio.mock; 19 | 20 | import org.xnio.OptionMap; 21 | 22 | /** 23 | * A Mock can contain extra info useful to the tests. 24 | * 25 | * @author Flavia Rainone 26 | * 27 | */ 28 | public interface Mock { 29 | public void setInfo(String info); 30 | public String getInfo(); 31 | public OptionMap getOptionMap(); 32 | } 33 | -------------------------------------------------------------------------------- /api/src/test/java/org/xnio/mock/XnioMock.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * 4 | * Copyright 2013 Red Hat, Inc. and/or its affiliates, and individual 5 | * contributors as indicated by the @author tags. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | 20 | package org.xnio.mock; 21 | 22 | import java.io.IOException; 23 | 24 | import org.xnio.FileSystemWatcher; 25 | import org.xnio.OptionMap; 26 | import org.xnio.Xnio; 27 | import org.xnio.XnioProvider; 28 | import org.xnio.XnioWorker; 29 | 30 | /** 31 | * {@link Xnio} mock. 32 | * 33 | * @author Flavia Rainone 34 | */ 35 | public class XnioMock extends Xnio { 36 | 37 | private static final XnioMock INSTANCE = new XnioMock("xnio-mock"); 38 | 39 | protected XnioMock(String name) { 40 | super(name); 41 | } 42 | 43 | @Override 44 | public XnioWorker createWorker(ThreadGroup threadGroup, OptionMap optionMap, Runnable terminationTask) throws IOException, 45 | IllegalArgumentException { 46 | return new XnioWorkerMock(this, threadGroup, optionMap, terminationTask); 47 | } 48 | 49 | public static class Provider implements XnioProvider { 50 | @Override 51 | public Xnio getInstance() { 52 | return INSTANCE; 53 | } 54 | 55 | @Override 56 | public String getName() { 57 | return INSTANCE.getName(); 58 | } 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /api/src/test/resources/META-INF/services/org.xnio.XnioProvider: -------------------------------------------------------------------------------- 1 | 2 | # This module defines the NIO XNIO mock provider 3 | org.xnio.mock.XnioMock$Provider -------------------------------------------------------------------------------- /api/src/test/resources/keystore.jks: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dmlloyd/xnio/d91e5e60377ec0eb6865965cb8a4f2180b055191/api/src/test/resources/keystore.jks -------------------------------------------------------------------------------- /api/src/test/resources/org/xnio/racecondition/CloseReadingSslChannelTestCase.btm: -------------------------------------------------------------------------------- 1 | 2 | RULE handling NEED_WRAP 3 | CLASS org.xnio.ssl.JsseConnectedSslStreamChannel 4 | METHOD handleHandshake 5 | #AT INVOKE org.xnio.ssl.JsseConnectedSslStreamChannel.handleWrapResult 6 | AFTER INVOKE org.xnio.Pooled.getResource 1 7 | IF TRUE 8 | DO 9 | debug("Read is trying to wrap as a result of NEED_WRAP... wait for the channel to be closed"), 10 | signalWake("handleHandshake at invoke handleWrapResult", true), 11 | waitFor("channel closed"), 12 | debug("Proceeding with handleWrapResult") 13 | ENDRULE 14 | 15 | RULE before close channel 16 | CLASS org.xnio.ssl.JsseConnectedSslStreamChannel 17 | METHOD closeAction 18 | AT ENTRY 19 | IF TRUE 20 | DO 21 | debug("Channel is closing... waiting for handleHandshake first"), 22 | waitFor("handleHandshake at invoke handleWrapResult"), 23 | debug("Proceeding with closeAction") 24 | ENDRULE 25 | 26 | 27 | RULE after close channel 28 | CLASS org.xnio.ssl.JsseConnectedSslStreamChannel 29 | METHOD closeAction 30 | AT EXIT 31 | IF TRUE 32 | DO 33 | debug("Channel is closed... waking read"), 34 | signalWake("channel closed", true) 35 | ENDRULE 36 | -------------------------------------------------------------------------------- /api/src/test/resources/org/xnio/racecondition/CloseWritingSslChannelTestCase.btm: -------------------------------------------------------------------------------- 1 | 2 | RULE handling NEED_UNWRAP 3 | CLASS org.xnio.ssl.JsseConnectedSslStreamChannel 4 | METHOD handleHandshake 5 | AFTER INVOKE org.xnio.Pooled.getResource 3 6 | IF TRUE 7 | DO 8 | debug("write is trying to unwrap as a result of NEED_UNWRAP... wait for the channel to be closed"), 9 | signalWake("handleHandshake at invoke handleUnwrapResult", true), 10 | waitFor("channel closed"), 11 | debug("Proceeding with handleUnwrapResult") 12 | ENDRULE 13 | 14 | RULE before close channel 15 | CLASS org.xnio.ssl.JsseConnectedSslStreamChannel 16 | METHOD closeAction 17 | AT ENTRY 18 | IF TRUE 19 | DO 20 | debug("Channel is closing... waiting for handleHandshake first"), 21 | waitFor("handleHandshake at invoke handleUnwrapResult"), 22 | debug("Proceeding with closeAction") 23 | ENDRULE 24 | 25 | 26 | RULE after close engine 27 | CLASS org.xnio.ssl.JsseConnectedSslStreamChannel 28 | METHOD closeAction 29 | AT EXIT 30 | IF TRUE 31 | DO 32 | debug("Channel is closed... waking write"), 33 | signalWake("channel closed", true) 34 | ENDRULE 35 | -------------------------------------------------------------------------------- /api/src/test/resources/org/xnio/racecondition/ResumeReadsOnHandlingReadableChannelTestCase.btm: -------------------------------------------------------------------------------- 1 | 2 | RULE enable race condition scenario 3 | CLASS org.xnio.racecondition.ResumeReadsOnHandlingReadableChannelTestCase 4 | METHOD test 5 | AT INVOKE java.lang.Thread.start 1 6 | IF TRUE 7 | DO 8 | debug("Enabling race condition scenario"), 9 | flag("race condition enabled for ResumeReadsOnHandlingReadableChannelTestCase") 10 | ENDRULE 11 | 12 | RULE handle readable checked read requested is false 13 | CLASS org.xnio.mock.ConnectedStreamChannelMock 14 | METHOD suspendReads 15 | AT ENTRY 16 | IF flagged("race condition enabled for ResumeReadsOnHandlingReadableChannelTestCase") 17 | DO 18 | debug("TranslatingSuspendableChannel just checked that read is not requested... waiting for resumeReads"), 19 | signalWake("read not requested checked", true), 20 | waitFor("read requested"), 21 | debug("Now read is requested... proceeding with handleReadable after a check that read is not requested") 22 | ENDRULE 23 | 24 | RULE resumeReads after handleReadable checked read is not requested 25 | CLASS org.xnio.channels.TranslatingSuspendableChannel 26 | METHOD resumeReads 27 | AT ENTRY 28 | IF flagged("race condition enabled for ResumeReadsOnHandlingReadableChannelTestCase") 29 | DO 30 | debug("resumeReads... waiting for handle readable to check read is not requested"), 31 | waitFor("read not requested checked"), 32 | debug("Proceeding with resumeReads") 33 | ENDRULE 34 | 35 | RULE after resumeReads 36 | CLASS org.xnio.channels.TranslatingSuspendableChannel 37 | METHOD resumeReads 38 | AT EXIT 39 | IF flagged("race condition enabled for ResumeReadsOnHandlingReadableChannelTestCase") 40 | DO 41 | debug("Finished resumeReads... waking handleReadable"), 42 | signalWake("read requested", true) 43 | ENDRULE -------------------------------------------------------------------------------- /api/src/test/resources/org/xnio/racecondition/ResumeWritesOnHandlingWritableChannelTestCase.btm: -------------------------------------------------------------------------------- 1 | 2 | RULE enable race condition scenario 3 | CLASS org.xnio.racecondition.ResumeWritesOnHandlingWritableChannelTestCase 4 | METHOD test 5 | AT INVOKE java.lang.Thread.start 1 6 | IF TRUE 7 | DO 8 | debug("Enabling race condition scenario"), 9 | flag("race condition enabled for ResumeWritesOnHandlingWritableChannelTestCase") 10 | ENDRULE 11 | 12 | RULE handle writable checked write requested is false 13 | CLASS org.xnio.mock.ConnectedStreamChannelMock 14 | METHOD suspendWrites 15 | AT ENTRY 16 | IF flagged("race condition enabled for ResumeWritesOnHandlingWritableChannelTestCase") 17 | DO 18 | debug("TranslatingSuspendableChannel just checked that write is not requested... waiting for resumeWrites"), 19 | signalWake("write not requested checked", true), 20 | waitFor("write requested"), 21 | debug("Now write is requested... proceeding with handleWritable after a check that write is not requested") 22 | ENDRULE 23 | 24 | RULE resumeWrites after handleWritable checked write is not requested 25 | CLASS org.xnio.channels.TranslatingSuspendableChannel 26 | METHOD resumeWrites 27 | AT ENTRY 28 | IF flagged("race condition enabled for ResumeWritesOnHandlingWritableChannelTestCase") 29 | DO 30 | debug("resumeWrites... waiting for handle writable to check write is not requested"), 31 | waitFor("write not requested checked"), 32 | debug("Proceeding with resumeWrites") 33 | ENDRULE 34 | 35 | RULE after resumeWrites 36 | CLASS org.xnio.channels.TranslatingSuspendableChannel 37 | METHOD resumeWrites 38 | AT EXIT 39 | IF flagged("race condition enabled for ResumeWritesOnHandlingWritableChannelTestCase") 40 | DO 41 | debug("Finished resumeWrites... waking handleWritable"), 42 | signalWake("write requested", true) 43 | ENDRULE -------------------------------------------------------------------------------- /api/src/test/resources/org/xnio/racecondition/SetReadReadyOnHandlingReadableChannelTestCase.btm: -------------------------------------------------------------------------------- 1 | 2 | RULE enable race condition scenario 3 | CLASS org.xnio.racecondition.SetReadReadyOnHandlingReadableChannelTestCase 4 | METHOD test 5 | AT INVOKE java.lang.Thread.start 1 6 | IF TRUE 7 | DO 8 | debug("Enabling race condition scenario"), 9 | flag("race condition enabled for SetReadReadyOnHandlingReadableChannelTestCase") 10 | ENDRULE 11 | 12 | RULE handle readable checked read ready is false 13 | CLASS org.xnio.channels.TranslatingSuspendableChannel 14 | METHOD handleReadable 15 | AFTER INVOKE org.xnio.Bits.allAreClear 1 16 | IF flagged("race condition enabled for SetReadReadyOnHandlingReadableChannelTestCase") 17 | DO 18 | debug("TranslatingSuspendableChannel just checked that read is not ready... waiting for setReadReady"), 19 | signalWake("read not ready checked", true), 20 | waitFor("read ready"), 21 | debug("Now read is ready... proceeding with handleReadable after a check that read is not ready") 22 | ENDRULE 23 | 24 | RULE setReadReady after handleReadable checked read ready is false 25 | CLASS org.xnio.channels.TranslatingSuspendableChannel 26 | METHOD setReadReady 27 | AT ENTRY 28 | IF flagged("race condition enabled for SetReadReadyOnHandlingReadableChannelTestCase") 29 | DO 30 | debug("setReadReady... waiting for handle readable to check read ready is false"), 31 | waitFor("read not ready checked"), 32 | debug("Proceeding with setReadReady") 33 | ENDRULE 34 | 35 | RULE after setReadReady 36 | CLASS org.xnio.channels.TranslatingSuspendableChannel 37 | METHOD setReadReady 38 | AT EXIT 39 | IF flagged("race condition enabled for SetReadReadyOnHandlingReadableChannelTestCase") 40 | DO 41 | debug("Finished setReadReady... waking handleReadable"), 42 | signalWake("read ready", true) 43 | ENDRULE -------------------------------------------------------------------------------- /api/src/test/resources/org/xnio/racecondition/SetReadRequiresWriteOnWritingSslChannelTestCase.btm: -------------------------------------------------------------------------------- 1 | 2 | RULE write cannot handle NEED_UNWRAP 3 | CLASS org.xnio.ssl.JsseConnectedSslStreamChannel 4 | METHOD handleHandshake 5 | #AT INVOKE org.xnio.ssl.JsseConnectedSslStreamChannel.readRequiresWrite 2 6 | AFTER INVOKE org.xnio.ssl.JsseConnectedSslStreamChannel.handleUnwrapResult 7 | IF TRUE 8 | DO 9 | debug("write could not handle NEED_UNWRAP... waking red thread before setWriteRequiresRead"), 10 | signalWake("write cannot handle NEED_UNWRAP", true), 11 | # if this thread manages to wait without timing out, an assert !readRequiesWrite() will fail 12 | waitFor("read thread finished", 300), 13 | debug("proceeding with assert !readRequiresWrite; setWriteRequiresRead"); 14 | ENDRULE 15 | 16 | RULE start Read thread 17 | CLASS org.xnio.racecondition.SetReadRequiresWriteOnWritingSslChannelTestCase$Read 18 | METHOD run 19 | AT ENTRY 20 | IF TRUE 21 | DO 22 | debug("holding read thread"), 23 | waitFor("write cannot handle NEED_UNWRAP"), 24 | debug("starting read thread") 25 | ENDRULE 26 | 27 | RULE finish Read thread 28 | CLASS org.xnio.racecondition.SetReadRequiresWriteOnWritingSslChannelTestCase$Read 29 | METHOD run 30 | AT EXIT 31 | IF TRUE 32 | DO 33 | debug("finished read thread... waking write thread"), 34 | signalWake("read thread finished") 35 | ENDRULE 36 | -------------------------------------------------------------------------------- /api/src/test/resources/org/xnio/racecondition/SetWriteReadyOnHandlingWritableChannelTestCase.btm: -------------------------------------------------------------------------------- 1 | 2 | RULE enable race condition scenario 3 | CLASS org.xnio.racecondition.SetWriteReadyOnHandlingWritableChannelTestCase 4 | METHOD test 5 | AT INVOKE java.lang.Thread.start 1 6 | IF TRUE 7 | DO 8 | debug("Enabling race condition scenario"), 9 | flag("race condition enabled for SetWriteReadyOnHandlingWritableChannelTestCase") 10 | ENDRULE 11 | 12 | RULE handle writable checked write ready is false 13 | CLASS org.xnio.channels.TranslatingSuspendableChannel 14 | METHOD handleWritable 15 | AFTER INVOKE org.xnio.Bits.allAreClear 1 16 | IF flagged("race condition enabled for SetWriteReadyOnHandlingWritableChannelTestCase") 17 | DO 18 | debug("TranslatingSuspendableChannel just checked that write is not ready... waiting for setWriteReady"), 19 | signalWake("write not ready checked", true), 20 | waitFor("write ready"), 21 | debug("Now write is ready... proceeding with handleWritable after a check that write is not ready") 22 | ENDRULE 23 | 24 | RULE setWriteReady after handleWritable checked write ready is false 25 | CLASS org.xnio.channels.TranslatingSuspendableChannel 26 | METHOD setWriteReady 27 | AT ENTRY 28 | IF flagged("race condition enabled for SetWriteReadyOnHandlingWritableChannelTestCase") 29 | DO 30 | debug("setWriteReady... waiting for handle writable to check write ready is false"), 31 | waitFor("write not ready checked"), 32 | debug("Proceeding with setWriteReady") 33 | ENDRULE 34 | 35 | RULE after setWriteReady 36 | CLASS org.xnio.channels.TranslatingSuspendableChannel 37 | METHOD setWriteReady 38 | AT EXIT 39 | IF flagged("race condition enabled for SetWriteReadyOnHandlingWritableChannelTestCase") 40 | DO 41 | debug("Finished setWriteReady... waking handleWritable"), 42 | signalWake("write ready", true) 43 | ENDRULE -------------------------------------------------------------------------------- /api/src/test/resources/org/xnio/racecondition/SetWriteRequiresReadOnReadingSslChannelTestCase.btm: -------------------------------------------------------------------------------- 1 | 2 | RULE read cannot handle NEED_WRAP 3 | CLASS org.xnio.ssl.JsseConnectedSslStreamChannel 4 | METHOD handleHandshake 5 | AFTER INVOKE org.xnio.ssl.JsseConnectedSslStreamChannel.handleWrapResult 6 | IF TRUE 7 | DO 8 | debug("read could not handle NEED_WRAP... waking write thread before setReadRequiresWrite"), 9 | signalWake("read cannot handle NEED_WRAP", true), 10 | # if this thread manages to wait without timing out, an assert !writeRequiresRead() will fail 11 | waitFor("write thread finished", 300), 12 | debug("proceeding with assert !writeRequiresRead; setReadRequiresWrite"); 13 | ENDRULE 14 | 15 | RULE start Write thread 16 | CLASS org.xnio.racecondition.SetWriteRequiresReadOnReadingSslChannelTestCase$Write 17 | METHOD run 18 | AT ENTRY 19 | IF TRUE 20 | DO 21 | debug("holding write thread"), 22 | waitFor("read cannot handle NEED_WRAP"), 23 | debug("starting write thread") 24 | ENDRULE 25 | 26 | RULE finish Write thread 27 | CLASS org.xnio.racecondition.SetWriteRequiresReadOnReadingSslChannelTestCase$Write 28 | METHOD run 29 | AT EXIT 30 | IF TRUE 31 | DO 32 | debug("finished write thread... waking read thread"), 33 | signalWake("write thread finished") 34 | ENDRULE 35 | -------------------------------------------------------------------------------- /api/src/test/resources/security.policy: -------------------------------------------------------------------------------- 1 | grant { 2 | permission java.util.PropertyPermission "java.security.policy", "write"; 3 | permission java.lang.RuntimePermission "createSecurityManager"; 4 | permission java.lang.RuntimePermission "setSecurityManager"; 5 | }; -------------------------------------------------------------------------------- /nio-impl/src/main/java/org/xnio/nio/AbstractNioChannel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2012 Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.xnio.nio; 20 | 21 | import org.xnio.ChannelListener; 22 | import org.xnio.ChannelListeners; 23 | import org.xnio.XnioIoThread; 24 | import org.xnio.XnioWorker; 25 | import org.xnio.channels.CloseableChannel; 26 | 27 | abstract class AbstractNioChannel> implements CloseableChannel { 28 | 29 | // default buffer size used by subclasses 30 | protected static final int DEFAULT_BUFFER_SIZE = 0x10000; 31 | 32 | private final ChannelListener.SimpleSetter closeSetter = new ChannelListener.SimpleSetter(); 33 | 34 | protected final NioXnioWorker worker; 35 | 36 | AbstractNioChannel(final NioXnioWorker worker) { 37 | this.worker = worker; 38 | } 39 | 40 | public final XnioWorker getWorker() { 41 | return worker; 42 | } 43 | 44 | public final ChannelListener.Setter getCloseSetter() { 45 | return closeSetter; 46 | } 47 | 48 | public XnioIoThread getIoThread() { 49 | return worker.chooseThread(); 50 | } 51 | 52 | @SuppressWarnings("unchecked") 53 | protected final C typed() { 54 | return (C) this; 55 | } 56 | 57 | protected final void invokeCloseHandler() { 58 | ChannelListeners.invokeChannelListener(typed(), closeSetter.get()); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /nio-impl/src/main/java/org/xnio/nio/AbstractNioStreamConnection.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * 4 | * Copyright 2013 Red Hat, Inc. and/or its affiliates. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.xnio.nio; 20 | 21 | import org.xnio.StreamConnection; 22 | import org.xnio.conduits.StreamSinkConduit; 23 | import org.xnio.conduits.StreamSourceConduit; 24 | 25 | /** 26 | * @author David M. Lloyd 27 | */ 28 | abstract class AbstractNioStreamConnection extends StreamConnection { 29 | 30 | protected AbstractNioStreamConnection(final WorkerThread workerThread) { 31 | super(workerThread); 32 | } 33 | 34 | protected void setSourceConduit(final StreamSourceConduit conduit) { 35 | super.setSourceConduit(conduit); 36 | } 37 | 38 | protected void setSinkConduit(final StreamSinkConduit conduit) { 39 | super.setSinkConduit(conduit); 40 | } 41 | 42 | protected boolean readClosed() { 43 | return super.readClosed(); 44 | } 45 | 46 | protected boolean writeClosed() { 47 | return super.writeClosed(); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /nio-impl/src/main/java/org/xnio/nio/NioHandle.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * 4 | * Copyright 2013 Red Hat, Inc. and/or its affiliates. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.xnio.nio; 20 | 21 | import java.nio.channels.CancelledKeyException; 22 | import java.nio.channels.SelectionKey; 23 | 24 | import static org.xnio.Bits.allAreClear; 25 | import static org.xnio.Bits.allAreSet; 26 | 27 | /** 28 | * @author David M. Lloyd 29 | */ 30 | abstract class NioHandle { 31 | private final WorkerThread workerThread; 32 | private final SelectionKey selectionKey; 33 | 34 | protected NioHandle(final WorkerThread workerThread, final SelectionKey selectionKey) { 35 | this.workerThread = workerThread; 36 | this.selectionKey = selectionKey; 37 | } 38 | 39 | void resume(final int ops) { 40 | try { 41 | if (! allAreSet(selectionKey.interestOps(), ops)) { 42 | workerThread.setOps(selectionKey, ops); 43 | } 44 | } catch (CancelledKeyException ignored) {} 45 | } 46 | 47 | void wakeup(final int ops) { 48 | workerThread.queueTask(new Runnable() { 49 | public void run() { 50 | handleReady(ops); 51 | } 52 | }); 53 | try { 54 | if (! allAreSet(selectionKey.interestOps(), ops)) { 55 | workerThread.setOps(selectionKey, ops); 56 | } 57 | } catch (CancelledKeyException ignored) {} 58 | } 59 | 60 | void suspend(final int ops) { 61 | try { 62 | if (! allAreClear(selectionKey.interestOps(), ops)) { 63 | workerThread.clearOps(selectionKey, ops); 64 | } 65 | } catch (CancelledKeyException ignored) {} 66 | } 67 | 68 | boolean isResumed(final int ops) { 69 | try { 70 | return allAreSet(selectionKey.interestOps(), ops); 71 | } catch (CancelledKeyException ignored) { 72 | return false; 73 | } 74 | } 75 | 76 | abstract void handleReady(final int ops); 77 | 78 | abstract void forceTermination(); 79 | 80 | abstract void terminated(); 81 | 82 | WorkerThread getWorkerThread() { 83 | return workerThread; 84 | } 85 | 86 | SelectionKey getSelectionKey() { 87 | return selectionKey; 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /nio-impl/src/main/java/org/xnio/nio/NioUdpChannelHandle.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * 4 | * Copyright 2013 Red Hat, Inc. and/or its affiliates. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.xnio.nio; 20 | 21 | import java.nio.channels.CancelledKeyException; 22 | import java.nio.channels.SelectionKey; 23 | import org.xnio.Bits; 24 | import org.xnio.ChannelListeners; 25 | import org.xnio.IoUtils; 26 | 27 | /** 28 | * @author David M. Lloyd 29 | */ 30 | final class NioUdpChannelHandle extends NioHandle { 31 | private final NioUdpChannel channel; 32 | 33 | NioUdpChannelHandle(final WorkerThread workerThread, final SelectionKey selectionKey, final NioUdpChannel channel) { 34 | super(workerThread, selectionKey); 35 | this.channel = channel; 36 | } 37 | 38 | void handleReady(int ops) { 39 | try { 40 | if (ops == 0) { 41 | // the dreaded bug 42 | final SelectionKey key = getSelectionKey(); 43 | final int interestOps = key.interestOps(); 44 | if (interestOps != 0) { 45 | ops = interestOps; 46 | } else { 47 | // urp 48 | forceTermination(); 49 | return; 50 | } 51 | } 52 | if (Bits.allAreSet(ops, SelectionKey.OP_READ)) try { 53 | ChannelListeners.invokeChannelListener(channel, channel.getReadListener()); 54 | } catch (Throwable ignored) { 55 | } 56 | if (Bits.allAreSet(ops, SelectionKey.OP_WRITE)) try { 57 | ChannelListeners.invokeChannelListener(channel, channel.getWriteListener()); 58 | } catch (Throwable ignored) { 59 | } 60 | } catch (CancelledKeyException ignored) {} 61 | } 62 | 63 | void forceTermination() { 64 | IoUtils.safeClose(channel); 65 | } 66 | 67 | void terminated() { 68 | channel.invokeCloseHandler(); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /nio-impl/src/main/java/org/xnio/nio/NioXnioProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2012 Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.xnio.nio; 20 | 21 | import org.xnio.Xnio; 22 | import org.xnio.XnioProvider; 23 | 24 | /** 25 | * The NIO XNIO provider. 26 | * 27 | * @author David M. Lloyd 28 | */ 29 | public final class NioXnioProvider implements XnioProvider { 30 | private static final Xnio INSTANCE = new NioXnio(); 31 | 32 | /** {@inheritDoc} */ 33 | public Xnio getInstance() { 34 | return INSTANCE; 35 | } 36 | 37 | /** {@inheritDoc} */ 38 | public String getName() { 39 | return INSTANCE.getName(); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /nio-impl/src/main/java/org/xnio/nio/SelectorUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2012 Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.xnio.nio; 20 | 21 | import static org.xnio.nio.Log.log; 22 | 23 | import java.io.IOException; 24 | import java.io.InterruptedIOException; 25 | import java.nio.channels.ClosedChannelException; 26 | import java.nio.channels.SelectableChannel; 27 | import java.nio.channels.SelectionKey; 28 | import java.nio.channels.Selector; 29 | import java.util.concurrent.TimeUnit; 30 | 31 | import org.xnio.Xnio; 32 | 33 | final class SelectorUtils { 34 | private SelectorUtils() { 35 | } 36 | 37 | public static void await(NioXnio nioXnio, SelectableChannel channel, int op) throws IOException { 38 | Xnio.checkBlockingAllowed(); 39 | final Selector selector = nioXnio.getSelector(); 40 | final SelectionKey selectionKey; 41 | try { 42 | selectionKey = channel.register(selector, op); 43 | } catch (ClosedChannelException e) { 44 | return; 45 | } 46 | selector.select(); 47 | selector.selectedKeys().clear(); 48 | if (Thread.currentThread().isInterrupted()) { 49 | throw log.interruptedIO(); 50 | } 51 | selectionKey.cancel(); 52 | selector.selectNow(); 53 | } 54 | 55 | public static void await(NioXnio nioXnio, SelectableChannel channel, int op, long time, TimeUnit unit) throws IOException { 56 | if (time <= 0) { 57 | await(nioXnio, channel, op); 58 | return; 59 | } 60 | Xnio.checkBlockingAllowed(); 61 | final Selector selector = nioXnio.getSelector(); 62 | final SelectionKey selectionKey; 63 | try { 64 | selectionKey = channel.register(selector, op); 65 | } catch (ClosedChannelException e) { 66 | return; 67 | } 68 | long timeoutInMillis = unit.toMillis(time); 69 | selector.select(timeoutInMillis == 0 ? 1: timeoutInMillis); 70 | selector.selectedKeys().clear(); 71 | if (Thread.currentThread().isInterrupted()) { 72 | throw log.interruptedIO(); 73 | } 74 | selectionKey.cancel(); 75 | selector.selectNow(); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /nio-impl/src/main/resources/META-INF/services/org.xnio.XnioProvider: -------------------------------------------------------------------------------- 1 | # 2 | # JBoss, Home of Professional Open Source. 3 | # Copyright 2012 Red Hat, Inc., and individual contributors 4 | # as indicated by the @author tags. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | # 20 | # This module defines the NIO XNIO provider 21 | org.xnio.nio.NioXnioProvider 22 | -------------------------------------------------------------------------------- /nio-impl/src/main/resources/org/xnio/nio/Version.properties: -------------------------------------------------------------------------------- 1 | version=${project.version} 2 | jarName=${project.artifactId} 3 | -------------------------------------------------------------------------------- /nio-impl/src/test/java/org/xnio/nio/test/CatchingChannelListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2012 Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.xnio.nio.test; 20 | 21 | import java.util.List; 22 | import org.xnio.ChannelListener; 23 | import java.nio.channels.Channel; 24 | 25 | final class CatchingChannelListener implements ChannelListener { 26 | 27 | private final ChannelListener delegate; 28 | private final List problems; 29 | 30 | CatchingChannelListener(final ChannelListener delegate, final List problems) { 31 | this.delegate = delegate; 32 | this.problems = problems; 33 | } 34 | 35 | public void handleEvent(final T channel) { 36 | try { 37 | if (delegate != null) delegate.handleEvent(channel); 38 | } catch (RuntimeException t) { 39 | problems.add(t); 40 | throw t; 41 | } catch (Error t) { 42 | problems.add(t); 43 | throw t; 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /nio-impl/src/test/java/org/xnio/nio/test/MultiThreadedNioSslTcpChannelTestCase.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * 4 | * Copyright 2013 Red Hat, Inc. and/or its affiliates. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package org.xnio.nio.test; 19 | 20 | import org.junit.Before; 21 | 22 | /** 23 | * Runs NioSslTcpChannelTestCase with 5 I/O threads. 24 | * 25 | * @author Flavia Rainone 26 | * 27 | */ 28 | public class MultiThreadedNioSslTcpChannelTestCase extends NioSslTcpChannelTestCase { 29 | 30 | @Before 31 | public void setThreads() { 32 | super.setNumberOfThreads(5); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /nio-impl/src/test/java/org/xnio/nio/test/MultiThreadedNioSslTcpConnectionTestCase.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * 4 | * Copyright 2013 Red Hat, Inc. and/or its affiliates. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package org.xnio.nio.test; 19 | 20 | import org.junit.Before; 21 | 22 | /** 23 | * Runs NioSslTcpConnectionTestCase with 3 I/O threads. 24 | * 25 | * @author Flavia Rainone 26 | * 27 | */ 28 | public class MultiThreadedNioSslTcpConnectionTestCase extends NioSslTcpConnectionTestCase { 29 | 30 | @Before 31 | public void setThreads() { 32 | super.setNumberOfThreads(3); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /nio-impl/src/test/java/org/xnio/nio/test/MultiThreadedNioStartTLSTcpChannelTestCase.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * 4 | * Copyright 2013 Red Hat, Inc. and/or its affiliates. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package org.xnio.nio.test; 19 | 20 | import org.junit.Before; 21 | 22 | /** 23 | * Runs NioStartTLSTcpChannelTestCase with 4 I/O threads. 24 | * 25 | * @author Flavia Rainone 26 | * 27 | */ 28 | public class MultiThreadedNioStartTLSTcpChannelTestCase extends NioStartTLSTcpChannelTestCase { 29 | 30 | @Before 31 | public void setThreads() { 32 | super.setNumberOfThreads(4); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /nio-impl/src/test/java/org/xnio/nio/test/MultiThreadedNioStartTLSTcpConnectionTestCase.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * 4 | * Copyright 2013 Red Hat, Inc. and/or its affiliates. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package org.xnio.nio.test; 19 | 20 | import org.junit.Before; 21 | 22 | /** 23 | * Runs NioStartTLSTcpConnectionTestCase with 6 I/O threads. 24 | * 25 | * @author Flavia Rainone 26 | * 27 | */ 28 | public class MultiThreadedNioStartTLSTcpConnectionTestCase extends NioStartTLSTcpConnectionTestCase { 29 | 30 | @Before 31 | public void setThreads() { 32 | super.setNumberOfThreads(6); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /nio-impl/src/test/java/org/xnio/nio/test/MultiThreadedNioTcpChannelTestCase.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * 4 | * Copyright 2013 Red Hat, Inc. and/or its affiliates. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package org.xnio.nio.test; 19 | 20 | import org.junit.Before; 21 | 22 | /** 23 | * Runs NioTcpChannelTestCase with 5 I/O threads. 24 | * 25 | * @author Flavia Rainone 26 | * 27 | */ 28 | public class MultiThreadedNioTcpChannelTestCase extends NioTcpChannelTestCase { 29 | 30 | @Before 31 | public void setThreads() { 32 | super.setNumberOfThreads(5); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /nio-impl/src/test/java/org/xnio/nio/test/MultiThreadedNioTcpConnectionTestCase.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source 3 | * 4 | * Copyright 2013 Red Hat, Inc. and/or its affiliates. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package org.xnio.nio.test; 19 | 20 | import org.junit.Before; 21 | 22 | /** 23 | * Runs NioTcpConnectionTestCase with 3 I/O threads. 24 | * 25 | * @author Flavia Rainone 26 | * 27 | */ 28 | public class MultiThreadedNioTcpConnectionTestCase extends NioTcpConnectionTestCase { 29 | 30 | @Before 31 | public void setThreads() { 32 | super.setNumberOfThreads(3); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /nio-impl/src/test/java/org/xnio/nio/test/NioHalfDuplexChannelPipeTestCase.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2012, Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. See the copyright.txt file in the 5 | * distribution for a full listing of individual contributors. 6 | * 7 | * This is free software; you can redistribute it and/or modify it 8 | * under the terms of the GNU Lesser General Public License as 9 | * published by the Free Software Foundation; either version 2.1 of 10 | * the License, or (at your option) any later version. 11 | * 12 | * This software is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this software; if not, write to the Free 19 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 20 | * 02110-1301 USA, or see the FSF site: http://www.fsf.org. 21 | */ 22 | package org.xnio.nio.test; 23 | 24 | import java.io.IOException; 25 | 26 | import org.xnio.ChannelPipe; 27 | import org.xnio.XnioWorker; 28 | import org.xnio.channels.StreamSinkChannel; 29 | import org.xnio.channels.StreamSourceChannel; 30 | 31 | /** 32 | * Test for half duplex channel pipe usage. 33 | * 34 | * @author Flavia Rainone 35 | */ 36 | public class NioHalfDuplexChannelPipeTestCase extends AbstractNioChannelPipeTest { 37 | 38 | @Override 39 | protected ChannelPipe createPipeChannel(XnioWorker worker) 40 | throws IOException { 41 | return worker.createHalfDuplexPipe(); 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /nio-impl/src/test/java/org/xnio/nio/test/TestChannelListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2012, Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. See the copyright.txt file in the 5 | * distribution for a full listing of individual contributors. 6 | * 7 | * This is free software; you can redistribute it and/or modify it 8 | * under the terms of the GNU Lesser General Public License as 9 | * published by the Free Software Foundation; either version 2.1 of 10 | * the License, or (at your option) any later version. 11 | * 12 | * This software is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this software; if not, write to the Free 19 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 20 | * 02110-1301 USA, or see the FSF site: http://www.fsf.org. 21 | */ 22 | package org.xnio.nio.test; 23 | 24 | import java.nio.channels.Channel; 25 | import java.util.concurrent.CountDownLatch; 26 | 27 | import org.xnio.ChannelListener; 28 | 29 | /** 30 | * Utility channel listener. 31 | * 32 | * @author Flavia Rainone 33 | * 34 | */ 35 | class TestChannelListener implements ChannelListener { 36 | 37 | private boolean invoked = false; 38 | private C channel = null; 39 | private CountDownLatch latch = new CountDownLatch(1); 40 | 41 | @Override 42 | public synchronized void handleEvent(C c) { 43 | invoked = true; 44 | channel = c; 45 | latch.countDown(); 46 | } 47 | 48 | public boolean isInvoked() { 49 | final CountDownLatch currentLatch; 50 | synchronized (this) { 51 | currentLatch = latch; 52 | } 53 | try { 54 | currentLatch.await(); 55 | } catch (InterruptedException e) { 56 | e.printStackTrace(); 57 | } 58 | synchronized (this) { 59 | return invoked; 60 | } 61 | } 62 | 63 | public synchronized boolean isInvokedYet() { 64 | return invoked; 65 | } 66 | 67 | public synchronized C getChannel() { 68 | return channel; 69 | } 70 | 71 | public synchronized void clear() { 72 | invoked = false; 73 | channel = null; 74 | latch = new CountDownLatch(1); 75 | } 76 | } -------------------------------------------------------------------------------- /nio-impl/src/test/java/org/xnio/nio/test/racecondition/NullHelper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JBoss, Home of Professional Open Source. 3 | * Copyright 2012, Red Hat, Inc., and individual contributors 4 | * as indicated by the @author tags. See the copyright.txt file in the 5 | * distribution for a full listing of individual contributors. 6 | * 7 | * This is free software; you can redistribute it and/or modify it 8 | * under the terms of the GNU Lesser General Public License as 9 | * published by the Free Software Foundation; either version 2.1 of 10 | * the License, or (at your option) any later version. 11 | * 12 | * This software is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this software; if not, write to the Free 19 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 20 | * 02110-1301 USA, or see the FSF site: http://www.fsf.org. 21 | */ 22 | package org.xnio.nio.test.racecondition; 23 | 24 | import org.jboss.byteman.rule.Rule; 25 | import org.jboss.byteman.rule.helper.Helper; 26 | 27 | /** 28 | * A helper with a isNull facility. 29 | * TODO remove this helper 30 | * 31 | * @author Flavia Rainone 32 | * 33 | */ 34 | public class NullHelper extends Helper { 35 | 36 | 37 | protected NullHelper(Rule rule) { 38 | super(rule); 39 | } 40 | 41 | public boolean isNull(Object object) { 42 | return object == null; 43 | } 44 | 45 | public String toString() { 46 | return "NullHelper"; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /nio-impl/src/test/resources/keystore.jks: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dmlloyd/xnio/d91e5e60377ec0eb6865965cb8a4f2180b055191/nio-impl/src/test/resources/keystore.jks -------------------------------------------------------------------------------- /nio-impl/src/test/resources/logging.properties: -------------------------------------------------------------------------------- 1 | 2 | # 3 | # JBoss, Home of Professional Open Source. 4 | # Copyright 2012 Red Hat, Inc., and individual contributors 5 | # as indicated by the @author tags. 6 | # 7 | # Licensed under the Apache License, Version 2.0 (the "License"); 8 | # you may not use this file except in compliance with the License. 9 | # You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, software 14 | # distributed under the License is distributed on an "AS IS" BASIS, 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | # See the License for the specific language governing permissions and 17 | # limitations under the License. 18 | # 19 | 20 | # Additional logger names to configure (root logger is always configured) 21 | loggers=org.xnio.listener,org.xnio.ssl 22 | 23 | # Root logger configuration 24 | logger.level=${test.level:INFO} 25 | logger.handlers=CONSOLE 26 | 27 | # Console handler configuration 28 | handler.CONSOLE=org.jboss.logmanager.handlers.ConsoleHandler 29 | handler.CONSOLE.properties=autoFlush,target 30 | handler.CONSOLE.target=SYSTEM_ERR 31 | handler.CONSOLE.level=ALL 32 | handler.CONSOLE.autoFlush=true 33 | handler.CONSOLE.formatter=PATTERN 34 | 35 | # The log format pattern 36 | formatter.PATTERN=org.jboss.logmanager.formatters.PatternFormatter 37 | formatter.PATTERN.properties=pattern 38 | formatter.PATTERN.pattern=%d{HH:mm:ss,SSS} %-5p (%t) [%c] <%F:%L> %m%n 39 | 40 | #logger.org.xnio.listener.level=INFO 41 | 42 | logger.org.xnio.ssl.level=DEBUG 43 | -------------------------------------------------------------------------------- /nio-impl/src/test/resources/org/xnio/nio/test/racecondition/SetConnFullDuringAwaitTestCase: -------------------------------------------------------------------------------- 1 | # 2 | # JBoss, Home of Professional Open Source. 3 | # Copyright 2012, Red Hat, Inc., and individual contributors 4 | # as indicated by the @author tags. See the copyright.txt file in the 5 | # distribution for a full listing of individual contributors. 6 | # 7 | # This is free software; you can redistribute it and/or modify it 8 | # under the terms of the GNU Lesser General Public License as 9 | # published by the Free Software Foundation; either version 2.1 of 10 | # the License, or (at your option) any later version. 11 | # 12 | # This software is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | # Lesser General Public License for more details. 16 | # 17 | # You should have received a copy of the GNU Lesser General Public 18 | # License along with this software; if not, write to the Free 19 | # Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 20 | # 02110-1301 USA, or see the FSF site: http://www.fsf.org. 21 | # 22 | 23 | RULE awaitAcceptable checks CONN_FULL is not set 24 | CLASS org.xnio.nio.NioTcpServer 25 | METHOD awaitAcceptable 26 | AFTER INVOKE org.xnio.nio.SelectorUtils.await 27 | IF incrementCounter("run 'awaitAcceptable checks CONN_FULL' not set once") == 1 28 | DO 29 | debug("AwaitWritable checked that connection is not full, waiting for CONN_FULL to be set before performing last check"), 30 | signalWake("CONN_FULL not set is verified", true), 31 | waitFor("CONN_FULL is set"), 32 | debug("Proceeding with the last check for CONN_FULL") 33 | ENDRULE 34 | 35 | RULE clear counters 36 | CLASS org.xnio.nio.test.racecondition.SetConnFullDuringAwaitTestCase 37 | METHOD afterTest 38 | AT ENTRY 39 | IF TRUE 40 | DO 41 | debug("Clearing counters"), 42 | deleteCounter("run 'awaitAcceptable checks CONN_FULL' not set once"), 43 | deleteCounter("wait for waiter on first accept only") 44 | ENDRULE 45 | 46 | 47 | RULE NioTcpServer sets CONN_FULL 48 | CLASS org.xnio.nio.NioTcpServer 49 | METHOD accept 50 | HELPER org.xnio.nio.test.racecondition.NullHelper 51 | AT EXIT 52 | IF isNull($!) 53 | DO 54 | debug("Connection limit is reached, waking awaitAcceptable"), 55 | signalWake("CONN_FULL is set", true), 56 | debug("Proceeding...") 57 | ENDRULE 58 | 59 | RULE NioTcpServer accept 60 | CLASS org.xnio.nio.NioTcpServer 61 | METHOD accept 62 | HELPER org.xnio.nio.test.racecondition.NullHelper 63 | AT ENTRY 64 | IF incrementCounter("wait for waiter on first accept only") == 1 65 | DO 66 | debug("Holding first accept..."), 67 | waitFor("CONN_FULL not set is verified") 68 | ENDRULE 69 | --------------------------------------------------------------------------------