Search in sources :

Example 11 with MultiUserChatServiceImpl

use of org.jivesoftware.openfire.muc.spi.MultiUserChatServiceImpl in project Openfire by igniterealtime.

the class MultiUserChatManager method removeMultiUserChatService.

/**
 * Deletes a configured MultiUserChatService by ID, and shuts it down.
 *
 * @param serviceID The ID opf the service to be deleted.
 * @throws NotFoundException if the service was not found.
 */
public void removeMultiUserChatService(final long serviceID) throws NotFoundException {
    final MultiUserChatServiceImpl muc = (MultiUserChatServiceImpl) getMultiUserChatService(serviceID);
    if (muc == null) {
        Log.info("Unable to find service to remove for service ID {}", serviceID);
        throw new NotFoundException();
    }
    final String subdomain = muc.getServiceName();
    Log.info("Removing MUC service '{}'", subdomain);
    unregisterMultiUserChatService(subdomain);
    deleteService(serviceID);
}
Also used : MultiUserChatServiceImpl(org.jivesoftware.openfire.muc.spi.MultiUserChatServiceImpl) NotFoundException(org.jivesoftware.util.NotFoundException)

Example 12 with MultiUserChatServiceImpl

use of org.jivesoftware.openfire.muc.spi.MultiUserChatServiceImpl in project Openfire by igniterealtime.

the class MultiUserChatManager method refreshService.

/**
 * Updates the in-memory representation of a previously loaded services from the database.
 *
 * This call will modify database-stored characteristics for a service previously loaded to memory on the local
 * cluster node. An exception will be thrown if used for a service that's not in memory.
 *
 * Note that this method will not cause MUCServiceProperties to be reloaded. It only operates on fields like the
 * service description.
 *
 * This method is primarily useful to cause a service to reload its state from the database after it was changed on
 * another cluster node.
 *
 * @param subdomain the domain of the service to refresh
 */
public void refreshService(String subdomain) {
    Log.debug("Refreshing MUC service {} from the database.", subdomain);
    if (!mucServices.containsKey(subdomain)) {
        throw new IllegalArgumentException("Cannot refresh a MUC service that is not loaded: " + subdomain);
    }
    Connection con = null;
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
        con = DbConnectionManager.getConnection();
        pstmt = con.prepareStatement(LOAD_SERVICE);
        pstmt.setString(1, subdomain);
        rs = pstmt.executeQuery();
        if (rs.next()) {
            String description = rs.getString(1);
            Boolean isHidden = Boolean.valueOf(rs.getString(2));
            ((MultiUserChatServiceImpl) mucServices.get(subdomain)).setDescription(description);
            ((MultiUserChatServiceImpl) mucServices.get(subdomain)).setHidden(isHidden);
        } else {
            throw new Exception("Unable to locate database row for subdomain " + subdomain);
        }
    } catch (Exception e) {
        Log.error("A database exception occurred while trying to refresh MUC service '{}' from the database.", subdomain, e);
    } finally {
        DbConnectionManager.closeConnection(rs, pstmt, con);
    }
    Log.trace("Refreshed MUC service '{}'", subdomain);
}
Also used : Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) MultiUserChatServiceImpl(org.jivesoftware.openfire.muc.spi.MultiUserChatServiceImpl) PreparedStatement(java.sql.PreparedStatement) ComponentException(org.xmpp.component.ComponentException) SQLException(java.sql.SQLException) NotFoundException(org.jivesoftware.util.NotFoundException) AlreadyExistsException(org.jivesoftware.util.AlreadyExistsException)

Example 13 with MultiUserChatServiceImpl

use of org.jivesoftware.openfire.muc.spi.MultiUserChatServiceImpl in project Openfire by igniterealtime.

the class MultiUserChatManager method loadServices.

/**
 * Loads the list of configured services stored in the database.
 *
 * This call will add the services to memory on the local cluster node, but will not propagate them to other nodes
 * in the cluster.
 */
private void loadServices() {
    Log.debug("Loading all MUC services from the database.");
    Connection con = null;
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
        con = DbConnectionManager.getConnection();
        pstmt = con.prepareStatement(LOAD_SERVICES);
        rs = pstmt.executeQuery();
        while (rs.next()) {
            String subdomain = rs.getString(1);
            String description = rs.getString(2);
            Boolean isHidden = Boolean.valueOf(rs.getString(3));
            final MultiUserChatServiceImpl muc = new MultiUserChatServiceImpl(subdomain, description, isHidden);
            Log.trace("... loaded '{}' MUC service from the database.", subdomain);
            mucServices.put(subdomain, muc);
        }
    } catch (Exception e) {
        Log.error("An unexpected exception occurred while trying to load all MUC services from the database.", e);
    } finally {
        DbConnectionManager.closeConnection(rs, pstmt, con);
    }
}
Also used : Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) MultiUserChatServiceImpl(org.jivesoftware.openfire.muc.spi.MultiUserChatServiceImpl) PreparedStatement(java.sql.PreparedStatement) ComponentException(org.xmpp.component.ComponentException) SQLException(java.sql.SQLException) NotFoundException(org.jivesoftware.util.NotFoundException) AlreadyExistsException(org.jivesoftware.util.AlreadyExistsException)

Example 14 with MultiUserChatServiceImpl

use of org.jivesoftware.openfire.muc.spi.MultiUserChatServiceImpl in project Openfire by igniterealtime.

the class ServiceAddedEvent method run.

@Override
public void run() {
    // should really never occur.
    if (!XMPPServer.getInstance().getMultiUserChatManager().isServiceRegistered(subdomain)) {
        MultiUserChatService service = new MultiUserChatServiceImpl(subdomain, description, isHidden);
        XMPPServer.getInstance().getMultiUserChatManager().registerMultiUserChatService(service, false);
    }
}
Also used : MultiUserChatServiceImpl(org.jivesoftware.openfire.muc.spi.MultiUserChatServiceImpl) MultiUserChatService(org.jivesoftware.openfire.muc.MultiUserChatService)

Aggregations

MultiUserChatServiceImpl (org.jivesoftware.openfire.muc.spi.MultiUserChatServiceImpl)14 NotFoundException (org.jivesoftware.util.NotFoundException)6 AlreadyExistsException (org.jivesoftware.util.AlreadyExistsException)4 MultiUserChatService (org.jivesoftware.openfire.muc.MultiUserChatService)3 Connection (java.sql.Connection)2 PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2 SQLException (java.sql.SQLException)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 OccupantAddedEvent (org.jivesoftware.openfire.muc.cluster.OccupantAddedEvent)2 RoomInfo (org.jivesoftware.openfire.muc.cluster.RoomInfo)2 LocalMUCRoom (org.jivesoftware.openfire.muc.spi.LocalMUCRoom)2 ComponentException (org.xmpp.component.ComponentException)2 Nonnull (javax.annotation.Nonnull)1 HistoryStrategy (org.jivesoftware.openfire.muc.HistoryStrategy)1 GetNewMemberRoomsRequest (org.jivesoftware.openfire.muc.cluster.GetNewMemberRoomsRequest)1 SeniorMemberServicesRequest (org.jivesoftware.openfire.muc.cluster.SeniorMemberServicesRequest)1 ServiceAddedEvent (org.jivesoftware.openfire.muc.cluster.ServiceAddedEvent)1 ServiceInfo (org.jivesoftware.openfire.muc.cluster.ServiceInfo)1