Exemplo n.º 1
0
  /** {@inheritDoc} */
  @Override
  protected DslExpressionDefinition handle(final List<?> parsing) {
    String preExpression = (String) parsing.get(0);
    String postExpression = (String) parsing.get(4);
    final Option<DslFieldDefinition> field;
    final Option<DslMultiFieldDefinition> multiField;
    final Choice fields = (Choice) parsing.get(1);
    switch (fields.getValue()) {
      case 0:
        field = Option.some((DslFieldDefinition) fields.getResult());
        multiField = Option.none();
        break;
      case 1:
        final List<?> multiFieldParsing = (List<?>) fields.getResult();
        preExpression = DslUtil.concat(preExpression, (String) multiFieldParsing.get(0));
        multiField = Option.some((DslMultiFieldDefinition) multiFieldParsing.get(1));
        postExpression = DslUtil.concat((String) multiFieldParsing.get(2), postExpression);
        field = Option.none();
        break;
      default:
        throw new IllegalArgumentException("case " + fields.getValue() + " not implemented");
    }

    final Choice queries = (Choice) parsing.get(3);
    final DslQueryDefinition query = (DslQueryDefinition) queries.getResult();

    return new DslExpressionDefinition(preExpression, field, multiField, query, postExpression);
  }
  /** {@inheritDoc} */
  @Override
  public Option<Definition> createDefinition(final DynamicDefinition xdefinition) {
    final Entity entity = xdefinition.getEntity();

    if (entity.equals(PublisherGrammar.publisherDefinition)) {
      final Definition definition = createPublisherDataDefinition(xdefinition);
      return Option.some(definition);
    } else if (entity.equals(PublisherGrammar.publisherNodeDefinition)) {
      createPublisherNodeDefinition(xdefinition);
      return Option.none();
    } else {
      throw new IllegalArgumentException("Type de définition non gérée: " + xdefinition.getName());
    }
  }
  /**
   * Lance l'environnement et attend indéfiniment.
   *
   * @param args "Usage: java kasper.kernel.Starter managers.xml <conf.properties>"
   */
  public static void main(final String[] args) {
    final String usageMsg =
        "Usage: java io.analytica.spies.impl.logs.LogSpyStandaloneParser \"http://analyticaServer:port/analytica/rest/process\" confPattern.json logFile.out";
    Assertion.checkArgument(
        args.length == 3, usageMsg + " (nombre d'arguments incorrect : " + args.length + ")");
    Assertion.checkArgument(args[0].contains("http://"), usageMsg + " (" + args[0] + ")");
    Assertion.checkArgument(args[1].endsWith(".json"), usageMsg + " (" + args[1] + ")");
    // ---------------------------------------------------------------------
    final String managersXmlFileName = "./managers.xml";
    final Option<String> propertiesFileName =
        args.length == 2 ? Option.<String>some(args[1]) : Option.<String>none();
    final Properties defaultProperties = new Properties();
    defaultProperties.setProperty("serverUrl", args[0]);
    defaultProperties.setProperty("confFileUrl", args[1]);
    defaultProperties.setProperty("logFileUrl", args[2]);

    final Starter starter =
        new Starter(
            managersXmlFileName,
            propertiesFileName,
            LogSpyStandaloneParser.class,
            Option.some(defaultProperties),
            0);
    starter.start();
    try {
      // final Container container = new DualContainer(Home.getComponentSpace(), new
      // ParamsContainer((Map) defaultProperties));
      final AgentManager agentManager = Home.getComponentSpace().resolve(AgentManager.class);
      final ResourceManager resourceManager =
          Home.getComponentSpace().resolve(ResourceManager.class);
      final String logFileUrl = defaultProperties.getProperty("logFileUrl");
      final String confFileUrl = defaultProperties.getProperty("confFileUrl");
      final LogSpyReader logSpyReader =
          new LogSpyReader(agentManager, resourceManager, logFileUrl, confFileUrl);
      // INJECTOR.newInstance(LogSpyReader.class, Home.getComponentSpace());
      try {
        logSpyReader.start();
      } finally {
        flushAgentToServer();
      }
    } finally {
      starter.stop();
    }
  }