Change EventDispatcher field visibility of AbstractHandler to protected.
[ovsdb.git] / openstack / net-virt / src / main / java / org / opendaylight / ovsdb / openstack / netvirt / SubnetHandler.java
1 /*
2  * Copyright (C) 2013 Red Hat, Inc.
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  * Authors : Madhu Venugopal, Brent Salisbury
9  */
10
11 package org.opendaylight.ovsdb.openstack.netvirt;
12
13 import java.net.HttpURLConnection;
14
15 import org.opendaylight.neutron.spi.INeutronSubnetAware;
16 import org.opendaylight.neutron.spi.NeutronSubnet;
17 import org.opendaylight.ovsdb.openstack.netvirt.api.Action;
18 import org.opendaylight.ovsdb.openstack.netvirt.api.EventDispatcher;
19 import org.opendaylight.ovsdb.openstack.netvirt.impl.NeutronL3Adapter;
20 import org.opendaylight.ovsdb.utils.servicehelper.ServiceHelper;
21 import org.osgi.framework.BundleContext;
22 import org.osgi.framework.ServiceReference;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
25
26 import com.google.common.base.Preconditions;
27
28 public class SubnetHandler extends AbstractHandler implements INeutronSubnetAware, ConfigInterface {
29
30     static final Logger logger = LoggerFactory.getLogger(SubnetHandler.class);
31
32     // The implementation for each of these services is resolved by the OSGi Service Manager
33     private volatile NeutronL3Adapter neutronL3Adapter;
34
35     @Override
36     public int canCreateSubnet(NeutronSubnet subnet) {
37         return HttpURLConnection.HTTP_OK;
38     }
39
40     @Override
41     public void neutronSubnetCreated(NeutronSubnet subnet) {
42         enqueueEvent(new NorthboundEvent(subnet, Action.ADD));
43     }
44
45     @Override
46     public int canUpdateSubnet(NeutronSubnet delta, NeutronSubnet original) {
47         return HttpURLConnection.HTTP_OK;
48     }
49
50     @Override
51     public void neutronSubnetUpdated(NeutronSubnet subnet) {
52         enqueueEvent(new NorthboundEvent(subnet, Action.UPDATE));
53     }
54
55     @Override
56     public int canDeleteSubnet(NeutronSubnet subnet) {
57         return HttpURLConnection.HTTP_OK;
58     }
59
60     @Override
61     public void neutronSubnetDeleted(NeutronSubnet subnet) {
62         enqueueEvent(new NorthboundEvent(subnet, Action.DELETE));
63     }
64
65     /**
66      * Process the event.
67      *
68      * @param abstractEvent the {@link org.opendaylight.ovsdb.openstack.netvirt.AbstractEvent} event to be handled.
69      * @see org.opendaylight.ovsdb.openstack.netvirt.api.EventDispatcher
70      */
71     @Override
72     public void processEvent(AbstractEvent abstractEvent) {
73         if (!(abstractEvent instanceof NorthboundEvent)) {
74             logger.error("Unable to process abstract event " + abstractEvent);
75             return;
76         }
77         NorthboundEvent ev = (NorthboundEvent) abstractEvent;
78         switch (ev.getAction()) {
79             case ADD:
80                 // fall through
81             case DELETE:
82                 // fall through
83             case UPDATE:
84                 Preconditions.checkNotNull(neutronL3Adapter);
85                 neutronL3Adapter.handleNeutronSubnetEvent(ev.getSubnet(), ev.getAction());
86                 break;
87             default:
88                 logger.warn("Unable to process event action " + ev.getAction());
89                 break;
90         }
91     }
92
93     @Override
94     public void setDependencies(BundleContext bundleContext, ServiceReference serviceReference) {
95         neutronL3Adapter =
96                 (NeutronL3Adapter) ServiceHelper.getGlobalInstance(NeutronL3Adapter.class, this);
97         eventDispatcher =
98                 (EventDispatcher) ServiceHelper.getGlobalInstance(EventDispatcher.class, this);
99         eventDispatcher.eventHandlerAdded(
100                 bundleContext.getServiceReference(INeutronSubnetAware.class.getName()), this);
101     }
102
103     @Override
104     public void setDependencies(Object impl) {
105
106     }
107 }