|
||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--spread.SpreadConnection
A SpreadConnection object is used to establish a connection to a spread daemon.
To connect to a spread daemon, first create a new SpreadConnection object, and then
call connect(InetAddress, int, String, boolean, boolean)
:
SpreadConnection connection = new SpreadConnection(); connection.connect(null, 0, "name", false, false);
The only methods that can be called before
connect(InetAddress, int, String, boolean, boolean)
are the add
(add(BasicMessageListener)
, add(AdvancedMessageListener)
)
and remove (remove(BasicMessageListener)
, remove(AdvancedMessageListener)
)
methods. If any other methods are called, a SpreadException is thrown, except for
getPrivateGroup()
, which returns null.
To disconnect from the daemon, call disconnect()
:
connection.disconnect();
To send a message on this connection, call multicast(SpreadMessage)
:
connection.multicast(message);
To receive a message sent to this connection, call receive()
:
SpreadMessage message = connection.receive();
Constructor Summary | |
SpreadConnection()
Initializes a new SpreadConnection object. |
Method Summary | |
void |
add(AdvancedMessageListener listener)
Adds the AdvancedMessageListener to this connection. |
void |
add(BasicMessageListener listener)
Adds the BasicMessageListener to this connection. |
void |
connect(java.net.InetAddress address,
int port,
java.lang.String privateName,
boolean priority,
boolean groupMembership)
Establishes a connection to a spread daemon. |
void |
disconnect()
Disconnects the connection to the daemon. |
SpreadGroup |
getPrivateGroup()
Gets the private group for this connection. |
void |
multicast(SpreadMessage message)
Multicasts a message. |
void |
multicast(SpreadMessage[] messages)
Multicasts an array of messages. |
boolean |
poll()
Returns true if there are any messages waiting on this connection. |
SpreadMessage |
receive()
Receives the next message waiting on this connection. |
SpreadMessage[] |
receive(int numMessages)
Receives numMessages messages on the connection and returns them in an array. |
void |
remove(AdvancedMessageListener listener)
Removes the AdvancedMessageListener from this connection. |
void |
remove(BasicMessageListener listener)
Removes the BasicMessageListener from this connection. |
Methods inherited from class java.lang.Object |
equals,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
Constructor Detail |
public SpreadConnection()
connect(InetAddress, int, String, boolean, boolean)
.connect(InetAddress, int, String, boolean, boolean)
Method Detail |
public void connect(java.net.InetAddress address, int port, java.lang.String privateName, boolean priority, boolean groupMembership) throws SpreadException
address
- the daemon's address, or null to connect to the localhostport
- the daemon's port, or 0 for the default port (4803)privateName
- the private name to use for this connectionpriority
- if true, this is a priority connectiongroupMembership
- if true, membership messages will be received on this connectiondisconnect()
public void disconnect() throws SpreadException
connect(InetAddress, int, String, boolean, boolean)
public SpreadGroup getPrivateGroup()
public SpreadMessage receive() throws SpreadException
public SpreadMessage[] receive(int numMessages) throws SpreadException
numMessages
messages on the connection and returns them in an array.
If there are not numMessages
messages waiting, the call will block until there are
enough messages available.numMessages
- the number of messages to receivepublic boolean poll() throws SpreadException
public void add(BasicMessageListener listener)
BasicMessageListener.messageReceived(SpreadMessage)
will
be called every time a message is received.listener
- a BasicMessageListener to add to this connectionremove(BasicMessageListener)
public void add(AdvancedMessageListener listener)
AdvancedMessageListener.regularMessageReceived(SpreadMessage)
will
be called every time a regular message is received, and
AdvancedMessageListener.membershipMessageReceived(SpreadMessage)
will be called every time
a membership message is received.listener
- an AdvancedMessageListener to add to this connectionremove(AdvancedMessageListener)
public void remove(BasicMessageListener listener)
listener
- the listener to removeadd(BasicMessageListener)
public void remove(AdvancedMessageListener listener)
listener
- the listener to removeadd(AdvancedMessageListener)
public void multicast(SpreadMessage message) throws SpreadException
message
- the message to multicastpublic void multicast(SpreadMessage[] messages) throws SpreadException
messages
- the messages to multicast
|
||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |