com.openexchange.mail.cache
Class JSONMessageCache

java.lang.Object
  extended by com.openexchange.mail.cache.JSONMessageCache

public final class JSONMessageCache
extends java.lang.Object

JSONMessageCache - A JSON message cache.

Author:
Thorben Betten

Method Summary
 void clear()
          Clears this cache.
 boolean containsFolder(int accountId, java.lang.String fullname, int userId, int cid)
          Checks if a JSON mail object is associated with specified account ID, folder fullname and mail ID.
 boolean containsFolder(int accountId, java.lang.String fullname, com.openexchange.session.Session session)
          Checks if a JSON mail object is associated with specified account ID, folder fullname and mail ID.
 boolean containsKey(int accountId, java.lang.String fullname, java.lang.String id, int userId, int cid)
          Checks if a JSON mail object is associated with specified account ID, folder fullname and mail ID.
 boolean containsKey(int accountId, java.lang.String fullname, java.lang.String id, com.openexchange.session.Session session)
          Checks if a JSON mail object is associated with specified account ID, folder fullname and mail ID.
 org.json.JSONObject get(int accountId, java.lang.String fullname, java.lang.String id, int userId, int cid)
          Gets the cloned JSON mail object associated with specified account ID, folder fullname and mail ID.
 org.json.JSONObject get(int accountId, java.lang.String fullname, java.lang.String id, com.openexchange.session.Session session)
          Gets the cloned JSON mail object associated with specified account ID, folder fullname and mail ID.
static JSONMessageCache getInstance()
          Gets the cache instance.
static void initInstance()
          Initializes the cache instance.
 void put(int accountId, java.lang.String fullname, java.lang.String id, java.util.concurrent.FutureTask<org.json.JSONObject> jsonMailObject, int userId, int cid)
          Associates given JSON mail object with specified account ID, folder fullname and mail ID.
 void put(int accountId, java.lang.String fullname, java.lang.String id, java.util.concurrent.FutureTask<org.json.JSONObject> jsonMailObject, com.openexchange.session.Session session)
          Associates given JSON mail object with specified account ID, folder fullname and mail ID.
static void releaseInstance()
          Releases the cache instance.
 org.json.JSONObject remove(int accountId, java.lang.String fullname, java.lang.String id, int userId, int cid)
          Removes the JSON mail object associated with specified account ID, folder fullname and mail ID.
 org.json.JSONObject remove(int accountId, java.lang.String fullname, java.lang.String id, com.openexchange.session.Session session)
          Removes the JSON mail object associated with specified account ID, folder fullname and mail ID.
 void removeAllFoldersExcept(int accountId, java.lang.String fullname, int userId, int cid)
          Removes all JSON mail objects except the ones associated with specified account ID and folder fullname.
 void removeAllFoldersExcept(int accountId, java.lang.String fullname, com.openexchange.session.Session session)
          Removes all JSON mail objects except the ones associated with specified account ID and folder fullname.
 void removeFolder(int accountId, java.lang.String fullname, int userId, int cid)
          Removes all JSON mail objects associated with specified account ID and folder fullname.
 void removeFolder(int accountId, java.lang.String fullname, com.openexchange.session.Session session)
          Removes all JSON mail objects associated with specified account ID and folder fullname.
 void removeUser(int userId, int cid)
          Removes all JSON mail objects associated with specified user ID and context ID.
 void removeUser(com.openexchange.session.Session session)
          Removes all JSON mail objects associated with specified user ID and context ID.
 void switchSeenFlag(int accountId, java.lang.String fullname, boolean seen, int unread, int userId, int cid)
          Switch the \Seen flag for specified mails' JSON representations.
 void switchSeenFlag(int accountId, java.lang.String fullname, boolean seen, int unread, com.openexchange.session.Session session)
          Switch the \Seen flag for specified mails' JSON representations.
 void switchSeenFlag(int accountId, java.lang.String fullname, java.lang.String[] ids, boolean seen, int unread, int userId, int cid)
          Switch the \Seen flag for specified mails' JSON representations.
 void switchSeenFlag(int accountId, java.lang.String fullname, java.lang.String[] ids, boolean seen, int unread, com.openexchange.session.Session session)
          Switch the \Seen flag for specified mails' JSON representations.
 void updateColorFlag(int accountId, java.lang.String fullname, int colorFlag, int userId, int cid)
          Updates the color flag for specified mails' JSON representations.
 void updateColorFlag(int accountId, java.lang.String fullname, int colorFlag, com.openexchange.session.Session session)
          Updates the color flag for specified mails' JSON representations.
 void updateColorFlag(int accountId, java.lang.String fullname, java.lang.String[] ids, int colorFlag, int userId, int cid)
          Updates the color flag for specified mails' JSON representations.
 void updateColorFlag(int accountId, java.lang.String fullname, java.lang.String[] ids, int colorFlag, com.openexchange.session.Session session)
          Updates the color flag for specified mails' JSON representations.
 void updateFlags(int accountId, java.lang.String fullname, int newFlags, boolean set, int userId, int cid)
          Updates flags for specified mails' JSON representations.
 void updateFlags(int accountId, java.lang.String fullname, int newFlags, boolean set, com.openexchange.session.Session session)
          Updates flags for specified mails' JSON representations.
 void updateFlags(int accountId, java.lang.String fullname, java.lang.String[] ids, int newFlags, boolean set, int userId, int cid)
          Updates flags for specified mails' JSON representations.
 void updateFlags(int accountId, java.lang.String fullname, java.lang.String[] ids, int newFlags, boolean set, com.openexchange.session.Session session)
          Updates flags for specified mails' JSON representations.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static JSONMessageCache getInstance()
