As written, your proposal involves 3 XA transaction managers, two of which are 
also packaged as XAResources.  For this scenario, that’s ridiculous.

If this is a toy problem for you to learn about XA, I think what you mean is:

department bundle starts an XA transaction and removes the department in a 
branch of this transaction

something communicates the departmentId and transaction Xid to the person 
bundle (normally the Xid is communicated via a thread local, i.e. it’s attached 
to the current thread)

Person bundle removes the relevant people in another branch of this same 
transaction.

Something (probably the department bundle) ends the XA transaction (commit or 
rollback).

I think there’s now an OSGI spec transaction coordinator that should help with 
this, but I don’t remember the details or whether the implementation is in 
felix or aries.

If this is a real problem, it’s usually better to find a way to avoid XA, such 
as sending idempotent messages.

David Jencks

> On Oct 10, 2021, at 11:37 AM, jgfrm <f...@gordijn.org> wrote:
> 
> Suppose the following case:
> 
> - there is a Person bundle, responsible of managing persons
> - there is a Department bundle, reponsible of managing departmens.
> 
> - there is a constraint: A person always works for precisely one department;
> hence a person can not exist without the department s/he works for.
> 
> Hi
> 
> I am interested to understand if Isolation of data (between bundles) is
> possible in Karaf.
> 
> Suppose the following case:
> - there is a Person bundle, responsible of managing persons
> - there is a Department bundle, responsible of managing departments.
> - there is a constraint: A person always works for precisely one department;
> hence a person can not exist without the department s/he works for.
> 
> I have the following requirements:
> - The Person bundle can not use the data (departments) stored by the
> Department bundle (e.g. a table "Department")
> - The Department bundle can not use the data(persons) stored by the Person
> bundle (e.g. a table "Person")
> - If a department is deleted, all persons that work for that department
> would be deleted too (due to the formulated constraint).
> 
> How to do this in Karaf/OSGI?
> My ideas:
> - each bundle (Department and Person) has an own persistence unit. The
> persistence unit refers to different databases with their own access
> control, or the different schemas in the same database with proper access
> control on the database level. Bundles can not see each other's persistence
> unit. Because these are effectively two separate databases, we can not use
> foreign keys to represent that an employee always works for precisely one
> department.
> Therefore:
> - there is a bundle that represents a transaction coordinator
> - the Person bundle tells the transaction coordinator that there is a
> constraint: namely that it want to informed if a person is deleted
> - in case a department is deleted the following happens:
> - the department bundle builds a XA transaction to delete the department
> - the department bundle informs the transaction coordinator that it created
> a transaction to delete the department, including the identifier of the
> department to be deleted
> - the transaction coordinator informs the person bundle that a department
> with a particular identifier is going to be deleted
> - the person bundle looks up all persons that work for the department, and
> creates a XA transaction to delete all these persons
> - the person bundle informs the transaction coordinator that it created a
> transaction to delete the persons, including a list with identifiers of the
> persons to be deleted
> - the transaction coordinator executes both transaction as one enclosing
> transaction using the 2-phase commit protocol.
> 
> Questions:
> - is this a feasible scenario in Karaf?
> - if so, how should it be implemented? Specific tips?
> - are there any examples doing similar things?
> 
> Best,
> 
> -- Jaap
> 

Reply via email to