private EntityCapabilitiesManager() {
   entityCapabilitiesMap = CacheFactory.createCache("Entity Capabilities");
   entityCapabilitiesUserMap = CacheFactory.createCache("Entity Capabilities Users");
   verAttributes = new HashMap<String, EntityCapabilities>();
 }
Пример #2
0
  private GroupManager() {
    // Initialize caches.
    groupCache = CacheFactory.createCache("Group");

    // A cache for meta-data around groups: count, group names, groups associated with
    // a particular user
    groupMetaCache = CacheFactory.createCache("Group Metadata Cache");

    initProvider();

    GroupEventDispatcher.addListener(
        new IGroupEventListener() {
          public void groupCreated(Group group, Map<String, Object> params) {

            // Adds default properties if they don't exists, since the creator of
            // the group could set them.
            if (group.getProperties().get("sharedRoster.showInRoster") == null) {
              group.getProperties().put("sharedRoster.showInRoster", "nobody");
              group.getProperties().put("sharedRoster.displayName", "");
              group.getProperties().put("sharedRoster.groupList", "");
            }

            // Since the group could be created by the provider, add it possible again
            groupCache.put(group.getName(), group);

            groupMetaCache.clear();
          }

          public void groupDeleting(Group group, Map<String, Object> params) {
            // Since the group could be deleted by the provider, remove it possible again
            groupCache.remove(group.getName());

            groupMetaCache.clear();
          }

          public void groupModified(Group group, Map<String, Object> params) {
            String type = (String) params.get("type");
            // If shared group settings changed, expire the cache.
            if (type != null
                && (type.equals("propertyModified")
                    || type.equals("propertyDeleted")
                    || type.equals("propertyAdded"))) {
              if (params.get("propertyKey") != null
                  && params.get("propertyKey").equals("sharedRoster.showInRoster")) {
                groupMetaCache.clear();
              }
            }
            // Set object again in cache. This is done so that other cluster nodes
            // get refreshed with latest version of the object
            groupCache.put(group.getName(), group);
          }

          public void memberAdded(Group group, Map<String, Object> params) {
            groupMetaCache.clear();
            // Set object again in cache. This is done so that other cluster nodes
            // get refreshed with latest version of the object
            groupCache.put(group.getName(), group);
          }

          public void memberRemoved(Group group, Map<String, Object> params) {
            groupMetaCache.clear();
            // Set object again in cache. This is done so that other cluster nodes
            // get refreshed with latest version of the object
            groupCache.put(group.getName(), group);
          }

          public void adminAdded(Group group, Map<String, Object> params) {
            groupMetaCache.clear();
            // Set object again in cache. This is done so that other cluster nodes
            // get refreshed with latest version of the object
            groupCache.put(group.getName(), group);
          }

          public void adminRemoved(Group group, Map<String, Object> params) {
            groupMetaCache.clear();
            // Set object again in cache. This is done so that other cluster nodes
            // get refreshed with latest version of the object
            groupCache.put(group.getName(), group);
          }
        });

    UserEventDispatcher.addListener(
        new IUserEventListener() {
          public void userCreated(User user, Map<String, Object> params) {
            // ignore
          }

          public void userDeleting(User user, Map<String, Object> params) {
            deleteUser(user);
          }

          public void userModified(User user, Map<String, Object> params) {
            // ignore
          }
        });

    // Detect when a new auth provider class is set
    PropertyEventListener propListener =
        new PropertyEventListener() {
          public void propertySet(String property, Map<String, Object> params) {
            if ("provider.group.className".equals(property)) {
              initProvider();
            }
          }

          public void propertyDeleted(String property, Map<String, Object> params) {
            // Ignore
          }

          public void xmlPropertySet(String property, Map<String, Object> params) {
            // Ignore
          }

          public void xmlPropertyDeleted(String property, Map<String, Object> params) {
            // Ignore
          }
        };
    PropertyEventDispatcher.addListener(propListener);

    // Pre-load shared groups. This will provide a faster response
    // time to the first client that logs in.
    Runnable task =
        new Runnable() {
          public void run() {
            Collection<Group> groups = getSharedGroups();
            // Load each group into cache.
            for (Group group : groups) {
              // Load each user in the group into cache.
              for (JID jid : group.getMembers()) {
                try {
                  if (XmppServer.getInstance().isLocal(jid)) {
                    UserManager.getInstance().getUser(jid.getNode());
                  }
                } catch (UserNotFoundException unfe) {
                  // Ignore.
                }
              }
            }
          }
        };
    TaskEngine.getInstance().submit(task);
  }