cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mike Kienenberger <mkien...@gmail.com>
Subject Re: sync cayenne cache in two web apps
Date Wed, 29 Jul 2009 20:28:58 GMT
Sorry.  I didn't see the part on multicasting.   After looking at that
article, I suppose you could try to share an actual datacontext, but
that's probably not realistic since few apps have only one
datacontext.

It'll be a bit more complicated, but you should be able to use a
custom EventBridge.

Here's how I set up an loopback event bridge under 1.1.x.  Things
might have changed a little bit, so I can't say for certain how
helpful this would be.  There's not much documentation, but it's
pretty straight-forward.

You'd want to extend it to transport the event somehow, perhaps by
queuing up an event in the shared session context, and then reading
the shared session context queue at the start of every request loop.
And you'll want to change it to ignore events sent by itself but not
by the other app.

In cayenne.xml:

<domain name="MyApp">
	<property name="cayenne.DataRowStore.remote.notify" value="true"/>
	<property name="cayenne.DataRowStore.EventBridge.factory"
value="com.xyz.cayenne.LocalEventBridgeFactory"/>



/*
 * Created on Dec 1, 2004
 */
package com.xyz.cayenne;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.objectstyle.cayenne.access.event.SnapshotEvent;
import org.objectstyle.cayenne.event.CayenneEvent;
import org.objectstyle.cayenne.event.EventBridge;
import org.objectstyle.cayenne.event.EventSubject;

/**
 * Class to automatically cause any snapshot changes for a particular
DataContext/DataRowStore to be broadcast to all other
DataContext/DataRowStores.
 */
public class LocalEventBridge extends EventBridge
{
	protected static Log log = LogFactory.getLog(LocalEventBridge.class);

    public LocalEventBridge(EventSubject localSubject, String externalSubject)
    {
        super(localSubject, externalSubject);
    }

    protected void startupExternal() throws Exception
    {
        // Do nothing
    }

    protected void shutdownExternal() throws Exception
    {
        // Do nothing
    }

    protected void sendExternalEvent(CayenneEvent localEvent) throws Exception
    {
        // Ignore events sent by all LocalEventBridges to prevent looping
        if (localEvent.getSource() instanceof LocalEventBridge)  return;

        if (localEvent instanceof SnapshotEvent)
        {
            // clone and post the event (source must be set to this
event bridge for our DataRowStore to receive it).
            SnapshotEvent snapshotEvent = (SnapshotEvent)localEvent;
            SnapshotEvent newSnapshotEvent = new SnapshotEvent(this,
snapshotEvent.getPostedBy(), snapshotEvent.getModifiedDiffs(),
snapshotEvent.getDeletedIds(), snapshotEvent.getInvalidatedIds(),
snapshotEvent.getIndirectlyModifiedIds());
            if (eventManager != null)
            {
                eventManager.postEvent(newSnapshotEvent, localSubject);
            }
            else {
                throw new IllegalStateException(
                    "Can't post events. EventBridge was not started properly. "
                        + "EventManager is null.");
            }
        }
    }
}


/*
 * Created on Dec 1, 2004
 */
package com.xyz.cayenne;

import java.util.Map;

import org.objectstyle.cayenne.event.EventBridge;
import org.objectstyle.cayenne.event.EventBridgeFactory;
import org.objectstyle.cayenne.event.EventSubject;

public class LocalEventBridgeFactory implements EventBridgeFactory
{
    public LocalEventBridgeFactory()
    {
        super();
    }

    public EventBridge createEventBridge(EventSubject localSubject,
            Map properties)
    {
        return new LocalEventBridge(localSubject,
EventBridge.convertToExternalSubject(localSubject));
    }
}

On Wed, Jul 29, 2009 at 4:16 PM, Tobias
Schoessler<tobias.schoessler@gmail.com> wrote:
> well i am reading this from the documentation:
>
> "... At the minimum, JMS setup requires a JMS server running, and subjects
> for each of the DataDomains to be configured. JavaGroups is peer-to-peer
> library that is embedded into applications. Default configuration provided
> by CayenneModeler will work out of the box, provided that IP multicast is
> enabled on the network."
>
> for the JMS solution the JMS server setup is a problem
> for the JavaGroups setup the "IP multicast is enabled on the network."  is a
> problem
>
> so  for the custom tranport mechanism that you mentioned I stumbled upon
> this here
>
> http://jee-bpel-soa.blogspot.com/2009/06/session-sharing-in-apache-tomcat.html
>
> which seems to describe cross context data sharing on tomcat web contexts
>
> but is there any code to look at to see how a custom transport mechanism can
> be setup?
>
> Tobias
>
>
> On Wed, Jul 29, 2009 at 8:28 PM, Mike Kienenberger <mkienenb@gmail.com>wrote:
>
>> I've never set it up, but it's easily configurable.
>>
>> If you don't like the javagroups or JMS methodologies, you can define
>> your own -- I don't know what tomcat app-data-sharing ability is
>> available -- it probably depends on the container, but I don't
>> remember reading about any in the past.
>>
>> However, the docs seem to indicate that using Javagroups is pretty
>> painless with no external configuration to deal with.
>>
>> I have a Cayenne 1.1.x application I wrote that used remote
>> notification internally to broadcast events between sessions, so I
>> know it's not difficult to set up and define your own event
>> broadcaster.  My guess is that doing it for javagroups is pretty easy
>> since it sounds like a matter of just filling in the forms on the
>> modeler.
>>
>> On Wed, Jul 29, 2009 at 2:15 PM, Tobias
>> Schoessler<tobias.schoessler@gmail.com> wrote:
>> > Thanks Mike,
>> >
>> > so the answer is yes, this can only be done using remote notification? is
>> > this correct?
>> >
>> > Isn't there a way to share the cache among two web application scopes
>> > without going through the hassle of setting up remote notification?
>> >
>> > When the two webapps are running on the same physical machine, inside the
>> > same application server this seems overkill.
>> >
>> > Tobias
>> >
>> > On Wed, Jul 29, 2009 at 6:50 PM, Mike Kienenberger <mkienenb@gmail.com
>> >wrote:
>> >
>> >> Yes,
>> >>
>> >> Here's a Cayenne 2.0 document on it:
>> >>
>> >> http://cayenne.apache.org/doc20/configuring-caching-behavior.html
>> >>
>> >> For 3.0:
>> >>
>> >> http://cayenne.apache.org/doc/configuring-caching-behavior.html
>> >>
>> >> On Wed, Jul 29, 2009 at 12:46 PM, Tobias
>> >> Schoessler<tobias.schoessler@gmail.com> wrote:
>> >> > Hi,
>> >> >
>> >> > is it possible to sync the cayenne cache of two web applications
>> running
>> >> in
>> >> > the same tomcat?
>> >> >
>> >> > I observe one web app showing outdated data when the other is
>> committing
>> >> > updates. Both apps are using the same mapping configuration.
>> >> >
>> >> > Do I need to use remote notification for this?
>> >> >
>> >> > thanks
>> >> >
>> >> > Tobias
>> >> >
>> >>
>> >
>>
>

Mime
View raw message