|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Objectjava.util.EventObject
NioServer.Event
public static class NioServer.Event
An event representing activity by a NioServer.
This code is released into the Public Domain. Since this is Public Domain, you don't need to worry about licensing, and you can simply copy this NioServer.java file to your own package and use it as you like. Enjoy. Please consider leaving the following statement here in this code:
This NioServer class was copied to this project from its source as found at iHarder.net.
NioServer,
NioServer.Adapter,
NioServer.Listener,
Serialized Form| Field Summary |
|---|
| Fields inherited from class java.util.EventObject |
|---|
source |
| Constructor Summary | |
|---|---|
NioServer.Event(NioServer src)
Creates a Event based on the given NioServer. |
|
| Method Summary | |
|---|---|
void |
close()
Closes the underlying channel. |
void |
closeAfterWriting()
Convenience method for indicating that you would like the connection closed after the last byte in the output buffer is written. |
java.nio.ByteBuffer |
getInputBuffer()
Returns the ByteBuffer that contains
the incoming data for this connection. |
java.nio.channels.SelectionKey |
getKey()
Returns the SelectionKey associated with this event. |
java.net.SocketAddress |
getLocalSocketAddress()
Returns the local address/port to which this connection is bound. |
NioServer |
getNioServer()
Returns the source of the event, a NioServer. |
java.nio.ByteBuffer |
getOutputBuffer()
Returns the ByteBuffer in which you leave
data to be written to the client. |
java.net.SocketAddress |
getRemoteSocketAddress()
Returns the address of the endpoint this socket is connected to, or null if it is unconnected. |
NioServer.State |
getState()
Shorthand for getNioServer().getState(). |
boolean |
isTcp()
Convenience method for checking getKey().channel() instanceof SocketChannel. |
boolean |
isUdp()
Convenience method for checking getKey().channel() instanceof DatagramChannel. |
protected void |
reset(java.nio.channels.SelectionKey key,
java.nio.ByteBuffer inBuff,
java.nio.ByteBuffer outBuff,
java.net.SocketAddress remoteUdp)
Resets an event between firings by updating the parameters that change. |
void |
setNotifyOnTcpWritable(boolean notify)
Convenience method for turning on and off writable notifications. |
| Methods inherited from class java.util.EventObject |
|---|
getSource, toString |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public NioServer.Event(NioServer src)
NioServer.
src - the source of the event| Method Detail |
|---|
public NioServer getNioServer()
NioServer.
Shorthand for (NioServer)getSource().
public NioServer.State getState()
NioServer.Statepublic java.nio.channels.SelectionKey getKey()
protected void reset(java.nio.channels.SelectionKey key,
java.nio.ByteBuffer inBuff,
java.nio.ByteBuffer outBuff,
java.net.SocketAddress remoteUdp)
key - The SelectionKey for the eventremoteUdp - the remote UDP source or null for TCPpublic java.nio.ByteBuffer getInputBuffer()
Returns the ByteBuffer that contains
the incoming data for this connection. Read from it as much as
you can. Any data that remains on or after the value
of position() will be saved for the next
time an event is fired. In this way, you can defer
processing incomplete data until everything arrives.
This applies to the
NioServer.Listener.tcpDataReceived(NioServer.Event)
event.
Example: You are receiving lines of text. The ByteBuffer returned here contains one and a half lines of text. When you realize this, you process the first line as you like, but you leave this outBuff's position at the beginning of the second line. In this way, The beginning of the second line will be the start of the outBuff the next time around.
public java.nio.ByteBuffer getOutputBuffer()
Returns the ByteBuffer in which you leave
data to be written to the client.
This applies to the
NioServer.Listener.newConnectionReceived(NioServer.Event),
NioServer.Listener.tcpDataReceived(NioServer.Event), and
NioServer.Listener.tcpReadyToWrite(NioServer.Event)
events.
public java.net.SocketAddress getLocalSocketAddress()
Returns the local address/port to which this connection is bound. That is, if you are listening on port 80, then this might return something like an InetSocketAddress (probably) that indicated /127.0.0.1:80.
This is essentially a convenience method for returning the same-name methods from the accKey's channel after checking the type of channel (SocketChannel or DatagramChannel).
public java.net.SocketAddress getRemoteSocketAddress()
Returns the address of the endpoint this socket is connected to, or null if it is unconnected.
This is essentially a convenience method for returning the same-name methods from the accKey's channel after checking the type of channel (SocketChannel or DatagramChannel).
public boolean isTcp()
getKey().channel() instanceof SocketChannel.
public boolean isUdp()
getKey().channel() instanceof DatagramChannel.
public void setNotifyOnTcpWritable(boolean notify)
evt.getNioServer().setNotifyOnWritable(evt.getKey(), notify);.
notify - whether or not to provide notifications.public void closeAfterWriting()
evt.getNioServer().closeAfterWriting(evt.getKey());.
public void close()
throws java.io.IOException
evt.getKey().channel().close().
java.io.IOException
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||