Search in sources :

Example 1 with ResourceFinalStopEvent

use of me.matoosh.undernet.event.resource.push.ResourceFinalStopEvent in project UnderNet by itsMatoosh.

the class ResourceManager method pushForward.

/**
 * Forwards a pushMessage to the next appropriate node.
 * Calls resource stored event if this node is the resource's destination.
 * @param pushMessage
 */
public void pushForward(ResourcePushMessage pushMessage) {
    // Getting the node closest to the resource.
    Node closest = router.neighborNodesManager.getClosestTo(pushMessage.resource.networkID);
    if (closest == Node.self) {
        // This is the final node of the resource.
        EventManager.callEvent(new ResourceFinalStopEvent(pushMessage.resource, pushMessage, null));
    } else {
        logger.info("Pushing resource: " + pushMessage.resource + " to node: " + closest);
        // Calling the onPush method.
        pushMessage.resource.onPush(pushMessage, closest);
        // Sending the push msg.
        closest.send(new NetworkMessage(MsgType.RES_PUSH, pushMessage));
        // Calling event.
        EventManager.callEvent(new ResourcePushSentEvent(pushMessage.resource, pushMessage, closest));
    }
}
Also used : ResourceFinalStopEvent(me.matoosh.undernet.event.resource.push.ResourceFinalStopEvent) Node(me.matoosh.undernet.p2p.node.Node) ResourcePushSentEvent(me.matoosh.undernet.event.resource.push.ResourcePushSentEvent) NetworkMessage(me.matoosh.undernet.p2p.router.data.message.NetworkMessage)

Aggregations

ResourceFinalStopEvent (me.matoosh.undernet.event.resource.push.ResourceFinalStopEvent)1 ResourcePushSentEvent (me.matoosh.undernet.event.resource.push.ResourcePushSentEvent)1 Node (me.matoosh.undernet.p2p.node.Node)1 NetworkMessage (me.matoosh.undernet.p2p.router.data.message.NetworkMessage)1