public interface PeerInterface
This interface define the low-level communication layer for the HyperGraphDB P2P framework. Implementations can use any transport and any presence model they wish.
The interface has some factory methods that allow implementers to decide how to create and allocate objects.
Modifier and Type | Method and Description |
---|---|
void |
addPeerPresenceListener(NetworkPeerPresenceListener listener) |
void |
broadcast(Json msg)
Broadcast a message to all members of this peer's group.
|
void |
configure(Json configuration)
Because implementors can be of any type, the configuration is an Object, no constraints
to impose here as there is no common set of configuration properties.
|
HyperGraphPeer |
getThisPeer()
Return the
HyperGraphPeer to which this PeerInterface
is bound. |
boolean |
isConnected()
Return
true if we are currently connected to the network
and false otherwise. |
PeerFilter |
newFilterActivity(PeerFilterEvaluator evaluator) |
PeerRelatedActivityFactory |
newSendActivityFactory() |
void |
removePeerPresenceListener(NetworkPeerPresenceListener listener) |
java.util.concurrent.Future<java.lang.Boolean> |
send(java.lang.Object networkTarget,
Json msg)
Send a message to a specific peer as identified by the
networkTarget parameter. |
void |
setMessageHandler(MessageHandler messageHandler)
The
MessageHandler is responsible for processing messages coming through
the PeerInterface . |
void |
setThisPeer(HyperGraphPeer thisPeer)
Internally used to initialize the
PeerInterface , don't call in
application code. |
void |
start()
Establish a connection with other peers and make one's presence in the network
known.
|
void |
stop()
Disconnect from the P2P network.
|
void setMessageHandler(MessageHandler messageHandler)
The MessageHandler
is responsible for processing messages coming through
the PeerInterface
. The PeerInterface
merely handles transport
duties, but it delegates the logic for message handling elsewhere. In the HyperGraphDB P2P
framework, that elsewhere is the ActivityManager
.
message
- void configure(Json configuration)
configuration
- A JSON-like structure holding the network-level configuration parameters.java.lang.RuntimeException
- This method may throw an unchecked exception if the configuration
is not correct.void start()
Establish a connection with other peers and make one's presence in the network known.
boolean isConnected()
Return true
if we are currently connected to the network
and false
otherwise. Because presence is negotiated asynchronously,
a connection doesn't imply that all peers are already known.
void stop()
Disconnect from the P2P network. No more messages are going to be received or sent.
HyperGraphPeer getThisPeer()
Return the HyperGraphPeer
to which this PeerInterface
is bound.
void setThisPeer(HyperGraphPeer thisPeer)
Internally used to initialize the PeerInterface
, don't call in
application code. Implementation should maintain a HyperGraphPeer
member variable and return it in the getThisPeer
method.
PeerFilter newFilterActivity(PeerFilterEvaluator evaluator)
PeerRelatedActivityFactory newSendActivityFactory()
void broadcast(Json msg)
Broadcast a message to all members of this peer's group.
msg
- java.util.concurrent.Future<java.lang.Boolean> send(java.lang.Object networkTarget, Json msg)
Send a message to a specific peer as identified by the
networkTarget
parameter.
networkTarget
- msg
- void addPeerPresenceListener(NetworkPeerPresenceListener listener)
void removePeerPresenceListener(NetworkPeerPresenceListener listener)