efdfa04b1613feec35894f9899a13445c206ea40
[controller.git] / opendaylight / md-sal / cds-access-client / src / main / java / org / opendaylight / controller / cluster / access / client / BackendInfo.java
1 /*
2  * Copyright (c) 2016 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.cluster.access.client;
9
10 import akka.actor.ActorRef;
11 import com.google.common.base.MoreObjects;
12 import com.google.common.base.MoreObjects.ToStringHelper;
13 import com.google.common.base.Preconditions;
14 import org.opendaylight.controller.cluster.access.ABIVersion;
15
16 /**
17  * Basic information about how to talk to the backend. ClientActorBehavior uses this information to dispatch requests
18  * to the backend.
19  *
20  * This class is not final so concrete actor behavior implementations may subclass it and track more information about
21  * the backend. The {@link #hashCode()} and {@link #equals(Object)} methods are made final to ensure subclasses compare
22  * on identity.
23  *
24  * @author Robert Varga
25  */
26 public class BackendInfo {
27     private final ABIVersion version;
28     private final ActorRef actor;
29
30     protected BackendInfo(final ActorRef actor, final ABIVersion version) {
31         this.version = Preconditions.checkNotNull(version);
32         this.actor = Preconditions.checkNotNull(actor);
33     }
34
35     public final ActorRef getActor() {
36         return actor;
37     }
38
39     public final ABIVersion getVersion() {
40         return version;
41     }
42
43     @Override
44     public final int hashCode() {
45         return super.hashCode();
46     }
47
48     @Override
49     public final boolean equals(final Object obj) {
50         return super.equals(obj);
51     }
52
53     @Override
54     public final String toString() {
55         return addToStringAttributes(MoreObjects.toStringHelper(this)).toString();
56     }
57
58     protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
59         return toStringHelper.add("actor", actor).add("version", version);
60     }
61 }