Kompics
In this document we will describe how to use the Kompics component framework. Wherever applicable, we will present all examples both in Scala and in Java. For features that are exclusively available in Kompics Java, the reader is redirected to the old documentation page.
Kompics Scala Quickstart
If you just want to get set up quickly with Kompics Scala, instead of reading throught the whole documentation, follow the following steps. These assume that are using sbt as your build tool. Otherwise, substitute as appropriate.
- Start a new sbt project
- Add the following dependency to your
build.sbt
file:- sbt
libraryDependencies += "se.sics.kompics" %% "kompics-scala" % "2.0.0"
- Maven
<dependency> <groupId>se.sics.kompics</groupId> <artifactId>kompics-scala_2.13</artifactId> <version>2.0.0</version> </dependency>
- Gradle
dependencies { compile group: 'se.sics.kompics', name: 'kompics-scala_2.13', version: '2.0.0' }
-
Write a component:
package mypackage import se.sics.kompics.sl._ class MyComponent(init: Init[MyComponent]) extends ComponentDefinition { val Init(/* init paramters */) = init; /* add ports */ /* add internal state */ ctrl uponEvent { case _: Start => { /* Do something when component is started */ } } /* add all your custom handlers */ }
-
Start the component and wait for it to complete, if it ever does:
package mypackage import se.sics.kompics.sl._ object Main { def main(args: Array[String]): Unit = { Kompics.createAndStart(classOf[MyComponent], Init[MyComponent](/* init paramters */), NUM_THREADS); Kompics.waitForTermination(); } }
-
Run from within sbt with
runMain mypackage.Main
The source code for this page can be found here.