How to implement a messaging system?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

How to implement a messaging system?

Amir Ansari
Dear list

(I guess this follows on from my previous posts...)

I'm trying to set up a simple messaging system using Magma, to enable users to pass messages to one another.  I considered creating a 'mailbox' Collection for each user, in which messages could be stored, and which could be polled at regular intervals to check for new messages.

However, since each session has its own view of this object, any other user/session dropping a message into the Collection would violate the rule 'do not share objects between MagmaSession instances'.

What is the proper way to implement such a system?  I'd be very grateful for any insight!

Amir
_______________________________________________
Magma mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/magma
Reply | Threaded
Open this post in threaded view
|

Re: How to implement a messaging system?

Chris Muller-3
> However, since each session has its own view of this object, any other user/session dropping a message into the Collection would violate the rule 'do not share objects between MagmaSession instances'.

Hi Amir, this does not have any bearing on the design of a messaging
system.  I don't understand what you mean, why you say:

"any other user/session dropping a message into the Collection would
violate the rule 'do not share objects between MagmaSession
instances'."

?

Because for user A and user B, each accessing the one persistent model
via Session A and Session B, respectively, A would add Message-A to
B's 'collection' which he accessed from his session.  After B
refreshed his session, his view of the model would reflect his own
copy of Message-A in his own copy of B's 'collection'.

> What is the proper way to implement such a system?  I'd be very grateful for any insight!

What you said should work just fine.  Use MagmaCollections with an
index on the timestamp so you don't have to worry about
commit-conflicts.

 - Chris


On Sun, Jan 2, 2011 at 3:58 PM, Amir Ansari <[hidden email]> wrote:

> Dear list
>
> (I guess this follows on from my previous posts...)
>
> I'm trying to set up a simple messaging system using Magma, to enable users to pass messages to one another.  I considered creating a 'mailbox' Collection for each user, in which messages could be stored, and which could be polled at regular intervals to check for new messages.
>
> However, since each session has its own view of this object, any other user/session dropping a message into the Collection would violate the rule 'do not share objects between MagmaSession instances'.
>
> What is the proper way to implement such a system?  I'd be very grateful for any insight!
>
> Amir
> _______________________________________________
> Magma mailing list
> [hidden email]
> http://lists.squeakfoundation.org/mailman/listinfo/magma
>
_______________________________________________
Magma mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/magma
Reply | Threaded
Open this post in threaded view
|

Re: How to implement a messaging system?

Amir Ansari
Hi Chris

I originally thought to create a mailbox for each user in a MagmaPreallocatedDictionary, with the association User -> OrderedCollection (where 'User' is an instance of class 'User', so each item would be unique).

So, checking up on one's own mailbox would simply entail finding oneself's User in the Dictionary and reading the associated collection of messages.

However, if another user were to drop a message into this collection, the same OrderedCollection would have to be accessed by another session.  Isn't this a no-no, even with refreshing a session?

Are you suggesting to use MagmaCollections instead of OrderedCollections?  Isn't that far more 'expensive', especially since each user on the system would be assigned such a collection just to hold their messages?

Amir


On Sun, 2 Jan 2011 19:30:19 -0600
Chris Muller <[hidden email]> wrote:

> Because for user A and user B, each accessing the one persistent model
> via Session A and Session B, respectively, A would add Message-A to
> B's 'collection' which he accessed from his session.  After B
> refreshed his session, his view of the model would reflect his own
> copy of Message-A in his own copy of B's 'collection'.
>
> > What is the proper way to implement such a system?  I'd be very grateful for any insight!
>
> What you said should work just fine.  Use MagmaCollections with an
> index on the timestamp so you don't have to worry about
> commit-conflicts.
_______________________________________________
Magma mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/magma
Reply | Threaded
Open this post in threaded view
|

Re: How to implement a messaging system?

fvozzi
Hi Amir,
I think that you can try modeling the MailingSystem class wich could be a 
singleton with users and each user would have his own messages. 
Users and messages would be MagmaCollections and then you would've three 
main classes MailingSystem, User and Message for the beggining.
Last, you would make persistent your singleton.

My two cents,
Facu



On Mon, Jan 3, 2011 at 7:32 AM, Amir Ansari <[hidden email]> wrote:
Hi Chris

I originally thought to create a mailbox for each user in a MagmaPreallocatedDictionary, with the association User -> OrderedCollection (where 'User' is an instance of class 'User', so each item would be unique).

So, checking up on one's own mailbox would simply entail finding oneself's User in the Dictionary and reading the associated collection of messages.

However, if another user were to drop a message into this collection, the same OrderedCollection would have to be accessed by another session.  Isn't this a no-no, even with refreshing a session?

Are you suggesting to use MagmaCollections instead of OrderedCollections?  Isn't that far more 'expensive', especially since each user on the system would be assigned such a collection just to hold their messages?

Amir


On Sun, 2 Jan 2011 19:30:19 -0600
Chris Muller <[hidden email]> wrote:

