2 * Copyright (c) 2013, 2015 Red Hat, Inc. and others. All rights reserved.
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
9 package org.opendaylight.ovsdb.openstack.netvirt;
11 import org.opendaylight.ovsdb.openstack.netvirt.api.EventDispatcher;
12 import org.opendaylight.ovsdb.openstack.netvirt.api.Status;
13 import org.opendaylight.ovsdb.openstack.netvirt.api.StatusCode;
15 import com.google.common.base.Preconditions;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
19 import java.net.HttpURLConnection;
22 * OpenStack related events originate from multiple north callbacks as well as south.
23 * This interface provides a layer of abstraction between the event dispatcher and the
26 public abstract class AbstractHandler {
27 private static final Logger LOG = LoggerFactory.getLogger(AbstractHandler.class);
29 // The implementation for each of these services is resolved by the OSGi Service Manager
30 protected volatile EventDispatcher eventDispatcher;
33 * Convert failure status returned by the manager into
34 * neutron API service errors.
36 * @param status manager status
37 * @return An error to be returned to neutron API service.
39 protected static int getException(Status status) {
40 assert !status.isSuccess();
42 StatusCode code = status.getCode();
43 LOG.debug(" Exception code - {}, description - {}",
44 code, status.getDescription());
48 return HttpURLConnection.HTTP_BAD_REQUEST;
50 return HttpURLConnection.HTTP_CONFLICT;
52 return HttpURLConnection.HTTP_NOT_ACCEPTABLE;
54 return HttpURLConnection.HTTP_NOT_FOUND;
56 return HttpURLConnection.HTTP_INTERNAL_ERROR;
63 * @param abstractEvent the {@link org.opendaylight.ovsdb.openstack.netvirt.AbstractEvent} event to be handled.
64 * @see org.opendaylight.ovsdb.openstack.netvirt.api.EventDispatcher
66 protected void enqueueEvent(AbstractEvent abstractEvent) {
67 LOG.info("enqueueEvent: evenDispatcher: {} - {}", eventDispatcher, abstractEvent);
68 Preconditions.checkNotNull(eventDispatcher);
69 eventDispatcher.enqueueEvent(abstractEvent);
75 * @param abstractEvent the {@link org.opendaylight.ovsdb.openstack.netvirt.AbstractEvent} event to be handled.
76 * @see org.opendaylight.ovsdb.openstack.netvirt.api.EventDispatcher
78 public abstract void processEvent(AbstractEvent abstractEvent);