コード例 #1
0
ファイル: PrService.java プロジェクト: iisi-nj/GemFireLite
 @Override
 public ArrayList<HashMap> doExecute(Map<String, Object> args) {
   Cache cache = CacheFactory.getAnyInstance();
   String regionPath = (String) args.get(ApiConstant.REGIONPATH);
   Region region = cache.getRegion(regionPath);
   ArrayList<HashMap> list = new ArrayList<HashMap>();
   if (region != null && region instanceof PartitionedRegion) {
     DistributedMember member = cache.getDistributedSystem().getDistributedMember();
     PartitionedRegion pr = (PartitionedRegion) region;
     if (pr.getDataStore() != null) {
       Set<BucketRegion> set2 = pr.getDataStore().getAllLocalBucketRegions();
       for (BucketRegion br : set2) {
         HashMap map = new HashMap();
         map.put("BucketId", br.getId());
         map.put("Size", br.size());
         map.put("Bytes", br.getTotalBytes());
         map.put("host", getHost());
         map.put("node", System.getProperty("NODE_NAME"));
         InternalDistributedMember m = pr.getBucketPrimary(br.getId());
         if (m != null && member.getId().equals(m.getId())) {
           map.put("type", "primary");
         } else {
           map.put("type", "redundant");
         }
         map.put("TotalNumBuckets", pr.getPartitionAttributes().getTotalNumBuckets());
         list.add(map);
       }
     }
   }
   return list;
 }
コード例 #2
0
 /**
  * Version-dependent support for {@link CacheHelper#getCache}.
  *
  * <p>Returns the cache if it exists and is open, or null if no cache exists.
  */
 protected static synchronized Cache getCache() {
   try {
     return CacheFactory.getAnyInstance();
   } catch (CancelException e) {
     return null;
   }
 }
コード例 #3
0
  @Override
  public void execute(FunctionContext context) {
    StringBuilder str1 = new StringBuilder();
    Map<String, String> resultMap = null;
    try {
      Cache cache = CacheFactory.getAnyInstance();
      DistributedMember member = cache.getDistributedSystem().getDistributedMember();
      long freeMemoeryBeforeGC = Runtime.getRuntime().freeMemory();
      long totalMemoryBeforeGC = Runtime.getRuntime().totalMemory();
      long timeBeforeGC = System.currentTimeMillis();
      Runtime.getRuntime().gc();

      long freeMemoeryAfterGC = Runtime.getRuntime().freeMemory();
      long totalMemoryAfterGC = Runtime.getRuntime().totalMemory();
      long timeAfterGC = System.currentTimeMillis();

      long megaBytes = 131072;
      resultMap = new HashMap<String, String>();
      resultMap.put("MemberId", member.getId());
      resultMap.put(
          "HeapSizeBeforeGC",
          String.valueOf((totalMemoryBeforeGC - freeMemoeryBeforeGC) / megaBytes));
      resultMap.put(
          "HeapSizeAfterGC", String.valueOf((totalMemoryAfterGC - freeMemoeryAfterGC) / megaBytes));
      resultMap.put("TimeSpentInGC", String.valueOf(timeAfterGC - timeBeforeGC));
    } catch (Exception ex) {
      str1.append(
          "Exception in GC:" + ex.getMessage() + CliUtil.stackTraceAsString((Throwable) ex));
      context.getResultSender().lastResult(str1.toString());
    }
    context.getResultSender().lastResult(resultMap);
  }
コード例 #4
0
 private void init() throws SystemException {
   this.cache = (GemFireCacheImpl) CacheFactory.getAnyInstance();
   LogWriter logger = this.cache.getLogger();
   if (logger.fineEnabled()) {
     logger.fine("JCAManagedConnection:init. Inside init");
   }
   gfTxMgr = cache.getTxManager();
   this.initDone = true;
 }
コード例 #5
0
  /**
   * Use the CacheXmlGenerator to create XML from the entity associated with the current cache.
   *
   * @return XML string representation of the entity.
   */
  private final String loadXmlDefinition() {
    final Cache cache = CacheFactory.getAnyInstance();

    final StringWriter stringWriter = new StringWriter();
    final PrintWriter printWriter = new PrintWriter(stringWriter);
    CacheXmlGenerator.generate(cache, printWriter, true, false, false);
    printWriter.close();

    return loadXmlDefinition(stringWriter.toString());
  }
コード例 #6
0
ファイル: GemfireLogger.java プロジェクト: netcrest/pado
 private static LogWriter getLogWriter() {
   try {
     Cache cache = CacheFactory.getAnyInstance();
     if (cache == null) {
       return null;
     }
     return cache.getLogger();
   } catch (Exception ex) {
     return null;
   }
 }
