

{"id":899,"date":"2013-02-20T12:02:29","date_gmt":"2013-02-20T11:02:29","guid":{"rendered":"https:\/\/project.inria.fr\/plasma-lab\/?page_id=899"},"modified":"2013-11-27T11:42:43","modified_gmt":"2013-11-27T10:42:43","slug":"plugin-tutorial","status":"publish","type":"page","link":"https:\/\/project.inria.fr\/plasma-lab\/plugin-tutorial\/","title":{"rendered":"Plugin tutorial"},"content":{"rendered":"<p><div class=\"alert alert-warning\" role=\"alert\"><p class=\"printonly\"><strong>Warning!<\/strong><\/p><strong>Prerequisite<\/strong><\/p>\n<p class=\"first-p\">For this tutorial you will need the package API (fr.inria.plasma.packages) in <strong><a href=\"http:\/\/maven.inria.fr\/artifactory\/simple\/plasmalab-public-release\/fr\/inria\/plasmalab\/fr.inria.plasmalab.packages\/\">its latest version<\/a><\/strong> or import <a href=\"http:\/\/maven.inria.fr\/artifactory\/simple\/plasmalab-public-release\/fr\/inria\/plasmalab\/fr.inria.plasmalab.plasmalab\/\"><strong>Plasma Lab in its latest version<\/strong><\/a> as a library. This jar contains interface and shared class that you will have to implement and\/or use.<\/p>\n<p>You will also need the Java Simple Plugin Framework. Their<strong><a href=\"http:\/\/code.google.com\/p\/jspf\/\"> web site is here<\/a><\/strong> but you can download it on <strong><a href=\"http:\/\/maven.inria.fr\/artifactory\/simple\/plasmalab-public-release\/jspf\/core\/jspf.core\/\">our artifactory repository here<\/a><\/strong>.<\/p>\n<p>Our plugin&#8217;s <a href=\"http:\/\/plasma-lab.gforge.inria.fr\/plasma_lab_plugins\/doc\/\"><strong>javadoc is here<\/strong><\/a>.<\/p>\n<p><\/div><\/p>\n<div class=\"alert alert-danger\" role=\"alert\"><p class=\"printonly\"><strong>Error!<\/strong><\/p><strong>PLASMA Lab beta 1.1.9<\/strong><\/p>\n<p class=\"first-p\"><strong>PLASMA Lab&#8217;s plugin architecture has been improved for our newest version<\/strong>. While the global mechanism and purpose stay similar to the previous versions, this tutorial is invalid since version 1.1.9.<\/div>\n<h3>Structure<\/h3>\n<p>A plugin is build around three main interfaces: Factory, <a href=\"https:\/\/project.inria.fr\/plasma-lab\/plasma-structure\/\"><strong>Simulator and Checker<\/strong><\/a>.<\/p>\n<ul>\n<li>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.<\/li>\n<\/ul>\n<ul>\n<li>The Factory interface can be seen as the plugin entry point. It implements methods to retrieve the plugin&#8217;s name and description. But its main task is to instantiate the class which is implementing the Simulator or Checker interfaces.<\/li>\n<\/ul>\n<p>A package also has to implement a State and Identifier interface respectively to represent a state of the model and elements of a state.<\/p>\n<p>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.<\/p>\n<div class=\"alert alert-success\" role=\"alert\"><p class=\"printonly\"><strong>Important!<\/strong><\/p> <a href=\"http:\/\/plasma-lab.gforge.inria.fr\/plasma_lab_plugins\/dummyPlugin\/fr.inria.plasma.dummy.jar\"><strong>Download the sources of this tutorial<\/strong><\/a>.<\/div>\n<hr \/>\n<h3>Factory<\/h3>\n<p>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.<\/p>\n<p>The important thing to note here is the <em>@PluginImplementation<\/em> annotation. This annotation will tell the Java Simple Plugin Framework where to find the class it is looking for.<\/p>\n<div class=\"alert alert-success\" role=\"alert\"><p class=\"printonly\"><strong>Important!<\/strong><\/p><br \/>\n@PluginImplementation<br \/>\npublic class DummyPlugin implements Factory, Checker, Simulator{<\/p>\n<p class=\"first-p\">}<\/div>\n<p>Then we have to implement functions of the Factory interface. These three functions shouldn&#8217;t need too much explanation, they will be used by the Graphical User Interface to display information about this plugin.<\/p>\n<div class=\"alert alert-success\" role=\"alert\"><p class=\"printonly\"><strong>Important!<\/strong><\/p><\/p>\n<p class=\"first-p\">@Override<br \/>\npublic String getPackageName() {<br \/>\nreturn &#8220;Dummy plugin&#8221;;<br \/>\n}<br \/>\n@Override<br \/>\npublic String getPackageDescription() {<br \/>\nreturn &#8220;Plugin for the tutorial&#8221;;<br \/>\n}<br \/>\n@Override<br \/>\npublic String[] getExtensions() {<br \/>\nreturn new String[]{&#8220;.dummy&#8221;};<br \/>\n}<\/p>\n<p><\/div>\n<p>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.<\/p>\n<div class=\"alert alert-success\" role=\"alert\"><p class=\"printonly\"><strong>Important!<\/strong><\/p><br \/>\n@Override<br \/>\npublic Simulator createNewSimulator() {<br \/>\nreturn this;<br \/>\n}<br \/>\n@Override<br \/>\npublic Checker createNewChecker() {<br \/>\nreturn this;<br \/>\n}<\/p>\n<p class=\"first-p\"><\/div>\n<p>In this example we return <em>this<\/em> 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.<\/p>\n<p>And that&#8217;s it for the Factory!<\/p>\n<hr \/>\n<h3>Simulator<\/h3>\n<p>The Simulator interface uses two main methods, newTrace() and nextState().<\/p>\n<ul>\n<li>newTrace() instantiates a new execution trace and set it to the initial state.<\/li>\n<\/ul>\n<p>Our dummy model language is a succession of &#8220;+&#8221; and &#8220;-&#8220;. Starting from 0 it will add or remove one to the current value. For instance the model &#8220;+++&#8211;&#8221; will produce the trace &#8220;0 1 2 3 2 1&#8221;.<\/p>\n<div class=\"alert alert-success\" role=\"alert\"><p class=\"printonly\"><strong>Important!<\/strong><\/p><\/p>\n<p class=\"first-p\">@Override<br \/>\npublic void newTrace() {<br \/>\ntrace = new ArrayList();<br \/>\nidentifiers = new HashMap();<br \/>\nidentifiers.put(&#8220;#&#8221;, new DummyId(&#8220;#&#8221;, 0));<br \/>\nidentifiers.put(&#8220;X&#8221;, new DummyId(&#8220;X&#8221;, 1));<\/p>\n<p>state = new DummyState(0, 0);<br \/>\ntrace.add(state);<\/p>\n<p>FileReader fr = null;<br \/>\ntry {<br \/>\nfr = new FileReader(model);<br \/>\n} catch (FileNotFoundException e) {<br \/>\ne.printStackTrace();<br \/>\n}<br \/>\nbr = new BufferedReader(fr);<br \/>\n}<\/p>\n<p><\/div>\n<ul>\n<li>nextTrace() returns the successor state of the current state.<\/li>\n<\/ul>\n<div class=\"alert alert-success\" role=\"alert\"><p class=\"printonly\"><strong>Important!<\/strong><\/p><\/p>\n<p class=\"first-p\">@Override<br \/>\npublic State nextState() {<br \/>\ntry {<br \/>\nint c = br.read();<br \/>\nif(c==-1)<br \/>\nreturn state;<br \/>\nelse{<br \/>\ndouble currentV = state.getAtPos(1);<br \/>\ndouble currentT = state.getAtPos(0);<br \/>\nif(c==&#8217;+&#8217;){<br \/>\nreturn new DummyState(currentT+1, currentV+1);<br \/>\n}<br \/>\nelse if(c==&#8217;-&#8216;){<br \/>\nreturn new DummyState(currentT+1, currentV-1);<br \/>\n}<br \/>\n}<br \/>\n} catch (IOException e) {}<br \/>\nreturn state;<br \/>\n}<\/p>\n<p><\/div>\n<p>There are others methods in this interface but they should not be a problem to implement. We will only take a look a the <em>newTrace(int stepcount, double steptime)<\/em> function. This method is called when Plasma Lab is set to the <em>simulate<\/em> mode and will generate a trace of a length equals to stepcount.<\/p>\n<div class=\"alert alert-success\" role=\"alert\"><p class=\"printonly\"><strong>Important!<\/strong><\/p><\/p>\n<p class=\"first-p\">@Override<br \/>\npublic void newTrace(int stepcount, double steptime) {<br \/>\nnewTrace();<br \/>\nfor(int i=1; i State next = nextState();<br \/>\ntrace.add(next);<br \/>\nstate = next;<br \/>\n}<br \/>\n}<\/p>\n<p><\/div>\n<p>At this point you should be able to run simulation of your model with Plasma Lab!<\/p>\n<hr \/>\n<h3>Checker<\/h3>\n<div class=\"alert alert-info\" role=\"alert\"><p class=\"printonly\"><strong>Notice<\/strong><\/p>Coming soon.<\/div>\n<hr \/>\n<h3  id=\"Deployment\">Deployment<\/h3>\n<ul>\n<li>Create a <strong>plugins directory<\/strong> next to the Plasma Lab executable.<\/li>\n<\/ul>\n<p><a href=\"https:\/\/project.inria.fr\/plasma-lab\/files\/2013\/02\/plugin1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-910 aligncenter\" title=\"plugin1\" alt=\"\" src=\"https:\/\/project.inria.fr\/plasma-lab\/files\/2013\/02\/plugin1-300x145.png\" width=\"300\" height=\"145\" srcset=\"https:\/\/project.inria.fr\/plasma-lab\/files\/2013\/02\/plugin1-300x145.png 300w, https:\/\/project.inria.fr\/plasma-lab\/files\/2013\/02\/plugin1.png 373w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<ul>\n<li>Put the <strong>jar plugin into this directory<\/strong>.<\/li>\n<\/ul>\n<p><a href=\"https:\/\/project.inria.fr\/plasma-lab\/files\/2013\/02\/plugin2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-911 aligncenter\" title=\"plugin2\" alt=\"\" src=\"https:\/\/project.inria.fr\/plasma-lab\/files\/2013\/02\/plugin2-300x145.png\" width=\"300\" height=\"145\" srcset=\"https:\/\/project.inria.fr\/plasma-lab\/files\/2013\/02\/plugin2-300x145.png 300w, https:\/\/project.inria.fr\/plasma-lab\/files\/2013\/02\/plugin2.png 371w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<ul>\n<li><strong>Run Plasma Lab<\/strong>.<\/li>\n<\/ul>\n<p><a href=\"https:\/\/project.inria.fr\/plasma-lab\/files\/2013\/02\/plugin3.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-912 aligncenter\" title=\"plugin3\" alt=\"\" src=\"https:\/\/project.inria.fr\/plasma-lab\/files\/2013\/02\/plugin3-300x163.png\" width=\"300\" height=\"163\" srcset=\"https:\/\/project.inria.fr\/plasma-lab\/files\/2013\/02\/plugin3-300x163.png 300w, https:\/\/project.inria.fr\/plasma-lab\/files\/2013\/02\/plugin3-1024x558.png 1024w, https:\/\/project.inria.fr\/plasma-lab\/files\/2013\/02\/plugin3.png 1653w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>","protected":false},"excerpt":{"rendered":"<p>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\u2026<\/p>\n<p> <a class=\"continue-reading-link\" href=\"https:\/\/project.inria.fr\/plasma-lab\/plugin-tutorial\/\"><span>Continue reading<\/span><i class=\"crycon-right-dir\"><\/i><\/a> <\/p>\n","protected":false},"author":234,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"open","template":"","meta":{"footnotes":""},"class_list":["post-899","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/project.inria.fr\/plasma-lab\/wp-json\/wp\/v2\/pages\/899","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/project.inria.fr\/plasma-lab\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/project.inria.fr\/plasma-lab\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/project.inria.fr\/plasma-lab\/wp-json\/wp\/v2\/users\/234"}],"replies":[{"embeddable":true,"href":"https:\/\/project.inria.fr\/plasma-lab\/wp-json\/wp\/v2\/comments?post=899"}],"version-history":[{"count":14,"href":"https:\/\/project.inria.fr\/plasma-lab\/wp-json\/wp\/v2\/pages\/899\/revisions"}],"predecessor-version":[{"id":1200,"href":"https:\/\/project.inria.fr\/plasma-lab\/wp-json\/wp\/v2\/pages\/899\/revisions\/1200"}],"wp:attachment":[{"href":"https:\/\/project.inria.fr\/plasma-lab\/wp-json\/wp\/v2\/media?parent=899"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}