Re: Shared cache

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Sun Oct 29 2006 - 19:05:11 EST

  • Next message: Andrus Adamchik: "Re: Cayenne 3.0 roadmap"

    Hi Marko,

    As the goal of the default synchronization mechanism is
    *synchronization*, new objects do not generate events as there are no
    stale cache entries in peer VMs that need to be refreshed. So your
    observations are consistent with desired Cayenne behavior.

    For custom event processing (unrelated to synchronization per se) I
    personally prefer to use the new callback mechanism introduced in
    3.0. With this you can still use Cayenne EventManager for transparent
    clustering, and callbacks allow a whole lot of control of what events
    are being sent. That's a bit of bleeding edge though. You can read
    more here:

    http://cwiki.apache.org/CAYDOC/lifecycle-callbacks.html
    http://objectstyle.org/cayenne/lists/cayenne-devel/2006/10/0112.html

    Andrus

    On Oct 18, 2006, at 5:20 AM, Marko wrote:
    > Hi, list!
    >
    > I have a problem setting up a shared cache between two JVMs. The
    > changes
    > in the JVM A don't all get propagated to JVM B. Here's the code:
    >
    > JVM A:
    >
    > // The following doesn't trigger the remote snapshot event...
    > DataContext context = DataContext.createDataContext();
    > Dbe001 e001 = (Dbe001)context.createAndRegisterNewObject
    > (Dbe001.class);
    > e001.setA002(777);
    > context.commitChanges();
    >
    > // While this does...
    > SelectQuery query = new SelectQuery(Dbe001.class);
    > List<Dbe001> artists = context.performQuery(query);
    > artists.get(0).setA002(237846);
    > context.commitChanges();
    >
    > JVM B:
    >
    > SnapshotEventListener customListener = new
    > DCSnapshotEventListener();
    >
    > DataDomain domain = Configuration.getSharedConfiguration()
    > .getDomain();
    >
    > domain.getEventManager().addListener(customListener,
    > "snapshotsChanged", SnapshotEvent.class,
    > domain.getSharedSnapshotCache
    > ().getSnapshotEventSubject(),
    > domain.getSharedSnapshotCache());
    >
    > System.in.read();
    >
    >
    > class DCSnapshotEventListener
    > implements SnapshotEventListener
    > {
    > public void snapshotsChanged(SnapshotEvent event)
    > {
    > Map<ObjectId, DataRow> diff = event.getModifiedDiffs();
    > System.err.println(diff);
    > }
    > }
    >
    >
    > The data object looks like this:
    >
    > public class _Dbe001 extends org.apache.cayenne.CayenneDataObject {
    >
    > public static final String A002_PROPERTY = "a002";
    >
    > public static final String A001_PK_COLUMN = "a001";
    >
    > public void setA002(Integer a002) {
    > writeProperty("a002", a002);
    > }
    > public Integer getA002() {
    > return (Integer)readProperty("a002");
    > }
    >
    >
    > }
    >
    >
    > And the database entity is as follows:
    >
    > <data-map project-version="2.0">
    > <db-entity name="dbe001">
    > <db-attribute name="a001" type="INTEGER"
    > isPrimaryKey="true"
    > isMandatory="true"/>
    > <db-attribute name="a002" type="INTEGER"/>
    > </db-entity>
    > <obj-entity name="Dbe001" className="Dbe001"
    > dbEntityName="dbe001">
    > <obj-attribute name="a002" type="java.lang.Integer"
    > db-attribute-path="a002"/>
    > </obj-entity>
    > </data-map>
    >
    >
    > The transport layer is JGroups with default settings. Any ideas?
    >
    >



    This archive was generated by hypermail 2.0.0 : Sun Oct 29 2006 - 19:05:38 EST