/**
   * Returns shared parameters for a given instance identifier.
   *
   * @param instanceId the instance identifier
   * @return shared parameters or null, if no shared parameters exist for given instance identifier
   * @throws Exception if an error occurs while reading parameters
   */
  public synchronized SharedParameters getShared(String instanceId) throws Exception {
    String safeInstanceId = escapeInstanceIdentifier(instanceId);

    log.trace("getShared(instance = {}, directory = {})", instanceId, safeInstanceId);

    SharedParameters parameters = sharedParameters.get(safeInstanceId);
    if (!reloadIfChanged) {
      return parameters;
    }

    if (parameters != null && parameters.hasChanged()) {
      parameters.reload();
    } else if (parameters == null) {
      // Parameters not cached, attempt to load it from disk.
      Path instanceDir = Paths.get(path.toString(), safeInstanceId);
      loadSharedParameters(instanceDir, sharedParameters);
    }

    return sharedParameters.get(safeInstanceId);
  }
  /**
   * 得到一个分组的全部信息
   *
   * <p><items name="group"> <item name="maxThread" value="maxThread"/> <item
   * name="currentThreadCount" value="currentThreadCount"/> </items> 结果:
   * (group,{maxThread,currentThreadCount}
   *
   * @param params
   * @return
   * @throws ProbeException
   */
  public static Map<String, String> getItems(ParameterHolder params) throws Exception {
    // 这样就保证 了返回 的顺序.
    Map<String, String> resultMap = new LinkedHashMap<String, String>();
    Set<String> KeySet = params.keySet();

    int keySize = KeySet.size();
    String groupName;
    // String[] attrValues = new String[keySize];
    Iterator<String> iterator = KeySet.iterator();

    for (int i = 0; iterator.hasNext(); i++) {
      String attrName = iterator.next();
      String attrValue = SharedParameters.parseString(params, attrName);
      resultMap.put(attrName, attrValue);
    }
    return resultMap;
  }
示例#3
0
 /**
  * @param node
  * @throws JsonParseException
  * @throws JsonMappingException
  * @throws JsonGenerationException
  * @throws JsonProcessingException
  * @throws InterruptedException
  * @throws IOException
  * @throws IncorrectReceivedMessageException
  */
 @Override
 protected void onReceive(XmlNode node)
     throws JsonParseException, JsonMappingException, JsonGenerationException,
         JsonProcessingException, InterruptedException, IOException,
         IncorrectReceivedMessageException {
   List<JsonNode> expectedNodes = convertToJson(node);
   List<JsonNode> receivedNodes = new ArrayList<JsonNode>(expectedNodes.size());
   do {
     String message = responseQueue.poll(TIME_TO_WAIT_ON_RECEIVE, TimeUnit.SECONDS);
     JsonNode receivedNode = null;
     try {
       Assert.assertNotNull(message);
       receivedNode = mapper.readTree(message);
       Assert.assertNotNull(receivedNode);
     } catch (Throwable e) {
       throw new IncorrectReceivedMessageException(
           getListener(), this, receivedNodes, expectedNodes, e.getMessage());
     }
     receivedNodes.add(receivedNode);
     parameters.collectParameters(receivedNode);
     getListener().collectParameters(receivedNode);
     boolean found = false;
     for (JsonNode expectedNode : expectedNodes) {
       if (JsonUtils.equalsIgnoreANY(receivedNode, expectedNode)) {
         expectedNodes.remove(expectedNode);
         receivedNodes.remove(receivedNode);
         found = true;
         break;
       }
     }
     try {
       Assert.assertEquals(true, found);
     } catch (Throwable e) {
       throw new IncorrectReceivedMessageException(
           getListener(), this, receivedNodes, expectedNodes, e.getMessage());
     }
   } while (expectedNodes.size() > 0);
 }
示例#4
0
 /**
  * @param node
  * @throws JsonParseException
  * @throws JsonMappingException
  * @throws JsonGenerationException
  * @throws IOException
  */
 @Override
 protected void send(XmlNode node)
     throws JsonParseException, JsonMappingException, JsonGenerationException, IOException {
   List<JsonNode> jsonList = convertToJson(node);
   send(getListener().updateParameters(parameters.updateParameters(jsonList)));
 }