View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements. See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache license, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License. You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the license for the specific language governing permissions and
15   * limitations under the license.
16   */
17  package org.apache.logging.log4j.flume.appender;
18  
19  import com.google.common.base.Preconditions;
20  import org.apache.flume.lifecycle.LifecycleAware;
21  import org.apache.flume.lifecycle.LifecycleState;
22  import org.apache.flume.node.NodeConfiguration;
23  import org.apache.flume.node.NodeManager;
24  import org.apache.flume.node.nodemanager.NodeConfigurationAware;
25  import org.slf4j.Logger;
26  import org.slf4j.LoggerFactory;
27  
28  /**
29   *
30   */
31  public class FlumeNode implements LifecycleAware {
32  
33      private static final Logger LOGGER = LoggerFactory.getLogger(FlumeNode.class);
34  
35      private LifecycleState lifecycleState;
36      private final NodeManager nodeManager;
37      private final NodeConfigurationAware configurationAware;
38      private final NodeConfiguration conf;
39  
40      public FlumeNode(final NodeConfigurationAware configurationAware, final NodeManager manager,
41                       final NodeConfiguration conf) {
42          this.nodeManager = manager;
43          this.conf = conf;
44          this.configurationAware = configurationAware;
45      }
46  
47      @Override
48      public void start() {
49  
50          Preconditions.checkState(nodeManager != null, "Node manager can not be null");
51  
52          LOGGER.info("Flume node starting");
53  
54          configurationAware.startAllComponents(conf);
55  
56          lifecycleState = LifecycleState.START;
57      }
58  
59      @Override
60      public void stop() {
61  
62          LOGGER.info("Flume node stopping");
63  
64          configurationAware.stopAllComponents();
65  
66          lifecycleState = LifecycleState.STOP;
67      }
68  
69      public NodeManager getNodeManager() {
70          return nodeManager;
71      }
72  
73      public NodeConfiguration getConfiguration() {
74          return conf;
75      }
76  
77      @Override
78      public LifecycleState getLifecycleState() {
79          return lifecycleState;
80      }
81  }