コード例 #7
0
  @Override
  public void execute(FunctionContext context) {
    final IndexInfo indexInfo = (IndexInfo) context.getArguments();
    String memberId = null;
    try {
      Cache cache = CacheFactory.getAnyInstance();
      memberId = cache.getDistributedSystem().getDistributedMember().getId();
      QueryService queryService = cache.getQueryService();
      String indexName = indexInfo.getIndexName();
      String indexedExpression = indexInfo.getIndexedExpression();
      String regionPath = indexInfo.getRegionPath();

      switch (indexInfo.getIndexType()) {
        case IndexInfo.RANGE_INDEX:
          queryService.createIndex(indexName, indexedExpression, regionPath);
          break;
        case IndexInfo.KEY_INDEX:
          queryService.createKeyIndex(indexName, indexedExpression, regionPath);
          break;
        case IndexInfo.HASH_INDEX:
          queryService.createHashIndex(indexName, indexedExpression, regionPath);
          break;
        default:
          queryService.createIndex(indexName, indexedExpression, regionPath);
      }

      XmlEntity xmlEntity =
          new XmlEntity(CacheXml.REGION, "name", cache.getRegion(regionPath).getName());
      context.getResultSender().lastResult(new CliFunctionResult(memberId, xmlEntity));
    } catch (IndexExistsException e) {
      String message =
          CliStrings.format(CliStrings.CREATE_INDEX__INDEX__EXISTS, indexInfo.getIndexName());
      context.getResultSender().lastResult(new CliFunctionResult(memberId, false, message));
    } catch (IndexNameConflictException e) {
      String message =
          CliStrings.format(CliStrings.CREATE_INDEX__NAME__CONFLICT, indexInfo.getIndexName());
      context.getResultSender().lastResult(new CliFunctionResult(memberId, false, message));
    } catch (RegionNotFoundException e) {
      String message =
          CliStrings.format(
              CliStrings.CREATE_INDEX__INVALID__REGIONPATH, indexInfo.getRegionPath());
      context.getResultSender().lastResult(new CliFunctionResult(memberId, false, message));
    } catch (IndexInvalidException e) {
      context.getResultSender().lastResult(new CliFunctionResult(memberId, e, e.getMessage()));
    } catch (Exception e) {
      String exceptionMessage =
          CliStrings.format(
              CliStrings.EXCEPTION_CLASS_AND_MESSAGE, e.getClass().getName(), e.getMessage());
      context.getResultSender().lastResult(new CliFunctionResult(memberId, e, exceptionMessage));
    }
  }
コード例 #8
0
 /**
  * Used supplied xmlDocument to extract the XML for the defined {@link XmlEntity}.
  *
  * @param xmlDocument to extract XML from.
  * @return XML for {@link XmlEntity} if found, otherwise <code>null</code>.
  * @since 8.1
  */
 private final String loadXmlDefinition(final String xmlDocument) {
   final Cache cache = CacheFactory.getAnyInstance();
   try {
     InputSource inputSource = new InputSource(new StringReader(xmlDocument));
     return loadXmlDefinition(XmlUtils.getDocumentBuilder().parse(inputSource));
   } catch (IOException
       | SAXException
       | ParserConfigurationException
       | XPathExpressionException
       | TransformerFactoryConfigurationError
       | TransformerException e) {
     throw new InternalGemFireError("Could not parse XML when creating XMLEntity", e);
   }
 }
    @Override
    public void init(final Properties parameters) {
      String regionName = parameters.getProperty(REGION_PARAMETER_NAME);
      String dataPolicyName = parameters.getProperty(DATA_POLICY_PARAMETER_NAME);

      Cache gemfireCache = CacheFactory.getAnyInstance();

      assertThat(gemfireCache, is(notNullValue()));

      Region<K, V> region = gemfireCache.getRegion(toRegionPath(regionName));

      assertRegion(region, regionName, resolveDataPolicy(dataPolicyName));

      region.putAll(getRegionData());
    }
コード例 #10
0
  @Override
  public RemoteResult remoteExecute(Object userArgs, Set<Object> filters) {
    Cache c = CacheFactory.getAnyInstance();

    Region r = c.getRegion(regionName);
    Map<String, Object> map = new HashMap<>();
    // class com.gemstone.gemfire.internal.cache.execute.PartitionedRegionFunctionExecutor
    Execution ex = FunctionService.onRegion(r);
    ex = ex.withFilter(filters);
    map.put(PARAM_MODULE_NAME, moduleName);
    map.put(PARAM_BEAN_NAME, beanName);
    map.put(PARAM_URSER_ARGS, userArgs);
    ex = ex.withArgs(map);
    RemoteResult rr = new RemoteResult(ex);
    return rr;
  }
