Bug 8424: Don't output data tree and tree candidates wih debug
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / databroker / actors / dds / ShardBackendInfo.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.databroker.actors.dds;
9
10 import akka.actor.ActorRef;
11 import com.google.common.base.MoreObjects.ToStringHelper;
12 import com.google.common.base.Preconditions;
13 import com.google.common.primitives.UnsignedLong;
14 import java.util.Optional;
15 import javax.annotation.concurrent.ThreadSafe;
16 import org.opendaylight.controller.cluster.access.ABIVersion;
17 import org.opendaylight.controller.cluster.access.client.BackendInfo;
18 import org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier;
19 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree;
20
21 /**
22  * Combined backend tracking. Aside from usual {@link BackendInfo}, this object also tracks the cookie assigned
23  * to the shard. This assignment remains constant for as long as the client is not restarted.
24  *
25  * @author Robert Varga
26  */
27 @ThreadSafe
28 final class ShardBackendInfo extends BackendInfo {
29     private final Optional<DataTree> dataTree;
30     private final UnsignedLong cookie;
31     private final String shardName;
32
33     ShardBackendInfo(final ActorRef actor, final long sessionId, final ABIVersion version, final String shardName,
34         final UnsignedLong cookie, final Optional<DataTree> dataTree, final int maxMessages) {
35         super(actor, sessionId, version, maxMessages);
36         this.shardName = Preconditions.checkNotNull(shardName);
37         this.cookie = Preconditions.checkNotNull(cookie);
38         this.dataTree = Preconditions.checkNotNull(dataTree);
39     }
40
41     UnsignedLong getCookie() {
42         return cookie;
43     }
44
45     Optional<DataTree> getDataTree() {
46         return dataTree;
47     }
48
49     String getShardName() {
50         return shardName;
51     }
52
53     LocalHistoryIdentifier brandHistory(final LocalHistoryIdentifier id) {
54         Preconditions.checkArgument(id.getCookie() == 0, "History %s is already branded", id);
55         return new LocalHistoryIdentifier(id.getClientId(), id.getHistoryId(), cookie.longValue());
56     }
57
58     @Override
59     protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
60         return super.addToStringAttributes(toStringHelper).add("cookie", cookie).add("shard", shardName)
61                 .add("dataTree present", getDataTree().isPresent());
62     }
63 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.