Gets the cache instance.

Returns:
The cache instance or null

initInstance

public static void initInstance()
                         throws MailException
Initializes the cache instance.

Throws:
MailException - If initialization fails

releaseInstance

public static void releaseInstance()
Releases the cache instance.


put

public void put(int accountId,
                java.lang.String fullname,
                java.lang.String id,
                java.util.concurrent.FutureTask<org.json.JSONObject> jsonMailObject,
                com.openexchange.session.Session session)
         throws MailException
Associates given JSON mail object with specified account ID, folder fullname and mail ID. If the cache previously contained a mapping for this key, the old value is replaced by the specified value.

Parameters:
accountId - The account ID
fullname - The folder fullname
id - The mail ID
jsonMailObject - The JSON mail object
session - The session providing user and context information
Throws:
MailException - If put fails

put

public void put(int accountId,
                java.lang.String fullname,
                java.lang.String id,
                java.util.concurrent.FutureTask<org.json.JSONObject> jsonMailObject,
                int userId,
                int cid)
         throws MailException
Associates given JSON mail object with specified account ID, folder fullname and mail ID. If the cache previously contained a mapping for this key, the old value is replaced by the specified value.

Parameters:
accountId - The account ID
fullname - The folder fullname
id - The mail ID
jsonMailObject - The JSON mail object
userId - The user ID
cid - The context ID
Throws:
MailException - If put fails

containsKey

public boolean containsKey(int accountId,
                           java.lang.String fullname,
                           java.lang.String id,
                           com.openexchange.session.Session session)
Checks if a JSON mail object is associated with specified account ID, folder fullname and mail ID.

Parameters:
accountId - The account ID
fullname - The folder fullname
id - The mail ID
session - The session providing user and context information
Returns:
true If this cache contains a mapping for given key; otherwise false

containsKey

public boolean containsKey(int accountId,
                           java.lang.String fullname,
                           java.lang.String id,
                           int userId,
                           int cid)
Checks if a JSON mail object is associated with specified account ID, folder fullname and mail ID.

Parameters:
accountId - The account ID
fullname - The folder fullname
id - The mail ID
userId - The user ID
cid - The context ID
Returns:
true If this cache contains a mapping for given key; otherwise false

containsFolder

public boolean containsFolder(int accountId,
                              java.lang.String fullname,
                              com.openexchange.session.Session session)
Checks if a JSON mail object is associated with specified account ID, folder fullname and mail ID.

Parameters:
accountId - The account ID
fullname - The folder fullname
id - The mail ID
session - The session providing user and context information
Returns:
true If this cache contains a mapping for given key; otherwise false

containsFolder

public boolean containsFolder(int accountId,
                              java.lang.String fullname,
                              int userId,
                              int cid)
Checks if a JSON mail object is associated with specified account ID, folder fullname and mail ID.

Parameters:
accountId - The account ID
fullname - The folder fullname
id - The mail ID
userId - The user ID
cid - The context ID
Returns:
true If this cache contains a mapping for given key; otherwise false

get

public org.json.JSONObject get(int accountId,
                               java.lang.String fullname,
                               java.lang.String id,
                               com.openexchange.session.Session session)
                        throws MailException
Gets the cloned JSON mail object associated with specified account ID, folder fullname and mail ID.

