List of usage examples for com.google.common.util.concurrent CheckedFuture checkedGet
V checkedGet() throws X;
From source file:org.opendaylight.messenger.impl.MessengerMdsalUtils.java
/** * 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 *//*from ww w . j a v a 2s. c o m*/ public static <D extends org.opendaylight.yangtools.yang.binding.DataObject> D read(final DataBroker dataBroker, final LogicalDatastoreType store, final InstanceIdentifier<D> path) { D result = null; final ReadOnlyTransaction transaction = dataBroker.newReadOnlyTransaction(); Optional<D> optionalDataObject; final 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 (final ReadFailedException e) { LOG.warn("Failed to read {} ", path, e); } transaction.close(); return result; }
From source file:ru.rulex.conclusion.execution.Callables.java
/** * /*from w w w . j av a 2s.co m*/ * Wrap values of type Future<T> inside of a Callable<T> so that we can * manipulate their return values while they are running * * Implicitly way to do similar {@code future.checkedGet() } * * @param ListenableFuture * <T> * @return Callable<T> */ public static <T> Callable<T> obtain(final CheckedFuture<T, PhraseExecutionException> future) { return new Callable<T>() { public T call() throws PhraseExecutionException { return future.checkedGet(); } }; }
From source file:org.opendaylight.faas.fabrics.vxlan.adapters.ovs.utils.MdsalUtils.java
/** * 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 *///www . j av a 2s .com 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; }
From source file:org.opendaylight.unimgr.utils.UniUtils.java
/** * Creates and submit an UNI Node by using the Data contained in the UniAugmentation. * @param dataBroker The instance of the DataBroker to create transactions * @param uni The UNI's data/*w w w.ja va 2 s .co m*/ * @return true if uni created */ public static boolean createUniNode(DataBroker dataBroker, UniAugmentation uni) { final NodeId uniNodeId = new NodeId(createUniNodeId(uni.getIpAddress())); boolean result = false; try { final InstanceIdentifier<Node> uniNodeIid = UnimgrMapper.getUniNodeIid(uniNodeId); final NodeKey uniNodeKey = new NodeKey(uniNodeId); final Node nodeData = new NodeBuilder().setNodeId(uniNodeId).setKey(uniNodeKey) .addAugmentation(UniAugmentation.class, uni).build(); final WriteTransaction transaction = dataBroker.newWriteOnlyTransaction(); transaction.put(LogicalDatastoreType.CONFIGURATION, uniNodeIid, nodeData); final CheckedFuture<Void, TransactionCommitFailedException> future = transaction.submit(); future.checkedGet(); result = true; LOG.info("Created and submitted a new Uni node {}", nodeData.getNodeId()); } catch (final Exception e) { LOG.error("Exception while creating Uni Node, Uni Node Id: {}", uniNodeId, e); } return result; }
From source file:ru.rulex.conclusion.execution.Callables.java
/** * //from w ww . ja v a2 s. co m * @param future * @param listener * @param executor * @return Callable<T> */ public static <T> Callable<T> obtain(final CheckedFuture<T, PhraseExecutionException> future, final Runnable listener, final Executor executor) { return new Callable<T>() { public T call() throws PhraseExecutionException { future.addListener(listener, executor); return future.checkedGet(); } }; }
From source file:com.blackducksoftware.bdio.io.BdioReader.java
/** * Returns an observable from a character source. *//*from w w w .j a va 2 s. co m*/ public static Observable<Node> open(final LinkedDataContext context, final CharSource source) { checkNotNull(context); checkNotNull(source); // Use CheckedFuture as a wrapper for either a BdioReader or an IOException return Observable.create(new SyncOnSubscribe<CheckedFuture<BdioReader, IOException>, Node>() { @Override protected CheckedFuture<BdioReader, IOException> generateState() { try { return Futures.immediateCheckedFuture(new BdioReader(context, source.openBufferedStream())); } catch (IOException e) { return Futures.immediateFailedCheckedFuture(e); } } @Override protected CheckedFuture<BdioReader, IOException> next(CheckedFuture<BdioReader, IOException> s, Observer<? super Node> t) { // Iterate over the nodes in the file as we see them try { Node node = s.checkedGet().read(); if (node != null) { t.onNext(node); } else { t.onCompleted(); } } catch (IOException e) { t.onError(e); } return s; } @Override protected void onUnsubscribe(CheckedFuture<BdioReader, IOException> s) { try { s.checkedGet().close(); } catch (IOException e) { return; } } }); }
From source file:org.opendaylight.vpnservice.neutronvpn.NeutronvpnUtils.java
protected static List<Uuid> getNeutronRouterSubnetIds(DataBroker broker, Uuid routerId) { logger.info("getNeutronRouterSubnetIds for {}", routerId.getValue()); List<Uuid> subnetIdList = new ArrayList<Uuid>(); InstanceIdentifier<Ports> path = InstanceIdentifier.create(Neutron.class).child(Ports.class); final Set<Uuid> subnetUuids = new HashSet<>(); try (ReadOnlyTransaction tx = broker.newReadOnlyTransaction()) { final CheckedFuture<Optional<Ports>, ReadFailedException> future = tx .read(LogicalDatastoreType.CONFIGURATION, path); Optional<Ports> optional = future.checkedGet(); if (optional.isPresent()) { for (final Port port : optional.get().getPort()) { if (port.getDeviceOwner().equals("network:router_interface") && port.getDeviceId().equals(routerId.getValue())) { for (FixedIps fixedIps : port.getFixedIps()) { subnetUuids.add(fixedIps.getSubnetId()); }/*from ww w . j a v a 2 s .co m*/ } } } } catch (final ReadFailedException e) { logger.error("Failed to read {}", path, e); } subnetIdList.addAll(subnetUuids); logger.info("returning from getNeutronRouterSubnetIds for {}", routerId.getValue()); return subnetIdList; }
From source file:org.opendaylight.netvirt.federation.plugin.FederationPluginCleaner.java
private static boolean deleteVpnInterface(DataBroker db, LogicalDatastoreType type, int remainingRetries, IEntityDeleteDecision<VpnInterface> entityDeleteDecision) { InstanceIdentifier<VpnInterfaces> path = InstanceIdentifier.create(VpnInterfaces.class); ReadTransaction readTx = db.newReadOnlyTransaction(); CheckedFuture<Optional<VpnInterfaces>, ReadFailedException> future = readTx.read(type, path); Optional<VpnInterfaces> optional = null; try {//from ww w. j a va 2 s .c o m optional = future.get(); } catch (InterruptedException | ExecutionException e) { LOG.error("deleteVpnInterface failed to get data"); return false; } if (optional.isPresent()) { WriteTransaction deleteTx = db.newWriteOnlyTransaction(); VpnInterfaces vpnInterfaces = optional.get(); for (VpnInterface iface : vpnInterfaces.getVpnInterface()) { if (entityDeleteDecision.shouldDelete(iface)) { LOG.debug("Delete shadow vpn Interface: DataStoreType {}, interface {}", type, iface); FederationPluginCounters.removed_shadow_vpn_interface.inc(); InstanceIdentifier<VpnInterface> iid = InstanceIdentifier.create(VpnInterfaces.class) .child(VpnInterface.class, new VpnInterfaceKey(iface.getKey())); deleteTx.delete(type, iid); } } CheckedFuture<Void, TransactionCommitFailedException> future1 = deleteTx.submit(); try { future1.checkedGet(); } catch (TransactionCommitFailedException e) { if (remainingRetries > 0) { LOG.warn("deleteVpnInterface - Failed to delete! {} {}" + e.getMessage(), e); deleteVpnInterface(db, type, --remainingRetries, entityDeleteDecision); } else { LOG.error("deleteVpnInterface - Failed to delete - no more retries! {} {}" + e.getMessage(), e); } } return true; } else { return false; } }
From source file:org.opendaylight.netvirt.federation.plugin.FederationPluginCleaner.java
private static boolean deleteInterfacesShadows(DataBroker db, LogicalDatastoreType type, int remainingRetries, IEntityDeleteDecision<Interface> entityDeleteDecision) { InstanceIdentifier<Interfaces> path = InstanceIdentifier.create(Interfaces.class); ReadTransaction readTx = db.newReadOnlyTransaction(); CheckedFuture<Optional<Interfaces>, ReadFailedException> future = readTx.read(type, path); Optional<Interfaces> optional = null; try {/*from w ww . j a v a2 s .c o m*/ optional = future.get(); } catch (InterruptedException | ExecutionException e) { LOG.error("deleteInterfacesShadows failed to get data"); return false; } if (optional.isPresent()) { WriteTransaction deleteTx = db.newWriteOnlyTransaction(); Interfaces interfaces = optional.get(); for (Interface iface : interfaces.getInterface()) { if (entityDeleteDecision.shouldDelete(iface)) { LOG.debug("Delete shadow interfaces: DataStoreType {}, interface {}", type, iface); FederationPluginCounters.removed_shadow_ietf_interface.inc(); InstanceIdentifier<Interface> iid = InstanceIdentifier.create(Interfaces.class) .child(Interface.class, new InterfaceKey(iface.getKey())); deleteTx.delete(type, iid); } } CheckedFuture<Void, TransactionCommitFailedException> future1 = deleteTx.submit(); try { future1.checkedGet(); } catch (TransactionCommitFailedException e) { if (remainingRetries > 0) { LOG.warn("deleteInterfacesShadows - Failed to delete! {} {}" + e.getMessage(), e); deleteInterfacesShadows(db, type, --remainingRetries, entityDeleteDecision); } else { LOG.error( "deleteInterfacesShadows - Failed to delete - no more retries! {} {}" + e.getMessage(), e); } } return true; } else { return false; } }
From source file:org.opendaylight.netvirt.federation.plugin.FederationPluginCleaner.java
private static boolean deleteL2GatewayShadows(DataBroker db, LogicalDatastoreType type, int remainingRetries, IEntityDeleteDecision<L2gateway> entityDeleteDecision) { InstanceIdentifier<L2gateways> path = InstanceIdentifier.create(Neutron.class).child(L2gateways.class); ReadTransaction readTx = db.newReadOnlyTransaction(); CheckedFuture<Optional<L2gateways>, ReadFailedException> future = readTx.read(type, path); Optional<L2gateways> optional = null; try {// ww w . j a va 2 s . c o m optional = future.get(); } catch (InterruptedException | ExecutionException e) { LOG.error("deleteL2GatewayShadows failed to get data"); return false; } if (optional.isPresent()) { WriteTransaction deleteTx = db.newWriteOnlyTransaction(); L2gateways l2gws = optional.get(); for (L2gateway iface : l2gws.getL2gateway()) { if (entityDeleteDecision.shouldDelete(iface)) { LOG.debug("Delete shadow l2 gateway: DataStoreType {}, interface {}", type, iface); FederationPluginCounters.removed_shadow_l2_gateway.inc(); InstanceIdentifier<L2gateway> iid = InstanceIdentifier.create(Neutron.class) .child(L2gateways.class).child(L2gateway.class, new L2gatewayKey(iface.getKey())); deleteTx.delete(type, iid); } } CheckedFuture<Void, TransactionCommitFailedException> future1 = deleteTx.submit(); try { future1.checkedGet(); } catch (TransactionCommitFailedException e) { if (remainingRetries > 0) { LOG.warn("deleteL2GatewayShadows - Failed to delete! {} {}" + e.getMessage(), e); deleteL2GatewayShadows(db, type, --remainingRetries, entityDeleteDecision); } else { LOG.error("deleteL2GatewayShadows - Failed to delete - no more retries! {} {}" + e.getMessage(), e); } } return true; } else { return false; } }