|
LimeWire Consolidated API | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.net.Socket
org.limewire.nio.NBSocket
org.limewire.nio.AbstractNBSocket
public abstract class AbstractNBSocket
Implements all common functionality that a non-blocking socket must contain.
Specifically, AbstractNBSocket handles
the multiplexing aspect of handing off reading, writing and connecting to
other Observers (org.limewire.nio.observer).
Additionally, AbstractNBSocket traverses the chain of readers
and writers to read leftover data and ensure remaining data is written.
AbstractNBSocket also exposes a common blocking input and output
stream.
| Constructor Summary | |
|---|---|
AbstractNBSocket()
|
|
| Method Summary | |
|---|---|
void |
close()
Closes the socket & all streams, waking up any waiting locks. |
void |
connect(SocketAddress addr)
Connects to addr with no timeout |
void |
connect(SocketAddress addr,
int timeout)
Connects to addr with the given timeout (in milliseconds) |
boolean |
connect(SocketAddress addr,
int timeout,
ConnectObserver observer)
Connects to the specified address within the given timeout (in milliseconds). |
protected abstract InterestReadableByteChannel |
getBaseReadChannel()
Retrieves the channel which should be used as the base channel for all reading operations. |
protected abstract InterestWritableByteChannel |
getBaseWriteChannel()
Retrieves the channel which should be used as the base channel for all writing operations. |
InputStream |
getInputStream()
Returns the InputStream from the NIOInputStream. |
OutputStream |
getOutputStream()
Returns the OutputStream from the NIOOutputStream. |
long |
getReadTimeout()
Gets the read timeout for this socket. |
void |
handleConnect(Socket s)
Notification that a connect can occur. |
void |
handleIOException(IOException iox)
Notification that an IOException occurred while processing a
read, connect, or write. |
void |
handleRead()
Notification that a read can occur. |
boolean |
handleWrite()
Notification that a write can occur. |
void |
setInitialReader()
Sets the initial reader value. |
void |
setInitialWriter()
Sets the initial writer value. |
void |
setReadObserver(ChannelReadObserver newReader)
Sets the new ReadObserver. |
void |
setShutdownObserver(Shutdownable observer)
Sets the Shutdown observer. |
void |
setWriteObserver(ChannelWriter newWriter)
Sets the new WriteObserver. |
void |
shutdown()
Shuts down this socket & all its streams. |
protected abstract void |
shutdownImpl()
Performs any operations required for shutting down this socket. |
protected void |
shutdownObservers()
Shuts down all observers. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface org.limewire.nio.timeout.SoTimeout |
|---|
getSoTimeout |
| Constructor Detail |
|---|
public AbstractNBSocket()
| Method Detail |
|---|
protected abstract InterestReadableByteChannel getBaseReadChannel()
protected abstract InterestWritableByteChannel getBaseWriteChannel()
If the base write channel is chained (that is, if there are multiple writing layers that will always be used) then this must return the top-most layer. That layer will be installed beneath the bottom layer that is set on the Socket. All layers except the last must implement ChannelWriter, so they can be iterated over in order to set the last writer.
protected abstract void shutdownImpl()
shutdownImpl method will only be called once per Socket.
public final void setInitialReader()
public final void setInitialWriter()
public final void setShutdownObserver(Shutdownable observer)
Shutdown observer.
This observer is useful for when the Socket is created,
but connect has not been called yet. This observer will be
notified when the socket is shutdown.
setShutdownObserver in class NBSocketpublic final void setReadObserver(ChannelReadObserver newReader)
ReadObserver.
The deepest ChannelReader in the chain first has its source
set to the prior reader (assuming it implemented ReadableByteChannel)
and a read is notified, in order to read any buffered data.
The source is then set to the Socket's channel and interest
in reading is turned on.
setReadObserver in interface NIOMultiplexorpublic final void setWriteObserver(ChannelWriter newWriter)
WriteObserver.
If a ThrottleWriter is one of the ChannelWriters,
the attachment of the ThrottleWriter is set to be this.
The deepest
If this is called while the existing
ChannelWriter in the chain has its source set to be
a new InterestWriteChannel, which will be used as the hub to receive
and forward interest events from/to the channel.
WriteObserver still has data left to
write, then an IllegalStateException is thrown.
setWriteObserver in interface NIOMultiplexor
public final void handleConnect(Socket s)
throws IOException
This passes it off on to the delegating connecter and then forgets the connecter for the duration of the connection.
handleConnect in interface ConnectObserverIOException
public final void handleRead()
throws IOException
handleRead in interface ReadObserverIOException
public final boolean handleWrite()
throws IOException
handleWrite in interface WriteObservertrue there is still data to be written, otherwise
false.
IOExceptionpublic final void close()
close in class Socket
public final void connect(SocketAddress addr)
throws IOException
addr with no timeout
connect in class SocketIOException
public final void connect(SocketAddress addr,
int timeout)
throws IOException
addr with the given timeout (in milliseconds)
connect in class SocketIOException
public boolean connect(SocketAddress addr,
int timeout,
ConnectObserver observer)
ConnectObserver will be notified of success or failure.
In the event of success, observer.handleConnect is called. In a failure,
observer.shutdown is called. observer.handleIOException
is never called.
Returns true if this was able to connect immediately. The observer is still notified about the success even it it was immediate.
connect in class NBSocket
public final InputStream getInputStream()
throws IOException
InputStream from the NIOInputStream.
Internally, this is a blocking Pipe from the non-blocking SocketChannel.
getInputStream in class SocketIOException
public final OutputStream getOutputStream()
throws IOException
OutputStream from the NIOOutputStream.
Internally, this is a blocking Pipe from the non-blocking SocketChannel.
getOutputStream in class SocketIOExceptionpublic long getReadTimeout()
getReadTimeout in interface ReadTimeoutpublic final void handleIOException(IOException iox)
IOException occurred while processing a
read, connect, or write.
handleIOException in interface IOErrorObserverpublic final void shutdown()
shutdown in interface Shutdownableprotected void shutdownObservers()
|
LimeWire Consolidated API | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||