Parameters:
accountId - The account ID
fullname - The folder fullname
id - The mail ID
session - The session providing user and context information
Returns:
The cloned JSON mail object or null
Throws:
MailException - If JSON mail object cannot be returned

get

public org.json.JSONObject get(int accountId,
                               java.lang.String fullname,
                               java.lang.String id,
                               int userId,
                               int cid)
                        throws MailException
Gets the cloned JSON mail object associated with specified account ID, folder fullname and mail ID.

Parameters:
accountId - The account ID
fullname - The folder fullname
id - The mail ID
userId - The user ID
cid - The context ID
Returns:
The cloned JSON mail object or null
Throws:
MailException - If JSON mail object cannot be returned

switchSeenFlag

public void switchSeenFlag(int accountId,
                           java.lang.String fullname,
                           java.lang.String[] ids,
                           boolean seen,
                           int unread,
                           com.openexchange.session.Session session)
                    throws MailException
Switch the \Seen flag for specified mails' JSON representations. Decrements unread message counter for each message.

Parameters:
accountId - The account ID
fullname - The fullname
id - The mail ID
seen - true to set \Seen flag; otherwise false
unread - The unread count
session - The session providing user and context information
Throws:
MailException - If an error occurs

switchSeenFlag

public void switchSeenFlag(int accountId,
                           java.lang.String fullname,
                           java.lang.String[] ids,
                           boolean seen,
                           int unread,
                           int userId,
                           int cid)
                    throws MailException
Switch the \Seen flag for specified mails' JSON representations. Decrements unread message counter for each message.

Parameters:
accountId - The account ID
fullname - The fullname
id - The mail ID
seen - true to set \Seen flag; otherwise false
unread - The unread count for specified folder
userId - The user ID
cid - The context ID
Throws:
MailException - If an error occurs

switchSeenFlag

public void switchSeenFlag(int accountId,
                           java.lang.String fullname,
                           boolean seen,
                           int unread,
                           com.openexchange.session.Session session)
                    throws MailException
Switch the \Seen flag for specified mails' JSON representations. Decrements unread message counter for each message.

Parameters:
accountId - The account ID
fullname - The fullname
seen - true to set \Seen flag; otherwise false
unread - The unread count
session - The session providing user and context information
Throws:
MailException - If an error occurs

switchSeenFlag

public void switchSeenFlag(int accountId,
                           java.lang.String fullname,
                           boolean seen,
                           int unread,
                           int userId,
                           int cid)
                    throws MailException
Switch the \Seen flag for specified mails' JSON representations. Decrements unread message counter for each message.

Parameters:
accountId - The account ID
fullname - The fullname
seen - true to set \Seen flag; otherwise false
unread - The unread count for specified folder
userId - The user ID
cid - The context ID
Throws:
MailException - If an error occurs

updateFlags

public void updateFlags(int accountId,
                        java.lang.String fullname,
                        java.lang.String[] ids,
                        int newFlags,
                        boolean set,
                        com.openexchange.session.Session session)
                 throws MailException
Updates flags for specified mails' JSON representations.

Parameters:
accountId - The account ID
fullname - The fullname
id - The mail ID
flags - The flags bit mask
set - true to set; otherwise false
session - The session providing user and context information
Throws:
MailException - If an error occurs

updateFlags

public void updateFlags(int accountId,
                        java.lang.String fullname,
                        java.lang.String[] ids,
                        int newFlags,
                        boolean set,
                        int userId,
                        int cid)
                 throws MailException
Updates flags for specified mails' JSON representations.

Parameters:
accountId - The account ID
fullname - The fullname
id - The mail ID
flags - The flags bit mask
set - true to set; otherwise false
userId - The user ID
cid - The context ID
Throws:
MailException - If an error occurs

updateFlags

public void updateFlags(int accountId,
                        java.lang.String fullname,
                        int newFlags,
                        boolean set,
                        com.openexchange.session.Session session)
                 throws MailException
Updates flags for specified mails' JSON representations.

Parameters:
accountId - The account ID
fullname - The fullname
flags - The flags bit mask
set - true to set; otherwise false
session - The session providing user and context information
Throws:
MailException - If an error occurs

updateFlags

public void updateFlags(int accountId,
                        java.lang.String fullname,
                        int newFlags,
                        boolean set,
                        int userId,
                        int cid)
                 throws MailException
Updates flags for specified mails' JSON representations.

