2 * Copyright (c) 2014 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.md.sal.common.impl.service;
10 import java.util.concurrent.Future;
12 import org.opendaylight.controller.md.sal.common.api.TransactionStatus;
13 import org.opendaylight.controller.md.sal.common.impl.AbstractDataModification;
14 import org.opendaylight.yangtools.concepts.Path;
15 import org.opendaylight.yangtools.yang.common.RpcResult;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
19 @SuppressWarnings("all")
20 public abstract class AbstractDataTransaction<P extends Path<P>, D extends Object> extends
21 AbstractDataModification<P, D> {
22 private final static Logger LOG = LoggerFactory.getLogger(AbstractDataTransaction.class);
24 private final Object identifier;
27 public Object getIdentifier() {
28 return this.identifier;
31 private TransactionStatus status;
33 private final AbstractDataBroker<P, D, ? extends Object> broker;
35 protected AbstractDataTransaction(final Object identifier,
36 final AbstractDataBroker<P, D, ? extends Object> dataBroker) {
38 this.identifier = identifier;
39 this.broker = dataBroker;
40 this.status = TransactionStatus.NEW;
41 AbstractDataTransaction.LOG.debug("Transaction {} Allocated.", identifier);
45 public Future<RpcResult<TransactionStatus>> commit() {
46 return this.broker.commit(this);
50 public D readConfigurationData(final P path) {
51 final D local = getUpdatedConfigurationData().get(path);
55 return this.broker.readConfigurationData(path);
59 public D readOperationalData(final P path) {
60 final D local = this.getUpdatedOperationalData().get(path);
64 return this.broker.readOperationalData(path);
70 public int hashCode() {
73 result = prime * result + ((identifier == null) ? 0 : identifier.hashCode());
78 public boolean equals(Object obj) {
83 if (getClass() != obj.getClass())
85 AbstractDataTransaction other = (AbstractDataTransaction) obj;
86 if (identifier == null) {
87 if (other.identifier != null)
89 } else if (!identifier.equals(other.identifier))
95 public TransactionStatus getStatus() {
99 protected abstract void onStatusChange(final TransactionStatus status);
101 public void changeStatus(final TransactionStatus status) {
102 Object _identifier = this.getIdentifier();
103 AbstractDataTransaction.LOG
104 .debug("Transaction {} transitioned from {} to {}", _identifier, this.status, status);
105 this.status = status;
106 this.onStatusChange(status);