Re: NOOB Question - Get / lock / update (unserializable transaction)

Klaus Wuestefeld <[email protected]>
Newsgroups gmane.comp.java.prevayler
Message-ID <CAMAooZGw+vd9S6F4P5EWtvtDhP7D+cfC5Bnz8LY0wUuEOkj8DA@mail.gmail.com>
Consumer does this:

1) transaction: {mark next message as "taken"}
2) send message
3) transaction: {mark message as "sent"}

On recovery after system crash:
For every "taken" but not "sent" message, one of these:
- Drop it. OR
- Query the destination system to see it if already has this message
and resend if not. OR
- Send it potentially redundantly.

Klaus


On Thu, Jun 21, 2012 at 10:24 PM, Trever Shick <[email protected]> wrote:
> I'm attempting to use Prevayler as a journalling mechanism for a distributed
> queueing mechanism.
> I have a producer and 'n' consumers across the network.
>
>
> If i send a message i
> 1) add it to my prevalent system (chat queue) via a transaction
> 2) send the message
> 3) remove it via a transaction
>
> this works, no issues.
>
> my issue is when i have no consumers.  i must queue up the messages and when
> a consumer comes online, i need to send all the queued messages.
>
> since my producer has multiple threads i cannot do a :
> 1) query for queue 'head' (in a query tx)
> 2) send message
> 3) remove message via tx
>
> because Thread 1 after executing #1 could pause, where in Thread 2 exeutes
> #1. they both have the same message object now and i will get dups.
>
>
> I temporary fixed the issue by synchronizing on the prevalentSystem() as
> that's what execute() syncs on (per the doc).
>
>
> What i thought i could do, or what i'd like to do is to have a 'send message
> transaction' that would :
> 1) send the message in executeOn()
> 2) mark the message sent
> all in one tx.
>
> I can't do this however because after de-serialization i have no 'output
> queue'.
>
> This is understood and that's fine.
>
> what i need to do though is to have a nice clean way to bundle the three
> operations in a threadsafe manner in the prevayler.
>
> I need prevayler to have a method like 'executeSafe(PrevaylerCallback);
>
> interface PrevaylerCallback {
> void executeWith(Prevayler prevayler) ;
> }
> executeSafe would synchronize appropriately and then allow me to run my
> query (tx) / send / update (tx) safely.
>
> so, for example i would have a
> prevayler.executeSafe(new PrevaylerCallback {
>   void executeWith(Prevayler prevayler) {
>     while (true) {
>       String message = prevayler.query(new Query() { // get queue 'top' });
>       if (message == null) break;
>       channel.send(message);
>       prevayler.execute(new RemoveMessageTransaction(message));
>     }
>   }
> });
>
>
> Am i going about this the wrong way?  Is there something there that would
> help me already?  Do i need to fork the code and add the PrevaylerCallback?
>
> Thanks for any help.
>
>
>
> ------------------------------------------------------------------------------
> Live Security Virtual Conference
> Exclusive live event will cover all the ways today's security and
> threat landscape has changed and how IT managers can respond. Discussions
> will include endpoint security, mobile security and the latest in malware
> threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
> _______________________________________________
> To unsubscribe go to the end of this page:
> http://lists.sourceforge.net/lists/listinfo/prevayler-discussion
> _______________________________________________
> "Databases in Memoriam" -- http://www.prevayler.org
>



-- 
Valeu, Klaus.

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
To unsubscribe go to the end of this page: http://lists.sourceforge.net/lists/listinfo/prevayler-discussion
_______________________________________________
"Databases in Memoriam" -- http://www.prevayler.org
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.