Bump versions by 0.1.0 for next dev cycle
[vpnservice.git] / natservice / natservice-impl / src / main / java / org / opendaylight / vpnservice / natservice / internal / EventDispatcher.java
1 /*
2  * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. 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
9 package org.opendaylight.vpnservice.natservice.internal;
10
11 import java.util.concurrent.BlockingQueue;
12 import org.slf4j.Logger;
13 import org.slf4j.LoggerFactory;
14
15 public class EventDispatcher implements Runnable {
16     private BlockingQueue<NAPTEntryEvent> eventQueue;
17     private NaptEventHandler naptEventHandler;
18     private static final Logger LOG = LoggerFactory.getLogger(NaptManager.class);
19
20     EventDispatcher(BlockingQueue<NAPTEntryEvent> eventQueue, NaptEventHandler naptEventHandler){
21         this.eventQueue = eventQueue;
22         this.naptEventHandler = naptEventHandler;
23     }
24
25     public void addNaptEvent(NAPTEntryEvent naptEntryEvent){
26         this.eventQueue.add(naptEntryEvent);
27     }
28
29     public void run(){
30         while(true) {
31             try {
32                 NAPTEntryEvent event = eventQueue.take();
33                 naptEventHandler.handleEvent(event);
34             } catch (InterruptedException e) {
35                 LOG.error("EventDispatcher : Error in handling the event queue : ", e.getMessage());
36                 e.printStackTrace();
37             }
38         }
39     }
40 }