Fix CS warnings in cds-access-client and enable enforcement
[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  * <p>
21  * This class is not final so concrete actor behavior implementations may subclass it and track more information about
22  * the backend. The {@link #hashCode()} and {@link #equals(Object)} methods are made final to ensure subclasses compare
23  * on identity.
24  *
25  * @author Robert Varga
26  */
27 public class BackendInfo {
28     private final ABIVersion version;
29     private final ActorRef actor;
30     private final int maxMessages;
31     private final long sessionId;
32
33     protected BackendInfo(final ActorRef actor, final long sessionId, final ABIVersion version, final int maxMessages) {
34         this.version = Preconditions.checkNotNull(version);
35         this.actor = Preconditions.checkNotNull(actor);
36         Preconditions.checkArgument(maxMessages > 0, "Maximum messages has to be positive, not %s", maxMessages);
37         this.maxMessages = maxMessages;
38         this.sessionId = sessionId;
39     }
40
41     public final ActorRef getActor() {
42         return actor;
43     }
44
45     public final ABIVersion getVersion() {
46         return version;
47     }
48
49     public final int getMaxMessages() {
50         return maxMessages;
51     }
52
53     public final long getSessionId() {
54         return sessionId;
55     }
56
57     @Override
58     public final int hashCode() {
59         return super.hashCode();
60     }
61
62     @Override
63     public final boolean equals(final Object obj) {
64         return super.equals(obj);
65     }
66
67     @Override
68     public final String toString() {
69         return addToStringAttributes(MoreObjects.toStringHelper(this)).toString();
70     }
71
72     protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
73         return toStringHelper.add("actor", actor).add("sessionId", sessionId).add("version", version)
74                 .add("maxMessages", maxMessages);
75     }
76 }