Java源码示例:org.kitesdk.morphline.base.Metrics

示例1
@Test
public void testReadLine() throws Exception {
  String threeLines = "first\nsecond\nthird";
  byte[] in = threeLines.getBytes("UTF-8");
  morphline = createMorphline("test-morphlines/readLine"); // uses ignoreFirstLine : true
  Record record = new Record();
  record.put(Fields.ATTACHMENT_BODY, in);
  processAndVerifySuccess(record, 
      ImmutableMultimap.of(Fields.MESSAGE, "second"), 
      ImmutableMultimap.of(Fields.MESSAGE, "third")
  );
  
  // verify counters
  boolean foundCounter = false;
  for (Entry<String, Meter> entry : morphContext.getMetricRegistry().getMeters().entrySet()) {
    if (entry.getKey().equals("morphline.readLine." + Metrics.NUM_RECORDS)) {
      assertEquals(2, entry.getValue().getCount());
      foundCounter = true;
    }
  }
  assertTrue(foundCounter);
}
 
示例2
public LoadSolr(CommandBuilder builder, Config config, Command parent, Command child, MorphlineContext context) {
  super(builder, config, parent, child, context);
  Config solrLocatorConfig = getConfigs().getConfig(config, SOLR_LOCATOR_PARAM);
  SolrLocator locator = new SolrLocator(solrLocatorConfig, context);
  LOG.debug("solrLocator: {}", locator);
  RetryPolicyFactory retryPolicyFactory = parseRetryPolicyFactory(
      getConfigs().getConfig(config, "retryPolicy", null));
  this.loader = locator.getLoader(retryPolicyFactory, new CodahaleMetricsFacade(context.getMetricRegistry()));

  Config boostsConfig = getConfigs().getConfig(config, "boosts", ConfigFactory.empty());
  for (Map.Entry<String, Object> entry : new Configs().getEntrySet(boostsConfig)) {
    String fieldName = entry.getKey();        
    float boost = Float.parseFloat(entry.getValue().toString().trim());
    boosts.put(fieldName, boost);
  }
  this.rateLimiter = RateLimiter.create(getConfigs().getDouble(config, "maxRecordsPerSecond", Double.MAX_VALUE));
  this.isDryRun = context.getTypedSettings().getBoolean(TypedSettings.DRY_RUN_SETTING_NAME, false);
  validateArguments();
  this.elapsedTime = getTimer(Metrics.ELAPSED_TIME);
}
 
示例3
protected AbstractParser(CommandBuilder builder, Config config, Command parent, Command child, MorphlineContext context) {
  super(builder, config, parent, child, context);      
  List<String> mimeTypes = getConfigs().getStringList(config, SUPPORTED_MIME_TYPES, Collections.<String>emptyList());
  for (String mimeType : mimeTypes) {
    addSupportedMimeType(mimeType);
  }
  this.numRecordsMeter = getMeter(Metrics.NUM_RECORDS);
}
 
示例4
/** Deprecated; will be removed in the next release */
@Deprecated
protected AbstractParser(Config config, Command parent, Command child, MorphlineContext context) {
  super(config, parent, child, context);      
  List<String> mimeTypes = getConfigs().getStringList(config, SUPPORTED_MIME_TYPES, Collections.<String>emptyList());
  for (String mimeType : mimeTypes) {
    addSupportedMimeType(mimeType);
  }
  this.numRecordsMeter = getMeter(Metrics.NUM_RECORDS);
}
 
示例5
@Test
public void testCompile() throws Exception {
  String file = "test-morphlines/pipeWithTwoBasicCommands";
  morphline = new Compiler().compile(
      new File(RESOURCES_DIR + "/" + file + ".conf"), 
      "", 
      new MorphlineContext.Builder().build(), 
      null);
  assertNotNull(morphline);
  
  new Fields();
  new Metrics();    
}
 
示例6
public UserAgent(CommandBuilder builder, Config config, Command parent, 
                 Command child, MorphlineContext context) {
  
  super(builder, config, parent, child, context);      
  this.inputFieldName = getConfigs().getString(config, "inputField");
  String databaseFile = getConfigs().getString(config, "database", null);
  int cacheCapacity = getConfigs().getInt(config, "cacheCapacity", 1000);
  String nullReplacement = getConfigs().getString(config, "nullReplacement", "");

  Parser parser;
  try {
    if (databaseFile == null) {
      parser = new Parser(); 
    } else {
      InputStream in = new BufferedInputStream(new FileInputStream(databaseFile));
      try {
        parser = new Parser(in);
      } finally {
        Closeables.closeQuietly(in);
      }
    }        
  } catch (IOException e) {
    throw new MorphlineCompilationException("Cannot parse UserAgent database: " + databaseFile, config, e);
  }
  
  Meter numCacheHitsMeter = isMeasuringMetrics() ? getMeter(Metrics.NUM_CACHE_HITS) : null;
  Meter numCacheMissesMeter = isMeasuringMetrics() ? getMeter(Metrics.NUM_CACHE_MISSES) : null;
  
  Config outputFields = getConfigs().getConfig(config, "outputFields", ConfigFactory.empty());
  for (Map.Entry<String, Object> entry : new Configs().getEntrySet(outputFields)) {
    mappings.add(
        new Mapping(
            entry.getKey(), 
            entry.getValue().toString().trim(), 
            parser, 
            new BoundedLRUHashMap(cacheCapacity), 
            nullReplacement, 
            config,
            numCacheHitsMeter,
            numCacheMissesMeter
            ));
  }
  validateArguments();
}