2 * Copyright (C) 2013 Red Hat, Inc.
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
8 * Authors : Madhu Venugopal, Brent Salisbury
10 package org.opendaylight.ovsdb.plugin;
12 import io.netty.channel.Channel;
14 import org.opendaylight.controller.sal.core.ConstructionException;
15 import org.opendaylight.controller.sal.core.Node;
16 import org.opendaylight.controller.sal.utils.Status;
17 import org.opendaylight.controller.sal.utils.StatusCode;
18 import org.opendaylight.ovsdb.lib.message.OvsdbRPC;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
22 public class Connection {
24 private String identifier;
25 private Channel channel;
28 public Long getIdCounter() {
32 public void setIdCounter(Long idCounter) {
33 this.idCounter = idCounter;
36 private Long idCounter;
38 private static final Logger logger = LoggerFactory.getLogger(Connection.class);
40 public Connection(String identifier, Channel channel) {
44 this.identifier = identifier;
45 this.channel = channel;
48 node = new Node("OVS", identifier);
49 } catch (ConstructionException e) {
50 logger.error("Error creating OVS node with identifier " + identifier, e);
54 public String getIdentifier() {
58 public void setIdentifier(String identifier) {
59 this.identifier = identifier;
62 public Channel getChannel() {
66 public void setChannel(Channel channel) {
67 this.channel = channel;
70 public Node getNode() {
74 public void setNode(Node node) {
78 public OvsdbRPC getRpc() {
82 public void setRpc(OvsdbRPC rpc) {
86 public void sendMessage(String message) {
87 channel.writeAndFlush(message);
91 public Status disconnect() {
93 return new Status(StatusCode.SUCCESS);
97 public int hashCode() {
100 result = prime * result + ((identifier == null) ? 0 : identifier.hashCode());
105 public boolean equals(Object obj) {
106 if (this == obj) return true;
107 if (obj == null) return false;
108 if (getClass() != obj.getClass()) return false;
109 Connection other = (Connection) obj;
110 if (identifier == null) {
111 if (other.identifier != null) return false;
112 } else if (!identifier.equals(other.identifier)) return false;