db10b08ff48c9cd1bf224891e8c7c3c9038f9453
[controller.git] / opendaylight / md-sal / sal-connector-api / src / main / java / org / opendaylight / controller / sal / connector / api / BindingAwareRpcRouter.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. 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 package org.opendaylight.controller.sal.connector.api;
9
10 import java.util.concurrent.Future;
11 import org.opendaylight.yangtools.concepts.Immutable;
12
13 public interface BindingAwareRpcRouter extends RpcRouter<String, String, String, byte[]> {
14
15     @Override
16     Future<org.opendaylight.controller.sal.connector.api.RpcRouter.RpcReply<byte[]>> sendRpc(
17             RpcRequest<String, String, String, byte[]> input);
18
19     class BindingAwareRequest implements RpcRequest<String, String, String, byte[]>, Immutable {
20
21         private final BindingAwareRouteIdentifier routingInformation;
22         private final byte[] payload;
23
24         public BindingAwareRequest(BindingAwareRouteIdentifier routingInformation, byte[] payload) {
25             this.routingInformation = routingInformation;
26             this.payload = payload;
27         }
28
29         @Override
30         public BindingAwareRouteIdentifier getRoutingInformation() {
31             return this.routingInformation;
32         }
33
34         @Override
35         public byte[] getPayload() {
36             return payload;
37         }
38     }
39
40     class BindingAwareRouteIdentifier implements RouteIdentifier<String, String, String>, Immutable {
41
42         private final String type;
43         private final String route;
44         private final String content;
45
46         public BindingAwareRouteIdentifier(String type, String route, String content) {
47             this.type = type;
48             this.route = route;
49             this.content = content;
50         }
51
52         /**
53          * Java class name of Rpc Context.
54          */
55         @Override
56         public String getContext() {
57             return this.content;
58         }
59
60         /**
61          * String representation of route e.g. node-id
62          *
63          */
64         @Override
65         public String getRoute() {
66             return this.route;
67         }
68
69         /**
70          * Java class name of Rpc Type e.g org.opendaylight.AddFlowInput.
71          */
72         @Override
73         public String getType() {
74             return this.type;
75         }
76
77         @Override
78         public int hashCode() {
79             final int prime = 31;
80             int result = 1;
81             result = prime * result + (content == null ? 0 : content.hashCode());
82             result = prime * result + (route == null ? 0 : route.hashCode());
83             result = prime * result + (type == null ? 0 : type.hashCode());
84             return result;
85         }
86
87         @Override
88         public boolean equals(Object obj) {
89             if (this == obj) {
90                 return true;
91             }
92             if (obj == null) {
93                 return false;
94             }
95             if (getClass() != obj.getClass()) {
96                 return false;
97             }
98             BindingAwareRouteIdentifier other = (BindingAwareRouteIdentifier) obj;
99             if (content == null) {
100                 if (other.content != null) {
101                     return false;
102                 }
103             } else if (!content.equals(other.content)) {
104                 return false;
105             }
106             if (route == null) {
107                 if (other.route != null) {
108                     return false;
109                 }
110             } else if (!route.equals(other.route)) {
111                 return false;
112             }
113             if (type == null) {
114                 if (other.type != null) {
115                     return false;
116                 }
117             } else if (!type.equals(other.type)) {
118                 return false;
119             }
120             return true;
121         }
122     }
123 }