public class MultiPeer
extends java.lang.Object
Example of use:
public class MultiPeerTest implements MultiPeerListener {
public void onMessage(Message m) {...}
}
...
MultiPeer mp = new MultiPeer();
MultiPeerTest sensor = new MultiPeerTest();
mp.addGeneralListener(sensor);
mp.send(new MessagePlain("Hola".getBytes()));
...
Modifier and Type | Class and Description |
---|---|
private class |
MultiPeer.PropagationThread
This private thread dequeues received messages and dispatch it to the local listeners.
|
private class |
MultiPeer.ServerThread
This private thread runs forever accepting connections
and creating accepted Destinations in the party.
|
Modifier and Type | Field and Description |
---|---|
private static java.lang.String |
defaultAddressMulticast |
private static int |
defaultPortMulticast |
private static int |
defaultPortServer |
private PeersSet |
destinationsSet |
private java.util.ArrayList<MultiPeerListener> |
generalListeners |
private IPPort |
localServiceIPPort |
private static boolean |
OPTION_SENDBYPROXY |
private static boolean |
OPTION_SYNCCLOCKS |
private QueueMessage |
receivedMessages |
private java.net.ServerSocket |
servSock |
private java.util.HashMap<Message.MessageType,java.util.ArrayList<MultiPeerListener>> |
specificListeners |
Constructor and Description |
---|
MultiPeer()
Create a default "MultiPeer" object (default "initialPort" and multicast discovering channel).
|
MultiPeer(int initialPort)
Create a customized "MultiPeer" object with the default multicast discovering channel.
|
MultiPeer(int initialPort,
java.lang.String ipMulticast,
int portMulticast)
Create a customized "MultiPeer" object calling the initialization method..
|
Modifier and Type | Method and Description |
---|---|
boolean |
addDestination(IPPort ipp)
Adds a destination suitable to "connect" to it.
|
boolean |
addDestination(java.net.Socket sock)
Add a destination "accepted" by the "ServerThread".
|
void |
addGeneralListener(MultiPeerListener obj)
Add a "MultiPeerListener" that will be called-back for all message types.
|
void |
addSpecificListener(Message.MessageType type,
MultiPeerListener obj)
Add a "MultiPeerListener" that will be called-back only when arrives
a message of a specific type.
|
Destination |
getDestinationByIPPort(IPPort ipp) |
IPPort |
getLocalIPPort() |
Destination |
getLocalLeader() |
Destination |
getNetworkLeader()
From the peers in the party, get "local" and "global" (network) leader attending to the IPPort ordering criteria.
|
void |
InitMultiPeer(int initialPort,
java.lang.String ipMulticast,
int portMulticast)
MultiPeer initialization procedure.
|
boolean |
isDestinationContained(IPPort ipp) |
void |
OnMessage(Message m)
Callback generated by "Destinations" when a message arrives.
|
private void |
propagateNewConection(Destination dest)
Propagate the new connection to listeners (callback)
|
private void |
propagateNewMessage(Message m)
Propagate the new message to listeners (callback)
|
void |
removeDestination(Destination dest)
Remove a destination from the party.
|
void |
removeGeneralListener(MultiPeerListener obj) |
void |
removeSpecificListener(Message.MessageType type,
MultiPeerListener obj) |
Destination[] |
send(Destination[] destArray,
Message m)
Send a Message to a subset of peers in the party.
|
void |
send(Message m)
Send a Message to ALL peers in the party.
|
private Destination[] |
sendByProxyPeersSet(Message m,
PeersSet pSet)
Auxiliary method to send a message to an arbitrary "PeersSet"
using the "ProxyManager" service.
|
private Destination[] |
sendDirectPeersSet(Message m,
PeersSet pSet)
Auxiliary method to send a message to an arbitrary "PeersSet" directly.
|
private boolean |
setServerSocket()
Create the server socket used in "ServerThread" to accept connections.
|
private static java.lang.String defaultAddressMulticast
private static int defaultPortMulticast
private static int defaultPortServer
private PeersSet destinationsSet
private java.util.ArrayList<MultiPeerListener> generalListeners
private IPPort localServiceIPPort
private static boolean OPTION_SENDBYPROXY
private static boolean OPTION_SYNCCLOCKS
private QueueMessage receivedMessages
private java.net.ServerSocket servSock
private java.util.HashMap<Message.MessageType,java.util.ArrayList<MultiPeerListener>> specificListeners
public MultiPeer()
public MultiPeer(int initialPort)
initialPort
- (int) is the intended port to accept connections.public MultiPeer(int initialPort, java.lang.String ipMulticast, int portMulticast)
initialPort
- (int) is the intended local port to accept connections.ipMulticast
- (String) is the IP for the multicast discovering service.portMulticast
- (int) is the port for the multicast discovering service.public boolean addDestination(IPPort ipp)
ipp
- The destination IPPort.public boolean addDestination(java.net.Socket sock)
sock
- public void addGeneralListener(MultiPeerListener obj)
obj
- public void addSpecificListener(Message.MessageType type, MultiPeerListener obj)
type
- obj
- public Destination getDestinationByIPPort(IPPort ipp)
public IPPort getLocalIPPort()
public Destination getLocalLeader()
public Destination getNetworkLeader()
public void InitMultiPeer(int initialPort, java.lang.String ipMulticast, int portMulticast)
initialPort
- (int) is the intended local port to accept connections.ipMulticast
- (String) is the IP for the multicast discovering service.portMulticast
- (int) is the port for the multicast discovering service.public boolean isDestinationContained(IPPort ipp)
ipp
- public void OnMessage(Message m)
m
- private void propagateNewConection(Destination dest)
dest
- private void propagateNewMessage(Message m)
m
- public void removeDestination(Destination dest)
dest
- public void removeGeneralListener(MultiPeerListener obj)
public void removeSpecificListener(Message.MessageType type, MultiPeerListener obj)
public Destination[] send(Destination[] destArray, Message m)
m
- public void send(Message m)
m
- private Destination[] sendByProxyPeersSet(Message m, PeersSet pSet)
m
- pSet
- private Destination[] sendDirectPeersSet(Message m, PeersSet pSet)
m
- pSet
- private boolean setServerSocket()