Java Scripts

Scripts are written in pure Java and, thus, may access all resources of the machine Iotellect Server is running on, including:

  • Any in-memory objects

  • File system

  • Network and serial I/O

  • Console, logging, and even GUI

  • Multithreaded processing

Scripts are executed in the server JVM, and their permissions are not restricted in any way. See Script Security for more information.

Script Interface

Scripts are written in Java. Every script is a single Java class that must implement a Script interface:

public interface FunctionImplementation
{
DataTable execute(Context con, FunctionDefinition def, CallerController caller, RequestController request, DataTable parameters) throws ContextException;
}

This interface declares a single execute() method that is called by Iotellect Server when a script is executed.

Developing Scripts

See Programming Guidelines section for common practices of developing Iotellect server scripts.

Script Template

When a new script is created, its text is not empty. It contains an auto-generated stub of a class implementing Script interface with an empty execute() method. Here is the default script text:

import com.tibbo.aggregate.common.context.*;
import com.tibbo.aggregate.common.datatable.*;
import com.tibbo.aggregate.common.server.*;
import com.tibbo.linkserver.*;
import com.tibbo.linkserver.context.*;
public class %ScriptClassNamePattern% implements FunctionImplementation
{
public DataTable execute(Context con, FunctionDefinition def, CallerController caller, RequestController request, DataTable parameters) throws ContextException
{
return null;
}
}

Note, that %ScriptClassNamePattern% will be replaced by an auto-generated Java class name during compilation. Do not change this part of the script to avoid compilation problems.

After you've put some meaningful code inside the body of execute() method, you may try to execute a script. Note, that script is re-compiled by Java compiler upon every execution. Any compilation errors are reported to the user. See description of the Execute action for more information.

Script Example

Here is an example of a Java script that changes IP address of a device:

import com.tibbo.aggregate.common.context.CallerController;
import com.tibbo.aggregate.common.context.Context;
import com.tibbo.aggregate.common.context.ContextException;
import com.tibbo.aggregate.common.context.FunctionDefinition;
import com.tibbo.aggregate.common.context.FunctionImplementation;
import com.tibbo.aggregate.common.context.RequestController;
import com.tibbo.aggregate.common.datatable.DataTable;

public class %ScriptClassNamePattern% implements FunctionImplementation
{
public DataTable execute(Context con, FunctionDefinition def, CallerController caller, RequestController request, DataTable parameters) throws ContextException
{
// Getting IP address
DataTable val = con.getVariable("IP_setting", caller);

// Changing IP address
val.rec().setValue("IP_setting", "192.168.1.235");

// Writing new value of variable
con.setVariable("IP_setting", caller, val);

// Rebooting Device Server
con.callFunction("reboot", caller);

return null;
}
}

Was this page helpful?