2c7ae15e0be10da7744c5a82d4a78ae1be99c20c
[netvirt.git] / plugin / src / main / java / org / opendaylight / ovsdb / plugin / Connection.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 package org.opendaylight.ovsdb.plugin;
11
12 import org.opendaylight.controller.sal.core.ConstructionException;
13 import org.opendaylight.controller.sal.core.Node;
14 import org.opendaylight.ovsdb.lib.OvsdbClient;
15 import org.slf4j.Logger;
16 import org.slf4j.LoggerFactory;
17
18 public class Connection {
19     private Node node;
20     private String identifier;
21     private OvsdbClient client;
22
23     public Long getIdCounter() {
24         return idCounter;
25     }
26
27     public void setIdCounter(Long idCounter) {
28         this.idCounter = idCounter;
29     }
30
31     private Long idCounter;
32
33     private static final Logger logger = LoggerFactory.getLogger(Connection.class);
34
35     public Connection(String identifier, OvsdbClient client) {
36
37         super();
38
39         this.identifier = identifier;
40         this.client = client;
41         this.idCounter = 0L;
42         try {
43             node = new Node("OVS", identifier);
44         } catch (ConstructionException e) {
45             logger.error("Error creating OVS node with identifier " + identifier, e);
46         }
47     }
48
49     public String getIdentifier() {
50         return identifier;
51     }
52
53     public void setIdentifier(String identifier) {
54         this.identifier = identifier;
55     }
56
57     public OvsdbClient getClient() {
58         return this.client;
59     }
60
61     public void setClient(OvsdbClient client) {
62         this.client = client;
63     }
64
65     public Node getNode() {
66         return node;
67     }
68
69     public void setNode(Node node) {
70         this.node = node;
71     }
72
73     public void disconnect() {
74         client.disconnect();
75     }
76
77     @Override
78     public int hashCode() {
79         final int prime = 31;
80         int result = 1;
81         result = prime * result + ((identifier == null) ? 0 : identifier.hashCode());
82         return result;
83     }
84
85     @Override
86     public boolean equals(Object obj) {
87         if (this == obj) return true;
88         if (obj == null) return false;
89         if (getClass() != obj.getClass()) return false;
90         Connection other = (Connection) obj;
91         if (identifier == null) {
92             if (other.identifier != null) return false;
93         } else if (!identifier.equals(other.identifier)) return false;
94         return true;
95     }
96 }