2

I'm developping a "kind-of" chat application using long-polling.

I'm using Play Framework 1.2.5 and i'm trying to handle multiple conversations storing their information in a database using JPA.

In order to listen and publish every event into the chat (someone joining, leaving, or texting) i'm using an object of the type ArchivedEventStream< Event >, but as this object is not an Entity, Play Framework doesn't find a proper type for him in the database.

For the moment I made a static HashMap with the Model id of every conversation as a key and my ArchivedEventStream object with the events. I added the @Transient annotation to it for not counting my Map into the database and evade the error.

@Transient
public final static HashMap<Long, ArchivedEventStream<PlayEvent>> playEvents =  new HashMap<Long, F.ArchivedEventStream<PlayEvent>>();

It works for the moment and many people can use their own conversation following their own flux, but after a while, the server destroys this static variable producing some NullPointerExceptions.

Is there any way to store this object into my database so it's accesible for each conversation?

or, can I stop my server Play from destroying my variable?

or even, is there any other better option to resolve this problem?

Thank you very much.

1 Answer 1

0

The best way to store state with Play is in the Cache. However that will not guaranty that your events will always be available (server restart, ttl...)

If you need these events to be permanently available you will need to persist them, possibly to the DB. You could get the ArchivedEventStream implement model, store them in the cache and on cache miss retrieve them from the database.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.