Previous topic  Top  Next topic  Print this Topic
 

Server Commands

 

You can use the "command.sh" or "command.cmd" script to execute OntoBroker server commands.

Command Client (command.cmd/command.sh)

The command client provides an additional option for specifying a command file:

command.cmd -cf myCommandFile.txt

The file is loaded and the command is executed.

Writing Your Own Commands

External commands can now be added as extension plugins to OntoBroker. Java classes implementing the SimpleAPICommand interface are packaged in a plugin exporting a CommandProvider service and can be used with OntoBroker by deploying the jar file to the extensions directory.

Command class

An external command is implemented as a Java class implementing the interface com.ontoprise.api.command.SimpleAPICommand.

public interface SimpleAPICommand {

  String getCommandName();

  Object execute(OntologyManager ontologyManager, Term[] args) throws KAON2Exception, InterruptedException;

}

 

The comma separated argument list is provided as term array. Typically, a command returns a String, but it can theoretically return any kind of Java object. However, there some restrictions to consider:

If using the method OntologyManager.execute from a collab server client, the returned class must be known to the Collabserver marshaller. This effectively means that only basic Java data types and collections and classes generated by the KAON2Factory can be used in this case.
If the command is executed by the socket protocol or OntoBroker web service the result is always translated into a string by calling toString().

CommandProvider

In additionally to the command class itself you need a CommandProvider service, which announces the command(s) to OntoBroker. Example:

public class CommandProviderImpl implements CommandProvider {

  @Override

  public Collection<Class<? extends APICommand>> getCommands() {

      ArrayList<Class<? extends APICommand>> list = new ArrayList<Class<? extends APICommand>>();

      list.add(MyCommand.class);

      return list;

  }

}

This provider must be registered as an OSGi service, e.g. defining a Declarative service. Add to the OSGI-INF directory of your plugin a file commands-provider.xml:

<?xml version="1.0"?>

<component name="com.ontoprise.ontobroker.examples.api.commands">

  <implementation class="com.yourcompany.x.y.CommandProviderImpl" />

  <service>

    <provide interface="com.ontoprise.api.command.CommandProvider"/>

  </service>

</component>

The package of the command class must be exported from META-INF/manifest.mf of the plug-in and the service component must also be added to the manifest, e.g.

Service-Component: OSGI-INF/commands-provider.xml

-runscript command line option

OntoBroker now supports a -runscript command line option for executing a command or command list from a file during launching.

NOTE: This option is not supported for OWL

Syntax

-runscript <filename>

Example

This example shows how to insert some facts, export the module, and exit OntoBroker automatically.

ontobroker32.exe -runscript sample.oblcmd

sample.oblcmd

:- default prefix = "http://yourcompany.com#".

:- module m1.

 

// try block to ensure execution of final shutdown command

try {

// first insert some facts

insert {

  Person[name {0:1} *=> _string, age {0:1} *=> _int].

  p1:Person[name->"Susan",age->11].

  p2:Person[name->"Mike",age->12].

}

// save Ontology <http://yourcompany.com#m1> to the file m1.obl

save m1 to "m1.obl".

}

// shutdown OntoBroker

shutdown