Mechanical code cleanup (config)
[controller.git] / opendaylight / config / config-persister-feature-adapter / src / main / java / org / opendaylight / controller / configpusherfeature / internal / ConfigFeaturesListener.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.controller.configpusherfeature.internal;
9
10 import java.util.concurrent.BlockingQueue;
11 import java.util.concurrent.LinkedBlockingQueue;
12 import org.apache.karaf.features.FeatureEvent;
13 import org.apache.karaf.features.FeaturesListener;
14 import org.apache.karaf.features.FeaturesService;
15 import org.apache.karaf.features.RepositoryEvent;
16 import org.opendaylight.controller.config.persist.api.ConfigPusher;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
19
20 public class ConfigFeaturesListener implements  FeaturesListener,  AutoCloseable {
21     private static final Logger LOG = LoggerFactory.getLogger(ConfigFeaturesListener.class);
22     private static final int QUEUE_SIZE = 1000;
23     private BlockingQueue<FeatureEvent> queue = new LinkedBlockingQueue<>(QUEUE_SIZE);
24     Thread pushingThread = null;
25
26     public ConfigFeaturesListener(ConfigPusher p, FeaturesService f) {
27         pushingThread = new Thread(new ConfigPushingRunnable(p, f, queue), "ConfigFeatureListener - ConfigPusher");
28         pushingThread.start();
29     }
30
31     @Override
32     public void featureEvent(FeatureEvent event) {
33         queue.offer(event);
34     }
35
36     @Override
37     public void repositoryEvent(RepositoryEvent event) {
38         LOG.debug("Repository: {} {}", event.getType(), event.getRepository());
39     }
40
41     @Override
42     public void close() {
43         if(pushingThread != null) {
44             pushingThread.interrupt();
45             pushingThread = null;
46         }
47     }
48 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.