|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.util.EventObject
edu.nps.moves.disutil.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 FormField 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 | |
---|---|
java.nio.ByteBuffer |
getBuffer()
Returns the ByteBuffer that contains
the 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.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 buffer,
java.net.SocketAddress remoteUdp)
Resets an event between firings by updating the parameters that change. |
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 eventMethod Detail |
---|
public NioServer getNioServer()
NioServer
.
Shorthand for (NioServer)getSource().
public NioServer.State getState()
NioServer.State
public java.nio.channels.SelectionKey getKey()
protected void reset(java.nio.channels.SelectionKey key, java.nio.ByteBuffer buffer, java.net.SocketAddress remoteUdp)
key
- The SelectionKey for the eventbuffer
- remoteUdp
- the remote UDP source or null for TCPpublic java.nio.ByteBuffer getBuffer()
Returns the ByteBuffer
that contains
the 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.
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 buffer's position at the beginning of the second line. In this way, The beginning of the second line will be the start of the buffer the next time around.
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 key'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 key'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
.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |