|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.iperg.part.core.IpConnection
public abstract class IpConnection
The IpConnection
class is the super class of all
protocol specific connection classes. Connections are
bi-directional communications channels that can be set up between
pairs of IPerG processes. Once a connection has been established,
it can be used to send events back and forth between the processes.
Field Summary | |
---|---|
static int |
BROKEN
A connection mode that means that the connection does not work properly for some reason, for instance due to a network error or the remote process having crashed. |
static int |
CLOSED_LOCALLY
A connection mode that means that the connection has been closed by the local process. |
static int |
CLOSED_REMOTELY
A connection mode that means that the connection has been closed by the remote process. |
static int |
CONNECTED
A connection status mode which means that the connection object has been successfully connected to a remote address via a call to connect or as a result of accepting an incoming
connection after having called listen . |
static int |
CONNECTING
A connection status mode which means that a connection to a remote process is in progress but not yet finished. |
static int |
LISTEN
A connection mode that means that the connection object is listening for incoming connections on a local address as a result of the listen method being called. |
static int |
UNCONNECTED
A connection status mode that means that the connection object has not yet been connected to a local or remote address using the listen or connect methods. |
Constructor Summary | |
---|---|
protected |
IpConnection(int status)
Create a new connection object. |
Method Summary | |
---|---|
protected abstract boolean |
_outgoingEventsAreCached()
Check if events sent via the send method are cached locally. |
protected void |
_send(IpNetworkEvent event)
Method that does the actual work of sending data to the network. |
protected abstract void |
close()
Method to be implemented by sub-classes. |
IpUrl |
getConnectionUrl()
Get url that can be used to connect to the local address monitored by this connection, assuming that the listen method has been called on the connection
object. |
IpIdentifier |
getRemoteProcessId()
Get the identifier of the remote process to which this connection object is connected |
long |
getSilence()
Get time (in milliseconds) since any data was last received using this connection. |
int |
getStatus()
Get the current connection status mode. |
int |
getTotalBytesReceived()
Return the number of bytes that has been received on this connection since it was created. |
int |
getTotalBytesSent()
Return the number of bytes that has been sent on this connection since it was created. |
IpUrl |
getUrl()
Get url used to create the connection that this object represents |
protected void |
notifyBrokenConnection()
Should be called by protocol specific connection subclasses when this connection has been broken. |
protected void |
notifyBytesReceived(int nrOfBytes)
Should be called by sub-classes to report that data has been received from the network. |
protected void |
notifyBytesSent(int nrOfBytes)
Should be called by sub-classes to report that data has been sent to the network. |
protected void |
notifyReceivedEvent(IpNetworkEvent event)
Should be called by protocol specific connection subclasses when an event has been received on this connection. |
protected abstract IpConnection |
protoAccept()
Accept an incoming connection |
protected abstract void |
protoConnect(IpUrl url)
Method to be implemented by sub-classes. |
protected abstract IpUrl |
protoListen(IpUrl url)
Method to be implemented by sub-classes. |
void |
run()
Connection thread's run method which checks for incoming connections if connection is in "listen mode", receives data chunks if the connection is in "connected mode", or performs connect if mode is "connecting". |
protected void |
setInputStream(java.io.InputStream in)
Set stream to be used for reading incoming network data. |
protected void |
setOutputStream(java.io.OutputStream out)
Set stream to be used for writing outgoing network data. |
protected void |
setUrl(IpUrl url)
Set url used to create the connection that this object represents |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int UNCONNECTED
listen
or connect
methods.
public static final int CONNECTING
public static final int CONNECTED
connect
or as a result of accepting an incoming
connection after having called listen
.
public static final int LISTEN
listen
method being called.
public static final int CLOSED_LOCALLY
public static final int CLOSED_REMOTELY
public static final int BROKEN
Constructor Detail |
---|
protected IpConnection(int status)
status
- The current status of the connection objectMethod Detail |
---|
public void run()
run
in interface java.lang.Runnable
protected abstract void protoConnect(IpUrl url) throws IpInvalidUrlException, java.io.IOException
url
- The url that specifies where to connect
IpInvalidUrlException
- if the url doesn't specify a
valid connection address
java.io.IOException
- if a protocol specific error occuredprotected abstract IpUrl protoListen(IpUrl url) throws IpInvalidUrlException, java.io.IOException
url
- A url specifying a local address
IpInvalidUrlException
- if the url doesn't identify a
local address
java.io.IOException
- if a protocol specific error occuredprotected abstract IpConnection protoAccept() throws java.io.IOException
java.io.IOException
public IpUrl getUrl()
protected void setUrl(IpUrl url)
protected void setOutputStream(java.io.OutputStream out)
protected void setInputStream(java.io.InputStream in)
public IpIdentifier getRemoteProcessId()
public IpUrl getConnectionUrl()
listen
method has been called on the connection
object.
null
otherwisepublic long getSilence()
public int getStatus()
IpConnection.UNCONNECTED IpConnection.CONNECTING IpConnection.CONNECTED IpConnection.LISTEN IpConnection.CLOSED IpConnection.BROKEN
protected void _send(IpNetworkEvent event) throws java.io.IOException
event
- The event to send
java.io.IOException
- if a protocol specific error occuredprotected void notifyBrokenConnection()
protected void notifyBytesSent(int nrOfBytes)
nrOfBytes
- The number of data bytes that was sentpublic int getTotalBytesSent()
protected void notifyBytesReceived(int nrOfBytes)
nrOfBytes
- The number of data bytes that was receivedpublic int getTotalBytesReceived()
protected void notifyReceivedEvent(IpNetworkEvent event)
event
- The event that was receivedprotected abstract void close() throws java.io.IOException
java.io.IOException
- if the close failed for some reasonprotected abstract boolean _outgoingEventsAreCached()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |