org.ccnx.ccn.impl.CCNNetworkChannel Class Reference
This guy manages all of the access to the network connection.
More...
List of all members.
Public Member Functions |
| CCNNetworkChannel (String host, int port, NetworkProtocol proto, FileOutputStream tapStreamIn) throws IOException |
void | open () throws IOException |
| Open the channel to ccnd depending on the protocol, connect on the ccnd port and set up the selector.
|
XMLEncodable | getPacket () throws IOException |
| Get the next packet from the network.
|
void | close () throws IOException |
| Close the channel depending on the protocol.
|
boolean | isConnected () |
| Check whether the channel is currently connected.
|
int | write (ByteBuffer src) throws IOException |
| Write to ccnd using methods based on the protocol type.
|
Selector | wakeup () |
| Force wakeup from a select.
|
void | init () throws IOException |
| Initialize the channel at the point when we are actually ready to create faces with ccnd.
|
int | read () throws IOException |
int | read (byte[] b) throws IOException |
int | read (byte[] b, int off, int len) throws IOException |
boolean | markSupported () |
void | mark (int readlimit) |
void | reset () throws IOException |
boolean | heartbeat () |
Static Public Attributes |
static final int | HEARTBEAT_PERIOD = 3500 |
static final int | SOCKET_TIMEOUT = SystemConfiguration.MEDIUM_TIMEOUT |
static final int | LINGER_TIME = 10 |
Protected Attributes |
final int | _channelId |
final String | _ncHost |
final int | _ncPort |
final NetworkProtocol | _ncProto |
final FileOutputStream | _ncTapStreamIn |
int | _ncLocalPort |
DatagramChannel | _ncDGrmChannel = null |
SocketChannel | _ncSockChannel = null |
Object | _opencloseLock = new Object() |
Selector | _ncReadSelector = null |
Selector | _ncWriteSelector = null |
int | _downDelay = 250 |
Object | _ncConnectedLock = new Object() |
boolean | _ncConnected = false |
boolean | _retry = true |
boolean | _ncInitialized = false |
Timer | _ncHeartBeatTimer = null |
Boolean | _ncStarted = false |
ByteBuffer | _datagram = ByteBuffer.allocateDirect(CCNNetworkManager.MAX_PAYLOAD) |
Static Protected Attributes |
static final AtomicInteger | _channelIdCounter = new AtomicInteger(0) |
Detailed Description
This guy manages all of the access to the network connection.
It is capable of supporting both UDP and TCP transport protocols
It also creates a stream interface for input to the decoders. It is necessary to create our own input stream for TCP because the stream that can be obtained via the socket interface is not markable. Originally the UDP code used to translate the UDP input data into a ByteArrayInputStream after reading it in, but we now an use the same input stream for both transports.
Member Function Documentation
void org.ccnx.ccn.impl.CCNNetworkChannel.close |
( |
|
) |
throws IOException |
Close the channel depending on the protocol.
- Exceptions:
-
XMLEncodable org.ccnx.ccn.impl.CCNNetworkChannel.getPacket |
( |
|
) |
throws IOException |
Get the next packet from the network.
It could be either an interest or data. If ccnd is down this is where we do a sleep to avoid a busy wait. We go ahead and try to read in the initial data here also because if there isn't any we want to find out here, not in the middle of thinking we might be able to decode something. Also since this is supposed to happen on packet boundaries, we reset the data buffer to its start during the initial read. We only do the initial read if there's nothing already in the buffer though because in TCP we could have read in some or all of a preceding packet during the last reading.
Also it should be noted that we are relying on ccnd to guarantee that all packets sent to us are complete ccn packets. This code does not have the ability to recover from receiving a partial ccn packet followed by correctly formed ones.
- Returns:
- a ContentObject, an Interest, or null if there's no data waiting
- Exceptions:
-
boolean org.ccnx.ccn.impl.CCNNetworkChannel.heartbeat |
( |
|
) |
|
- Returns:
- true if heartbeat sent
void org.ccnx.ccn.impl.CCNNetworkChannel.init |
( |
|
) |
throws IOException |
Initialize the channel at the point when we are actually ready to create faces with ccnd.
- Exceptions:
-
boolean org.ccnx.ccn.impl.CCNNetworkChannel.isConnected |
( |
|
) |
|
Check whether the channel is currently connected.
This is really a test to see whether ccnd is running. If it isn't the channel is not connected.
- Returns:
- true if connected
void org.ccnx.ccn.impl.CCNNetworkChannel.open |
( |
|
) |
throws IOException |
Open the channel to ccnd depending on the protocol, connect on the ccnd port and set up the selector.
- Exceptions:
-
Selector org.ccnx.ccn.impl.CCNNetworkChannel.wakeup |
( |
|
) |
|
Force wakeup from a select.
- Returns:
- the selector
int org.ccnx.ccn.impl.CCNNetworkChannel.write |
( |
ByteBuffer |
src |
) |
throws IOException |
Write to ccnd using methods based on the protocol type.
- Parameters:
-
| src | - ByteBuffer to write |
- Returns:
- - number of bytes written
- Exceptions:
-
The documentation for this class was generated from the following file:
- src/org/ccnx/ccn/impl/CCNNetworkChannel.java