|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.eclipse.ecf.provider.datashare.nio.NIOChannel
public abstract class NIOChannel
An abstract implementation of IChannel
that uses Java 1.4 NIO
APIs for sending and retrieving data.
This channel will inherently spawn multiple socket connections as messages
are sent to different remote clients via sendMessage(ID, byte[])
.
Please note that the current implementation does not handle repeated
invocations to that method well. Please refer to its javadoc for further
information.
Subclasses must implement the following:
Note: This class/interface is part of an interim API that is still under development and expected to change significantly before reaching stability. It is being made available at this early stage to solicit feedback from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken (repeatedly) as the API evolves.
Constructor Summary | |
---|---|
NIOChannel(NIODatashareContainer datashareContainer,
ID containerId,
ID id,
IChannelListener listener)
Instantiates a new channel for sending and receiving messages in a non-blocking manner via sockets. |
Method Summary | |
---|---|
void |
dispose()
Disposes of this channel. |
java.lang.Object |
getAdapter(java.lang.Class adapter)
|
protected int |
getBackLog()
Retrieves the listen backlog length of this channel's server socket. |
protected java.net.SocketAddress |
getBindAddress()
Returns the address that this channel's server socket should bind to. |
ID |
getID()
Return the ID for this 'identifiable' object. |
IChannelListener |
getListener()
Get IChannelListener instance for this IAbstractChannel |
protected int |
getLocalPort()
Returns the port that is currently open for incoming socket connections. |
protected abstract void |
log(org.eclipse.core.runtime.IStatus status)
|
void |
sendMessage(byte[] message)
Send message to remote instances of this channel |
void |
sendMessage(ID receiver,
byte[] message)
Sends a message to a remote instance of this channel of the target peer. |
protected abstract void |
sendRequest(ID receiver)
Sends a request to the receiver to notify them that a socket is open and waiting for incoming connections to establish a channel connection. |
IChannelListener |
setListener(IChannelListener listener)
Set listener to new IChannelListener instance |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public NIOChannel(NIODatashareContainer datashareContainer, ID containerId, ID id, IChannelListener listener) throws ECFException
datashareContainer
- the source NIODatashareContainer that created this channel,
cannot be null
containerId
- the id of the originating owner container, this should
not be the id of the datashare container that created
this channel but the parent container of the datashare
container, may not be null
id
- the id of this channel, may not be null
listener
- the channel listener for this channel, may be
null
if no notification is required
ECFException
- if an error occurred while creating this channelMethod Detail |
---|
protected abstract void log(org.eclipse.core.runtime.IStatus status)
protected java.net.SocketAddress getBindAddress()
null
, a default port and valid local address will be used.
null
if a default should be usedprotected int getBackLog()
protected final int getLocalPort()
sendRequest(ID)
,
NIODatashareContainer.enqueue(SocketAddress)
protected abstract void sendRequest(ID receiver) throws ECFException
This method will be invoked when a socket corresponding to the receiver's ID cannot be found.
receiver
- the receiver to contact, will not be null
ECFException
- if an error occurred while attempting to send the requestgetLocalPort()
,
NIODatashareContainer.enqueue(SocketAddress)
public void sendMessage(byte[] message) throws ECFException
IChannel
sendMessage
in interface IChannel
message
- the byte [] message to send. Must not be null
.
ECFException
- if some problem sending messagepublic void sendMessage(ID receiver, byte[] message) throws ECFException
Note: The current implementation does not handle repeated
invocations of this method in succession prior to a socket connection
established. For optimal performance and some assurance of success, there
needs to be a time lag between the first message that is sent and the
ones that follow it. This lag should hopefully allow the provider
sufficient time for establishing a socket connection with the remote
peer. Otherwise, there may be multiple invocations of
sendRequest(ID)
and clients are responsible for handling this
individually.
sendMessage
in interface IChannel
receiver
- the receiver to send the message to, must not be
null
message
- the message to send, must not be null
ECFException
- if some problem sending messagepublic void dispose()
super.dispose()
before the
method returns.
dispose
in interface IAbstractChannel
public IChannelListener getListener()
IAbstractChannel
getListener
in interface IAbstractChannel
null
, the channel has no listener.public IChannelListener setListener(IChannelListener listener)
IAbstractChannel
setListener
in interface IAbstractChannel
listener
- the new listener to set for this channel. If null, then there
will be no new listener for this channel.
public java.lang.Object getAdapter(java.lang.Class adapter)
getAdapter
in interface org.eclipse.core.runtime.IAdaptable
public ID getID()
IIdentifiable
null
.
getID
in interface IIdentifiable
null
.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |