public interface Network
Node
, the most basic form.Component
, used to expose callbacks to user code.Connector
, used for consuming of producing energy.Visibility
.
Note that network access in general is not thread safe! Networks
should only be accessed from the main server thread. The exception are the
connector nodes, which can be used to consume or produce energy from other
threads.
IMPORTANT: do *not* implement this interface yourself and create
instances of your own network implementation; this will lead to
incompatibilities with the built-in network implementation (which can only
merge with other networks of its own type). Always use the methods provided
in Network
to create and join networks.Modifier and Type | Method and Description |
---|---|
boolean |
connect(Node nodeA,
Node nodeB)
Adds a new node connection in the network.
|
boolean |
disconnect(Node nodeA,
Node nodeB)
Removes a node connection in the network.
|
java.lang.Iterable<Node> |
neighbors(Node node)
The list of nodes the specified node is directly connected to.
|
Node |
node(java.lang.String address)
Get the network node with the specified address.
|
java.lang.Iterable<Node> |
nodes()
The list of all nodes in this network.
|
java.lang.Iterable<Node> |
nodes(Node reference)
The list of addressed nodes in the network reachable by the specified node.
|
boolean |
remove(Node node)
Removes a node from the network.
|
void |
sendToAddress(Node source,
java.lang.String target,
java.lang.String name,
java.lang.Object... data)
Sends a message to the node with the specified address.
|
void |
sendToNeighbors(Node source,
java.lang.String name,
java.lang.Object... data)
Sends a message to all addressed, visible neighbors of the source node.
|
void |
sendToReachable(Node source,
java.lang.String name,
java.lang.Object... data)
Sends a message to all addressed nodes reachable to the source node.
|
void |
sendToVisible(Node source,
java.lang.String name,
java.lang.Object... data)
Sends a message to all addressed nodes visible to the source node.
|
boolean connect(Node nodeA, Node nodeB)
nodeA
- the first node.nodeB
- the second node.java.lang.IllegalArgumentException
- if neither node is in this network.boolean disconnect(Node nodeA, Node nodeB)
nodeA
- the first node.nodeB
- the second node.java.lang.IllegalArgumentException
- if the nodes are not in this network.boolean remove(Node node)
TileEntity.invalidate()
) or unloaded
(e.g. in TileEntity.onChunkUnload()
).
Removing the node can lead to one or more new networks if it was the a
bridge node, i.e. the only node connecting the resulting networks.node
- the node to remove from the network.Node node(java.lang.String address)
address
- the address of the node to get.java.lang.Iterable<Node> nodes()
java.lang.Iterable<Node> nodes(Node reference)
reference
- the node to get the visible other nodes for.java.lang.Iterable<Node> neighbors(Node node)
node
- the node to get the neighbors for.java.lang.IllegalArgumentException
- if the specified node is not in this network.void sendToAddress(Node source, java.lang.String target, java.lang.String name, java.lang.Object... data)
source
- the node that sends the message.target
- the id of the node to send the message to.name
- the name of the message.data
- the message to send.java.lang.IllegalArgumentException
- if the source node is not in this network.void sendToNeighbors(Node source, java.lang.String name, java.lang.Object... data)
neighbors(Node)
and additionally
filtered for reachability (so that unreachable nodes are ignored).
Messages should have a unique name to allow differentiating them when
handling them in a network node. For example, computers will try to parse
messages named computer.signal by converting the message data to
a signal and inject that signal into the machine, so no message not used
for this purpose should be named computer.signal.source
- the node that sends the message.name
- the name of the message.data
- the message to send.java.lang.IllegalArgumentException
- if the source node is not in this network.neighbors(Node)
void sendToReachable(Node source, java.lang.String name, java.lang.Object... data)
nodes(Node)
.
Messages should have a unique name to allow differentiating them when
handling them in a network node. For example, computers will try to parse
messages named computer.signal by converting the message data to
a signal and inject that signal into the machine, so no message not used
for this purpose should be named computer.signal.source
- the node that sends the message.data
- the message to send.java.lang.IllegalArgumentException
- if the source node is not in this network.nodes(Node)
void sendToVisible(Node source, java.lang.String name, java.lang.Object... data)
nodes(Node)
and additionally
filtered for visibility (so that invisible nodes are ignored).
Note that messages sent this way are only delivered to other
components. The message will not be delivered to normal nodes.
Messages should have a unique name to allow differentiating them when
handling them in a network node. For example, computers will try to parse
messages named computer.signal by converting the message data to
a signal and inject that signal into the machine, so no message not used
for this purpose should be named computer.signal.source
- the node that sends the message.data
- the message to send.java.lang.IllegalArgumentException
- if the source node is not in this network.nodes(Node)
,
Component.canBeSeenFrom(Node)