Parameters:
accountId - The account ID
fullname - The fullname
flags - The flags bit mask
set - true to set; otherwise false
userId - The user ID
cid - The context ID
Throws:
MailException - If an error occurs

updateColorFlag

public void updateColorFlag(int accountId,
                            java.lang.String fullname,
                            java.lang.String[] ids,
                            int colorFlag,
                            com.openexchange.session.Session session)
                     throws MailException
Updates the color flag for specified mails' JSON representations.

Parameters:
accountId - The account ID
fullname - The fullname
ids - The mail IDs
colorFlag - The color flag to set
session - The session providing user and context information
Throws:
MailException - If an error occurs

updateColorFlag

public void updateColorFlag(int accountId,
                            java.lang.String fullname,
                            java.lang.String[] ids,
                            int colorFlag,
                            int userId,
                            int cid)
                     throws MailException
Updates the color flag for specified mails' JSON representations.

Parameters:
accountId - The account ID
fullname - The fullname
ids - The mail IDs
colorFlag - The color flag to set
userId - The user ID
cid - The context ID
Throws:
MailException - If an error occurs

updateColorFlag

public void updateColorFlag(int accountId,
                            java.lang.String fullname,
                            int colorFlag,
                            com.openexchange.session.Session session)
                     throws MailException
Updates the color flag for specified mails' JSON representations.

Parameters:
accountId - The account ID
fullname - The fullname
colorFlag - The color flag to set
session - The session providing user and context information
Throws:
MailException - If an error occurs

updateColorFlag

public void updateColorFlag(int accountId,
                            java.lang.String fullname,
                            int colorFlag,
                            int userId,
                            int cid)
                     throws MailException
Updates the color flag for specified mails' JSON representations.

Parameters:
accountId - The account ID
fullname - The fullname
colorFlag - The color flag to set
userId - The user ID
cid - The context ID
Throws:
MailException - If an error occurs

remove

public org.json.JSONObject remove(int accountId,
                                  java.lang.String fullname,
                                  java.lang.String id,
                                  com.openexchange.session.Session session)
                           throws MailException
Removes the JSON mail object associated with specified account ID, folder fullname and mail ID.

Parameters:
accountId - The account ID
fullname - The folder fullname
id - The mail ID
session - The session providing user and context information
Returns:
The removed JSON mail object or null
Throws:
MailException - If JSON mail object cannot be removed

remove

public org.json.JSONObject remove(int accountId,
                                  java.lang.String fullname,
                                  java.lang.String id,
                                  int userId,
                                  int cid)
                           throws MailException
Removes the JSON mail object associated with specified account ID, folder fullname and mail ID.

Parameters:
accountId - The account ID
fullname - The folder fullname
id - The mail ID
userId - The user ID
cid - The context ID
Returns:
The removed JSON mail object or null
Throws:
MailException - If JSON mail object cannot be removed

removeFolder

public void removeFolder(int accountId,
                         java.lang.String fullname,
                         com.openexchange.session.Session session)
Removes all JSON mail objects associated with specified account ID and folder fullname.

Parameters:
accountId - The account ID
fullname - The folder fullname
session - The session providing user and context information

removeFolder

public void removeFolder(int accountId,
                         java.lang.String fullname,
                         int userId,
                         int cid)
Removes all JSON mail objects associated with specified account ID and folder fullname.

Parameters:
accountId - The account ID
fullname - The folder fullname
userId - The user ID
cid - The context ID

removeAllFoldersExcept

public void removeAllFoldersExcept(int accountId,
                                   java.lang.String fullname,
                                   com.openexchange.session.Session session)
Removes all JSON mail objects except the ones associated with specified account ID and folder fullname.

Parameters:
accountId - The account ID
fullname - The fullname of the folder whose mails shall be kept
session - The session providing user and context information

removeAllFoldersExcept

public void removeAllFoldersExcept(int accountId,
                                   java.lang.String fullname,
                                   int userId,
                                   int cid)
Removes all JSON mail objects except the ones associated with specified account ID and folder fullname.

Parameters:
accountId - The account ID
fullname - The fullname of the folder whose mails shall be kept
userId - The user ID
cid - The context ID

removeUser

public void removeUser(com.openexchange.session.Session session)
Removes all JSON mail objects associated with specified user ID and context ID.

Parameters:
session - The session providing user and context information

removeUser

public void removeUser(int userId,
                       int cid)
Removes all JSON mail objects associated with specified user ID and context ID.

Parameters:
userId - The user ID
cid - The context ID

clear

public void clear()
Clears this cache.