@Retention(value=RUNTIME)
@Target(value=METHOD)
public @interface Callback
Environment
to mark
them for exposure to computers.
Any method exposed like this can be enumerated and called from a computer
that can see the node of the environment.
Note that methods annotated with this interface must have the following
signature:
Object[] f(Context context, Arguments arguments) throws Exception;The method may return null in case it doesn't wish return anything, which is functionally equivalent to returning an empty array. To raise an error from your callback, simply throw an exception. The convention for Lua is to return (null, "reason") for 'soft' errors, i.e. errors that are no fault of the caller. For example, passing invalid arguments will generate an exception, requesting information and the lookup of said information failing should not.
Modifier and Type | Optional Element and Description |
---|---|
boolean |
direct
Whether this function may be called directly from the computer's executor
thread instead of from the server thread.
|
java.lang.String |
doc
A documentation string that is made available to the computers the
component this callback belongs to is connected to.
|
boolean |
getter
Whether this callback should work like a getter.
|
int |
limit
The maximum number of direct calls that may be performed on this
component in a single tick on a tier two computer.
|
boolean |
setter
Whether this callback should work like a setter.
|
java.lang.String |
value
The name under which to make the callback available.
|
public abstract java.lang.String value
public abstract boolean direct
Network
is not thread safe!
Be sure you know what you're doing if you're working with a node's
network in a direct callback.
An exception to that rule is Connector.changeBuffer(double)
,
which is synchronized, so you can consume/produce power in direct calls.public abstract int limit
Component.invoke(String, Context, Object...)
from the host side. Also, this limit is per-computer, so the method may
be invoked more often than this per tick, if different computers call it.
Note that the interpretation of this value changed a bit in OC 1.4.
Before, it was the actual number of calls that could be performed on
the component per tick. Now it's more of a general cost value: for each
direct call a computer makes, 1/limit is subtracted from the
computer's call budget. This budget may vary between computers, for
example, tier three computers have a higher call budget than tier two
computers.public abstract java.lang.String doc
public abstract boolean getter
public abstract boolean setter