Archived

This forum has been archived. Please start a new discussion on GitHub.

Freeze evictor synchronization with Java tie classes

Hi,

First, congratulations!! ICE is really a great software!! Simple and powerful!!

Then my problem (certainly more a misunderstanding than a real bug...):

I've read the documentation about the Freeze evictor and I need some details about its synchronization.

I plan to use the tie classes to separate persistence data from interface implementation. On top of that, I also need implementation inheritance rather than interface inheritance.
The Ice manual highlights the concurrency issue between the Freeze saving thread and the servant implementation, the solution consists in synchronizing the servant. But with the tie classes, this code is generated and I don't want to specialize the tie classes only to put the "synchronized" keyword. I've got a lot of functions and a lot of classes, and this job would be fastidious.

So I'm wondering how to perform synchronization in a simple manner. My idea is that it would be useful to put an option on the slice2java command line.

Any advice would be welcome!

As examples are always clearer to understand, here is the sample of code:
(I know that if I put the keyword "nonmutating" here, it would be OK, but I've got other functions that really modify the servant tie class, it's only an example, not the real code...)

Root.ice
module Inter {
interface Root {
int getID();
};
};

Entity.ice
module Inter {
interface Entity extends Root {
int getClassID();
};
};

RootClass.ice
module InterPersis {
class RootClass implements Inter::Root {
int ID;
};
};

EntityClass.ice
module InterPersis {
class EntityClass extends RootClass implements Inter::Entity {
int ClassID;
};
};

RootImpl.java
public class RootImpl extends _RootClassTie {
public RootImpl() {
super();
ice_delegate(new RootBehavior(this));
}
}

EntityImpl.java
public class EntityImpl extends _EntityClassTie {
public EntityImpl() {
super();
ice_delegate(new EntityBehavior(this));
}
}

RootBehavior.java
public class RootBehavior implements _RootOperations {
private RootClass attributes;
public RootBehavior(RootClass attr) {
attributes = attr;
}
public int getID(Current __current) {
return attributes.ID;
}
}

EntityBehavior.java
public class EntityBehavior extends RootBehavior implements _EntityOperations {
private EntityClass attributes;
public EntityBehavior(EntityClass attr) {
super(attr);
attributes = attr;
}
public int getClassID(Current __current) {
return attributes.ClassID;
}
}

Bye

Comments

  • benoit
    benoit Rennes, France
    Hi Julien,

    You don't need to specialize the tie class to add synchronization. You can just synchronize on the tie object from the delegate implementation, like the following for example:

    public int getClassID(Current __current)
    {
    synchronized(attributes)
    {
    return attributes.ClassID;
    }
    }

    This synchronization will prevent the Freeze evictor saving thread from reading the "attributes" servant concurrently.

    Cheers,
    Benoit.
  • Hi Benoit,

    I realize that my question was a bit silly! I've never wrote a single line of Java code, only C++, and I didn't know this syntax for the synchronized keyword.

    So, I really thank you for the reply and apologize for the wasted time.

    Bye