Improve segmented journal actor metrics
[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 static com.google.common.base.Preconditions.checkArgument;
11 import static java.util.Objects.requireNonNull;
12
13 import akka.actor.ActorRef;
14 import com.google.common.base.MoreObjects;
15 import com.google.common.base.MoreObjects.ToStringHelper;
16 import org.opendaylight.controller.cluster.access.ABIVersion;
17
18 /**
19  * Basic information about how to talk to the backend. ClientActorBehavior uses this information to dispatch requests
20  * to the backend.
21  *
22  * <p>
23  * This class is not final so concrete actor behavior implementations may subclass it and track more information about
24  * the backend. The {@link #hashCode()} and {@link #equals(Object)} methods are made final to ensure subclasses compare
25  * on object identity.
26  *
27  * @author Robert Varga
28  */
29 public class BackendInfo {
30     private final ABIVersion version;
31     private final ActorRef actor;
32     private final int maxMessages;
33     private final long sessionId;
34     private final String name;
35
36     protected BackendInfo(final ActorRef actor, final String name, final long sessionId, final ABIVersion version,
37             final int maxMessages) {
38         this.version = requireNonNull(version);
39         this.actor = requireNonNull(actor);
40         this.name = requireNonNull(name);
41         checkArgument(maxMessages > 0, "Maximum messages has to be positive, not %s", maxMessages);
42         this.maxMessages = maxMessages;
43         this.sessionId = sessionId;
44     }
45
46     public final ActorRef getActor() {
47         return actor;
48     }
49
50     public final String getName() {
51         return name;
52     }
53
54     public final ABIVersion getVersion() {
55         return version;
56     }
57
58     public final int getMaxMessages() {
59         return maxMessages;
60     }
61
62     public final long getSessionId() {
63         return sessionId;
64     }
65
66     @Override
67     public final int hashCode() {
68         return super.hashCode();
69     }
70
71     @Override
72     public final boolean equals(final Object obj) {
73         return super.equals(obj);
74     }
75
76     @Override
77     public final String toString() {
78         return addToStringAttributes(MoreObjects.toStringHelper(this).omitNullValues()).toString();
79     }
80
81     protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
82         return toStringHelper.add("actor", actor).add("sessionId", sessionId).add("version", version)
83                 .add("maxMessages", maxMessages);
84     }
85 }