All Packages Class Hierarchy This Package Previous Next Index
Class iBus.layers.TCP
java.lang.Object
|
+----iBus.ProtocolObject
|
+----iBus.layers.TCP
- public class TCP
- extends ProtocolObject
TCP: TCP protocol object
TCP is used for push and pull communication via a point-to-point
TCP link
PARAMETERS:
-
bufsize: int: >= 0. Size (in bytes) of the TCP output buffer. bufsize=0
turns buffering off. If bufsize is > 0 then a JDK BufferedOutputStream
is used. Note that data will be delivered only when the buffer is full
to its limit. You can force the delivery of any buffered
data by calling dnFlush() on the TCP protocol object. For example:
((TCP)stack.getProtocolObject("TCP")).dnFlush();
For high throughput we recommend setting bufsize to 65535
Default: 0.
-
listenerconnect: int: 0/1. If set to 0, then the subscribe operation
will open a server socket and accept() connections on it. If set to 1,
then subscribe will open a client socket and establish a TCP connection.
Default: 0.
-
talkerconnect: int: 0/1. If set to 0, then the registerTalker operation
will open a server socket and accept() connections on it. If set to 1,
then registerTalker will open a client socket and establish a TCP
connection. Default: 1.
-
Consider two peer applications, A and B. If A has
listenerconnect=1 then
B *must* have talkerconnect=0, and vice versa. If A has
talkerconnect=1 then B *must* have listenerconnect=0, and vice versa.
(A may have both talkerconnect and listenerconnect set to 1, granted
that B has talkerconnect and listenerconnect set to 0.)
POSITION IN STACK:
-
Typically the sole object in a stack. No NAK nor any membership object
is allowed.
USAGE:
-
Only point-to-point URLs are allowed, for example
"ibus://warp.tectec.com:8999/foo".
-
You typically run the listener application on the host that is specified
in the URL, e.g., on warp.tectec.com. The listener subscribes to
"ibus://warp.tectec.com:8999/foo", which opens a TCP server socket and
a thread is spawned that listens for connection requests. (If your
firewall set up demands that subscribe connects instead of
listening, then specify the listenerconnect=1 parameter).
-
You typically call registerTalker with a URL containing the address of
the destination host, e.g., "ibus://warp.tectec.com:8999/foo".
A TCP connection is established to that destination. (If your
firewall set up demands that registerTalker listens instead of
connecting, then specify the talkerconnect=0 parameter).
-
this protocol object supports the following communication modes:
One talker and one listener, one talker and many listeners, many talkers
and one listener.
-
For many talkers and one listener (the default). Assuming the listener
runs on warp.tectec.com: run the listener on host warp and subscribe it
to ibus://warp.tectec.com:8999/foo. Run the talkers anywhere you want and
register them with ibus://warp.tectec.com:8999/foo.
For one talker and many listeners. Assuming the listener
runs on warp.tectec.com: initialize the protocol object with
"TCP(listenerconnect=1,talkerconnect=0)". Run the talker on host warp
and register it with ibus://warp.tectec.com:8999/foo. Run the listeners
anywhere you want and subscribe them to ibus://warp.tectec.com:8999/foo.
DESIGN:
-
dnSubscribe creates a TCP_Listener object and puts it into the
listeners_ Hashtable. dnRegisterTalker creates a TCP_Talker object
and puts it into the talkers_ Hashtable.
-
TCP_Talker and TCP_Listener
are subclasses of TCP_Endpoint. A TCP_Endpoint maintains
a list of local subscriptions. After the last subscription is
removed, the endpoint is closed. An endpoint either initiates a connection
or accepts() incoming connections.
EVENTS PRODUCED:
-
MessageEvent when a posting is received
EVENTS HANDLED:
EVENTS CONSUMED:
THREADS:
-
for "localhost" URLs a thread is spawned that listens for connection
requests (TCP_Endpoint.run).
-
for subscribe requests: a thread is spawned that receives events
on that connection (TCP_ListenerThread.run).
-
bufSize_
-
-
log_
-
-
TCP()
- Create an TCP protocol object
-
checkThrottle()
- Called by TCP_ListenerThread.run to suspend reception of further
messages when the event queue of the stack is full.
-
createInputStream(InputStream)
- Factory method for input stream creation.
-
createOutputStream(OutputStream)
- Factory method for output stream creation.
-
dnFlush()
- Flush the protocol object.
-
dnGetStackURL()
- Called by the API protocol object to obtain an URL used
to reply to this stack.
-
dnInit()
- Initialize the protocol object after the protocol stack is
created.
-
dnPull(iBusURL, MessageEvent)
- Called by the object above to issue a blocking pull request.
-
dnPullReply(MessageEvent, PullContext, MessageEvent)
- Reply to a pull request.
-
dnPush(iBusURL, MessageEvent)
- Called by the object above to send a message to a channel by
multicast or unicast communication, depending on the channel URL:
-
dnRegisterTalker(iBusURL)
- Called by the object above or by an iBus application to register
as a talker for a channel.
-
dnSubscribe(iBusURL)
- Called by the object above to subscribe to a channel.
-
dnTerminate()
- Terminate any threads in the protocol object.
-
dnThrottle(boolean)
- The stack is getting overloaded.
-
dnUnregisterTalker(iBusURL)
- Called by the object above or by an iBus application to unregister
as a talker from a channel.
-
dnUnsubscribe(iBusURL)
- Called by the object above or by an iBus application to unsubscribe
from a certain channel.
bufSize_
protected static int bufSize_
log_
protected static final Log log_
TCP
public TCP()
- Create an TCP protocol object
dnInit
public void dnInit()
- Initialize the protocol object after the protocol stack is
created. Also checks whether the right parameters were given to the
protocol object.
- Overrides:
- dnInit in class ProtocolObject
dnFlush
public void dnFlush()
- Flush the protocol object. Deliver any buffered messages, call
flush on any output streams.
- Overrides:
- dnFlush in class ProtocolObject
dnTerminate
public void dnTerminate()
- Terminate any threads in the protocol object.
- Overrides:
- dnTerminate in class ProtocolObject
dnPush
public void dnPush(iBusURL channel,
MessageEvent msg) throws CommException, NotRegistered
- Called by the object above to send a message to a channel by
multicast or unicast communication, depending on the channel URL:
- Parameters:
- channel - the destination channel of the posting
- msg - the message to be sent
- Throws: CommException
- on communication failure
- Throws: NotRegistered
- in case registerTalker was not called for
the channel
- Overrides:
- dnPush in class ProtocolObject
dnPull
public synchronized MessageEvent[] dnPull(iBusURL channel,
MessageEvent msg) throws CommException, NotRegistered
- Called by the object above to issue a blocking pull request.
- Parameters:
- channel - the destination channel of the posting
- msg - the request message to be sent
- Returns:
- an array of zero or more reply messages
- Throws: CommException
- on communication failure
- Throws: NotRegistered
- in case registerTalker was not called for
the channel
- Overrides:
- dnPull in class ProtocolObject
dnPullReply
public void dnPullReply(MessageEvent reply,
PullContext pctx,
MessageEvent request) throws CommException
- Reply to a pull request.
- Parameters:
- reply - the reply message to return
- pctx - the context of the associated pull request
- request - the request message
- Throws: CommException
- on communication failure
- Overrides:
- dnPullReply in class ProtocolObject
dnSubscribe
public synchronized void dnSubscribe(iBusURL channel) throws AlreadySubscribed, CommException
- Called by the object above to subscribe to a channel.
- Parameters:
- channel - the channel to subscribe to
- Throws: AlreadySubscribed
- if this stack is already
subscribed to the channel
- Throws: CommException
- in case of a communication
error
- Overrides:
- dnSubscribe in class ProtocolObject
dnUnsubscribe
public synchronized void dnUnsubscribe(iBusURL channel) throws NotSubscribed, CommException
- Called by the object above or by an iBus application to unsubscribe
from a certain channel.
- Parameters:
- channel - the channel to unsubscribe from
- Throws: NotSubscribed
- if this stack is not subscribed
to the channel
- Throws: CommException
- in case of a communication
error
- Overrides:
- dnUnsubscribe in class ProtocolObject
dnRegisterTalker
public synchronized void dnRegisterTalker(iBusURL channel) throws AlreadyRegistered, CommException
- Called by the object above or by an iBus application to register
as a talker for a channel.
- Parameters:
- channel - the channel to register for
- Throws: AlreadyRegistered
- if this stack is already
registered for the channel
- Throws: CommException
- in case of a communication
error
- Overrides:
- dnRegisterTalker in class ProtocolObject
dnUnregisterTalker
public synchronized void dnUnregisterTalker(iBusURL channel) throws NotRegistered, CommException
- Called by the object above or by an iBus application to unregister
as a talker from a channel.
- Parameters:
- channel - the channel to unregister from
- Throws: NotRegistered
- if this stack is not
registered with the channel
- Throws: CommException
- in case of a communication
error
- Overrides:
- dnUnregisterTalker in class ProtocolObject
checkThrottle
protected void checkThrottle()
- Called by TCP_ListenerThread.run to suspend reception of further
messages when the event queue of the stack is full.
NOTE: a deadlock occurs if this method is tagged synchronized,
and both client and server are in the same JVM.
dnGetStackURL
public synchronized iBusURL dnGetStackURL()
- Called by the API protocol object to obtain an URL used
to reply to this stack. dnGetStackURL is typically implemented by the
bottommost protocol object only.
- Returns:
- the URL of the stack
- Overrides:
- dnGetStackURL in class ProtocolObject
dnThrottle
public synchronized void dnThrottle(boolean stop)
- The stack is getting overloaded. Tell the senders to slow
down the rate at which they send messages to us.
- Parameters:
- stop - true if throttling is required, false if unthrottling
is required.
- Overrides:
- dnThrottle in class ProtocolObject
createOutputStream
protected static OutputStream createOutputStream(OutputStream os)
- Factory method for output stream creation.
- Parameters:
- os - the low level output stream to write to
- Returns:
- the output stream to use
createInputStream
protected static InputStream createInputStream(InputStream is)
- Factory method for input stream creation.
- Parameters:
- is - the low level input stream to read from
- Returns:
- the input stream to use
All Packages Class Hierarchy This Package Previous Next Index