> Because for user A and user B, each accessing the one persistent model
> via Session A and Session B, respectively, A would add Message-A to
> B's 'collection' which he accessed from his session.  After B
> refreshed his session, his view of the model would reflect his own
> copy of Message-A in his own copy of B's 'collection'.
>
> > What is the proper way to implement such a system?  I'd be very grateful for any insight!
>
> What you said should work just fine.  Use MagmaCollections with an
> index on the timestamp so you don't have to worry about
> commit-conflicts.
_______________________________________________
Magma mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/magma


_______________________________________________
Magma mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/magma
Reply | Threaded
Open this post in threaded view
|

Re: How to implement a messaging system?

Chris Muller-3
In reply to this post by Amir Ansari
> I originally thought to create a mailbox for each user in a MagmaPreallocatedDictionary, with the association User -> OrderedCollection (where 'User' is an instance of class 'User', so each item would be unique).

Why are you wanting to use a MagmaPreallocatedDictionary to hold
Users?  How many users are in the system and how fast do they need
access to their list of new messages?

When I pull up my mail client, it takes a couple of seconds for my
Inbox to be displayed.  This is analagous to using a MagmaCollection
for each user's message.

Recall what I said MagmaCollections were designed for:  For end-user
query requirements, which is exactly the case you've stated:  A user
comes to check on their messages.  So a MagmaCollection is perfectly
appropriate for that, not a MagmaPreallocatedDictionary.

I don't know how many users you will have, but given the extremely
simple access requirements, you could put htem into a MagmaCollection
as well.

So, you have one MC for "AllUsers" and then one MC for each user
containing that users messages.

> So, checking up on one's own mailbox would simply entail finding oneself's User in the Dictionary and reading the associated collection of messages.
>
> However, if another user were to drop a message into this collection, the same OrderedCollection would have to be accessed by another session.  Isn't this a no-no, even with refreshing a session?

I'm wondering what you mean by "the same OrderedCollection".  The same
one in the database?  Or the same one in image memory?

Yes, it will be the same one in the database, but it will be different
ones in image memory if they are retrieved by different sessions.

>
> Are you suggesting to use MagmaCollections instead of OrderedCollections?  Isn't that far more 'expensive', especially since each user on the system would be assigned such a collection just to hold their messages?

MagmaCollections consume more resources than a OrderedCollection, yes,
but the reason I stated was that it would allow multiple messages to
come into the same user and avoid a commit-conflict.

 - Chris
_______________________________________________
Magma mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/magma
Reply | Threaded
Open this post in threaded view
|

Re: How to implement a messaging system?

Amir Ansari
OK, I made the system far more complex than necessary; your comments about the suitability of MagmaCollection made everything clear.  It'll work fine now.

Actually, I started this simply enough, in exactly the way you suggested, but using OrderedCollection - and when it didn't work properly I complicated everything instead of simply using a MagmaCollection.

Thanks for your help Chris!

And, of course, thanks for your comments Facu.

Amir


On Mon, 3 Jan 2011 12:33:11 -0600
Chris Muller <[hidden email]> wrote:

> > I originally thought to create a mailbox for each user in a MagmaPreallocatedDictionary, with the association User -> OrderedCollection (where 'User' is an instance of class 'User', so each item would be unique).
>
> Why are you wanting to use a MagmaPreallocatedDictionary to hold
> Users?  How many users are in the system and how fast do they need
> access to their list of new messages?
>
> When I pull up my mail client, it takes a couple of seconds for my
> Inbox to be displayed.  This is analagous to using a MagmaCollection
> for each user's message.
>
> Recall what I said MagmaCollections were designed for:  For end-user
> query requirements, which is exactly the case you've stated:  A user
> comes to check on their messages.  So a MagmaCollection is perfectly
> appropriate for that, not a MagmaPreallocatedDictionary.
>
> I don't know how many users you will have, but given the extremely
> simple access requirements, you could put htem into a MagmaCollection
> as well.
>
> So, you have one MC for "AllUsers" and then one MC for each user
> containing that users messages.
>
> > So, checking up on one's own mailbox would simply entail finding oneself's User in the Dictionary and reading the associated collection of messages.
> >
> > However, if another user were to drop a message into this collection, the same OrderedCollection would have to be accessed by another session.  Isn't this a no-no, even with refreshing a session?
>
> I'm wondering what you mean by "the same OrderedCollection".  The same
> one in the database?  Or the same one in image memory?
>
> Yes, it will be the same one in the database, but it will be different
> ones in image memory if they are retrieved by different sessions.
>
> >
> > Are you suggesting to use MagmaCollections instead of OrderedCollections?  Isn't that far more 'expensive', especially since each user on the system would be assigned such a collection just to hold their messages?
>
> MagmaCollections consume more resources than a OrderedCollection, yes,
> but the reason I stated was that it would allow multiple messages to
> come into the same user and avoid a commit-conflict.
>
>  - Chris
_______________________________________________
Magma mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/magma