Package org.apache.flume

Examples of org.apache.flume.Source


  public void testLifecycle() throws LifecycleException, InterruptedException {

    Channel channel = new MemoryChannel();
    Configurables.configure(channel, new Context());

    Source generatorSource = new SequenceGeneratorSource();
    List<Channel> channels = new ArrayList<Channel>();
    channels.add(channel);

    ChannelSelector rcs = new ReplicatingChannelSelector();
    rcs.setChannels(channels);

    generatorSource.setChannelProcessor(new ChannelProcessor(rcs));

    NullSink nullSink = new NullSink();
    nullSink.configure(new Context());
    nullSink.setChannel(channel);
View Full Code Here


  InterruptedException {

    Channel channel = new MemoryChannel();
    Configurables.configure(channel, new Context());

    Source source = new SequenceGeneratorSource();
    List<Channel> channels = new ArrayList<Channel>();
    channels.add(channel);
    ChannelSelector rcs = new ReplicatingChannelSelector();
    rcs.setChannels(channels);

    source.setChannelProcessor(new ChannelProcessor(rcs));

    NullSink sink = new NullSink();
    sink.configure(new Context());
    sink.setChannel(channel);
View Full Code Here

    if (sourceMap == null) {
      sourceMap = new HashMap<String, Source>();
      sources.put(sourceClass, sourceMap);
    }

    Source source = sourceMap.get(name);

    if (source == null) {
      try {
        source = sourceClass.newInstance();
        source.setName(name);
        sourceMap.put(name, source);
      } catch (Exception ex) {
        // Clean up the source map
        sources.remove(sourceClass);
        throw new FlumeException("Unable to create source: " + name
View Full Code Here

    Preconditions.checkNotNull(name, "name");
    Preconditions.checkNotNull(type, "type");
    logger.info("Creating instance of source {}, type {}", name, type);
    Class<? extends Source> sourceClass = getClass(type);
    try {
      Source source = sourceClass.newInstance();
      source.setName(name);
      return source;
    } catch (Exception ex) {
      throw new FlumeException("Unable to create source: " + name
          +", type: " + type + ", class: " + sourceClass.getName(), ex);
    }
View Full Code Here

    for (String sourceName : sourceNames) {
      ComponentConfiguration comp = compMap.get(sourceName);
      if(comp != null) {
        SourceConfiguration config = (SourceConfiguration) comp;

        Source source = sourceFactory.create(comp.getComponentName(),
            comp.getType());
        try {
          Configurables.configure(source, config);
          Set<String> channelNames = config.getChannels();
          List<Channel> sourceChannels = new ArrayList<Channel>();
          for (String chName : channelNames) {
            ChannelComponent channelComponent = channelComponentMap.get(chName);
            if(channelComponent != null) {
              sourceChannels.add(channelComponent.channel);
            }
          }
          if(sourceChannels.isEmpty()) {
            String msg = String.format("Source %s is not connected to a " +
                "channel",  sourceName);
            throw new IllegalStateException(msg);
          }
          ChannelSelectorConfiguration selectorConfig =
              config.getSelectorConfiguration();

          ChannelSelector selector = ChannelSelectorFactory.create(
              sourceChannels, selectorConfig);

          ChannelProcessor channelProcessor = new ChannelProcessor(selector);
          Configurables.configure(channelProcessor, config);

          source.setChannelProcessor(channelProcessor);
          sourceRunnerMap.put(comp.getComponentName(),
              SourceRunner.forSource(source));
          for(Channel channel : sourceChannels) {
            ChannelComponent channelComponent = Preconditions.
                checkNotNull(channelComponentMap.get(channel.getName()),
                    String.format("Channel %s", channel.getName()));
            channelComponent.components.add(sourceName);
          }
        } catch (Exception e) {
          String msg = String.format("Source %s has been removed due to an " +
              "error during configuration", sourceName);
          LOGGER.error(msg, e);
        }
      }
    }
    /*
     * Components which DO NOT have a ComponentConfiguration object
     * and use only Context
     */
    Map<String, Context> sourceContexts = agentConf.getSourceContext();
    for (String sourceName : sourceNames) {
      Context context = sourceContexts.get(sourceName);
      if(context != null){
        Source source =
            sourceFactory.create(sourceName,
                context.getString(BasicConfigurationConstants.CONFIG_TYPE));
        try {
          Configurables.configure(source, context);
          List<Channel> sourceChannels = new ArrayList<Channel>();
          String[] channelNames = context.getString(
              BasicConfigurationConstants.CONFIG_CHANNELS).split("\\s+");
          for (String chName : channelNames) {
            ChannelComponent channelComponent = channelComponentMap.get(chName);
            if(channelComponent != null) {
              sourceChannels.add(channelComponent.channel);
            }
          }
          if(sourceChannels.isEmpty()) {
            String msg = String.format("Source %s is not connected to a " +
                "channel",  sourceName);
            throw new IllegalStateException(msg);
          }
          Map<String, String> selectorConfig = context.getSubProperties(
              BasicConfigurationConstants.CONFIG_SOURCE_CHANNELSELECTOR_PREFIX);

          ChannelSelector selector = ChannelSelectorFactory.create(
              sourceChannels, selectorConfig);

          ChannelProcessor channelProcessor = new ChannelProcessor(selector);
          Configurables.configure(channelProcessor, context);
          source.setChannelProcessor(channelProcessor);
          sourceRunnerMap.put(sourceName,
              SourceRunner.forSource(source));
          for(Channel channel : sourceChannels) {
            ChannelComponent channelComponent = Preconditions.
                checkNotNull(channelComponentMap.get(channel.getName()),
View Full Code Here

      throw new IllegalStateException("Cannot be started before being " +
          "configured");
    }
    // This check needs to be done before doStart(),
    // as doStart() accesses sourceRunner.getSource()
    Source source = Preconditions.checkNotNull(sourceRunner.getSource(),
        "Source runner returned null source");
    if(source instanceof EmbeddedSource) {
      embeddedSource = (EmbeddedSource)source;
    } else {
      throw new IllegalStateException("Unknown source type: " + source.
          getClass().getName());
    }
    doStart();
    state = State.STARTED;
  }
View Full Code Here

          "Interrupted while waiting for polling runner to stop. Please report this.",
          e);
      Thread.currentThread().interrupt();
    }

    Source source = getSource();
    source.stop();
    ChannelProcessor cp = source.getChannelProcessor();
    cp.close();

    lifecycleState = LifecycleState.STOP;
  }
View Full Code Here

    for (Map<String, Object> sourceDef : defs) {
      logger.debug("source:{}", sourceDef);

      if (sourceDef.containsKey("type")) {
        Source source =
            getSourceFactory().create((String) sourceDef.get("type"));
        Channel channel = conf.getChannels().get(sourceDef.get("channel"));

        Context context = new Context();
        context.setParameters(sourceDef);

        Configurables.configure(source, context);

        if (channel != null) {
          source.setChannel(channel);
        } else {
          logger.warn(
              "No channel named {} - source:{} is likely non-functional.",
              source, sourceDef.get("channel"));
        }
View Full Code Here

    /* FIXME: Is returning null really a good idea? Should we just panic? */
    if (!sourceRegistry.containsKey(name)) {
      return null;
    }

    Source source = null;

    try {
      source = sourceRegistry.get(name).newInstance();
    } catch (IllegalAccessException e) {
      throw new InstantiationException("Unable to create source " + name
View Full Code Here

    sourceFactory = new DefaultSourceFactory();
  }

  private void verifySourceCreation(String name, String type,
      Class<?> typeClass) throws FlumeException {
    Source src = sourceFactory.create(name, type);
    Assert.assertNotNull(src);
    Assert.assertTrue(typeClass.isInstance(src));
  }
View Full Code Here

TOP

Related Classes of org.apache.flume.Source

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.