コード例 #11
0
  /**
   * Used supplied XML {@link Document} to extract the XML for the defined {@link XmlEntity}.
   *
   * @param document to extract XML from.
   * @return XML for {@link XmlEntity} if found, otherwise <code>null</code>.
   * @throws XPathExpressionException
   * @throws TransformerException
   * @throws TransformerFactoryConfigurationError
   * @since 8.1
   */
  private final String loadXmlDefinition(final Document document)
      throws XPathExpressionException, TransformerFactoryConfigurationError, TransformerException {
    final Cache cache = CacheFactory.getAnyInstance();

    this.searchString = createQueryString(prefix, type, attributes);
    logger.info("XmlEntity:searchString: {}", this.searchString);

    if (document != null) {
      XPathContext xpathContext = new XPathContext();
      xpathContext.addNamespace(prefix, namespace);
      // Create an XPathContext here
      Node element = XmlUtils.querySingleElement(document, this.searchString, xpathContext);
      // Must copy to preserve namespaces.
      if (null != element) {
        return XmlUtils.elementToString(element);
      }
    }

    logger.warn(
        "No XML definition could be found with name={} and attributes={}", type, attributes);
    return null;
  }
コード例 #12
0
ファイル: GemfireRegionInfo.java プロジェクト: netcrest/pado
  /**
   * Initializes without children.
   *
   * @param region The region from which RegionInfo is extracted.
   */
  @SuppressWarnings({"unchecked", "rawtypes"})
  private void init(Region region) {
    if (region == null) {
      return;
    }
    DistributedMember member =
        CacheFactory.getAnyInstance().getDistributedSystem().getDistributedMember();
    setName(region.getName());
    setFullPath(region.getFullPath());
    GemfireRegionAttributeInfo attrInfo = new GemfireRegionAttributeInfo();
    RegionAttributes<?, ?> attr = region.getAttributes();
    attrInfo.setAttribute(GemfireRegionAttributeInfo.DATA_POLICY, attr.getDataPolicy().toString());
    attrInfo.setAttribute(GemfireRegionAttributeInfo.SCOPE, attr.getScope().toString());
    if (region instanceof PartitionedRegion) {
      PartitionedRegion pr = (PartitionedRegion) region;
      PartitionAttributes pattr = pr.getPartitionAttributes();
      attrInfo.setAttribute(
          GemfireRegionAttributeInfo.LOCAL_MAX_MEMORY, pattr.getLocalMaxMemory() + "");
      attrInfo.setAttribute(
          GemfireRegionAttributeInfo.REDUNDANT_COPIES, pattr.getRedundantCopies() + "");
      attrInfo.setAttribute(
          GemfireRegionAttributeInfo.TOTAL_MAX_MEMORY, pattr.getTotalMaxMemory() + "");
      attrInfo.setAttribute(
          GemfireRegionAttributeInfo.TOTAL_NUM_BUCKETS, pattr.getTotalNumBuckets() + "");

      // data store is null if it's a proxy, i.e., LOCAL_MAX_MEMORY=0
      if (pr.getDataStore() != null) {
        Set<BucketRegion> localtBuketSet = pr.getDataStore().getAllLocalBucketRegions();
        List<BucketInfo> primaryList = new ArrayList<BucketInfo>();
        List<BucketInfo> redundantList = new ArrayList<BucketInfo>();
        this.size = 0;
        for (BucketRegion br : localtBuketSet) {
          BucketInfo bucketInfo =
              new GemfireBucketInfo(
                  br.getId(), br.getBucketAdvisor().isPrimary(), br.size(), br.getTotalBytes());
          //					InternalDistributedMember m = pr.getBucketPrimary(br.getId());
          //					if (m.getId().equals(member.getId())) {
          if (bucketInfo.isPrimary()) {
            primaryList.add(bucketInfo);
            this.size += bucketInfo.getSize();
          } else {
            redundantList.add(bucketInfo);
          }
        }
        Collections.sort(primaryList);
        Collections.sort(redundantList);
        setPrimaryBucketInfoList(primaryList);
        setRedundantBucketInfoList(redundantList);
      }
    } else {
      this.size = region.size();
    }
    setAttrInfo(attrInfo);
    temporalType = GemfireTemporalManager.getTemporalType(region);
    if (region.isDestroyed() == false && region.isEmpty() == false) {
      Set<Map.Entry> regionEntrySet = region.entrySet();
      for (Map.Entry entry : regionEntrySet) {
        Object key = entry.getKey();
        Object value = entry.getValue();
        keyTypeName = key.getClass().getName();
        valueTypeName = value.getClass().getName();
        break;
      }
    }
  }
コード例 #13
0
  @BeforeClass
  public static void setUp() throws Exception {
    CacheSingleton.getCache();

    regionFactory = CacheFactory.getAnyInstance().createRegionFactory();
  }