本文整理汇总了Java中org.opendaylight.controller.md.sal.binding.api.DataBroker.newReadOnlyTransaction方法的典型用法代码示例。如果您正苦于以下问题:Java DataBroker.newReadOnlyTransaction方法的具体用法?Java DataBroker.newReadOnlyTransaction怎么用?Java DataBroker.newReadOnlyTransaction使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.opendaylight.controller.md.sal.binding.api.DataBroker
的用法示例。
在下文中一共展示了DataBroker.newReadOnlyTransaction方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testToasterInitOnStartUp
import org.opendaylight.controller.md.sal.binding.api.DataBroker; //导入方法依赖的package包/类
@Test
public void testToasterInitOnStartUp() throws Exception {
DataBroker broker = getDataBroker();
ReadOnlyTransaction readTx = broker.newReadOnlyTransaction();
Optional<Toaster> optional = readTx.read(LogicalDatastoreType.OPERATIONAL, TOASTER_IID).get();
assertNotNull(optional);
assertTrue("Operational toaster not present", optional.isPresent());
Toaster toasterData = optional.get();
assertEquals(Toaster.ToasterStatus.Up, toasterData.getToasterStatus());
assertEquals(new DisplayString("Opendaylight"), toasterData.getToasterManufacturer());
assertEquals(new DisplayString("Model 1 - Binding Aware"), toasterData.getToasterModelNumber());
Optional<Toaster> configToaster = readTx.read(LogicalDatastoreType.CONFIGURATION, TOASTER_IID).get();
assertFalse("Didn't expect config data for toaster.", configToaster.isPresent());
}
示例2: getSubnetMapBuilder
import org.opendaylight.controller.md.sal.binding.api.DataBroker; //导入方法依赖的package包/类
private SubnetmapBuilder getSubnetMapBuilder(DataBroker broker, Uuid subnetId) {
SubnetmapBuilder builder = null ;
InstanceIdentifier<Subnetmap> id = InstanceIdentifier.builder(Subnetmaps.class)
.child(Subnetmap.class, new SubnetmapKey(subnetId)).build();
ReadOnlyTransaction tx = broker.newReadOnlyTransaction();
Optional<Subnetmap> sn ;
try {
sn = tx.read(LogicalDatastoreType.CONFIGURATION, id).get();
} catch (InterruptedException | ExecutionException e) {
throw new RuntimeException(e);
}
if (sn.isPresent()) {
builder = new SubnetmapBuilder(sn.get());
} else {
builder = new SubnetmapBuilder().setKey(new SubnetmapKey(subnetId)).setId(subnetId);
}
return builder;
}
示例3: validateGreetingRegistry
import org.opendaylight.controller.md.sal.binding.api.DataBroker; //导入方法依赖的package包/类
private void validateGreetingRegistry(String name) {
InstanceIdentifier<GreetingRegistryEntry> iid = InstanceIdentifier.create(GreetingRegistry.class)
.child(GreetingRegistryEntry.class, new GreetingRegistryEntryKey(name));
DataBroker db = getSession().getSALService(DataBroker.class);
ReadOnlyTransaction transaction = db.newReadOnlyTransaction();
CheckedFuture<Optional<GreetingRegistryEntry>, ReadFailedException> future =
transaction.read(LogicalDatastoreType.OPERATIONAL, iid);
Optional<GreetingRegistryEntry> optional = Optional.absent();
try {
optional = future.checkedGet();
} catch (ReadFailedException e) {
LOG.warn("Reading greeting failed:",e);
}
Assert.assertTrue(name + " not recorded in greeting registry",optional.isPresent());
}
示例4: readInitialAppConfig
import org.opendaylight.controller.md.sal.binding.api.DataBroker; //导入方法依赖的package包/类
private void readInitialAppConfig(final DataBroker dataBroker) {
final ReadOnlyTransaction readOnlyTx = dataBroker.newReadOnlyTransaction();
ListenableFuture<Optional<DataObject>> future = readOnlyTx.read(
LogicalDatastoreType.CONFIGURATION, bindingContext.appConfigPath);
Futures.addCallback(future, new FutureCallback<Optional<DataObject>>() {
@Override
public void onSuccess(final Optional<DataObject> possibleAppConfig) {
LOG.debug("{}: Read of app config {} succeeded: {}", logName(), bindingContext
.appConfigBindingClass.getName(), possibleAppConfig);
readOnlyTx.close();
setInitialAppConfig(possibleAppConfig);
}
@Override
public void onFailure(final Throwable failure) {
readOnlyTx.close();
// We may have gotten the app config via the data tree change listener so only retry if not.
if (readingInitialAppConfig.get()) {
LOG.warn("{}: Read of app config {} failed - retrying", logName(),
bindingContext.appConfigBindingClass.getName(), failure);
readInitialAppConfig(dataBroker);
}
}
}, MoreExecutors.directExecutor());
}
示例5: read
import org.opendaylight.controller.md.sal.binding.api.DataBroker; //导入方法依赖的package包/类
/**
* Retrieves the object from the datastore.
* @param broker the data broker.
* @param datastoreType the data store type.
* @param path the wild card path.
* @param <T> type of DataObject
* @return the required object.
*/
public static <T extends DataObject> Optional<T> read(
DataBroker broker, LogicalDatastoreType datastoreType, InstanceIdentifier<T> path) {
try (ReadOnlyTransaction tx = broker.newReadOnlyTransaction()) {
return tx.read(datastoreType, path).checkedGet();
} catch (ReadFailedException e) {
LOG.error("Failed to read InstanceIdentifier {} from {}", path, datastoreType, e);
return Optional.absent();
}
}
示例6: read
import org.opendaylight.controller.md.sal.binding.api.DataBroker; //导入方法依赖的package包/类
@SuppressWarnings("checkstyle:IllegalCatch")
public static <T extends DataObject> Optional<T> read(DataBroker broker, LogicalDatastoreType datastoreType,
InstanceIdentifier<T> path) {
ReadOnlyTransaction tx = broker.newReadOnlyTransaction();
try {
return tx.read(datastoreType, path).get();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例7: read
import org.opendaylight.controller.md.sal.binding.api.DataBroker; //导入方法依赖的package包/类
private static <T extends DataObject> com.google.common.base.Optional<T> read(DataBroker broker,
LogicalDatastoreType datastoreType, InstanceIdentifier<T> path) {
try (ReadOnlyTransaction tx = broker.newReadOnlyTransaction()) {
return tx.read(datastoreType, path).get();
} catch (InterruptedException | ExecutionException e) {
throw new RuntimeException(e);
}
}
示例8: read
import org.opendaylight.controller.md.sal.binding.api.DataBroker; //导入方法依赖的package包/类
public static <T extends DataObject> Optional<T> read(DataBroker broker, LogicalDatastoreType datastoreType,
InstanceIdentifier<T> path) {
try (ReadOnlyTransaction tx = broker.newReadOnlyTransaction()) {
return tx.read(datastoreType, path).get();
} catch (InterruptedException | ExecutionException e) {
throw new RuntimeException(e);
}
}
示例9: read
import org.opendaylight.controller.md.sal.binding.api.DataBroker; //导入方法依赖的package包/类
public static <T extends DataObject> Optional<T> read(DataBroker dataBroker, LogicalDatastoreType datastoreType,
InstanceIdentifier<T> path) {
ReadOnlyTransaction tx = dataBroker.newReadOnlyTransaction();
Optional<T> result;
try {
result = tx.read(datastoreType, path).get();
} catch (InterruptedException | ExecutionException e) {
LOG.debug("read: Error while reading data from path {}", path);
throw new RuntimeException(e);
}
return result;
}
示例10: read
import org.opendaylight.controller.md.sal.binding.api.DataBroker; //导入方法依赖的package包/类
/**
* Read utility.
*
* @deprecated Consider using {@link #read2(LogicalDatastoreType, InstanceIdentifier)} with proper exception
* handling instead
*/
@Deprecated
@SuppressWarnings("checkstyle:IllegalCatch")
public static <T extends DataObject> Optional<T> read(@Nonnull DataBroker broker,
LogicalDatastoreType datastoreType, InstanceIdentifier<T> path) {
try (ReadOnlyTransaction tx = broker.newReadOnlyTransaction()) {
return tx.read(datastoreType, path).get();
} catch (Exception e) {
throw new RuntimeException(e);
}
}