2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.controller.cluster.databroker.actors.dds;
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 org.opendaylight.controller.cluster.access.ABIVersion;
16 import org.opendaylight.controller.cluster.access.client.BackendInfo;
17 import org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier;
18 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree;
21 * Combined backend tracking. Aside from usual {@link BackendInfo}, this object also tracks the cookie assigned
22 * to the shard. This assignment remains constant for as long as the client is not restarted. This class is thread-safe.
24 * @author Robert Varga
26 final class ShardBackendInfo extends BackendInfo {
27 private final Optional<DataTree> dataTree;
28 private final UnsignedLong cookie;
30 ShardBackendInfo(final ActorRef actor, final long sessionId, final ABIVersion version, final String shardName,
31 final UnsignedLong cookie, final Optional<DataTree> dataTree, final int maxMessages) {
32 super(actor, shardName, sessionId, version, maxMessages);
33 this.cookie = Preconditions.checkNotNull(cookie);
34 this.dataTree = Preconditions.checkNotNull(dataTree);
37 UnsignedLong getCookie() {
41 Optional<DataTree> getDataTree() {
45 LocalHistoryIdentifier brandHistory(final LocalHistoryIdentifier id) {
46 Preconditions.checkArgument(id.getCookie() == 0, "History %s is already branded", id);
47 return new LocalHistoryIdentifier(id.getClientId(), id.getHistoryId(), cookie.longValue());
51 protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
52 return super.addToStringAttributes(toStringHelper).add("cookie", cookie).add("shard", getName())
53 .add("dataTree", getDataTree().isPresent() ? "present" : "absent");