Simplifying enterprise applications with durable stm

One of the things I’m currently playing with is creating a durable Stm, functionality is going to be integrated in the main Stm implementation of the Multiverse STM. I’m doing a poc to figure out what kind of interfaces and changes the Multiverse STM is going to need.

The idea is that persistence for a lot of enterprisy applications I have seen just didn’t feel very comfortable:

  1. dealing with proxies; so problematic self calls in services and identity problems on entities
  2. dealing with or mapping
  3. dealing with setting up the db and creating ddl
  4. not being able to do dependency injection on entities
  5. objects getting an id once they are going to commit and not before

It takes up too much time and since STM already manages states of your objects, adding a storage-engine
behind is not that strange. To give you an idea how simple it could be, lets create a small Bank example:

class Customer{
   	private final String id;

	public Customer(String id){
		return id;

	public String getId(){
		return name;

class Account{
	private final Customer customer;
	private int balance;

	public Account(Customer customer){
		this.customer = customer;

	public Customer getCustomer(){
		return customer;

	public int getBalance(){
		return balance;

	public void setBalance(int newBalance){
			throw new NotEnoughMoneyException();

		this.balance = newBalance;

class Bank{
	private final TransactionalMap customers = 
		new TransactionalHashMap();
	private final TransactionalMap accounts = 
		new TransactionalHashMap();

	public Account find(String id){
		Account account = accounts.get(id);
		if(account == null){
			throw new AccountNotFoundException();
		return account;

	public void transfer(String fromId, String toId, int amount){
			throw new IllegalArgumentException();

		Account from = find(fromId);
		Account to = find(fromId);

	public Customer createCustomer(){
		Customer customer = new Customer();
		return customer;

	public Accoount createAccount(Customer customer){
		Account found = accounts.get(customer.getId());
			throw new AccountAlreadyExists();
		Account newAccount = new Account(customer);
		accounts.put(customer.getId(), newAccount);
		return newAccount;

And you could wire it up in Spring like this:

<bean id="bank" class="DurableTransactionalObjectFactoryBean">
         <property name="id" value="bank">
         <property name="class" value="Bank">

And use this bean in your controllers for example. The DurableTransactionalObjectFactory will create or load a durable transactional object with the given id from disk.

As you can see there is:

  1. no or-mapping needed
  2. no dao’s needed
  3. no fuss with transaction configuration
  4. no need for rolling back state on objects manually, check the tranfer function where the setBalance on the from could thrown a NotEnoughMoneyException and normally could leave the to account in an illegal state

All operations on the bank are executed in full ACID nature.

I hope I’m able to add a experimental storage engine to Multiverse 0.6 (planned in 3 months) so I can learn more about what I’m going to need and what the exact semantics need to be for durable/non-durable objects and about their lifecycles.

10 Responses to Simplifying enterprise applications with durable stm

  1. Alex Cruise says:

    Peer, I’ve been following your involvement in Akka with interest, and this post struck a chord with me. Have you read the JVSTM thesis? One of his most interesting contributions is a declarative language for describing invariants and relationships between managed entities.

    I do think that getting intimately involved in the state space of trees of domain entities is a good direction for STMs, but there need to be ways to hide the plumbing. 🙂

    • pveentjer says:

      Hi Alex,

      thanks for posting. I have read the thesis some time ago, it seems to me that the versioned boxes are the same thing as ‘managed references’. This essentially is the approach the Akka project currently is using. But I can do a lot more cool stuff in Java (on the bytecode level or using object granularity for example) that it is likely to outperform a managed reference approach that isn’t using instrumentation.

      I haven’t looked at the thesis in more depth caused by lack of time (or lack of priority).

  2. rossputin says:

    This looks so promising! Pretty much the saviour of enterprise devs everywhere, good luck with it, can’t wait for the prototype.

    • pveentjer says:

      Hi Ross,

      I hope I can include some experimental support right after the 0.5 release since I already got a basic storage mechanism up and running. So hooking it up to the manual instrumented AlphaRef (used in Akka) would be no problem. It won’t be fast or protected against system failure, but it nice for experimentation purposes.

      • rossputin says:

        Hi Peer.

        More than happy to provide you with feedback / testing on anything you release in prototype form. You can get my details of the Akka list probably.


        — Ross

  3. Lucky says:

    How could I use Multiverse with Spring. I tried instrumentation mode in my Spring application ie;providing javagent in runtime. But it failed.

    • pveentjer says:

      He Lucky,

      what is the exception you get? And you can exclude packages from being instrumented.

      PS: For the 0.7 release (which is in development for a long time), I have decided to drop the instrumentation. It will be added in the near future again, but the focus atm is on transactional references. So you get something like:

      class Person{
      IntRef ageRef = newIntRef(10);

      • Lucky says:

        org.multiverse.javaagent.MultiverseClassFileTransformer handleThrowable
        SEVERE: Failed while instrumenting class ‘com/xyz/myApp/bpo/StudentService$$EnhancerByCGLIB$$387853e1’. It is not possible to abort the Javaagent instrumentation process, so the JVM is going to continue, but since this class is not instrumented, it is not transactional so all bets are off.
        java.lang.RuntimeException: java.lang.ClassNotFoundException: org.springframework.aop.framework.AopConfigException
        at Source)
        at Source)
        at Source)
        at Source)
        at Source)
        at Source)
        at Source)
        at Source)
        at org.multiverse.instrumentation.asm.AsmUtils.toBytecode(
        at org.multiverse.instrumentation.PreventReinstrumentationInstrumentationPhase.doInstrument(
        at org.multiverse.instrumentation.AbstractInstrumentationPhase.instrument(
        at org.multiverse.instrumentation.StandardInstrumentor.process(
        at org.multiverse.javaagent.MultiverseClassFileTransformer.transform(
        at sun.instrument.TransformerManager.transform(
        at sun.instrument.InstrumentationImpl.transform(
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClass(
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(
        at java.lang.reflect.Method.invoke(
        at net.sf.cglib.core.ReflectUtils.defineClass(
        at net.sf.cglib.core.AbstractClassGenerator.create(
        at net.sf.cglib.proxy.Enhancer.createHelper(
        at net.sf.cglib.proxy.Enhancer.create(
        at org.springframework.aop.framework.Cglib2AopProxy.getProxy(
        at org.springframework.aop.framework.ProxyFactory.getProxy(
        at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.createProxy(
        at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.wrapIfNecessary(
        at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessAfterInitialization(
        at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(
        at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(
        at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(
        at org.springframework.web.servlet.FrameworkServlet.initServletBean(
        at org.springframework.web.servlet.HttpServletBean.init(
        at javax.servlet.GenericServlet.init(
        at org.apache.catalina.core.StandardWrapper.loadServlet(
        at org.apache.catalina.core.StandardWrapper.load(
        at org.apache.catalina.core.StandardContext.loadOnStartup(
        at org.apache.catalina.core.StandardContext.start(
        at org.apache.catalina.core.ContainerBase.start(
        at org.apache.catalina.core.StandardHost.start(
        at org.apache.catalina.core.ContainerBase.start(
        at org.apache.catalina.core.StandardEngine.start(
        at org.apache.catalina.core.StandardService.start(
        at org.apache.catalina.core.StandardServer.start(
        at org.apache.catalina.startup.Catalina.start(
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(
        at java.lang.reflect.Method.invoke(
        at org.apache.catalina.startup.Bootstrap.start(
        at org.apache.catalina.startup.Bootstrap.main(

        org.multiverse.javaagent.JavaAgentProblemMonitor$LoggingDaemon run
        SEVERE: STM integrity compromised, instrumentation problems encountered. Partial instrumented classes could give unexpected results. Check the logging for the instrumentation exception(s).
        List of problem classes: (10 max)

        This is the exception I got when using javaagent..I could successfully able to use multiverse transaction template. But I prefer using annotations because I wont like to change my code developed on SpringFramework.

      • pveentjer says:

        Hi Lucky,

        it appears that it failed during the instrumentation of the org/springframework/web/servlet/FrameworkServlet. Since this class doesn’t contain any Multiverse stuff, there is no issue. Even though an exception is thrown, the Java agent just skips the class file transformers that causes the problem. So I don’t think that will be causing problems.

        Which version are you using? The 0.6.1 contains a whole bunch of automatically excluded projects, and one of them is Spring.

        I see that the instrumentation fails on ‘Failed while instrumenting class ‘com/xyz/myApp/bpo/StudentService$$EnhancerByCGLIB$$387853e1′ which already is a generated proxy. This could be more complicated, you can contact me on alarmnummer at and lets see if we can solve the problem.

  4. snnn says:

    Has it been released? (durable stm)

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: