The Java API provides high throughput connection to the kernel and is ideal for Java applications.

Setup

The use of the Java API is enabled from the kernel configuration file config.xml (aion/config/config.xml). The active attribute must be set to "true" before starting the kernel to allow the API to interact with the Aion network through the local kernel.

<api>
  <java active="true" ip="127.0.0.1" port="8547"></java>
  <!-- other API settings -->
</api>

Dependencies

An application interacting with the Aion kernel through the Java API must include the following jar dependencies:

  • modAionBase.jar
  • modAionApi-[version].jar

The modAionBase.jar contains the classes in modAionBase. The jar can be found in the mod folder delivered with every kernel release, or it can be compiled from the sources available online inside the module.

The latest release for modAionApi-[version].jar is available online in the aion_api project. Alternatively, the file can be created by compiling the source files.

Use

To use the Java API in an application, first the IAionAPI object must be initialized. Then a connection must be established to a kernel, as shown below:

// connect to Java API
IAionAPI api = IAionAPI.init();
ApiMsg apiMsg = api.connect(IAionAPI.LOCALHOST_URL);

// failed connection
if (apiMsg.isError()) {
    System.out.format("Could not connect due to <%s>%n", apiMsg.getErrString());
    System.exit(-1);
}

// code to use API
// ...

// disconnect from api  
api.destroyApi();

If the kernel is running on the same machine as the application using the API, the connection is established through the call:

api.connect(IAionAPI.LOCALHOST_URL);

Otherwise, the host and port where the kernel is running must be passed as parameters, for example, assuming the IP is 123.123.123.123 and the port is 4567:

api.connect("tcp://123.123.123.123:4567");