</dependency>
</dependencies>
<build>
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <artifactId>maven-checkstyle-plugin</artifactId>
+ <dependencies>
+ <dependency>
+ <groupId>org.opendaylight.genius</groupId>
+ <artifactId>checkstyle</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
+ <executions>
+ <execution>
+ <id>check-databroker</id>
+ <goals>
+ <goal>check</goal>
+ </goals>
+ <phase>process-sources</phase>
+ <configuration>
+ <configLocation>databroker-checks.xml</configLocation>
+ <includeResources>false</includeResources>
+ <includeTestSourceDirectory>false</includeTestSourceDirectory>
+ <includeTestResources>false</includeTestResources>
+ <sourceDirectory>${project.build.sourceDirectory}</sourceDirectory>
+ <failsOnError>true</failsOnError>
+ <consoleOutput>true</consoleOutput>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.aries.blueprint</groupId>
import javax.inject.Singleton;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.controller.md.sal.common.api.data.OptimisticLockFailedException;
+import org.opendaylight.genius.infra.Datastore;
import org.opendaylight.genius.infra.RetryingManagedNewTransactionRunner;
import org.opendaylight.serviceutils.tools.mdsal.rpc.FutureRpcResults;
import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.lockmanager.rev160413.LockInput;
private static final Logger LOG = LoggerFactory.getLogger(LockManagerServiceImpl.class);
- private final DataBroker broker;
private final RetryingManagedNewTransactionRunner txRunner;
private final LockManagerUtils lockManagerUtils;
@Inject
public LockManagerServiceImpl(final @OsgiService DataBroker dataBroker, final LockManagerUtils lockManagerUtils) {
- this.broker = dataBroker;
this.lockManagerUtils = lockManagerUtils;
this.txRunner = new RetryingManagedNewTransactionRunner(dataBroker);
}
throws InterruptedException, ExecutionException {
String lockName = lockData.getLockName();
synchronized (lockName.intern()) {
- ReadWriteTransaction tx = broker.newReadWriteTransaction();
- Optional<Lock> result = tx.read(LogicalDatastoreType.OPERATIONAL, lockInstanceIdentifier).get();
- if (!result.isPresent()) {
- LOG.debug("Writing lock lockData {}", lockData);
- tx.put(LogicalDatastoreType.OPERATIONAL, lockInstanceIdentifier, lockData, true);
- tx.commit().get();
- return true;
- } else {
- String lockDataOwner = result.get().getLockOwner();
- String currentOwner = lockData.getLockOwner();
- if (currentOwner.equals(lockDataOwner)) {
+ return txRunner.applyWithNewReadWriteTransactionAndSubmit(Datastore.OPERATIONAL, tx -> {
+ Optional<Lock> result = tx.read(lockInstanceIdentifier).get();
+ if (!result.isPresent()) {
+ LOG.debug("Writing lock lockData {}", lockData);
+ tx.put(lockInstanceIdentifier, lockData, true);
return true;
+ } else {
+ String lockDataOwner = result.get().getLockOwner();
+ String currentOwner = lockData.getLockOwner();
+ if (currentOwner.equals(lockDataOwner)) {
+ return true;
+ }
}
- }
- tx.cancel();
- return false;
+ return false;
+ }).get();
}
}
}