Class CachingNetworkManager

java.lang.Object
org.protelis.test.infrastructure.CachingNetworkManager
All Implemented Interfaces:
org.protelis.vm.NetworkManager

public class CachingNetworkManager extends Object implements org.protelis.vm.NetworkManager
Abstraction of networking used by the virtual machine: at each execution round, the VM needs to be able to access the most recent state received from neighbors and to be able to update the state that it is exporting to neighbors.

Note, however, that there is no requirement that state actually be sent or received in each round: it is up to the individual implementation of a NetworkManager to best optimize to best trade off between effective state sharing and efficiency.

This implementation just tracks the most recent message sent from this device and the most recent messages received from each neighbor.

  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    Map<org.protelis.lang.datatype.DeviceUID,Map<org.protelis.vm.CodePath,Object>>
    Called by ProtelisVM during execution to collect the most recent information available from neighbors.
    Map<org.protelis.vm.CodePath,Object>
    External access to sending cache.
    void
    receiveFromNeighbor(org.protelis.lang.datatype.DeviceUID neighbor, Map<org.protelis.vm.CodePath,Object> message)
    External access to put messages into the received messages cache.
    void
    removeNeighbor(org.protelis.lang.datatype.DeviceUID neighbor)
    External access to note when a device is no longer a neighbor, wiping cache.
    void
    shareState(Map<org.protelis.vm.CodePath,Object> toSend)
    Called by ProtelisVM during execution to send its current shared state to neighbors.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • CachingNetworkManager

      public CachingNetworkManager()
  • Method Details

    • getSendCache

      public Map<org.protelis.vm.CodePath,Object> getSendCache()
      External access to sending cache.
      Returns:
      cache
    • receiveFromNeighbor

      public void receiveFromNeighbor(org.protelis.lang.datatype.DeviceUID neighbor, Map<org.protelis.vm.CodePath,Object> message)
      External access to put messages into the received messages cache.
      Parameters:
      neighbor - sender
      message - message to be received
    • removeNeighbor

      public void removeNeighbor(org.protelis.lang.datatype.DeviceUID neighbor)
      External access to note when a device is no longer a neighbor, wiping cache.
      Parameters:
      neighbor - to be removed
    • getNeighborState

      public Map<org.protelis.lang.datatype.DeviceUID,Map<org.protelis.vm.CodePath,Object>> getNeighborState()
      Called by ProtelisVM during execution to collect the most recent information available from neighbors. The call is serial within the execution, so this should probably poll state maintained by a separate thread, rather than gathering state during this call.
      Specified by:
      getNeighborState in interface org.protelis.vm.NetworkManager
      Returns:
      A map associating each neighbor with its shared state. The object returned should not be modified, and ProtelisVM will not change it either.
    • shareState

      public void shareState(Map<org.protelis.vm.CodePath,Object> toSend)
      Called by ProtelisVM during execution to send its current shared state to neighbors. The call is serial within the execution, so this should probably queue up a message to be sent, rather than actually carrying out a lengthy operation during this call.
      Specified by:
      shareState in interface org.protelis.vm.NetworkManager
      Parameters:
      toSend - Shared state to be transmitted to neighbors.