Class CachingNetworkManager

  • All Implemented Interfaces:
    org.protelis.vm.NetworkManager

    public class CachingNetworkManager
    extends java.lang.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 in order to best trade off between effective state sharing and efficiency. This simple implementation just tracks the most recent message sent from this device and the most recent messages received from each neighbor.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.util.Map<org.protelis.lang.datatype.DeviceUID,​java.util.Map<org.protelis.vm.CodePath,​java.lang.Object>> getNeighborState()
      Called by ProtelisVM during execution to collect the most recent information available from neighbors.
      java.util.Map<org.protelis.vm.CodePath,​java.lang.Object> getSendCache()
      External access to sending cache.
      void receiveFromNeighbor​(org.protelis.lang.datatype.DeviceUID neighbor, java.util.Map<org.protelis.vm.CodePath,​java.lang.Object> message)
      External access to put messages into receive 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​(java.util.Map<org.protelis.vm.CodePath,​java.lang.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 Detail

      • CachingNetworkManager

        public CachingNetworkManager()
    • Method Detail

      • getSendCache

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

        public void receiveFromNeighbor​(org.protelis.lang.datatype.DeviceUID neighbor,
                                        java.util.Map<org.protelis.vm.CodePath,​java.lang.Object> message)
        External access to put messages into receive cache.
        Parameters:
        neighbor - sender
        message - messege 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 java.util.Map<org.protelis.lang.datatype.DeviceUID,​java.util.Map<org.protelis.vm.CodePath,​java.lang.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​(java.util.Map<org.protelis.vm.CodePath,​java.lang.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 operations during this call.
        Specified by:
        shareState in interface org.protelis.vm.NetworkManager
        Parameters:
        toSend - Shared state to be transmitted to neighbors.