Class MUCPersistenceManager
- java.lang.Object
-
- org.jivesoftware.openfire.muc.spi.MUCPersistenceManager
-
public class MUCPersistenceManager extends Object
A manager responsible for ensuring room persistence. There are different ways to make a room persistent. The first attempt will be to save the room in a relation database. If for some reason the room can't be saved in the database an alternative repository will be used to save the room such as XML files.After the problem with the database has been solved, the information saved in the XML files will be moved to the database.
- Author:
- Gaston Dombiak
-
-
Constructor Summary
Constructors Constructor Description MUCPersistenceManager()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static int
countRooms(MultiUserChatService service)
Counts all rooms of a chat service.static void
deleteFromDB(MUCRoom room)
Removes the room configuration and its affiliates from the database.static void
deleteLocalProperty(String subdomain, String name)
static void
deleteProperty(String subdomain, String name)
Deletes a Jive property.static boolean
getBooleanProperty(String subdomain, String name)
Returns a boolean value Jive property.static boolean
getBooleanProperty(String subdomain, String name, boolean defaultValue)
Returns a boolean value Jive property.static int
getIntProperty(String subdomain, String name, int defaultValue)
Returns an integer value Jive property.static long
getLongProperty(String subdomain, String name, long defaultValue)
Returns a long value Jive property.static List<String>
getProperties(String subdomain, String parent)
Return all immediate children property values of a parent Jive property as a list of strings, or an empty list if there are no children.static String
getProperty(String subdomain, String name)
Returns a Jive property.static String
getProperty(String subdomain, String name, String defaultValue)
Returns a Jive property.static List<String>
getPropertyNames(String subdomain)
Returns all MUC service property names.static List<String>
getPropertyNames(String subdomain, String parent)
Return all immediate children property names of a parent Jive property as a list of strings, or an empty list if there are no children.static String
getReservedNickname(MUCRoom room, String bareJID)
Returns the reserved room nickname for the bare JID in a given room or null if none.static void
loadFromDB(MUCRoom room)
Loads the room configuration from the database if the room was persistent.static void
loadHistory(MUCRoom room)
Load or reload the room history for a particular room from the database into memory.static void
loadHistory(MUCRoom room, int maxNumber)
Load or reload the room history for a particular room from the database into memory.static Collection<String>
loadRoomNamesFromDB(MultiUserChatService chatserver)
Loads the name of all the rooms that are in the database.static Collection<MUCRoom>
loadRoomsFromDB(MultiUserChatService chatserver, Date cleanupDate)
Loads all the rooms that had occupants after a given date from the database.static void
refreshProperties(String subdomain)
Resets (reloads) the properties for a specified subdomain.static void
removeAffiliationFromDB(MUCRoom room, org.xmpp.packet.JID jid, MUCRole.Affiliation oldAffiliation)
Removes the affiliation of the user from the DB if the room is persistent.static void
removeAffiliationFromDB(org.xmpp.packet.JID affiliationJID)
Removes the affiliation of the user from the DB if ANY room that is persistent.static void
saveAffiliationToDB(MUCRoom room, org.xmpp.packet.JID jid, String nickname, MUCRole.Affiliation newAffiliation, MUCRole.Affiliation oldAffiliation)
Update the DB with the new affiliation of the user in the room.static boolean
saveConversationLogBatch(List<org.jivesoftware.openfire.muc.spi.ConversationLogEntry> batch)
Saves the conversation log entry batch to the database.static void
saveToDB(MUCRoom room)
Save the room configuration to the DB.static void
setLocalProperty(String subdomain, String name, String value)
static void
setProperties(String subdomain, Map<String,String> propertyMap)
Sets multiple Jive properties at once.static void
setProperty(String subdomain, String name, String value)
Sets a Jive property.static void
updateRoomEmptyDate(MUCRoom room)
Updates the room's lock status in the database.static void
updateRoomLock(MUCRoom room)
Updates the room's lock status in the database.static void
updateRoomSubject(MUCRoom room)
Updates the room's subject in the database.
-
-
-
Method Detail
-
getReservedNickname
public static String getReservedNickname(MUCRoom room, String bareJID)
Returns the reserved room nickname for the bare JID in a given room or null if none.- Parameters:
room
- the room where the user would like to obtain his reserved nickname.bareJID
- The bare jid of the user of which you'd like to obtain his reserved nickname.- Returns:
- the reserved room nickname for the bare JID or null if none.
-
countRooms
public static int countRooms(MultiUserChatService service)
Counts all rooms of a chat service. Note that this method will count only rooms that are persisted in the database, and can exclude in-memory rooms that are not persisted.- Parameters:
service
- the chat service for which to return a room count.- Returns:
- A room number count
-
loadFromDB
public static void loadFromDB(MUCRoom room)
Loads the room configuration from the database if the room was persistent.- Parameters:
room
- the room to load from the database if persistent
-
saveToDB
public static void saveToDB(MUCRoom room)
Save the room configuration to the DB.- Parameters:
room
- The room to save its configuration.
-
deleteFromDB
public static void deleteFromDB(MUCRoom room)
Removes the room configuration and its affiliates from the database.- Parameters:
room
- the room to remove from the database.
-
loadRoomNamesFromDB
public static Collection<String> loadRoomNamesFromDB(MultiUserChatService chatserver)
Loads the name of all the rooms that are in the database.- Parameters:
chatserver
- the chat server that will hold the loaded rooms.- Returns:
- a collection with all room names.
-
loadRoomsFromDB
public static Collection<MUCRoom> loadRoomsFromDB(MultiUserChatService chatserver, Date cleanupDate)
Loads all the rooms that had occupants after a given date from the database. This query will be executed only when the service is starting up.- Parameters:
chatserver
- the chat server that will hold the loaded rooms.cleanupDate
- rooms that hadn't been used after this date won't be loaded.- Returns:
- a collection with all the persistent rooms.
-
loadHistory
public static void loadHistory(@Nonnull MUCRoom room) throws SQLException
Load or reload the room history for a particular room from the database into memory. Invocation of this method will replace exising room history that's stored in memory (if any) with a freshly set of messages obtained from the database.- Parameters:
room
- The room for which to load message history from the database into memory.- Throws:
SQLException
-
loadHistory
public static void loadHistory(@Nonnull MUCRoom room, int maxNumber) throws SQLException
Load or reload the room history for a particular room from the database into memory. Invocation of this method will replace exising room history that's stored in memory (if any) with a freshly set of messages obtained from the database.- Parameters:
room
- The room for which to load message history from the database into memory.maxNumber
- A hint for the maximum number of messages that need to be read from the database. -1 for all messages.- Throws:
SQLException
-
updateRoomSubject
public static void updateRoomSubject(MUCRoom room)
Updates the room's subject in the database.- Parameters:
room
- the room to update its subject in the database.
-
updateRoomLock
public static void updateRoomLock(MUCRoom room)
Updates the room's lock status in the database.- Parameters:
room
- the room to update its lock status in the database.
-
updateRoomEmptyDate
public static void updateRoomEmptyDate(MUCRoom room)
Updates the room's lock status in the database.- Parameters:
room
- the room to update its lock status in the database.
-
saveAffiliationToDB
public static void saveAffiliationToDB(MUCRoom room, org.xmpp.packet.JID jid, String nickname, MUCRole.Affiliation newAffiliation, MUCRole.Affiliation oldAffiliation)
Update the DB with the new affiliation of the user in the room. The new information will be saved only if the room is_persistent and has already been saved to the database previously.- Parameters:
room
- The room where the affiliation of the user was updated.jid
- The bareJID of the user to update this affiliation.nickname
- The reserved nickname of the user in the room or null if none.newAffiliation
- the new affiliation of the user in the room.oldAffiliation
- the previous affiliation of the user in the room.
-
removeAffiliationFromDB
public static void removeAffiliationFromDB(MUCRoom room, org.xmpp.packet.JID jid, MUCRole.Affiliation oldAffiliation)
Removes the affiliation of the user from the DB if the room is persistent.- Parameters:
room
- The room where the affiliation of the user was removed.jid
- The bareJID of the user to remove his affiliation.oldAffiliation
- the previous affiliation of the user in the room.
-
removeAffiliationFromDB
public static void removeAffiliationFromDB(org.xmpp.packet.JID affiliationJID)
Removes the affiliation of the user from the DB if ANY room that is persistent.- Parameters:
affiliationJID
- The bareJID of the user to remove his affiliation from ALL persistent rooms.
-
saveConversationLogBatch
public static boolean saveConversationLogBatch(List<org.jivesoftware.openfire.muc.spi.ConversationLogEntry> batch)
Saves the conversation log entry batch to the database.- Parameters:
batch
- a list of ConversationLogEntry to save to the database.- Returns:
- true if the batch was saved successfully to the database.
-
getProperty
public static String getProperty(String subdomain, String name)
Returns a Jive property.- Parameters:
subdomain
- the subdomain of the service to retrieve a property fromname
- the name of the property to return.- Returns:
- the property value specified by name.
-
getProperty
public static String getProperty(String subdomain, String name, String defaultValue)
Returns a Jive property. If the specified property doesn't exist, thedefaultValue
will be returned.- Parameters:
subdomain
- the subdomain of the service to retrieve a property fromname
- the name of the property to return.defaultValue
- value returned if the property doesn't exist.- Returns:
- the property value specified by name.
-
getIntProperty
public static int getIntProperty(String subdomain, String name, int defaultValue)
Returns an integer value Jive property. If the specified property doesn't exist, thedefaultValue
will be returned.- Parameters:
subdomain
- the subdomain of the service to retrieve a property fromname
- the name of the property to return.defaultValue
- value returned if the property doesn't exist or was not a number.- Returns:
- the property value specified by name or
defaultValue
.
-
getLongProperty
public static long getLongProperty(String subdomain, String name, long defaultValue)
Returns a long value Jive property. If the specified property doesn't exist, thedefaultValue
will be returned.- Parameters:
subdomain
- the subdomain of the service to retrieve a property fromname
- the name of the property to return.defaultValue
- value returned if the property doesn't exist or was not a number.- Returns:
- the property value specified by name or
defaultValue
.
-
getBooleanProperty
public static boolean getBooleanProperty(String subdomain, String name)
Returns a boolean value Jive property.- Parameters:
subdomain
- the subdomain of the service to retrieve a property fromname
- the name of the property to return.- Returns:
- true if the property value exists and is set to
"true"
(ignoring case). Otherwisefalse
is returned.
-
getBooleanProperty
public static boolean getBooleanProperty(String subdomain, String name, boolean defaultValue)
Returns a boolean value Jive property. If the property doesn't exist, thedefaultValue
will be returned. If the specified property can't be found, or if the value is not a number, thedefaultValue
will be returned.- Parameters:
subdomain
- the subdomain of the service to retrieve a property fromname
- the name of the property to return.defaultValue
- value returned if the property doesn't exist.- Returns:
- true if the property value exists and is set to
"true"
(ignoring case). Otherwisefalse
is returned.
-
getPropertyNames
public static List<String> getPropertyNames(String subdomain, String parent)
Return all immediate children property names of a parent Jive property as a list of strings, or an empty list if there are no children. For example, given the propertiesX.Y.A
,X.Y.B
,X.Y.C
andX.Y.C.D
, then the immediate child properties ofX.Y
areA
,B
, andC
(C.D
would not be returned using this method).- Parameters:
subdomain
- the subdomain of the service to retrieve a property fromparent
- the root "node" of the properties to retrieve- Returns:
- a List of all immediate children property names (Strings).
-
getProperties
public static List<String> getProperties(String subdomain, String parent)
Return all immediate children property values of a parent Jive property as a list of strings, or an empty list if there are no children. For example, given the propertiesX.Y.A
,X.Y.B
,X.Y.C
andX.Y.C.D
, then the immediate child properties ofX.Y
areX.Y.A
,X.Y.B
, andX.Y.C
(the value ofX.Y.C.D
would not be returned using this method).- Parameters:
subdomain
- the subdomain of the service to retrieve a property fromparent
- the name of the parent property to return the children for.- Returns:
- all child property values for the given parent.
-
getPropertyNames
public static List<String> getPropertyNames(String subdomain)
Returns all MUC service property names.- Parameters:
subdomain
- the subdomain of the service to retrieve a property from- Returns:
- a List of all property names (Strings).
-
setProperty
public static void setProperty(String subdomain, String name, String value)
Sets a Jive property. If the property doesn't already exists, a new one will be created.- Parameters:
subdomain
- the subdomain of the service to set a property forname
- the name of the property being set.value
- the value of the property being set.
-
setProperties
public static void setProperties(String subdomain, Map<String,String> propertyMap)
Sets multiple Jive properties at once. If a property doesn't already exists, a new one will be created.- Parameters:
subdomain
- the subdomain of the service to set properties forpropertyMap
- a map of properties, keyed on property name.
-
deleteProperty
public static void deleteProperty(String subdomain, String name)
Deletes a Jive property. If the property doesn't exist, the method does nothing. All children of the property will be deleted as well.- Parameters:
subdomain
- the subdomain of the service to delete a property fromname
- the name of the property to delete.
-
refreshProperties
public static void refreshProperties(String subdomain)
Resets (reloads) the properties for a specified subdomain.- Parameters:
subdomain
- the subdomain of the service to reload properties for.
-
-