Package org.protelis.test.infrastructure
Class CachingNetworkManager
java.lang.Object
org.protelis.test.infrastructure.CachingNetworkManager
- All Implemented Interfaces:
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 -
Method Summary
Modifier and TypeMethodDescriptionCalled byProtelisVMduring execution to collect the most recent information available from neighbors.External access to sending cache.voidreceiveFromNeighbor(org.protelis.lang.datatype.DeviceUID neighbor, Map<org.protelis.vm.CodePath, Object> message) External access to put messages into the received messages cache.voidremoveNeighbor(org.protelis.lang.datatype.DeviceUID neighbor) External access to note when a device is no longer a neighbor, wiping cache.voidshareState(Map<org.protelis.vm.CodePath, Object> toSend) Called byProtelisVMduring execution to send its current shared state to neighbors.
-
Constructor Details
-
CachingNetworkManager
public CachingNetworkManager()
-
-
Method Details
-
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- sendermessage- 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, getNeighborState()Object>> Called byProtelisVMduring 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:
getNeighborStatein interfaceorg.protelis.vm.NetworkManager- Returns:
- A map associating each neighbor with its shared state. The object
returned should not be modified, and
ProtelisVMwill not change it either.
-