|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectca.mcgill.cs.postina.scribe.ScribeNetworkLayer
public class ScribeNetworkLayer
| Field Summary | |
|---|---|
protected static PostinaTopic |
BROADCAST_TOPIC
The string representing the topic to which all nodes have to subscribe to enable broadcasting. |
private java.util.LinkedList<PostinaClientListener> |
clientListenersToNetworkLayer
|
protected rice.environment.Environment |
env
The environment in Pastry. |
private boolean |
isConnected
The boolean indicates if the node is connected to the
network. |
private static org.apache.log4j.Logger |
logger
|
private java.util.Collection<PostinaMessage> |
messageQueue
The message queue where incoming PostinaMessages can be placed. |
private java.util.ArrayList<PostinaMsgListener> |
msgListenersToNetworkLayer
The list of PostinaMsgListeners registered to the application. |
protected rice.pastry.transport.TLPastryNode |
node
The representation of the node in the Pastry network. |
protected PostinaID |
nodeID
The PostinaID uniquely identifying the node. |
protected rice.pastry.commonapi.PastryIdFactory |
pastryIdFactory
The PastryIdFactory is used to create the Id of the
TLPastryNode representing this application in the P2P-network. |
protected ScribeApplication |
scribeApp
The ScribeApplication keeps a reference to the
ScribeApplication that is, it is the linking point to the
P2P-network. |
private java.util.Hashtable<java.lang.String,PostinaTopic> |
topics
The Hashtable topics maps the string representation of
topics to the corresponding PostinaTopic. |
| Constructor Summary | |
|---|---|
ScribeNetworkLayer()
The default constructor to prepare the application. |
|
| Method Summary | |
|---|---|
void |
addClientListener(PostinaClientListener listener)
This method registers a listener to changes in the client structure. |
void |
addMsgListener(PostinaMsgListener listener)
Registers a listener to messages being delivered. |
void |
broadcast(java.io.Serializable content)
This method broadcasts a serializable, that is it all clients in the network will receive this message. |
void |
clientLeft(PostinaID clientID)
The method clientLeft is called when a client has left or is supposed to have left the network. |
PostinaID |
connect()
Connects to the P2P-network and initializes the node. |
PostinaID |
connect(java.net.InetAddress bindAddress,
int bindport,
java.util.Collection<java.net.InetSocketAddress> bootAddresses)
This method is an alternative to the other connect method to
specify all configuration parameters as an argument, which is especially
important for the localBindAddress. |
PostinaID |
connect(int bindport,
java.util.Collection<java.net.InetSocketAddress> bootAddresses)
Connects to the P2P-network and initializes the node. |
void |
disconnect()
Disconnects the node from the P2P-network. |
PostinaID |
getID()
Gets the PostinaID of the current client. |
PostinaMessage |
getNextMessage()
Gets the next message in the queue. |
PostinaTopic |
getTopic(java.lang.String topicName)
Gets the PostinaTopic for a given string name of a topic. |
boolean |
isConnected()
This method checks if the node is connected to the network. |
void |
publish(PostinaTopic topic,
java.io.Serializable content)
Publishes a message to a PostinaTopic. |
void |
publish(java.lang.String topicName,
java.io.Serializable content)
Publishes a message to the topic identified by a string. |
void |
receiveMessage(PostinaMessage msg)
receiveMessage is called to inform applications about a new PostinaMessage. |
void |
removeClientListener(PostinaClientListener listener)
This method unregisters a listener to changes in the client structure. |
void |
removeMsgListener(PostinaMsgListener listener)
Removes a listener, that is this listener will not be informed about any future messages. |
void |
send(PostinaID destination,
java.io.Serializable content)
Sends a message directly to the client identified by the PostinaID. |
void |
sendReliable(PostinaID destination,
java.io.Serializable content)
|
void |
subscribe(java.util.Collection<PostinaTopic> topics)
Subscribes the current client to the Collection of
PostinaTopics. |
void |
subscribe(PostinaTopic topic)
Subscribes the current client to a PostinaTopic. |
void |
subscribe(java.lang.String topicName)
Subscribes the current client to the topic identified by a string. |
void |
subscribeOther(java.util.Collection<PostinaTopic> topics,
PostinaID client)
Subscribes the client specified by the PostinaID to a
Collection of PostinaTopics. |
void |
subscribeOther(PostinaTopic topic,
PostinaID client)
Subscribes the client specified by the PostinaID to a
PostinaTopic. |
void |
subscribeOther(java.lang.String topicName,
PostinaID client)
Subscribes the client specified by the PostinaID to the
topic identified by the string. |
void |
unsubscribe(java.util.Collection<PostinaTopic> topics)
Unsubscribes the current client from the Collection of
PostinaTopics. |
void |
unsubscribe(PostinaTopic topic)
Unsubscribes the current client from the PostinaTopic. |
void |
unsubscribe(java.lang.String topicName)
Unsubscribes the current client from the topic identified by the given string. |
void |
unsubscribeOther(java.util.Collection<PostinaTopic> topics,
PostinaID client)
Unsubscribes the client specified by the PostinaID from a
Collectionof PostinaTopics. |
void |
unsubscribeOther(PostinaTopic topic,
PostinaID client)
Unsubscribes the client specified by the PostinaID to a
PostinaTopic. |
void |
unsubscribeOther(java.lang.String topicName,
PostinaID client)
Unsubscribes the client specified by the PostinaID from
the topic identified by the string. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected static PostinaTopic BROADCAST_TOPIC
private static final org.apache.log4j.Logger logger
private final java.util.LinkedList<PostinaClientListener> clientListenersToNetworkLayer
protected rice.environment.Environment env
private boolean isConnected
boolean indicates if the node is connected to the
network.
private final java.util.Collection<PostinaMessage> messageQueue
PostinaMessages can be placed.
If there are any listeners registered, the queue is deactivated.
private final java.util.ArrayList<PostinaMsgListener> msgListenersToNetworkLayer
PostinaMsgListeners registered to the application.
protected rice.pastry.transport.TLPastryNode node
protected PostinaID nodeID
PostinaID uniquely identifying the node.
protected rice.pastry.commonapi.PastryIdFactory pastryIdFactory
PastryIdFactory is used to create the Id of the
TLPastryNode representing this application in the P2P-network.
protected ScribeApplication scribeApp
ScribeApplication keeps a reference to the
ScribeApplication that is, it is the linking point to the
P2P-network.
private final java.util.Hashtable<java.lang.String,PostinaTopic> topics
Hashtable topics maps the string representation of
topics to the corresponding PostinaTopic. The first time a topic
is used, it is added to the hashtable. On further uses, the topic is
taken from the hashtable. This avoids unnecessary creations of
PostinaTopics.
| Constructor Detail |
|---|
public ScribeNetworkLayer()
| Method Detail |
|---|
public void addClientListener(PostinaClientListener listener)
PostinaNetworkLayer
addClientListener in interface PostinaNetworkLayerlistener - The listener registering.public void addMsgListener(PostinaMsgListener listener)
PostinaNetworkLayer
addMsgListener in interface PostinaNetworkLayerlistener - The PostinaMsgListener registering as a
listener.
public void broadcast(java.io.Serializable content)
throws PostinaNotConnectedException
PostinaNetworkLayer
broadcast in interface PostinaNetworkLayercontent - The serializable that has to be broadcasted.
PostinaNotConnectedException - If the node is not connected to the network, an exception is
thrown.public void clientLeft(PostinaID clientID)
PostinaClientListener
clientLeft in interface PostinaClientListenerclientID - The unique identifier of the client that has quit the network.
public PostinaID connect()
throws PostinaJoinFailedException,
PostinaAlreadyConnectedException
PostinaNetworkLayerconnect(bindport,bootAddresses).
connect in interface PostinaNetworkLayerPostinaID of the node.
PostinaJoinFailedException
PostinaAlreadyConnectedException - If a connected client tries to connect a second time, an
exception is thrown.
public PostinaID connect(java.net.InetAddress bindAddress,
int bindport,
java.util.Collection<java.net.InetSocketAddress> bootAddresses)
throws PostinaJoinFailedException,
PostinaAlreadyConnectedException
PostinaNetworkLayerconnect method to
specify all configuration parameters as an argument, which is especially
important for the localBindAddress. This is useful when the application
is run on a computer having multiple network interfaces (i.e. multiple
network addresses), especially for servers. It is the responsibility of
the application using Postina that the chosen interface is visible to
other clients, otherwise Postina will not work.
connect in interface PostinaNetworkLayerbindAddress - The InetAddress to which the node should bind locally.bindport - The port (integer value) the node should bind to locally.bootAddresses - A Collection of InetSocketAddresses
(i.e. IP:Port) indicating bootstrap nodes
PostinaID of the node.
PostinaJoinFailedException - thrown when process of connecting is interrupted
unexpectedly.
PostinaAlreadyConnectedException - If a connected client tries to connect a second time, an
exception is thrown.
public PostinaID connect(int bindport,
java.util.Collection<java.net.InetSocketAddress> bootAddresses)
throws PostinaJoinFailedException,
PostinaAlreadyConnectedException
PostinaNetworkLayer
connect in interface PostinaNetworkLayerbindport - The port (integer value) the node should bind to locally.bootAddresses - A Collection of InetSocketAddresses
(i.e. IP:Port) indicating bootstrap nodes
PostinaID of the node.
PostinaJoinFailedException - thrown when process of connecting is interrupted
unexpectedly.
PostinaAlreadyConnectedException - If a connected client tries to connect a second time, an
exception is thrown.
public void disconnect()
throws PostinaNotConnectedException
PostinaNetworkLayer
disconnect in interface PostinaNetworkLayerPostinaNotConnectedException - If the node is not connected to the network, an exception is
thrown.
public PostinaID getID()
throws PostinaNotConnectedException
PostinaNetworkLayerPostinaID of the current client. Once the
connection is established, this is the only possibility for an
application to get the PostinaID.
getID in interface PostinaNetworkLayerPostinaID of the current client.
PostinaNotConnectedException - If the node is not connected to the network, an exception is
thrown.
public PostinaMessage getNextMessage()
throws PostinaNoQueueException,
PostinaNotConnectedException
PostinaNetworkLayerPostinaNoQueueException is
thrown.
getNextMessage in interface PostinaNetworkLayerPostinaMessage representing the message that
has been published or sent by another client.
PostinaNoQueueException - If there are any listeneres registered to the client, the
queue is deactivated and requests to get next message in the
queue cause an PostinaNoQueueException
exception to be thrown.
PostinaNotConnectedException - If the node is not connected to the network, an exception is
thrown.
public PostinaTopic getTopic(java.lang.String topicName)
throws PostinaNotConnectedException
PostinaNetworkLayerPostinaTopic for a given string name of a topic.
This is the only way for an application to get an
PostinaTopic. The PostinaTopic is used
when issuing (un)subscriptions and publications.
getTopic in interface PostinaNetworkLayertopicName - The string name of the topic.
PostinaTopic representing the given topic.
PostinaNotConnectedException - If the node is not connected to the network, an exception is
thrown.public boolean isConnected()
PostinaNetworkLayer
isConnected in interface PostinaNetworkLayertrue if we are connected.
public void publish(PostinaTopic topic,
java.io.Serializable content)
throws PostinaNotConnectedException
PostinaNetworkLayerPostinaTopic. All clients
subscribed to this topic will get the message. Note that any
Serializable can be published, but subscribers will
receive an PostinaMessage containing the submitted
Serializable.
publish in interface PostinaNetworkLayertopic - The PostinaTopic to which the
Serializable will be published.content - The Serializable to be published.
PostinaNotConnectedException - If the node is not connected to the network, an exception is
thrown.
public void publish(java.lang.String topicName,
java.io.Serializable content)
throws PostinaNotConnectedException
PostinaNetworkLayerpublish(PostinaTopic, Serializable).
publish in interface PostinaNetworkLayertopicName - The string identifying the topic to which the message should
be published.content - The Serializable to be published.
PostinaNotConnectedException - If the node is not connected to the network, an exception is
thrown.public void receiveMessage(PostinaMessage msg)
PostinaMsgListenerPostinaMessage. The same method is used for private (i.e.
direct) messages as well as publications.
receiveMessage in interface PostinaMsgListenermsg - The PostinaMessage that has just arrived and
has to be passed to the application.public void removeClientListener(PostinaClientListener listener)
PostinaNetworkLayer
removeClientListener in interface PostinaNetworkLayerlistener - The listener unregistering.public void removeMsgListener(PostinaMsgListener listener)
PostinaNetworkLayer
removeMsgListener in interface PostinaNetworkLayerlistener - The PostinaMsgListener unregistering.
public void send(PostinaID destination,
java.io.Serializable content)
throws PostinaNotConnectedException
PostinaNetworkLayerPostinaID. Only the client specified receives this
private message. Note that the message will be delivered as a
PostinaMessage.
send in interface PostinaNetworkLayerdestination - The PostinaID uniquely identifying the client
which should receive the private message.content - The Serializable representing the message to be
sent.
PostinaNotConnectedException
public void sendReliable(PostinaID destination,
java.io.Serializable content)
throws PostinaNotConnectedException
sendReliable in interface PostinaNetworkLayerPostinaNotConnectedException
public void subscribe(java.util.Collection<PostinaTopic> topics)
throws PostinaNotConnectedException
PostinaNetworkLayerCollection of
PostinaTopics. This is more efficient than issuing
several separate subscriptions.
subscribe in interface PostinaNetworkLayertopics - The Collection of PostinaTopics
to which the current client subscribes.
PostinaNotConnectedException - If the node is not connected to the network, an exception is
thrown.
public void subscribe(PostinaTopic topic)
throws PostinaNotConnectedException
PostinaNetworkLayerPostinaTopic.
subscribe in interface PostinaNetworkLayertopic - The PostinaTopic to which the client should be
subscribed.
PostinaNotConnectedException - If the node is not connected to the network, an exception is
thrown.
public void subscribe(java.lang.String topicName)
throws PostinaNotConnectedException
PostinaNetworkLayerstring. This is syntactic sugar for
subscribe(PostinaTopic).
subscribe in interface PostinaNetworkLayertopicName - The string identifying the topic to which the current client
subscribes.
PostinaNotConnectedException - If the node is not connected to the network, an exception is
thrown.
public void subscribeOther(java.util.Collection<PostinaTopic> topics,
PostinaID client)
throws PostinaNotConnectedException
PostinaNetworkLayerPostinaID to a
Collection of PostinaTopics. This is more
efficient than issuing several separate subscriptions.
subscribeOther in interface PostinaNetworkLayertopics - The Collection of PostinaTopics
to which the client should subscribe.client - The PostinaID identifying the client which
should be subscribed to the given PostinaTopics.
PostinaNotConnectedException - If the node is not connected to the network, an exception is
thrown.
public void subscribeOther(PostinaTopic topic,
PostinaID client)
throws PostinaNotConnectedException
PostinaNetworkLayerPostinaID to a
PostinaTopic.
subscribeOther in interface PostinaNetworkLayertopic - The PostinaTopic to which the client should be
subscribed.client - The PostinaID identifying the client which
should be subscribed to the given PostinaTopic
PostinaNotConnectedException - If the node is not connected to the network, an exception is
thrown.
public void subscribeOther(java.lang.String topicName,
PostinaID client)
throws PostinaNotConnectedException
PostinaNetworkLayerPostinaID to the
topic identified by the string. This is only syntactic
sugar for subscribeOther(PostinaTopic, PostinaID).
subscribeOther in interface PostinaNetworkLayertopicName - The string identifying the topic to which the
given client should subscribe.client - The PostinaID identifying the client which
should be subscribed to the given topic.
PostinaNotConnectedException - If the node is not connected to the network, an exception is
thrown.
public void unsubscribe(java.util.Collection<PostinaTopic> topics)
throws PostinaNotConnectedException
PostinaNetworkLayerCollection of
PostinaTopics. This is more efficient than issuing
several separate subscriptions.
unsubscribe in interface PostinaNetworkLayertopics - The Collection of PostinaTopics
from which the current client should be unsubscribed.
PostinaNotConnectedException - If the node is not connected to the network, an exception is
thrown.
public void unsubscribe(PostinaTopic topic)
throws PostinaNotConnectedException
PostinaNetworkLayerPostinaTopic.
The client will not get any future publications to this topic. Note that
a subscription is not confirmed as there is no positive feedback.
However, a PostinaSubscribeFailedException is thrown when
the subscription fails.
unsubscribe in interface PostinaNetworkLayertopic - The PostinaTopic from which the client does
have to unsubscribe.
PostinaNotConnectedException - If the node is not connected to the network, an exception is
thrown.
public void unsubscribe(java.lang.String topicName)
throws PostinaNotConnectedException
PostinaNetworkLayerstring. This is syntactic sugar for
unsubscribe(PostinaTopic).
unsubscribe in interface PostinaNetworkLayertopicName - The string identifying the topic from which the
client should unsubscribe.
PostinaNotConnectedException - If the node is not connected to the network, an exception is
thrown.
public void unsubscribeOther(java.util.Collection<PostinaTopic> topics,
PostinaID client)
throws PostinaNotConnectedException
PostinaNetworkLayerPostinaID from a
Collectionof PostinaTopics. This is more
efficient than issuing several separate unsubscriptions.
unsubscribeOther in interface PostinaNetworkLayertopics - The Collection of PostinaTopics
from which the client should be unsubscribed.client - The PostinaID identifying the client which
should be unsubscribed from the given
PostinaTopics.
PostinaNotConnectedException - If the node is not connected to the network, an exception is
thrown.
public void unsubscribeOther(PostinaTopic topic,
PostinaID client)
throws PostinaNotConnectedException
PostinaNetworkLayerPostinaID to a
PostinaTopic.
unsubscribeOther in interface PostinaNetworkLayertopic - The PostinaTopic from which the client should
be unsubscribed.client - The PostinaID identifying the client which
should be unsubscribed from the given
PostinaTopic
PostinaNotConnectedException - If the node is not connected to the network, an exception is
thrown.
public void unsubscribeOther(java.lang.String topicName,
PostinaID client)
throws PostinaNotConnectedException
PostinaNetworkLayerPostinaID from
the topic identified by the string. This is only
syntactic sugar for
unsubscribeOther(PostinaTopic, PostinaID).
unsubscribeOther in interface PostinaNetworkLayertopicName - The string identifying the topic from which the
given client should unsubscribe.client - The PostinaID identifying the client which
should be unsubscribed from the given topic.
PostinaNotConnectedException - If the node is not connected to the network, an exception is
thrown.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||