本文整理汇总了Java中org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction类的典型用法代码示例。如果您正苦于以下问题:Java ReadOnlyTransaction类的具体用法?Java ReadOnlyTransaction怎么用?Java ReadOnlyTransaction使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ReadOnlyTransaction类属于org.opendaylight.controller.md.sal.binding.api包,在下文中一共展示了ReadOnlyTransaction类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: readFromGreetingRegistry
import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction; //导入依赖的package包/类
private String readFromGreetingRegistry(HelloWorldInput input) {
String result = "Hello " + input.getName();
ReadOnlyTransaction transaction = db.newReadOnlyTransaction();
InstanceIdentifier<GreetingRegistryEntry> iid = toInstanceIdentifier(input);
CheckedFuture<Optional<GreetingRegistryEntry>, ReadFailedException> future =
transaction.read(LogicalDatastoreType.CONFIGURATION, iid);
Optional<GreetingRegistryEntry> optional = Optional.absent();
try {
optional = future.checkedGet();
} catch (ReadFailedException e) {
LOG.warn("Reading greeting failed:",e);
}
if(optional.isPresent()) {
result = optional.get().getGreeting();
}
return result;
}
示例2: load
import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction; //导入依赖的package包/类
/**
* Loads the Connection Information from the data store
*/
private void load() {
ReadOnlyTransaction rtrans = dataBroker.newReadOnlyTransaction();
try {
Optional<ConnectionInfo> connInfo = rtrans.read(LogicalDatastoreType.OPERATIONAL,
InstanceIdentifier.create(ConnectionInfo.class)).get();
if (connInfo.isPresent()) {
for (Connections conn : (connInfo.get().getConnections() == null) ?
Collections.<Connections>emptyList() : connInfo.get().getConnections()) {
connections.put(conn.getAssignedInfo().getClientId().toString(), conn);
}
}
} catch (Exception exc) {
ErrorLog.logError("FpcServiceImpl - Error in loading Connection information from the datastore\n" + exc.getMessage(), exc.getStackTrace());
}
}
示例3: setUp
import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
NotificationPattern notificationPattern = new NotificationPattern("value1");
eventSourceServiceMock = mock(EventSourceService.class);
eventSourceTopologyMock = mock(EventSourceTopology.class);
dataBrokerMock = mock(DataBroker.class);
doReturn(eventSourceServiceMock).when(eventSourceTopologyMock).getEventSourceService();
doReturn(dataBrokerMock).when(eventSourceTopologyMock).getDataBroker();
WriteTransaction writeTransactionMock = mock(WriteTransaction.class);
doReturn(writeTransactionMock).when(dataBrokerMock).newWriteOnlyTransaction();
doNothing().when(writeTransactionMock).put(any(LogicalDatastoreType.class), any(InstanceIdentifier.class), any(DataObject.class),eq(true));
CheckedFuture checkedFutureWriteMock = mock(CheckedFuture.class);
doReturn(checkedFutureWriteMock).when(writeTransactionMock).submit();
ReadOnlyTransaction readOnlyTransactionMock = mock(ReadOnlyTransaction.class);
doReturn(readOnlyTransactionMock).when(dataBrokerMock).newReadOnlyTransaction();
CheckedFuture checkedFutureReadMock = mock(CheckedFuture.class);
doReturn(checkedFutureReadMock).when(readOnlyTransactionMock).read(LogicalDatastoreType.OPERATIONAL, EventSourceTopology.EVENT_SOURCE_TOPOLOGY_PATH);
eventSourceTopic = EventSourceTopic.create(notificationPattern, "nodeIdPattern1", eventSourceTopologyMock);
}
示例4: testToasterInitOnStartUp
import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction; //导入依赖的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());
}
示例5: getSubnetMapBuilder
import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction; //导入依赖的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;
}
示例6: handleInterfaceRemoval
import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction; //导入依赖的package包/类
@Override
public void handleInterfaceRemoval(String interfaceId) {
CheckedFuture<Optional<IngressElementCountersRequestConfig>, ReadFailedException> iecrc;
CheckedFuture<Optional<EgressElementCountersRequestConfig>, ReadFailedException> eecrc;
try (ReadOnlyTransaction tx = db.newReadOnlyTransaction()) {
iecrc = tx.read(LogicalDatastoreType.CONFIGURATION, CountersServiceUtils.IECRC_IDENTIFIER);
eecrc = tx.read(LogicalDatastoreType.CONFIGURATION, CountersServiceUtils.EECRC_IDENTIFIER);
}
try {
Optional<IngressElementCountersRequestConfig> iecrcOpt = iecrc.get();
Optional<EgressElementCountersRequestConfig> eecrcOpt = eecrc.get();
if (!iecrcOpt.isPresent() || !eecrcOpt.isPresent()) {
LOG.warn("Couldn't read element counters config data from DB");
StatisticsPluginImplCounters.failed_reading_counter_data_from_config.inc();
return;
}
removeAllElementCounterRequestsOnPort(interfaceId, iecrcOpt.get().getCounterRequests());
removeAllElementCounterRequestsOnPort(interfaceId, eecrcOpt.get().getCounterRequests());
} catch (InterruptedException | ExecutionException e) {
LOG.warn("failed to get counter request data from DB");
StatisticsPluginImplCounters.failed_getting_counter_results_port_removal.inc();
return;
}
}
示例7: checkPoolExists
import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction; //导入依赖的package包/类
private boolean checkPoolExists() {
ReadOnlyTransaction roTransaction = db.newReadOnlyTransaction();
InstanceIdentifier<IdPool> path = InstanceIdentifier.create(IdPools.class).child(IdPool.class,
new IdPoolKey(CountersServiceUtils.COUNTERS_PULL_NAME));
CheckedFuture<Optional<IdPool>, ReadFailedException> pool =
roTransaction.read(LogicalDatastoreType.CONFIGURATION, path);
try {
Optional<IdPool> poolOpt = pool.get();
if (poolOpt.isPresent()) {
return true;
}
} catch (InterruptedException | ExecutionException e) {
return false;
}
return false;
}
示例8: readNodes
import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction; //导入依赖的package包/类
public void readNodes() throws Exception {
ReadOnlyTransaction tx = this.dataBroker.newReadOnlyTransaction();
d1GlobalOpNode = TestUtil.readNode(OPERATIONAL, d1NodePath, tx);
d2GlobalOpNode = TestUtil.readNode(OPERATIONAL, d2NodePath, tx);
haGlobalOpNode = TestUtil.readNode(OPERATIONAL, haNodePath, tx);
d1PsOpNode = TestUtil.readNode(OPERATIONAL, d1PsNodePath, tx);
d2PsOpNode = TestUtil.readNode(OPERATIONAL, d2PsNodePath, tx);
haPsOpNode = TestUtil.readNode(OPERATIONAL, haPsNodePath, tx);
haGlobalConfigNode = TestUtil.readNode(CONFIGURATION, haNodePath, tx);
d1GlobalConfigNode = TestUtil.readNode(CONFIGURATION, d1NodePath, tx);
d2GlobalConfigNode = TestUtil.readNode(CONFIGURATION, d2NodePath, tx);
haPsConfigNode = TestUtil.readNode(CONFIGURATION, haPsNodePath, tx);
d1PsConfigNode = TestUtil.readNode(CONFIGURATION, d1PsNodePath, tx);
d2PsConfigNode = TestUtil.readNode(CONFIGURATION, d2PsNodePath, tx);
tx.close();
}
示例9: readFromApplicationRegistry
import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction; //导入依赖的package包/类
public AddApplicationInput readFromApplicationRegistry(int appId) {
LOG.info("Reading from application registry for appID {}.", appId);
AddApplicationInput application = null;
ReadOnlyTransaction transaction = db.newReadOnlyTransaction();
InstanceIdentifier<ApplicationRegistryEntry> iid = toInstanceIdentifier(appId);
CheckedFuture<Optional<ApplicationRegistryEntry>, ReadFailedException> future =
transaction.read(LogicalDatastoreType.OPERATIONAL, iid);
Optional<ApplicationRegistryEntry> optional = Optional.absent();
try {
optional = future.checkedGet();
} catch (ReadFailedException e) {
LOG.error("Reading application failed:",e);
}
if(optional.isPresent()) {
application = new AddApplicationInputBuilder()
.setAppId(optional.get().getAppId())
.setJitter(optional.get().getJitter())
.setPacketLoss(optional.get().getPacketLoss())
.setPacketDelay(optional.get().getPacketDelay())
.setBandwidth(optional.get().getBandwidth())
.build();
}
return application;
}
示例10: onDataTreeChanged
import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction; //导入依赖的package包/类
@Override
public synchronized void onDataTreeChanged(Collection<DataTreeModification<T>> changes) {
// TODO Auto-generated method stub
if (this.closed) {
LOG.trace("Transaction chain was already closed, skipping update.");
return;
}
final ReadOnlyTransaction trans = this.chain.newReadOnlyTransaction();
LOG.debug("Received data change {} event with transaction {}", changes, trans.getIdentifier());
for (final DataTreeModification<T> change : changes) {
try {
routeChanged(change, trans);
} catch (final RuntimeException e) {
LOG.warn("Data change {} was not completely propagated to listener {}, aborting", change, this, e);
// trans.cancel();
return;
}
}
}
示例11: packetReceived
import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction; //导入依赖的package包/类
public void packetReceived(ConnectorAddress addrs, InstanceIdentifier<?> ii) {
InstanceIdentifier<NodeConnector> iinc = ii.firstIdentifierOf(NodeConnector.class);
InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node> iin//
= ii.firstIdentifierOf(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node.class);
ListenableFuture<Optional<NodeConnector>> futureNodeConnector;
ListenableFuture<Optional<org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node>> futureNode;
try (ReadOnlyTransaction readTx = dataService.newReadOnlyTransaction()) {
futureNodeConnector = readTx.read(LogicalDatastoreType.OPERATIONAL, iinc);
futureNode = readTx.read(LogicalDatastoreType.OPERATIONAL, iin);
readTx.close();
}
Optional<NodeConnector> opNodeConnector = null;
Optional<org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node> opNode = null;
try {
opNodeConnector = futureNodeConnector.get();
opNode = futureNode.get();
} catch (ExecutionException | InterruptedException ex) {
LOG.warn(ex.getLocalizedMessage());
}
if (opNode != null && opNode.isPresent() && opNodeConnector != null && opNodeConnector.isPresent()) {
processHost(opNode.get(), opNodeConnector.get(), addrs);
}
}
示例12: getGroup
import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction; //导入依赖的package包/类
private Group getGroup(GroupBuilder groupBuilder, NodeBuilder nodeBuilder) {
InstanceIdentifier<Group> path1 = InstanceIdentifier.builder(Nodes.class)
.child(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node.class,
nodeBuilder.getKey())
.augmentation(FlowCapableNode.class).child(Group.class, new GroupKey(groupBuilder.getGroupId()))
.build();
DataBroker databroker = getDataBroker();
ReadOnlyTransaction readTx = databroker.newReadOnlyTransaction();
try {
Optional<Group> data = readTx.read(LogicalDatastoreType.CONFIGURATION, path1).get();
if (data.isPresent()) {
return data.get();
}
} catch (InterruptedException | ExecutionException e) {
LOG.error(e.getMessage(), e);
}
LOG.debug("Cannot find data for Group " + groupBuilder.getGroupName());
return null;
}
示例13: read
import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction; //导入依赖的package包/类
/**
* Executes read as a blocking transaction.
*
* @param store {@link LogicalDatastoreType} to read
* @param path {@link InstanceIdentifier} for path to read
* @param <D> the data object type
* @return the result as the data object requested
*/
public static <D extends org.opendaylight.yangtools.yang.binding.DataObject> D read(
final LogicalDatastoreType store, final InstanceIdentifier<D> path, DataBroker databroker) {
D result = null;
final ReadOnlyTransaction transaction = databroker.newReadOnlyTransaction();
Optional<D> optionalDataObject;
CheckedFuture<Optional<D>, ReadFailedException> future = transaction.read(store, path);
try {
optionalDataObject = future.checkedGet();
if (optionalDataObject.isPresent()) {
result = optionalDataObject.get();
} else {
LOG.debug("{}: Failed to read {}",
Thread.currentThread().getStackTrace()[1], path);
}
} catch (ReadFailedException e) {
LOG.warn("Failed to read {} ", path, e);
}
transaction.close();
return result;
}
示例14: read
import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction; //导入依赖的package包/类
/**
* Executes read as a blocking transaction.
*
* @param store
* {@link LogicalDatastoreType} to read
* @param path
* {@link InstanceIdentifier} for path to read
* @param <D>
* the data object type
* @return the result as the data object requested
*/
public <D extends org.opendaylight.yangtools.yang.binding.DataObject> D read(final LogicalDatastoreType store,
final InstanceIdentifier<D> path) {
D result = null;
final ReadOnlyTransaction transaction = databroker.newReadOnlyTransaction();
Optional<D> optionalDataObject;
CheckedFuture<Optional<D>, ReadFailedException> future = transaction.read(store, path);
try {
optionalDataObject = future.checkedGet();
if (optionalDataObject.isPresent()) {
result = optionalDataObject.get();
} else {
LOG.debug("{}: Failed to read {}", Thread.currentThread().getStackTrace()[1], path);
}
} catch (ReadFailedException e) {
LOG.warn("Failed to read {} ", path, e);
}
transaction.close();
return result;
}
示例15: setUp
import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction; //导入依赖的package包/类
/**
* It creates the required objects for every unit test cases.
*
* @throws Exception
*/
@Before
public void setUp() throws Exception {
instanceIdentifier = mock(InstanceIdentifier.class);
checkedFuture = mock(CheckedFuture.class);
optional = mock(Optional.class);
writeTransaction = mock(WriteTransaction.class);
readOnlyTransaction = mock(ReadOnlyTransaction.class);
dataBroker = mock(DataBroker.class);
when(checkedFuture.checkedGet()).thenReturn(optional);
when(writeTransaction.submit()).thenReturn(checkedFuture);
when(readOnlyTransaction.read(isA(LogicalDatastoreType.class), isA(InstanceIdentifier.class)))
.thenReturn(checkedFuture);
when(dataBroker.newWriteOnlyTransaction()).thenReturn(writeTransaction);
when(dataBroker.newReadOnlyTransaction()).thenReturn(readOnlyTransaction);
mdsalUtils = new MdsalUtils(dataBroker);
}