## [Scala][Akka] How to create supervised actors only for the single operation

At first, let's define the Supervisor:

class Supervisor extends Actor {

override val supervisorStrategy =
OneForOneStrategy() {
case _: IllegalStateException =>
Restart
case _: Exception => Stop
}

case op: Operation => context.actorOf(Props(classOf[Worker], op))
}
}


I chose OneForOneStrategy which restarts or stops an actor in case of specified exception. It is worth noting that the operation is passed by the constructor of the newly created actor.

Secondly, let's take a look at Worker, which handles the operation:

class Worker(op: Operation) extends Actor {

override def preStart(): Unit = {
self ! op
}

case op: Operation => op.execute()
}
}


As you can see, the operation is sent to the worker itself in the preStart method. This enables simple restarting or other supervision strategies to be done.

Any better solutions would be appreciated.

## How to handle external jars with Maven

...the elegant way

If you've been struggling to add some jars to your maven project and maybe you've finished by adding them as a system scope dependency - you are in the right place!

After I spent some time on Stackoverflow, I decided to gather useful information and write a brief advice on how to deal with jar dependencies.

All you need to do is add and configure maven-install-plugin in your main pom.xml like this:

            <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.3.1</version>
<executions>
<execution>
<id>my-fancy-id</id>
<phase>prepare-package</phase>
<goals>
<goal>install-file</goal>
</goals>
<configuration>
<file>${session.executionRootDirectory}/lib/some-crap.jar</file> <groupId>pl.edu.agh</groupId> <artifactId>some-crap</artifactId> <version>0.0.1</version> <packaging>jar</packaging> </configuration> </execution> </executions> </plugin>  Then, Maven will install the configured jar in a prepare-package phase. The${session.executionRootDirectory} variable points to the directory from which the maven command was executed.

Of course it would be better to have your own repository like Artifactory. But there isn't always such a possibility.

Hubert Słojewski

Kraków