Plugin tutorial

Structure

A plugin is build around three main interfaces: Factory, Simulator and Checker.

  • Given a model, the Simulator will generate execution traces of various length. These traces will then be checked against a set of requirement by the Checker. Our architecture page details their role in Plasma Lab.
  • The Factory interface can be seen as the plugin entry point. It implements methods to retrieve the plugin’s name and description. But its main task is to instantiate the class which is implementing the Simulator or Checker interfaces.

A package also has to implement a State and Identifier interface respectively to represent a state of the model and elements of a state.

The API also comes with concrete classes to represent results and parser errors. These class can be found in the fr.inria.plasma.package.shared package.


Factory

First thing is to implement the Factory interface. For the purpose of this tutorial we will only uses one class for the Factory, Simulator and Checker interface.

The important thing to note here is the @PluginImplementation annotation. This annotation will tell the Java Simple Plugin Framework where to find the class it is looking for.

Then we have to implement functions of the Factory interface. These three functions shouldn’t need too much explanation, they will be used by the Graphical User Interface to display information about this plugin.

As said previously, the main purpose of the Factory interface is to provide a way of accessing to a Simulator and a Checker without knowing them. This is done by implementing the next two methods.

In this example we return this because the DummyPlugin class implements the Simulator and Checker interface. In a real plugin, we will create new instances of out Simulator and Checker classes and return them.

And that’s it for the Factory!


Simulator

The Simulator interface uses two main methods, newTrace() and nextState().

  • newTrace() instantiates a new execution trace and set it to the initial state.

Our dummy model language is a succession of “+” and “-“. Starting from 0 it will add or remove one to the current value. For instance the model “+++–” will produce the trace “0 1 2 3 2 1”.

  • nextTrace() returns the successor state of the current state.

There are others methods in this interface but they should not be a problem to implement. We will only take a look a the newTrace(int stepcount, double steptime) function. This method is called when Plasma Lab is set to the simulate mode and will generate a trace of a length equals to stepcount.

At this point you should be able to run simulation of your model with Plasma Lab!


Checker


Deployment

  • Create a plugins directory next to the Plasma Lab executable.

  • Put the jar plugin into this directory.

  • Run Plasma Lab.

Comments are closed.