public abstract class AbstractNetworkChannel extends Object implements NetworkChannel
| Modifier and Type | Field and Description |
|---|---|
protected DatagramChannel |
dataChannel |
protected SelectionKey |
selectionKey |
| Constructor and Description |
|---|
AbstractNetworkChannel(NetworkGuard guard) |
| Modifier and Type | Method and Description |
|---|---|
void |
bind(InetSocketAddress address)
Binds the channel to an address.
|
void |
close()
Disconnects and closes the channel.
Invoking this method will have no effect if the channel is already closed. |
void |
connect(InetSocketAddress address)
Connects the channel to a remote peer.
The channel will only be able to accept traffic from that peer. |
void |
disconnect()
Disconnect the channel
|
InetSocketAddress |
getLocalAddress()
Gets the address the channel is bound to.
|
InetSocketAddress |
getRemoteAddress()
Gets the address of the remote peer this channel is connected to.
|
boolean |
isConnected()
Gets whether channel is connected or not.
|
boolean |
isOpen()
Gets whether channel is open or not.
|
boolean |
isRegistered()
Gets whether channel is registered in a Selector.
|
protected abstract org.apache.log4j.Logger |
log() |
protected abstract void |
onIncomingPacket(byte[] data,
InetSocketAddress remotePeer) |
void |
open()
Opens the channel.
|
void |
receive()
Receives incoming data.
|
void |
register(Selector selector,
int opts)
Registers this channel into a selector for multiplexing purposes.
|
void |
send(byte[] data)
Sends data to the remote peer.
|
void |
send(byte[] data,
InetSocketAddress remotePeer)
Send data through the channel.
|
void |
send(ByteBuffer data,
InetSocketAddress remotePeer)
Send data through the channel.
|
protected SelectionKey selectionKey
protected DatagramChannel dataChannel
public AbstractNetworkChannel(NetworkGuard guard)
public void bind(InetSocketAddress address) throws IOException
NetworkChannelbind in interface NetworkChanneladdress - the address the channel will be bounds toIOException - In case the channel is closed or could not be bound.public void open()
throws IOException
NetworkChannelopen in interface NetworkChannelIOException - If the channel is already open or if it could not be opened.public void close()
NetworkChannelclose in interface AutoCloseableclose in interface NetworkChannelpublic void register(Selector selector, int opts) throws ClosedChannelException
NetworkChannelregister in interface NetworkChannelselector - The selector where the channel will be registered.ClosedChannelException - If the channel is closedpublic void connect(InetSocketAddress address) throws IOException
NetworkChannelconnect in interface NetworkChanneladdress - The address of the remote peer to connect toIOExceptionpublic void disconnect()
throws IOException
NetworkChanneldisconnect in interface NetworkChannelIOExceptionpublic InetSocketAddress getLocalAddress()
NetworkChannelgetLocalAddress in interface NetworkChannelpublic InetSocketAddress getRemoteAddress()
NetworkChannelgetRemoteAddress in interface NetworkChannelpublic boolean isOpen()
NetworkChannelisOpen in interface NetworkChanneltrue if the channel is open. Otherwise, returns false.public boolean isConnected()
NetworkChannelisConnected in interface NetworkChanneltrue if the channel is connected. Otherwise, returns false.public boolean isRegistered()
NetworkChannelisRegistered in interface NetworkChanneltrue if the channel is registered. Otherwise, returns false.public void receive()
throws IOException
NetworkChannelreceive in interface NetworkChannelIOExceptionpublic void send(byte[] data)
throws IOException
NetworkChannelsend in interface NetworkChanneldata - The data to be sent.IOExceptionpublic void send(byte[] data,
InetSocketAddress remotePeer)
throws IOException
NetworkChannelsend in interface NetworkChanneldata - The data to be sent.remotePeer - The address of the remote peer.IOExceptionpublic void send(ByteBuffer data, InetSocketAddress remotePeer) throws IOException
NetworkChannelsend in interface NetworkChanneldata - The data to be sent.remotePeer - The address of the remote peer.IOExceptionprotected abstract void onIncomingPacket(byte[] data,
InetSocketAddress remotePeer)
protected abstract org.apache.log4j.Logger log()
Copyright © 2017 TeleStax, Inc.. All Rights Reserved.