Protected
Protected

Spring Integration


Module stability: IN PROGRESS

Akkas integration with the Spring Framework supplies the spring way of using the Active Object Java API. It uses Spring's custom namespaces to create Active Objects and supervisor hierarchies in a Spring environment.

To use the custom name space tags for Akka you have to add the XML schema definition to your spring configuration. It is available at http://scalablesolutions.se/akka/akka.xsd. The namespace for Akka is:

xmlns:akka="http://akkasource.org/schema/akka"

Example header for Akka Spring configuration:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:akka="http://akkasource.org/schema/akka"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
       http://akkasource.org/schema/akka
       http://scalablesolutions.se/akka/akka.xsd">

Creating Active Objects


Here are some examples how to create Active Objects with the Spring framework:

Creating an active object:


<beans>
  <akka:active-object id="myActiveObject"
                      target="com.biz.MyPOJO"
                      transactional="true"
                      timeout="1000" />
</beans>

Get the active object from the Spring context:

ApplicationContext context = new ClassPathXmlApplicationContext("akka-spring-config.xml");
MyPojo myPojo = (MyPojo) context.getBean("myActiveObject");
 

Configuration for a remote active object with callbacks


<beans>
  <akka:active-object id="remote-active-object"
                        target="com.biz.MyPojo"
                        timeout="2000">
        <akka:restart-callbacks pre="preRestartMethod" post="postRestartMethod"/>
        <akka:remote host="localhost" port="9999" />
  </akka:active-object>
</beans>

Configuration for an active object with a custom dispatcher


If you don't want to use the default dispatcher you can define your own dispatcher in the spring configuration. For more information on dispatchers have a look at dispatchers.

<akka:active-object id="remote-active-object" target="com.biz.MyPojo" timeout="2000">
  <akka:dispatcher id="my-dispatcher" type="executor-based-event-driven" name="myDispatcher">
    <akka:thread-pool queue="unbounded-linked-blocking-queue" capacity="100" />
  </akka:dispatcher>
</akka:active-object>
If you want to or have to share the dispatcher between active objects you can define a dispatcher and reference it from the active object configuration:
<akka:dispatcher id="dispatcher-1" type="executor-based-event-driven" name="myDispatcher">
  <akka:thread-pool queue="bounded-array-blocking-queue"
                    capacity="100"
                    fairness="true"
                    core-pool-size="1"
                    max-pool-size="20"
                    keep-alive="3000"
                    rejection-policy="caller-runs-policy"/>
</akka:dispatcher>
 
<akka:active-object id="active-object-with-dispatcher-ref" target="com.biz.MyPojo" timeout="1000">
    <akka:dispatcher ref="dispatcher-1"/>
</akka:active-object>

The following dispatcher types are available in spring configuration:
  • executor-based-event-driven
  • reactor-based-thread-pool-event-driven
  • reactor-based-single-thread-event-driven
  • thread-based (in progress)

The following queue types are configurable for dispatchers using thread pools:
  • bounded-linked-blocking-queue
  • unbounded-linked-blocking-queue
  • synchronous-queue
  • bounded-array-blocking-queue

If you have set up your IDE to be XSD-aware you can easily write your configuration through auto-completion.

Supervisor Hierarchies


The supervisor configuration in Spring follows the declarative configuration for the Java API. Have a look at Akka's approach to fault tolerance.

Example spring supervisor configuration


<beans>
  <akka:supervision id="my-supervisor">
 
    <akka:restart-strategy failover="AllForOne"
                           retries="3"
                           timerange="1000">
      <akka:trap-exits>
        <akka:trap-exit>java.io.IOException</akka:trap-exit>
      </akka:trap-exits>
    </akka:restart-strategy>
 
    <akka:active-objects>
      <akka:active-object target="com.biz.MyPOJO"
                          lifecycle="permanent"
                          timeout="1000">
        <akka:restart-callbacks pre="preRestart"
                                post="postRestart"/>
      </akka:active-object>
      <akka:active-object target="com.biz.FooBar"
                          lifecycle="permanent"
                          transactional="true"
                          timeout="1000" />
    </akka:active-objects>
  </akka:supervision>
</beans>

Get the ActiveObjectConfigurator from the Spring context


ActiveObjectConfigurator myConfigurator = (ActiveObjectConfigurator) context.getBean("my-supervisor");
MyPojo myPojo = myConfigurator.getInstance(MyPojo.class);

Work in progress


  • configuration of thread based dispatchers
  • nested supervisor hierarchies
Home
close
Loading...
Home Turn Off "Getting Started"
close
Loading...