public interface Node extends Persistable
Network
.
All nodes in a network have a unique address; the network will generate a
unique address and assign it to new nodes.
Per default there are two kinds of nodes: tile entities and items.
Items will usually only have nodes when in containers, such as a computer or
disk drive. Otherwise you'll have to connect/disconnect them manually as
desired.
All other kinds of nodes you may come up with will also have to be
handled manually.
Items have to be handled by a corresponding Item
.
Existing blocks may be interfaced with the adapter block if a
Block
exists that supports the block.
Important: like the Network interface you must not create
your own implementations of this interface. Use the factory methods in the
network API to create new node instances and store them in your environment.Component
Modifier and Type | Method and Description |
---|---|
java.lang.String |
address()
The address of the node, so that it can be found in the network.
|
boolean |
canBeReachedFrom(Node other)
Checks whether this node can be reached from the specified node.
|
void |
connect(Node node)
Connects the specified node to this node.
|
void |
disconnect(Node node)
Disconnects the specified node from this node.
|
Environment |
host()
The environment hosting this node.
|
boolean |
isNeighborOf(Node other)
Checks whether this node is a neighbor of the specified node.
|
java.lang.Iterable<Node> |
neighbors()
Get the list of neighbor nodes, i.e.
|
Network |
network()
The network this node is currently in.
|
Visibility |
reachability()
The reachability of this node.
|
java.lang.Iterable<Node> |
reachableNodes()
Get the list of nodes reachable from this node, based on their
reachability() . |
void |
remove()
Removes this node from its network.
|
void |
sendToAddress(java.lang.String target,
java.lang.String name,
java.lang.Object... data)
Send a message to a node with the specified address.
|
void |
sendToNeighbors(java.lang.String name,
java.lang.Object... data)
Send a message to all neighbors of this node.
|
void |
sendToReachable(java.lang.String name,
java.lang.Object... data)
Send a message to all nodes reachable from this node.
|
void |
sendToVisible(java.lang.String name,
java.lang.Object... data)
Send a message to all nodes visible from this node.
|
load, save
Environment host()
Environment
this will
be the tile entity. For all other implementations this will be a managed
environment.Visibility reachability()
Component
's visibility, which is
checked before delivering messages a computer tries to send.java.lang.String address()
Network network()
boolean isNeighborOf(Node other)
other
- the node to check for.boolean canBeReachedFrom(Node other)
other
- the node to check for.java.lang.Iterable<Node> neighbors()
java.lang.Iterable<Node> reachableNodes()
reachability()
.
This is a shortcut for node.network.nodes(node).
If this node is not in a network, i.e. network is null,
this returns an empty list.void connect(Node node)
node
- the node to connect to this node.java.lang.NullPointerException
- if network is null.void disconnect(Node node)
node
- the node to connect to this node.java.lang.NullPointerException
- if network is null.void remove()
void sendToAddress(java.lang.String target, java.lang.String name, java.lang.Object... data)
target
- the address of the node to send the message to.name
- the name of the message.data
- the data to pass along with the message.void sendToNeighbors(java.lang.String name, java.lang.Object... data)
name
- the name of the message.data
- the data to pass along with the message.void sendToReachable(java.lang.String name, java.lang.Object... data)
name
- the name of the message.data
- the data to pass along with the message.void sendToVisible(java.lang.String name, java.lang.Object... data)
name
- the name of the message.data
- the data to pass along with the message.