Class MultiUserChatServiceImpl
- java.lang.Object
-
- org.jivesoftware.openfire.muc.spi.MultiUserChatServiceImpl
-
- All Implemented Interfaces:
ClusterEventListener
,DiscoInfoProvider
,DiscoItemsProvider
,ServerItemsProvider
,MultiUserChatService
,XMPPServerListener
,org.xmpp.component.Component
public class MultiUserChatServiceImpl extends Object implements org.xmpp.component.Component, MultiUserChatService, ServerItemsProvider, DiscoInfoProvider, DiscoItemsProvider, XMPPServerListener, ClusterEventListener
Implements the chat server as a cached memory resident chat server. The server is also responsible for responding Multi-User Chat disco requests as well as removing inactive users from the rooms after a period of time and to maintain a log of the conversation in the rooms that require to log their conversations. The conversations log is saved to the database using a separate process.Temporary rooms are held in memory as long as they have occupants. They will be destroyed after the last occupant left the room. On the other hand, persistent rooms are always present in memory even after the last occupant left the room. In order to keep memory clean of persistent rooms that have been forgotten or abandoned this class includes a clean up process. The clean up process will remove from memory rooms that haven't had occupants for a while. Moreover, forgotten or abandoned rooms won't be loaded into memory when the Multi-User Chat service starts up.
- Author:
- Gaston Dombiak, Guus der Kinderen, guus@goodbytes.nl
-
-
Constructor Summary
Constructors Constructor Description MultiUserChatServiceImpl(String subdomain, String description, Boolean isHidden)
Create a new group chat server.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addExtraFeature(String feature)
Adds an extra Disco feature to the list of features returned for the conference service.void
addExtraIdentity(String category, String name, String type)
Adds an extra Disco identity to the list of identities returned for the conference service.void
addIQHandler(IQHandler iqHandler)
Add a IQHandler to MUC rooms and services.void
addSysadmin(org.xmpp.packet.JID userJID)
Adds a new system administrator of the MUC service.void
addSysadmins(Collection<org.xmpp.packet.JID> userJIDs)
Adds multiple system administrators for the MUC service.void
addUserAllowedToCreate(org.xmpp.packet.JID userJID)
Adds a new user/group to the list of JIDs that are allowed to create MUC rooms.void
addUsersAllowedToCreate(Collection<org.xmpp.packet.JID> userJIDs)
Adds new users/groups to the list of JIDs that are allowed to create MUC rooms.boolean
canDiscoverRoom(MUCRoom room, org.xmpp.packet.JID entity)
Checks if the a particular entity is allowed to discover the room's existence.void
enableService(boolean enabled, boolean persistent)
Enables or disables the MUC service.List<MUCRoom>
getActiveAndInactiveRooms()
Returns all rooms serviced by this service.List<MUCRoom>
getActiveChatRooms()
Returns a list with a snapshot of all the rooms in the server that are actively loaded in memory.org.xmpp.packet.JID
getAddress()
Set<String>
getAllRoomNames()
Combine names of all rooms in the database (to catch any rooms that aren't currently in memory) with all names of rooms currently in memory (to include rooms that are non-persistent / never saved in the database).Collection<MUCRoomSearchInfo>
getAllRoomSearchInfo()
Archiver<org.jivesoftware.openfire.muc.spi.ConversationLogEntry>
getArchiver()
Accessor uses the "double-check idiom" for proper lazy instantiation.MUCRoom
getChatRoom(String roomName)
Obtains a chatroom by name.MUCRoom
getChatRoom(String roomName, org.xmpp.packet.JID userjid)
Obtains a chatroom by name.Lock
getChatRoomLock(String roomName)
Generates a mutex object that controls cluster-wide access to a MUCRoom instance that represents the room in this service identified by the provided name.String
getDescription()
Set<org.xmpp.forms.DataForm>
getExtendedInfos(String name, String node, org.xmpp.packet.JID senderJID)
Returns a collection of XDataForm with the extended information about the entity or an empty collection if none.Iterator<String>
getFeatures(String name, String node, org.xmpp.packet.JID senderJID)
Returns an Iterator (of String) with the supported features.HistoryStrategy
getHistoryStrategy()
Obtain the server-wide default message history settings.Iterator<org.dom4j.Element>
getIdentities(String name, String node, org.xmpp.packet.JID senderJID)
Returns an Iterator (of Element) with the target entity's identities.Duration
getIdleUserKickThreshold()
Returns the duration that a user must be idle before he/she gets kicked from all the rooms.Duration
getIdleUserPingThreshold()
Returns the duration that a user must be idle before he/she gets pinged by the rooms that they're an occupant of (to determine if they're a 'ghost user').Duration
getIdleUserTaskInterval()
Returns the period of fixed-delay executions of tasks that operate on idle users.long
getIncomingMessageCount(boolean resetAfter)
Returns the total number of incoming messages since last reset.Iterator<DiscoServerItem>
getItems()
Returns an Iterator (of DiscoServerItem) with the items associated with the server or null if none.Iterator<DiscoItem>
getItems(String name, String node, org.xmpp.packet.JID senderJID)
Returns an Iterator (of DiscoItem) with the target entity's items or null if none.LocalMUCRoomManager
getLocalMUCRoomManager()
Duration
getLogBatchGracePeriod()
Returns the maximum time to wait for a next incoming entry before writing the batch to the database.Duration
getLogMaxBatchInterval()
Returns the maximum time allowed to elapse between writing archive entries to the database.int
getLogMaxConversationBatchSize()
Returns the maximum number of messages to save to the database on each run of the archiving process.MUCEventDelegate
getMUCDelegate()
Gets the MUC event delegate handler for this service.Collection<MUCRole>
getMUCRoles(org.xmpp.packet.JID user)
Returns the list ofMUCRole
in all rooms for the specified user's session.String
getName()
int
getNumberChatRooms()
Returns the number of existing rooms in the server (i.e.int
getNumberConnectedUsers()
Returns the total number of occupants in all rooms.int
getNumberRoomOccupants()
Returns the total number of users that have joined in all rooms in the server.OccupantManager
getOccupantManager()
long
getOutgoingMessageCount(boolean resetAfter)
Returns the total number of outgoing messages since last reset.String
getServiceDomain()
Returns the fully-qualifed domain name of this chat service.String
getServiceName()
Returns the subdomain of the chat service.Collection<org.xmpp.packet.JID>
getSysadmins()
Returns the collection of JIDs that are system administrators of the MUC service.long
getTotalChatTime()
Returns the total chat time of all rooms combined.Collection<org.xmpp.packet.JID>
getUsersAllowedToCreate()
Returns the collection of JIDs that are allowed to create MUC rooms.boolean
hasChatRoom(String roomName)
Returns true if the server includes a chatroom with the requested name.boolean
hasInfo(String name, String node, org.xmpp.packet.JID senderJID)
Returns true if we can provide information related to the requested name and node.void
initialize(XMPPServer server)
void
initialize(org.xmpp.packet.JID jid, org.xmpp.component.ComponentManager componentManager)
void
initializeSettings()
boolean
isAllowToDiscoverLockedRooms()
Returns the flag that indicates if the service should provide information about locked rooms when handling service discovery requests.boolean
isAllowToDiscoverMembersOnlyRooms()
Returns the flag that indicates if the service should provide information about non-public members-only rooms when handling service discovery requests.boolean
isAllRegisteredUsersAllowedToCreate()
Sets if all registered users of Openfire are allowed to create rooms.boolean
isDeliveryRelatedErrorResponse(org.xmpp.packet.Packet stanza)
Determines if a stanza is sent by (on behalf of) an entity that MUC room believes to be an occupant when they've left: a 'ghost' occupant For message and presence stanzas, the delivery errors as defined in section 18.1.2 of XEP-0045 are used.boolean
isHidden()
Returns true if the MUC service is a hidden, externally managed, service.boolean
isPendingPingResponse(org.xmpp.packet.Packet stanza)
Determines if a stanza is a client-generated response to an IQ Ping request sent by this server.boolean
isRoomCreationRestricted()
Returns false if anyone can create rooms or true if only the returned JIDs ingetUsersAllowedToCreate
are allowed to create rooms.boolean
isServiceEnabled()
Returns true if the MUC service is available.boolean
isSysadmin(org.xmpp.packet.JID bareJID)
Validates the given JID as a MUC service administrator.void
joinedCluster()
Notification event indicating that this JVM is now part of a cluster.void
joinedCluster(byte[] nodeID)
Notification event indicating that another JVM is now part of a cluster.void
leftCluster()
Notification event indicating that this JVM is no longer part of the cluster.void
leftCluster(byte[] nodeID)
Notification event indicating that another JVM is no longer part of the cluster.void
logConversation(MUCRoom room, org.xmpp.packet.Message message, org.xmpp.packet.JID sender)
Logs that a given message was sent to a room as part of a conversation.void
markedAsSeniorClusterMember()
Notification event indicating that this JVM is now the senior cluster member.void
messageBroadcastedTo(int numOccupants)
Notification message indicating the server that an incoming message was broadcasted to a given number of occupants.void
process(SyncLocalOccupantsAndSendJoinPresenceTask task)
Used by other nodes telling us about their occupants.void
processPacket(org.xmpp.packet.Packet packet)
void
processRegularStanza(org.xmpp.packet.Packet packet)
This method does all stanza routing in the chat server for 'regular' MUC stanzas.void
processVCardResponse(org.xmpp.packet.IQ response)
Processes a VCard response stanza that is supposedly sent to an occupant of a room as a result of that occupant having requested the VCard of another occupant earlier.void
removeChatRoom(String roomName)
Removes the room associated with the given name.void
removeExtraFeature(String feature)
Removes an extra Disco feature from the list of features returned for the conference service.void
removeExtraIdentity(String name)
Removes an extra Disco identity from the list of identities returned for the conference service.void
removeIQHandler(IQHandler iqHandler)
void
removeSysadmin(org.xmpp.packet.JID userJID)
Removes a system administrator of the MUC service.void
removeUserAllowedToCreate(org.xmpp.packet.JID userJID)
Removes a user/group from list of JIDs that are allowed to create MUC rooms.void
removeUsersAllowedToCreate(Collection<org.xmpp.packet.JID> userJIDs)
Removes users/groups from list of JIDs that are allowed to create MUC rooms.void
serverStarted()
Notification message indicating that the server has been started.void
serverStopping()
Notification message indication that the server is about to be stopped.void
setAllowToDiscoverLockedRooms(boolean allowToDiscoverLockedRooms)
Sets the flag that indicates if the service should provide information about locked rooms when handling service discovery requests.void
setAllowToDiscoverMembersOnlyRooms(boolean allowToDiscoverMembersOnlyRooms)
Sets the flag that indicates if the service should provide information about non-public members-only rooms when handling service discovery requests.void
setAllRegisteredUsersAllowedToCreate(boolean allow)
Sets if all registered users of Openfire are allowed to create rooms.void
setDescription(String desc)
void
setHidden(boolean isHidden)
void
setIdleUserKickThreshold(Duration duration)
Sets the duration that a user must be idle before he/she gets kicked from all the rooms.void
setIdleUserPingThreshold(Duration duration)
Sets the duration that a user must be idle before he/she gets pinged by the room, to determine if the user is a 'ghost user'.void
setIdleUserTaskInterval(Duration duration)
Sets the period of the fixed-delay execution of tasks by theTimer
whose main responsibility is to process users that have been idle for a certain time.void
setLogBatchGracePeriod(Duration interval)
Sets the maximum time to wait for a next incoming entry before writing the batch to the database.void
setLogMaxBatchInterval(Duration interval)
Sets the maximum time allowed to elapse between writing archive batches to the database.void
setLogMaxConversationBatchSize(int size)
Sets the maximum number of messages to save to the database on each run of the archiving process.void
setMUCDelegate(MUCEventDelegate delegate)
Sets the MUC event delegate handler for this service.void
setRoomCreationRestricted(boolean roomCreationRestricted)
Sets if anyone can create rooms.void
shutdown()
void
start()
void
syncChatRoom(MUCRoom room)
Makes available the current state of the provided MUCRoom instance to all nodes in the Openfire cluster (if the local server is part of such a cluster).-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.jivesoftware.openfire.muc.MultiUserChatService
isPasswordRequiredForSysadminsToJoinRoom, setPasswordRequiredForSysadminsToJoinRoom
-
-
-
-
Constructor Detail
-
MultiUserChatServiceImpl
public MultiUserChatServiceImpl(String subdomain, String description, Boolean isHidden)
Create a new group chat server.- Parameters:
subdomain
- Subdomain portion of the conference services (for example, conference for conference.example.org)description
- Short description of service for disco and such. Ifnull
or empty, a default value will be used.isHidden
- True if this service should be hidden from services views.- Throws:
IllegalArgumentException
- if the provided subdomain is an invalid, according to the JID domain definition.
-
-
Method Detail
-
getOccupantManager
@Nonnull public OccupantManager getOccupantManager()
- Specified by:
getOccupantManager
in interfaceMultiUserChatService
-
addIQHandler
public void addIQHandler(IQHandler iqHandler)
Description copied from interface:MultiUserChatService
Add a IQHandler to MUC rooms and services. If the IQHandler only supports one or other, it should quietly ignore it.- Specified by:
addIQHandler
in interfaceMultiUserChatService
- Parameters:
iqHandler
- the IQ handler to add
-
removeIQHandler
public void removeIQHandler(IQHandler iqHandler)
- Specified by:
removeIQHandler
in interfaceMultiUserChatService
-
getDescription
public String getDescription()
- Specified by:
getDescription
in interfaceorg.xmpp.component.Component
-
setDescription
public void setDescription(String desc)
-
processPacket
public void processPacket(org.xmpp.packet.Packet packet)
- Specified by:
processPacket
in interfaceorg.xmpp.component.Component
-
processVCardResponse
public void processVCardResponse(@Nonnull org.xmpp.packet.IQ response)
Processes a VCard response stanza that is supposedly sent to an occupant of a room as a result of that occupant having requested the VCard of another occupant earlier. VCard processing in MUC rooms depends on a bit of a hack: most clients of requestees cannot process a request for a VCard themselves (see XEP-0054). Instead, the request is rerouted to the bare JID of the requestee, which is responded to by its home server.MUCRoom.sendPrivatePacket(Packet, MUCRole)
implements this rerouting. The response from the home server is then processed by this method. It needs special care as its 'from' address is a bare JID (and thus not directly related to a single occupant).- Parameters:
response
- An IQ stanza that should be a response to an earlier VCard request.
-
processRegularStanza
public void processRegularStanza(org.xmpp.packet.Packet packet) throws UnauthorizedException, PacketException
This method does all stanza routing in the chat server for 'regular' MUC stanzas. Packet routing is actually very simple:- Discover the room the user is talking to
- If the room is not registered and this is a presence "available" packet, try to join the room
- If the room is registered, and presence "unavailable" leave the room
- Otherwise, rewrite the sender address and send to the room.
- Parameters:
packet
- The stanza to route- Throws:
UnauthorizedException
PacketException
-
isPendingPingResponse
public boolean isPendingPingResponse(@Nonnull org.xmpp.packet.Packet stanza)
Determines if a stanza is a client-generated response to an IQ Ping request sent by this server. A 'true' result of this method indicates that the client sending the IQ response is currently reachable.- Parameters:
stanza
- The stanza to check- Returns:
- true if the stanza is a response to an IQ Ping request sent by the server, otherwise false.
-
isDeliveryRelatedErrorResponse
public boolean isDeliveryRelatedErrorResponse(@Nonnull org.xmpp.packet.Packet stanza)
Determines if a stanza is sent by (on behalf of) an entity that MUC room believes to be an occupant when they've left: a 'ghost' occupant For message and presence stanzas, the delivery errors as defined in section 18.1.2 of XEP-0045 are used. For IQ stanzas, these errors may be due to lack of client support rather than a vanished occupant. Therefore, IQ stanzas will only return 'true' when they are an error response to an IQ Ping request sent by this server.- Parameters:
stanza
- The stanza to check- Returns:
- true if the stanza is a delivery related error response (from a 'ghost user'), otherwise false.
- See Also:
- XEP-0045, section 'ghost users'
-
initialize
public void initialize(org.xmpp.packet.JID jid, org.xmpp.component.ComponentManager componentManager)
- Specified by:
initialize
in interfaceorg.xmpp.component.Component
-
shutdown
public void shutdown()
- Specified by:
shutdown
in interfaceorg.xmpp.component.Component
-
getServiceDomain
public String getServiceDomain()
Description copied from interface:MultiUserChatService
Returns the fully-qualifed domain name of this chat service. The domain is composed by the service name and the name of the XMPP server where the service is running.- Specified by:
getServiceDomain
in interfaceMultiUserChatService
- Returns:
- the chat server domain (service name + host name).
-
getAddress
public org.xmpp.packet.JID getAddress()
-
serverStarted
public void serverStarted()
Description copied from interface:XMPPServerListener
Notification message indicating that the server has been started. At this point all server modules have been initialized and started. Message sending and receiving is now possible. However, some plugins may still be pending to be loaded.- Specified by:
serverStarted
in interfaceXMPPServerListener
-
serverStopping
public void serverStopping()
Description copied from interface:XMPPServerListener
Notification message indication that the server is about to be stopped. At this point all modules are still running so all services are still available.- Specified by:
serverStopping
in interfaceXMPPServerListener
-
getChatRoomLock
@Nonnull public Lock getChatRoomLock(@Nonnull String roomName)
Description copied from interface:MultiUserChatService
Generates a mutex object that controls cluster-wide access to a MUCRoom instance that represents the room in this service identified by the provided name. The lock, once returned, is not acquired/set.- Specified by:
getChatRoomLock
in interfaceMultiUserChatService
- Parameters:
roomName
- Name of the room for which to return a lock.- Returns:
- The lock (which has not been set yet).
-
syncChatRoom
public void syncChatRoom(@Nonnull MUCRoom room)
Description copied from interface:MultiUserChatService
Makes available the current state of the provided MUCRoom instance to all nodes in the Openfire cluster (if the local server is part of such a cluster). This method should be used whenever a MUCRoom instance has been changed.- Specified by:
syncChatRoom
in interfaceMultiUserChatService
- Parameters:
room
- The room for which to persist state changes across the Openfire cluster.
-
getChatRoom
@Nonnull public MUCRoom getChatRoom(@Nonnull String roomName, @Nonnull org.xmpp.packet.JID userjid) throws NotAllowedException
Description copied from interface:MultiUserChatService
Obtains a chatroom by name. A chatroom is created for that name if none exists and the user has permission. The user that asked for the chatroom will be the room's owner if the chatroom was created. Note that when obtaining a room instance using this method, the caller should take responsibility to make sure that any changes to the instance will become visible to other cluster nodes (which is done by invokingMultiUserChatService.syncChatRoom(MUCRoom)
. Where appropriate, the caller should apply mutex (as returned byMultiUserChatService.getChatRoomLock(String)
) to control concurrent access to the returned instance.- Specified by:
getChatRoom
in interfaceMultiUserChatService
- Parameters:
roomName
- Name of the room to get.userjid
- The user's normal jid, not the chat nickname jid.- Returns:
- The chatroom for the given name.
- Throws:
NotAllowedException
- If the caller doesn't have permission to create a new room.- See Also:
MultiUserChatService.syncChatRoom(MUCRoom)
-
getChatRoom
public MUCRoom getChatRoom(@Nonnull String roomName)
Description copied from interface:MultiUserChatService
Obtains a chatroom by name. If the chatroom does not exists then null will be returned. Note that when obtaining a room instance using this method, the caller should take responsibility to make sure that any changes to the instance will become visible to other cluster nodes (which is done by invokingMultiUserChatService.syncChatRoom(MUCRoom)
. Where appropriate, the caller should apply a mutex (as returned byMultiUserChatService.getChatRoomLock(String)
) to control concurrent access to the returned instance.- Specified by:
getChatRoom
in interfaceMultiUserChatService
- Parameters:
roomName
- Name of the room to get.- Returns:
- The chatroom for the given name or null if the room does not exists.
- See Also:
MultiUserChatService.syncChatRoom(MUCRoom)
-
getActiveChatRooms
public List<MUCRoom> getActiveChatRooms()
Description copied from interface:MultiUserChatService
Returns a list with a snapshot of all the rooms in the server that are actively loaded in memory.- Specified by:
getActiveChatRooms
in interfaceMultiUserChatService
- Returns:
- a list with a snapshot of rooms.
-
getAllRoomNames
public Set<String> getAllRoomNames()
Combine names of all rooms in the database (to catch any rooms that aren't currently in memory) with all names of rooms currently in memory (to include rooms that are non-persistent / never saved in the database). Duplicates will be removed by virtue of using a Set.- Specified by:
getAllRoomNames
in interfaceMultiUserChatService
- Returns:
- Names of all rooms that are known to this service.
-
getAllRoomSearchInfo
public Collection<MUCRoomSearchInfo> getAllRoomSearchInfo()
- Specified by:
getAllRoomSearchInfo
in interfaceMultiUserChatService
-
getActiveAndInactiveRooms
public List<MUCRoom> getActiveAndInactiveRooms()
Returns all rooms serviced by this service. This includes rooms designated as non-active, which are loaded from the database if necessary. This method can also be used solely for that 'side' effect of ensuring that all rooms are loaded.- Returns:
- All rooms serviced by this service.
-
hasChatRoom
public boolean hasChatRoom(String roomName)
Description copied from interface:MultiUserChatService
Returns true if the server includes a chatroom with the requested name.- Specified by:
hasChatRoom
in interfaceMultiUserChatService
- Parameters:
roomName
- the name of the chatroom to check.- Returns:
- true if the server includes a chatroom with the requested name.
-
removeChatRoom
public void removeChatRoom(String roomName)
Description copied from interface:MultiUserChatService
Removes the room associated with the given name.- Specified by:
removeChatRoom
in interfaceMultiUserChatService
- Parameters:
roomName
- The room to remove.
-
getServiceName
public String getServiceName()
Description copied from interface:MultiUserChatService
Returns the subdomain of the chat service.- Specified by:
getServiceName
in interfaceMultiUserChatService
- Returns:
- the subdomain of the chat service.
-
getName
public String getName()
- Specified by:
getName
in interfaceorg.xmpp.component.Component
-
getHistoryStrategy
public HistoryStrategy getHistoryStrategy()
Description copied from interface:MultiUserChatService
Obtain the server-wide default message history settings.- Specified by:
getHistoryStrategy
in interfaceMultiUserChatService
- Returns:
- The message history strategy defaults for the server.
-
getMUCRoles
public Collection<MUCRole> getMUCRoles(org.xmpp.packet.JID user)
Description copied from interface:MultiUserChatService
Returns the list ofMUCRole
in all rooms for the specified user's session.- Specified by:
getMUCRoles
in interfaceMultiUserChatService
- Parameters:
user
- the full JID that identifies the session of the user.- Returns:
- the list of MUCRoles in all rooms for the specified user's session.
-
setIdleUserTaskInterval
public void setIdleUserTaskInterval(@Nonnull Duration duration)
Description copied from interface:MultiUserChatService
Sets the period of the fixed-delay execution of tasks by theTimer
whose main responsibility is to process users that have been idle for a certain time. A user is considered idle if he/she didn't send any message to any group chat room for a certain amount of time.- Specified by:
setIdleUserTaskInterval
in interfaceMultiUserChatService
- Parameters:
duration
- The fixed-delay interval in which idle checks need to be performed.- See Also:
MultiUserChatService.getIdleUserKickThreshold()
,MultiUserChatService.getIdleUserPingThreshold()
-
getIdleUserTaskInterval
@Nonnull public Duration getIdleUserTaskInterval()
Description copied from interface:MultiUserChatService
Returns the period of fixed-delay executions of tasks that operate on idle users.- Specified by:
getIdleUserTaskInterval
in interfaceMultiUserChatService
- Returns:
- The fixed-delay interval in which idle checks need to be performed.
-
setIdleUserKickThreshold
public void setIdleUserKickThreshold(@Nullable Duration duration)
Description copied from interface:MultiUserChatService
Sets the duration that a user must be idle before he/she gets kicked from all the rooms. By idle we mean that the user didn't send any message to any group chat room. Set to null to disable the feature.- Specified by:
setIdleUserKickThreshold
in interfaceMultiUserChatService
- Parameters:
duration
- the amount of time to wait before considering a user idle.
-
getIdleUserKickThreshold
public Duration getIdleUserKickThreshold()
Description copied from interface:MultiUserChatService
Returns the duration that a user must be idle before he/she gets kicked from all the rooms. By idle we mean that the user didn't send any message to any group chat room. Returns null if the feature is disabled.- Specified by:
getIdleUserKickThreshold
in interfaceMultiUserChatService
- Returns:
- the amount of time to wait before considering a user idle.
-
setIdleUserPingThreshold
public void setIdleUserPingThreshold(@Nullable Duration duration)
Description copied from interface:MultiUserChatService
Sets the duration that a user must be idle before he/she gets pinged by the room, to determine if the user is a 'ghost user'. By idle we mean that the user didn't send any message to any group chat room. Set to null to disable the feature.- Specified by:
setIdleUserPingThreshold
in interfaceMultiUserChatService
- Parameters:
duration
- the amount of time to wait before considering a user idle.
-
getIdleUserPingThreshold
@Nullable public Duration getIdleUserPingThreshold()
Description copied from interface:MultiUserChatService
Returns the duration that a user must be idle before he/she gets pinged by the rooms that they're an occupant of (to determine if they're a 'ghost user'). By idle we mean that the user didn't send any message to any group chat room. Returns null if the feature is disabled.- Specified by:
getIdleUserPingThreshold
in interfaceMultiUserChatService
- Returns:
- the amount of time to wait before considering a user idle.
-
getUsersAllowedToCreate
public Collection<org.xmpp.packet.JID> getUsersAllowedToCreate()
Description copied from interface:MultiUserChatService
Returns the collection of JIDs that are allowed to create MUC rooms. WhenisAllRegisteredUsersAllowedToCreate
, this method will not return a JID of every user in the system.- Specified by:
getUsersAllowedToCreate
in interfaceMultiUserChatService
- Returns:
- a list of user/group JIDs.
-
getSysadmins
public Collection<org.xmpp.packet.JID> getSysadmins()
Description copied from interface:MultiUserChatService
Returns the collection of JIDs that are system administrators of the MUC service. A sysadmin has the same permissions as a room owner.- Specified by:
getSysadmins
in interfaceMultiUserChatService
- Returns:
- a list of user/group JIDs.
-
isSysadmin
public boolean isSysadmin(org.xmpp.packet.JID bareJID)
Description copied from interface:MultiUserChatService
Validates the given JID as a MUC service administrator.- Specified by:
isSysadmin
in interfaceMultiUserChatService
- Parameters:
bareJID
- the bare JID of the user- Returns:
- true if the given JID is a MUC service administrator
-
addSysadmins
public void addSysadmins(Collection<org.xmpp.packet.JID> userJIDs)
Description copied from interface:MultiUserChatService
Adds multiple system administrators for the MUC service. A sysadmin has the same permissions as a room owner.- Specified by:
addSysadmins
in interfaceMultiUserChatService
- Parameters:
userJIDs
- the JIDs of the new users/groups to add as a system administrator.
-
addSysadmin
public void addSysadmin(org.xmpp.packet.JID userJID)
Description copied from interface:MultiUserChatService
Adds a new system administrator of the MUC service. A sysadmin has the same permissions as a room owner.- Specified by:
addSysadmin
in interfaceMultiUserChatService
- Parameters:
userJID
- the bare JID of the new user/group to add as a system administrator.
-
removeSysadmin
public void removeSysadmin(org.xmpp.packet.JID userJID)
Description copied from interface:MultiUserChatService
Removes a system administrator of the MUC service.- Specified by:
removeSysadmin
in interfaceMultiUserChatService
- Parameters:
userJID
- the bare JID of the user/group to remove from the list.
-
isAllowToDiscoverMembersOnlyRooms
public boolean isAllowToDiscoverMembersOnlyRooms()
Returns the flag that indicates if the service should provide information about non-public members-only rooms when handling service discovery requests.- Returns:
- true if the service should provide information about non-public members-only rooms.
-
setAllowToDiscoverMembersOnlyRooms
public void setAllowToDiscoverMembersOnlyRooms(boolean allowToDiscoverMembersOnlyRooms)
Sets the flag that indicates if the service should provide information about non-public members-only rooms when handling service discovery requests.- Parameters:
allowToDiscoverMembersOnlyRooms
- if the service should provide information about non-public members-only rooms.
-
isAllowToDiscoverLockedRooms
public boolean isAllowToDiscoverLockedRooms()
Returns the flag that indicates if the service should provide information about locked rooms when handling service discovery requests.- Returns:
- true if the service should provide information about locked rooms.
-
setAllowToDiscoverLockedRooms
public void setAllowToDiscoverLockedRooms(boolean allowToDiscoverLockedRooms)
Sets the flag that indicates if the service should provide information about locked rooms when handling service discovery requests. Note: Setting this flag in false is not compliant with the spec. A user may try to join a locked room thinking that the room doesn't exist because the user didn't discover it before.- Parameters:
allowToDiscoverLockedRooms
- if the service should provide information about locked rooms.
-
isRoomCreationRestricted
public boolean isRoomCreationRestricted()
Description copied from interface:MultiUserChatService
Returns false if anyone can create rooms or true if only the returned JIDs ingetUsersAllowedToCreate
are allowed to create rooms.- Specified by:
isRoomCreationRestricted
in interfaceMultiUserChatService
- Returns:
- true if only some JIDs are allowed to create rooms.
-
setRoomCreationRestricted
public void setRoomCreationRestricted(boolean roomCreationRestricted)
Description copied from interface:MultiUserChatService
Sets if anyone can create rooms. When set to true, users are allowed to create rooms only whenisAllRegisteredUsersAllowedToCreate
orgetUsersAllowedToCreate
(or both) allow them to.- Specified by:
setRoomCreationRestricted
in interfaceMultiUserChatService
- Parameters:
roomCreationRestricted
- whether anyone can create rooms or not.
-
isAllRegisteredUsersAllowedToCreate
public boolean isAllRegisteredUsersAllowedToCreate()
Description copied from interface:MultiUserChatService
Sets if all registered users of Openfire are allowed to create rooms. When true, anonymous users and users from other domains (through federation) are initially prohibited from creating rooms, but can still be allowed by registering their JIDs inaddUserAllowedToCreate
.- Specified by:
isAllRegisteredUsersAllowedToCreate
in interfaceMultiUserChatService
- Returns:
- true if all registered users are allowed to create rooms.
-
setAllRegisteredUsersAllowedToCreate
public void setAllRegisteredUsersAllowedToCreate(boolean allow)
Description copied from interface:MultiUserChatService
Sets if all registered users of Openfire are allowed to create rooms.- Specified by:
setAllRegisteredUsersAllowedToCreate
in interfaceMultiUserChatService
- Parameters:
allow
- whether all registered users can create rooms.
-
addUsersAllowedToCreate
public void addUsersAllowedToCreate(Collection<org.xmpp.packet.JID> userJIDs)
Description copied from interface:MultiUserChatService
Adds new users/groups to the list of JIDs that are allowed to create MUC rooms.- Specified by:
addUsersAllowedToCreate
in interfaceMultiUserChatService
- Parameters:
userJIDs
- collection of JIDs for users/groups to add to list.
-
addUserAllowedToCreate
public void addUserAllowedToCreate(org.xmpp.packet.JID userJID)
Description copied from interface:MultiUserChatService
Adds a new user/group to the list of JIDs that are allowed to create MUC rooms.- Specified by:
addUserAllowedToCreate
in interfaceMultiUserChatService
- Parameters:
userJID
- the JID of the new user/group to add to list.
-
removeUsersAllowedToCreate
public void removeUsersAllowedToCreate(Collection<org.xmpp.packet.JID> userJIDs)
Description copied from interface:MultiUserChatService
Removes users/groups from list of JIDs that are allowed to create MUC rooms.- Specified by:
removeUsersAllowedToCreate
in interfaceMultiUserChatService
- Parameters:
userJIDs
- collection of JIDs of users/groups to remove from the list.
-
removeUserAllowedToCreate
public void removeUserAllowedToCreate(org.xmpp.packet.JID userJID)
Description copied from interface:MultiUserChatService
Removes a user/group from list of JIDs that are allowed to create MUC rooms.- Specified by:
removeUserAllowedToCreate
in interfaceMultiUserChatService
- Parameters:
userJID
- the JID of the user/group to remove from the list.
-
initialize
public void initialize(XMPPServer server)
-
initializeSettings
public void initializeSettings()
-
setLogMaxConversationBatchSize
public void setLogMaxConversationBatchSize(int size)
Sets the maximum number of messages to save to the database on each run of the archiving process. Even though the saving of queued conversations takes place in another thread it is not recommended specifying a big number.- Specified by:
setLogMaxConversationBatchSize
in interfaceMultiUserChatService
- Parameters:
size
- the maximum number of messages to save to the database on each run of the archiving process.
-
getLogMaxConversationBatchSize
public int getLogMaxConversationBatchSize()
Returns the maximum number of messages to save to the database on each run of the archiving process.- Specified by:
getLogMaxConversationBatchSize
in interfaceMultiUserChatService
- Returns:
- the maximum number of messages to save to the database on each run of the archiving process.
-
setLogMaxBatchInterval
public void setLogMaxBatchInterval(Duration interval)
Sets the maximum time allowed to elapse between writing archive batches to the database.- Specified by:
setLogMaxBatchInterval
in interfaceMultiUserChatService
- Parameters:
interval
- the maximum time allowed to elapse between writing archive batches to the database.
-
getLogMaxBatchInterval
public Duration getLogMaxBatchInterval()
Returns the maximum time allowed to elapse between writing archive entries to the database.- Specified by:
getLogMaxBatchInterval
in interfaceMultiUserChatService
- Returns:
- the maximum time allowed to elapse between writing archive entries to the database.
-
setLogBatchGracePeriod
public void setLogBatchGracePeriod(Duration interval)
Sets the maximum time to wait for a next incoming entry before writing the batch to the database.- Specified by:
setLogBatchGracePeriod
in interfaceMultiUserChatService
- Parameters:
interval
- the maximum time to wait for a next incoming entry before writing the batch to the database.
-
getLogBatchGracePeriod
public Duration getLogBatchGracePeriod()
Returns the maximum time to wait for a next incoming entry before writing the batch to the database.- Specified by:
getLogBatchGracePeriod
in interfaceMultiUserChatService
- Returns:
- the maximum time to wait for a next incoming entry before writing the batch to the database.
-
getArchiver
public Archiver<org.jivesoftware.openfire.muc.spi.ConversationLogEntry> getArchiver()
Accessor uses the "double-check idiom" for proper lazy instantiation.- Specified by:
getArchiver
in interfaceMultiUserChatService
- Returns:
- An Archiver instance, never null.
-
start
public void start()
- Specified by:
start
in interfaceorg.xmpp.component.Component
-
enableService
public void enableService(boolean enabled, boolean persistent)
Description copied from interface:MultiUserChatService
Enables or disables the MUC service. When disabled the MUC service will disappear from the disco#items list. Moreover, service discovery features will be disabled.- Specified by:
enableService
in interfaceMultiUserChatService
- Parameters:
enabled
- true if the service is enabled.persistent
- true if the new setting will persist across restarts.
-
isServiceEnabled
public boolean isServiceEnabled()
Description copied from interface:MultiUserChatService
Returns true if the MUC service is available. UseMultiUserChatService.enableService(boolean, boolean)
to enable or disable the service.- Specified by:
isServiceEnabled
in interfaceMultiUserChatService
- Returns:
- true if the MUC service is available.
-
getTotalChatTime
public long getTotalChatTime()
Description copied from interface:MultiUserChatService
Returns the total chat time of all rooms combined.- Specified by:
getTotalChatTime
in interfaceMultiUserChatService
- Returns:
- total chat time in milliseconds.
-
getNumberChatRooms
public int getNumberChatRooms()
Returns the number of existing rooms in the server (i.e. persistent or not, in memory or not).- Specified by:
getNumberChatRooms
in interfaceMultiUserChatService
- Returns:
- the number of existing rooms in the server.
-
getNumberConnectedUsers
public int getNumberConnectedUsers()
Returns the total number of occupants in all rooms.- Specified by:
getNumberConnectedUsers
in interfaceMultiUserChatService
- Returns:
- the total number of occupants.
-
getNumberRoomOccupants
public int getNumberRoomOccupants()
Returns the total number of users that have joined in all rooms in the server.- Specified by:
getNumberRoomOccupants
in interfaceMultiUserChatService
- Returns:
- the number of existing rooms in the server.
-
getIncomingMessageCount
public long getIncomingMessageCount(boolean resetAfter)
Returns the total number of incoming messages since last reset.- Specified by:
getIncomingMessageCount
in interfaceMultiUserChatService
- Parameters:
resetAfter
- True if you want the counter to be reset after results returned.- Returns:
- the number of incoming messages through the service.
-
getOutgoingMessageCount
public long getOutgoingMessageCount(boolean resetAfter)
Returns the total number of outgoing messages since last reset.- Specified by:
getOutgoingMessageCount
in interfaceMultiUserChatService
- Parameters:
resetAfter
- True if you want the counter to be reset after results returned.- Returns:
- the number of outgoing messages through the service.
-
logConversation
public void logConversation(MUCRoom room, org.xmpp.packet.Message message, org.xmpp.packet.JID sender)
Description copied from interface:MultiUserChatService
Logs that a given message was sent to a room as part of a conversation. Every message sent to the room that is allowed to be broadcasted and that was sent either from the room itself or from an occupant will be logged.Note: For performane reasons, the logged message won't be immediately saved. Instead we keep the logged messages in memory until the logging process saves them to the database. It's possible to configure the logging process to run every X milliseconds and also the number of messages to log on each execution.
- Specified by:
logConversation
in interfaceMultiUserChatService
- Parameters:
room
- the room that received the message.message
- the message to log as part of the conversation in the room.sender
- the real XMPPAddress of the sender (e.g. john@example.org).- See Also:
initialize(org.jivesoftware.openfire.XMPPServer)
-
messageBroadcastedTo
public void messageBroadcastedTo(int numOccupants)
Description copied from interface:MultiUserChatService
Notification message indicating the server that an incoming message was broadcasted to a given number of occupants.- Specified by:
messageBroadcastedTo
in interfaceMultiUserChatService
- Parameters:
numOccupants
- number of occupants that received the message.
-
getItems
public Iterator<DiscoServerItem> getItems()
Description copied from interface:ServerItemsProvider
Returns an Iterator (of DiscoServerItem) with the items associated with the server or null if none.- Specified by:
getItems
in interfaceServerItemsProvider
- Returns:
- an Iterator (of DiscoServerItem) with the items associated with the server or null if none.
-
getIdentities
public Iterator<org.dom4j.Element> getIdentities(String name, String node, org.xmpp.packet.JID senderJID)
Description copied from interface:DiscoInfoProvider
Returns an Iterator (of Element) with the target entity's identities. Each Element must include the categoty, type and name attributes of the entity.- Specified by:
getIdentities
in interfaceDiscoInfoProvider
- Parameters:
name
- the recipient JID's name.node
- the requested disco node.senderJID
- the XMPPAddress of user that sent the disco info request.- Returns:
- an Iterator (of Element) with the target entity's identities.
-
getFeatures
public Iterator<String> getFeatures(String name, String node, org.xmpp.packet.JID senderJID)
Description copied from interface:DiscoInfoProvider
Returns an Iterator (of String) with the supported features. The features to include are the features offered and supported protocols by the target entity identified by the requested name and node.- Specified by:
getFeatures
in interfaceDiscoInfoProvider
- Parameters:
name
- the recipient JID's name.node
- the requested disco node.senderJID
- the XMPPAddress of user that sent the disco info request.- Returns:
- an Iterator (of String) with the supported features.
-
getExtendedInfos
public Set<org.xmpp.forms.DataForm> getExtendedInfos(String name, String node, org.xmpp.packet.JID senderJID)
Description copied from interface:DiscoInfoProvider
Returns a collection of XDataForm with the extended information about the entity or an empty collection if none. Each bit of information about the entity must be included as a value of a field of the form.- Specified by:
getExtendedInfos
in interfaceDiscoInfoProvider
- Parameters:
name
- the recipient JID's name.node
- the requested disco node.senderJID
- the XMPPAddress of user that sent the disco info request.- Returns:
- A collection of XDataForms with the extended information about the entity or an empty collection if none.
-
addExtraFeature
public void addExtraFeature(String feature)
Adds an extra Disco feature to the list of features returned for the conference service.- Specified by:
addExtraFeature
in interfaceMultiUserChatService
- Parameters:
feature
- Feature to add.
-
removeExtraFeature
public void removeExtraFeature(String feature)
Removes an extra Disco feature from the list of features returned for the conference service.- Specified by:
removeExtraFeature
in interfaceMultiUserChatService
- Parameters:
feature
- Feature to remove.
-
addExtraIdentity
public void addExtraIdentity(String category, String name, String type)
Adds an extra Disco identity to the list of identities returned for the conference service.- Specified by:
addExtraIdentity
in interfaceMultiUserChatService
- Parameters:
category
- Category for identity. e.g. conferencename
- Descriptive name for identity. e.g. Public Chatroomstype
- Type for identity. e.g. text
-
removeExtraIdentity
public void removeExtraIdentity(String name)
Removes an extra Disco identity from the list of identities returned for the conference service.- Specified by:
removeExtraIdentity
in interfaceMultiUserChatService
- Parameters:
name
- Name of identity to remove.
-
setMUCDelegate
public void setMUCDelegate(MUCEventDelegate delegate)
Sets the MUC event delegate handler for this service.- Specified by:
setMUCDelegate
in interfaceMultiUserChatService
- Parameters:
delegate
- Handler for MUC events.
-
getMUCDelegate
public MUCEventDelegate getMUCDelegate()
Gets the MUC event delegate handler for this service.- Specified by:
getMUCDelegate
in interfaceMultiUserChatService
- Returns:
- Handler for MUC events (delegate)
-
hasInfo
public boolean hasInfo(String name, String node, org.xmpp.packet.JID senderJID)
Description copied from interface:DiscoInfoProvider
Returns true if we can provide information related to the requested name and node. For example, if the requested name refers to a non-existent MUC room then the answer will be false. In case that the sender of the disco request is not authorized to discover this information an UnauthorizedException will be thrown.- Specified by:
hasInfo
in interfaceDiscoInfoProvider
- Parameters:
name
- the recipient JID's name.node
- the requested disco node.senderJID
- the XMPPAddress of user that sent the disco info request.- Returns:
- true if we can provide information related to the requested name and node.
-
getItems
public Iterator<DiscoItem> getItems(String name, String node, org.xmpp.packet.JID senderJID)
Description copied from interface:DiscoItemsProvider
Returns an Iterator (of DiscoItem) with the target entity's items or null if none. Each DiscoItem must include a JID attribute and may include the name and node attributes of the entity. In case that the sender of the disco request is not authorized to discover items an UnauthorizedException will be thrown.- Specified by:
getItems
in interfaceDiscoItemsProvider
- Parameters:
name
- the recipient JID's name.node
- the requested disco node.senderJID
- the XMPPAddress of user that sent the disco items request.- Returns:
- an Iterator (of DiscoItem) with the target entity's items or null if none.
-
canDiscoverRoom
public boolean canDiscoverRoom(MUCRoom room, org.xmpp.packet.JID entity)
Description copied from interface:MultiUserChatService
Checks if the a particular entity is allowed to discover the room's existence.- Specified by:
canDiscoverRoom
in interfaceMultiUserChatService
- Parameters:
room
- The room to be discovered (cannot be null).entity
- The JID of the entity (cannot be null).- Returns:
- true if the entity can discover the room, otherwise false.
-
setHidden
public void setHidden(boolean isHidden)
-
isHidden
public boolean isHidden()
Description copied from interface:MultiUserChatService
Returns true if the MUC service is a hidden, externally managed, service. This is typically set to true when the implementation is not the default one, and is not to be managed by the standard Openfire interface. If this is set to true, the service will not show up in the service list in the admin console.- Specified by:
isHidden
in interfaceMultiUserChatService
- Returns:
- true if the MUC service is hidden and externally managed.
-
joinedCluster
public void joinedCluster()
Description copied from interface:ClusterEventListener
Notification event indicating that this JVM is now part of a cluster. At this point theXMPPServer.getNodeID()
holds the new nodeID value.When joining the cluster as the senior cluster member the
ClusterEventListener.markedAsSeniorClusterMember()
event will be sent right after this event.At this point the CacheFactory holds clustered caches. That means that modifications to the caches will be reflected in the cluster. The clustered caches were just obtained from the cluster and no local cached data was automatically moved.
It is generally advisable that implementations of this method:- enrich clustered cache data, by (re)adding data from this JVM/cluster node to relevant caches
- invoke applicable event listeners, to reflect changes in availability of data on other cluster nodes.
- Specified by:
joinedCluster
in interfaceClusterEventListener
-
joinedCluster
public void joinedCluster(byte[] nodeID)
Description copied from interface:ClusterEventListener
Notification event indicating that another JVM is now part of a cluster.At this point the CacheFactory of the new node holds clustered caches. That means that modifications to the caches of this JVM will be reflected in the cluster and in particular in the new node.
- Specified by:
joinedCluster
in interfaceClusterEventListener
- Parameters:
nodeID
- ID of the node that joined the cluster.
-
leftCluster
public void leftCluster()
Description copied from interface:ClusterEventListener
Notification event indicating that this JVM is no longer part of the cluster. This could happen when disabling clustering support, removing the enterprise plugin that provides clustering support or connection to cluster got lost.Moreover, if we were in a "split brain" scenario (ie. separated cluster islands) and the island were this JVM belonged was marked as "old" then all nodes of that island will get the
left cluster event
andjoined cluster events
. That means that caches will be reset and thus will need to be repopulated again with fresh data from this JVM. This also includes the case where this JVM was the senior cluster member and when the islands met again then this JVM stopped being the senior member.At this point the CacheFactory holds local caches. That means that modifications to the caches will only affect this JVM. It is generally advisable that implementations of this method:
- restore relevant caches content, by repopulating the caches with data from this JVM/cluster node
- invoke applicable event listeners, to reflect changes in availability of data on other cluster nodes.
- Specified by:
leftCluster
in interfaceClusterEventListener
-
leftCluster
public void leftCluster(byte[] nodeID)
Description copied from interface:ClusterEventListener
Notification event indicating that another JVM is no longer part of the cluster. This could happen when disabling clustering support, removing the enterprise plugin that provides clustering support or connection to cluster got lost.Moreover, if we were in a "split brain" scenario (ie. separated cluster islands) and the island were the other JVM belonged was marked as "old" then all nodes of that island will get the
left cluster event
andjoined cluster events
. That means that caches will be reset and thus will need to be repopulated again with fresh data from this JVM. This also includes the case where the other JVM was the senior cluster member and when the islands met again then the other JVM stopped being the senior member.At this point the CacheFactory of the leaving node holds local caches. That means that modifications to the caches of this JVM will not affect the leaving node but other cluster members. It is generally advisable that implementations of this method invoke applicable event listeners, to reflect changes in availability of data (related to the node that left). Often, this action is orchestrated by only one of the remaining cluster nodes: the senior member.
- Specified by:
leftCluster
in interfaceClusterEventListener
- Parameters:
nodeID
- ID of the node that is left the cluster.
-
markedAsSeniorClusterMember
public void markedAsSeniorClusterMember()
Description copied from interface:ClusterEventListener
Notification event indicating that this JVM is now the senior cluster member. This could either happen when initially joining the cluster or when the senior cluster member node left the cluster and this JVM was marked as the new senior cluster member.Moreover, in the case of a "split brain" scenario (ie. separated cluster islands) each island will have its own senior cluster member. However, when the islands meet again there could only be one senior cluster member so one of the senior cluster members will stop playing that role. When that happens the JVM no longer playing that role will receive the
ClusterEventListener.leftCluster()
andClusterEventListener.joinedCluster()
events.- Specified by:
markedAsSeniorClusterMember
in interfaceClusterEventListener
-
getLocalMUCRoomManager
public LocalMUCRoomManager getLocalMUCRoomManager()
- Specified by:
getLocalMUCRoomManager
in interfaceMultiUserChatService
-
process
public void process(@Nonnull SyncLocalOccupantsAndSendJoinPresenceTask task)
Used by other nodes telling us about their occupants.- Parameters:
task
-
-
-