|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectpeerbase.Node
public class Node
This is the primary class for the PeerBase peer-to-peer development system. It maintains this node's information (id, host, port), a list of known peers, list of message handlers, and a handler for routing data through the P2P network.
Constructor Summary | |
---|---|
Node(int port)
Initialize this node with no limit on the size of the peer list and set up to listen for incoming connections on the specified port. |
|
Node(int maxPeers,
PeerInfo info)
Initialize this node with the given info and the specified limit on the size of the peer list. |
Method Summary | |
---|---|
void |
addHandler(java.lang.String msgtype,
HandlerInterface handler)
|
boolean |
addPeer(PeerInfo pd)
|
boolean |
addPeer(java.lang.String key,
PeerInfo pd)
Add new peer information to the peer list, indexed by the given key. |
void |
addRouter(RouterInterface router)
|
java.util.List<PeerMessage> |
connectAndSend(PeerInfo pd,
java.lang.String msgtype,
java.lang.String msgdata,
boolean waitreply)
Connects to the specified peer and sends a message, optionally waiting and returning any replies. |
java.lang.String |
getHost()
|
java.lang.String |
getId()
|
int |
getMaxPeers()
|
int |
getNumberOfPeers()
|
PeerInfo |
getPeer(java.lang.String key)
|
java.util.Set<java.lang.String> |
getPeerKeys()
|
int |
getPort()
|
void |
mainLoop()
Starts the loop which is the primary operation of the Node. |
java.net.ServerSocket |
makeServerSocket(int port)
Create a socket to listen for incoming connections. |
java.net.ServerSocket |
makeServerSocket(int port,
int backlog)
Create a socket to listen for incoming connections. |
boolean |
maxPeersReached()
|
PeerInfo |
removePeer(java.lang.String key)
|
java.util.List<PeerMessage> |
sendToPeer(java.lang.String peerid,
java.lang.String msgtype,
java.lang.String msgdata,
boolean waitreply)
Attempts to route and send a message to the specified peer, optionally waiting and returning any replies. |
void |
startStabilizer(StabilizerInterface st,
int delay)
Starts a "stabilizer" function running at the specified interval. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Node(int maxPeers, PeerInfo info)
maxPeers
- the maximum size of the peer list (0 means 'no limit')info
- the id and host/port information for this nodepublic Node(int port)
Method Detail |
---|
public java.net.ServerSocket makeServerSocket(int port) throws java.io.IOException
port
- the port number to listen on, or 0 to use any free port
java.io.IOException
- if error occurspublic java.net.ServerSocket makeServerSocket(int port, int backlog) throws java.io.IOException
port
- the port number to listen on, or 0 to use any free portbacklog
- he maximum length of the queue
java.io.IOException
- if error occurspublic java.util.List<PeerMessage> sendToPeer(java.lang.String peerid, java.lang.String msgtype, java.lang.String msgdata, boolean waitreply)
peerid
- the destination peer identifiermsgtype
- the type of the message being sendmsgdata
- the message datawaitreply
- whether to wait for reply(ies)
public java.util.List<PeerMessage> connectAndSend(PeerInfo pd, java.lang.String msgtype, java.lang.String msgdata, boolean waitreply)
pd
- the peer informationmsgtype
- the type of the message being sendmsgdata
- the message datawaitreply
- whether to wait for reply(ies)
public void mainLoop()
public void startStabilizer(StabilizerInterface st, int delay)
st
- the stabilizer function objectdelay
- the delay (in milliseconds)public void addHandler(java.lang.String msgtype, HandlerInterface handler)
public void addRouter(RouterInterface router)
public boolean addPeer(PeerInfo pd)
public boolean addPeer(java.lang.String key, PeerInfo pd)
key
- the key associated with the peerpd
- the peer information
public PeerInfo getPeer(java.lang.String key)
public PeerInfo removePeer(java.lang.String key)
public java.util.Set<java.lang.String> getPeerKeys()
public int getNumberOfPeers()
public int getMaxPeers()
public boolean maxPeersReached()
public java.lang.String getId()
public java.lang.String getHost()
public int getPort()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |