2

I define a transaction is a set of continuous activities (one method or set of methods) in a component.

I wrote a simple example as follows:

//service interface
public interface Hello {
    String sayHello(String name);
    String sayBonjour(String name);
}

//service implementation 
@Component
public class HelloImpl implements Hello {  

    public String sayHello(String name) {
       //start local transaction
       return "hello " + name; 
       //finish local transaction
    }
    public String sayBonjour(String name) {
       //start local transaction
       return "bonjour " + name; 
       //finish local transaction
    }
}

//client
@Component
public class Client {

   Hello client;
   public Client() {
      //start local transaction
      client.sayBonjour(client.sayHello("world"));
      //finish local transaction 
   }
  }

In this example, there are local transactions in the components HelloImpl and Client. I define that global transaction of the system consists of a set of local transactions through all components.

How to manage transactions (global transaction and the local transtions in this example) in OSGi or iPOJO ?

Regards,

HNT
  • 147
  • 1
  • 10
  • As you would do it in any other non-JEE application: by using a `TransactionManager` preferably available as a service so it can be injected in various components. – Arie van Wijngaarden May 28 '16 at 11:01
  • could you give me more detail, please ? – HNT May 30 '16 at 15:51
  • Then you need to provide more information about where the transactions are needed for: do you access a database and if so how (via JPA, JDBC, ...) or do you need to synchronize remote resources, etc.? – Arie van Wijngaarden May 30 '16 at 16:34

1 Answers1

0

As in the example, when the client calls "client.sayBonjour(client.sayHello("world"))" on HelloImpl component, the client initiates a transaction (T0) to send "world" and then send the result of sayHello("world") to the HelloImpl component. After receiving the "world", HelloImpl component initiates a subtransaction (T1) to process request and return the result "helloworld" to client. Then HelloImpl component receives also "helloworld" request (in the method sayBonjour) , it initiates a new subtransaction T2 to process it. How to know T1 and T2 serve T0 if there many clients in the same time.

HNT
  • 147
  • 1
  • 10