001 /* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache license, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the license for the specific language governing permissions and 015 * limitations under the license. 016 */ 017 package org.apache.logging.log4j.flume.appender; 018 019 import com.google.common.base.Preconditions; 020 import org.apache.flume.lifecycle.LifecycleAware; 021 import org.apache.flume.lifecycle.LifecycleState; 022 import org.apache.flume.node.NodeConfiguration; 023 import org.apache.flume.node.NodeManager; 024 import org.apache.flume.node.nodemanager.NodeConfigurationAware; 025 import org.slf4j.Logger; 026 import org.slf4j.LoggerFactory; 027 028 /** 029 * 030 */ 031 public class FlumeNode implements LifecycleAware { 032 033 private static final Logger LOGGER = LoggerFactory.getLogger(FlumeNode.class); 034 035 private LifecycleState lifecycleState; 036 private final NodeManager nodeManager; 037 private final NodeConfigurationAware configurationAware; 038 private final NodeConfiguration conf; 039 040 public FlumeNode(final NodeConfigurationAware configurationAware, final NodeManager manager, 041 final NodeConfiguration conf) { 042 this.nodeManager = manager; 043 this.conf = conf; 044 this.configurationAware = configurationAware; 045 } 046 047 public void start() { 048 049 Preconditions.checkState(nodeManager != null, "Node manager can not be null"); 050 051 LOGGER.info("Flume node starting"); 052 053 configurationAware.startAllComponents(conf); 054 055 lifecycleState = LifecycleState.START; 056 } 057 058 public void stop() { 059 060 LOGGER.info("Flume node stopping"); 061 062 configurationAware.stopAllComponents(); 063 064 lifecycleState = LifecycleState.STOP; 065 } 066 067 public NodeManager getNodeManager() { 068 return nodeManager; 069 } 070 071 public NodeConfiguration getConfiguration() { 072 return conf; 073 } 074 075 public LifecycleState getLifecycleState() { 076 return lifecycleState; 077 } 078 }