|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectspread.SpreadConnection
public class 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();
Nested Class Summary | |
---|---|
private class |
SpreadConnection.Listener
|
Field Summary | |
---|---|
private static int |
ACCEPT_SESSION
|
private java.net.InetAddress |
address
|
protected java.util.Vector |
advancedListeners
|
private java.lang.String |
authClassName
|
private java.lang.reflect.Method |
authMethodAuthenticate
|
private java.lang.String |
authName
|
private java.lang.Object |
authObj
|
protected java.util.Vector |
basicListeners
|
private static java.lang.Object |
BUFFER_ADD_ADVANCED
|
private static java.lang.Object |
BUFFER_ADD_BASIC
|
private static java.lang.Object |
BUFFER_DISCONNECT
|
private static java.lang.Object |
BUFFER_REMOVE_ADVANCED
|
private static java.lang.Object |
BUFFER_REMOVE_BASIC
|
private boolean |
callingListeners
|
private boolean |
connected
|
private static java.lang.String |
DEFAULT_AUTH_NAME
|
private static java.lang.String |
DEFAULT_AUTHCLASS_NAME
|
private static int |
DEFAULT_SPREAD_PORT
|
private static int |
ENDIAN_TYPE
|
private SpreadGroup |
group
|
private boolean |
groupMembership
|
private SpreadConnection.Listener |
listener
|
private java.util.Vector |
listenerBuffer
|
private java.lang.Boolean |
listenersynchro
|
private static int |
MAX_AUTH_METHODS
|
private static int |
MAX_AUTH_NAME
|
protected static int |
MAX_GROUP_NAME
|
private static int |
MAX_MESSAGE_LENGTH
|
private static int |
MAX_PRIVATE_NAME
|
private int |
port
|
private boolean |
priority
|
private java.lang.Boolean |
rsynchro
|
private java.net.Socket |
socket
|
private java.io.InputStream |
socketInput
|
private java.io.OutputStream |
socketOutput
|
private static int |
SP_MAJOR_VERSION
|
private static int |
SP_MINOR_VERSION
|
private static int |
SP_PATCH_VERSION
|
private java.lang.Boolean |
wsynchro
|
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. |
private void |
checkAccept()
|
private void |
checkVersion()
|
private static int |
clearEndian(int i)
|
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. |
protected static int |
flip(int i)
|
private static short |
flip(short s)
|
SpreadGroup |
getPrivateGroup()
Gets the private group for this connection. |
private void |
instantiateAuthMethod()
|
private SpreadMessage |
internal_receive()
|
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. |
private void |
readAuthMethods()
|
private void |
readBytesFromSocket(byte[] buffer,
java.lang.String bufferTypeString)
|
private void |
readGroup()
|
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 |
registerAuthentication(java.lang.String authName,
java.lang.String authClassName)
Sets the authentication name and class string for the client side authentication method. |
void |
remove(AdvancedMessageListener listener)
Removes the AdvancedMessageListener from this connection. |
void |
remove(BasicMessageListener listener)
Removes the BasicMessageListener from this connection. |
private static boolean |
sameEndian(int i)
|
private void |
sendAuthMethod()
|
private void |
sendConnect(java.lang.String privateName)
|
private void |
setBufferSizes()
|
private void |
startListener()
|
private void |
stopListener()
|
private static void |
toBytes(int i,
byte[] buffer,
int bufferIndex)
|
private static void |
toBytes(SpreadGroup group,
byte[] buffer,
int bufferIndex)
|
protected SpreadGroup |
toGroup(byte[] buffer,
int bufferIndex)
|
protected static int |
toInt(byte[] buffer,
int bufferIndex)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static final int DEFAULT_SPREAD_PORT
private static final int MAX_PRIVATE_NAME
private static final int MAX_MESSAGE_LENGTH
protected static final int MAX_GROUP_NAME
private static final int SP_MAJOR_VERSION
private static final int SP_MINOR_VERSION
private static final int SP_PATCH_VERSION
private static final java.lang.String DEFAULT_AUTH_NAME
private static final java.lang.String DEFAULT_AUTHCLASS_NAME
private static final int MAX_AUTH_NAME
private static final int MAX_AUTH_METHODS
private static final int ACCEPT_SESSION
private static final int ENDIAN_TYPE
private boolean connected
private java.lang.Boolean rsynchro
private java.lang.Boolean wsynchro
private java.lang.Boolean listenersynchro
private boolean callingListeners
private SpreadConnection.Listener listener
protected java.util.Vector basicListeners
protected java.util.Vector advancedListeners
private java.net.InetAddress address
private int port
private boolean priority
private boolean groupMembership
private java.lang.String authName
private java.lang.String authClassName
private java.lang.Object authObj
private java.lang.reflect.Method authMethodAuthenticate
private java.net.Socket socket
private java.io.InputStream socketInput
private java.io.OutputStream socketOutput
private SpreadGroup group
private java.util.Vector listenerBuffer
private static final java.lang.Object BUFFER_DISCONNECT
private static final java.lang.Object BUFFER_ADD_BASIC
private static final java.lang.Object BUFFER_ADD_ADVANCED
private static final java.lang.Object BUFFER_REMOVE_BASIC
private static final java.lang.Object BUFFER_REMOVE_ADVANCED
Constructor Detail |
---|
public SpreadConnection()
connect(InetAddress, int, String, boolean, boolean)
.
connect(InetAddress, int, String, boolean, boolean)
Method Detail |
---|
private static boolean sameEndian(int i)
private static int clearEndian(int i)
protected static int flip(int i)
private static short flip(short s)
private static void toBytes(SpreadGroup group, byte[] buffer, int bufferIndex)
private static void toBytes(int i, byte[] buffer, int bufferIndex)
protected static int toInt(byte[] buffer, int bufferIndex)
private void readBytesFromSocket(byte[] buffer, java.lang.String bufferTypeString) throws SpreadException
SpreadException
protected SpreadGroup toGroup(byte[] buffer, int bufferIndex)
private void setBufferSizes() throws SpreadException
SpreadException
private void sendConnect(java.lang.String privateName) throws SpreadException
SpreadException
private void readAuthMethods() throws SpreadException
SpreadException
private void sendAuthMethod() throws SpreadException
SpreadException
private void instantiateAuthMethod() throws SpreadException
SpreadException
private void checkAccept() throws SpreadException
SpreadException
private void checkVersion() throws SpreadException
SpreadException
private void readGroup() throws SpreadException
SpreadException
public void registerAuthentication(java.lang.String authName, java.lang.String authClassName) throws SpreadException
connect(InetAddress, int, String, boolean, boolean)
is called.
authName
- the short official "name" of the method begin registered.authClassName
- the complete class name for the method (including package)
SpreadException
- if the connection is already establishedpublic 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 connection
SpreadException
- if the connection cannot be establisheddisconnect()
public void disconnect() throws SpreadException
SpreadException
- if there is no connection or there is an error disconnectingconnect(InetAddress, int, String, boolean, boolean)
public SpreadGroup getPrivateGroup()
public SpreadMessage receive() throws SpreadException, java.io.InterruptedIOException
SpreadException
- if there is no connection or there is any error reading a new message
java.io.InterruptedIOException
private SpreadMessage internal_receive() throws SpreadException, java.io.InterruptedIOException
SpreadException
java.io.InterruptedIOException
public SpreadMessage[] receive(int numMessages) throws SpreadException, java.io.InterruptedIOException
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 receive
SpreadException
- if there is no connection or if there is any error reading the messages
java.io.InterruptedIOException
public boolean poll() throws SpreadException
SpreadException
- if there is no connection or if there is an error checking for messagesprivate void startListener()
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)
private void stopListener()
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 multicast
SpreadException
- if there is no connection or if there is any error sending the messagepublic void multicast(SpreadMessage[] messages) throws SpreadException
messages
- the messages to multicast
SpreadException
- if there is no connection or if there is any error sending the messages
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |