All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.gemstone.gemfire.management.internal.ManagementResourceRepo Maven / Gradle / Ivy

/*
 * Copyright (c) 2010-2015 Pivotal Software, Inc. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you
 * may not use this file except in compliance with the License. You
 * may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
 * implied. See the License for the specific language governing
 * permissions and limitations under the License. See accompanying
 * LICENSE file.
 */
package com.gemstone.gemfire.management.internal;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import javax.management.Notification;
import javax.management.ObjectName;

import com.gemstone.gemfire.cache.Region;
import com.gemstone.gemfire.cache.RegionDestroyedException;
import com.gemstone.gemfire.distributed.DistributedMember;

/**
 * Instance of this object behaves as a cache wide repository in the context of
 * management and monitoring. Various management infrastructures are initialized
 * by this class
 * 
 * Various repository related methods are declared here These methods provide a
 * consistent view to read and update the repository.
 * 
 * @author rishim
 * 
 */

public class ManagementResourceRepo {

  /**
   * Map containing member to Monitoring region mapping.
   */
  private Map> monitoringRegionMap;

  /**
   * Map containing member to Notification region mapping.
   */
  private Map> notifRegionMap;

  /**
   * local monitoring region
   */
  private Region localMonitoringRegion;

  /**
   * local notification region
   */
  private Region localNotificationRegion;

  public ManagementResourceRepo() {
    monitoringRegionMap = new ConcurrentHashMap>();
    notifRegionMap = new ConcurrentHashMap>();
  }

  /**
   * 
   * @return local monitoring region
   */
  public Region getLocalMonitoringRegion() {
    return localMonitoringRegion;
  }
  
  public void destroyLocalMonitoringRegion(){
    localMonitoringRegion.localDestroyRegion();
    localMonitoringRegion = null;
  }
  
  public void destroyLocalNotifRegion(){
    localNotificationRegion.localDestroyRegion();
    localNotificationRegion = null;
  }

  /**
   * Sets the repository local monitoring region to the given Region
   * 
   * @param localMonitoringRegion
   *          local monitoring region
   */
  public void setLocalMonitoringRegion(
      Region localMonitoringRegion) {
    this.localMonitoringRegion = localMonitoringRegion;
  }

  /**
   * put an entry in local monitoring region
   * 
   * @param name
   *          MBean name
   * @param data
   *          The value part of the Map
   */
  public void putEntryInLocalMonitoringRegion(String name, Object data) {
    if (localMonitoringRegion != null && !localMonitoringRegion.isDestroyed()) {
      try {
        localMonitoringRegion.put(name, data);
      } catch (RegionDestroyedException rde) {
        // ignore
      }
    }
  }

  /**
   * uses putAll operation of region
   * 
   * @param objectMap
   *          Object Map containing key-value operations
   */
  public void putAllInLocalMonitoringRegion(
      Map objectMap) {
    if (localMonitoringRegion != null && !localMonitoringRegion.isDestroyed()) {
      try {
        localMonitoringRegion.putAll(objectMap);
      } catch (RegionDestroyedException rde) {
        // ignore
      }
    }
  }
  
  public boolean keyExistsInLocalMonitoringRegion(String key) {
    if (localMonitoringRegion != null && !localMonitoringRegion.isDestroyed()) {
      // We want to just check locally without sending a message to the manager.
      // containsKey does this.
      try {
        return localMonitoringRegion.containsKey(key);
      } catch (RegionDestroyedException rde) {
        return true; // so caller will think he does not need to do a putAll
      }
    } else {
      return true; // so caller will think he does not need to do a putAll
    }
  }


  /**
   * get a entry from local monitoring region
   * 
   * @param name
   *          MBean name
   * @return the value
   */
  public Object getEntryFromLocalMonitoringRegion(ObjectName name) {

    return localMonitoringRegion.get(name);
  }

  /**
   * 
   * @return local notification region
   */
  public Region getLocalNotificationRegion() {
    return localNotificationRegion;
  }

  /**
   * sets the local notification region
   * 
   * @param localNotificationRegion
   *          local notification region
   */
  public void setLocalNotificationRegion(
      Region localNotificationRegion) {
    this.localNotificationRegion = localNotificationRegion;
  }

  /**
   * put an entry in local notification region
   * 
   * @param key
   *          Notiofication key
   * @param notif
   *          Notification Object
   */
  public void putEntryInLocalNotificationRegion(NotificationKey key,
      Notification notif) {
    localNotificationRegion.put(key, notif);
  }

  /**
   * put an entry in Monitoring Region Map
   * 
   * @param member
   *          Distributed member
   * @param region
   *          Corresponding region
   */
  public void putEntryInMonitoringRegionMap(DistributedMember member,
      Region region) {
    monitoringRegionMap.put(member, region);
  }

  /**
   * 
   * @param member
   *          Distributed Member
   * @return the corresponding Monitoring region at Managing Node side
   */
  public Region getEntryFromMonitoringRegionMap(
      DistributedMember member) {

    return monitoringRegionMap.get(member);
  }

  /**
   * remove the entry corresponding to the distributed member
   * 
   * @param member
   *          Distributed Member
   */
  public void romoveEntryFromMonitoringRegionMap(DistributedMember member) {

    monitoringRegionMap.remove(member);
  }

  /**
   * 
   * @return the map containing all the member and region map
   */
  public Map> getMonitoringRegionMap() {
    return monitoringRegionMap;
  }

  /**
   * put an entry into notification region map
   * 
   * @param member
   *          Distributed Member
   * @param region
   *          Corresponding notification region
   */
  public void putEntryInNotifRegionMap(DistributedMember member,
      Region region) {
    notifRegionMap.put(member, region);
  }

  /**
   * get the notification region for a corresponding member
   * 
   * @param member
   *          Distributed Member
   * @return notification Region for the member
   */
  public Region getEntryFromNotifRegionMap(
      DistributedMember member) {

    return notifRegionMap.get(member);
  }

  /**
   * removes an entry from notification region
   * 
   * @param member
   *          Distributed Member
   */
  public void removeEntryFromNotifRegionMap(DistributedMember member) {

    notifRegionMap.remove(member);
  }


}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy