List of usage examples for com.google.common.util.concurrent JdkFutureAdapters listenInPoolThread
public static <V> ListenableFuture<V> listenInPoolThread(Future<V> future)
From source file:org.opendaylight.openflowplugin.openflow.md.core.sal.OFRpcTaskFactory.java
public static OFRpcTask<SetConfigInput, RpcResult<SetConfigOutput>> createSetNodeConfigTask( final OFRpcTaskContext taskContext, final SetConfigInput input, final SwitchConnectionDistinguisher cookie) { class OFRpcTaskImpl extends OFRpcTask<SetConfigInput, RpcResult<SetConfigOutput>> { public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie, SetConfigInput input) {/*from w w w . ja va 2 s. c o m*/ super(taskContext, cookie, input); } @Override public ListenableFuture<RpcResult<SetConfigOutput>> call() throws Exception { final SettableFuture<RpcResult<SetConfigOutput>> result = SettableFuture.create(); final Long xid = taskContext.getSession().getNextXid(); SetConfigInputBuilder builder = new SetConfigInputBuilder(); SwitchConfigFlag flag = SwitchConfigFlag.valueOf(input.getFlag()); builder.setXid(xid); builder.setFlags(flag); builder.setMissSendLen(input.getMissSearchLength()); builder.setVersion(getVersion()); ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(taskContext .getSession().getPrimaryConductor().getConnectionAdapter().setConfig(builder.build())); Futures.addCallback(resultLib, new ResultCallback<SetConfigOutput>(result) { @Override public SetConfigOutput createResult() { SetConfigOutputBuilder setConfigOutputBuilder = new SetConfigOutputBuilder(); setConfigOutputBuilder.setTransactionId(new TransactionId(BigInteger.valueOf(xid))); return setConfigOutputBuilder.build(); } }); return result; } } return new OFRpcTaskImpl(taskContext, cookie, input); }
From source file:org.opendaylight.netvirt.natservice.internal.ExternalRoutersListener.java
private void delFibTsAndReverseTraffic(final BigInteger dpnId, long routerId, String extIp, final String vpnName) { LOG.debug("NAT Service : Removing fib entry for externalIp {} in routerId {}", extIp, routerId); String routerName = NatUtil.getRouterName(dataBroker, routerId); if (routerName == null) { LOG.error("NAT Service : Could not retrieve Router Name from Router ID {} ", routerId); return;//from w ww .ja v a2 s. com } ProviderTypes extNwProvType = NatEvpnUtil.getExtNwProvTypeFromRouterName(dataBroker, routerName); if (extNwProvType == null) { return; } /* Remove the flow table19->44 and table36->44 entries for SNAT reverse traffic flow if the * external network provided type is VxLAN */ if (extNwProvType == ProviderTypes.VXLAN) { evpnSnatFlowProgrammer.evpnDelFibTsAndReverseTraffic(dpnId, routerId, extIp, vpnName); return; } //Get IPMaps from the DB for the router ID List<IpMap> dbIpMaps = NaptManager.getIpMapList(dataBroker, routerId); if (dbIpMaps == null || dbIpMaps.isEmpty()) { LOG.error("NAT Service : IPMaps not found for router {}", routerId); return; } long tempLabel = NatConstants.INVALID_ID; for (IpMap dbIpMap : dbIpMaps) { String dbExternalIp = dbIpMap.getExternalIp(); LOG.debug("Retrieved dbExternalIp {} for router id {}", dbExternalIp, routerId); //Select the IPMap, whose external IP is the IP for which FIB is installed if (extIp.equals(dbExternalIp)) { tempLabel = dbIpMap.getLabel(); LOG.debug("Retrieved label {} for dbExternalIp {} with router id {}", tempLabel, dbExternalIp, routerId); break; } } if (tempLabel < 0 || tempLabel == NatConstants.INVALID_ID) { LOG.error("NAT Service : Label not found for externalIp {} with router id {}", extIp, routerId); return; } final long label = tempLabel; final String externalIp = extIp; RemoveFibEntryInput input = new RemoveFibEntryInputBuilder().setVpnName(vpnName).setSourceDpid(dpnId) .setIpAddress(externalIp).setServiceId(label).build(); Future<RpcResult<Void>> future = fibService.removeFibEntry(input); ListenableFuture<RpcResult<Void>> labelFuture = Futures.transform( JdkFutureAdapters.listenInPoolThread(future), (AsyncFunction<RpcResult<Void>, RpcResult<Void>>) result -> { //Release label if (result.isSuccessful()) { removeTunnelTableEntry(dpnId, label); removeLFibTableEntry(dpnId, label); RemoveVpnLabelInput labelInput = new RemoveVpnLabelInputBuilder().setVpnName(vpnName) .setIpPrefix(externalIp).build(); Future<RpcResult<Void>> labelFuture1 = vpnService.removeVpnLabel(labelInput); return JdkFutureAdapters.listenInPoolThread(labelFuture1); } else { String errMsg = String.format( "RPC call to remove custom FIB entries on dpn %s for " + "prefix %s Failed - %s", dpnId, externalIp, result.getErrors()); LOG.error(errMsg); return Futures.immediateFailedFuture(new RuntimeException(errMsg)); } }); Futures.addCallback(labelFuture, new FutureCallback<RpcResult<Void>>() { @Override public void onFailure(Throwable error) { LOG.error("NAT Service : Error in removing the label or custom fib entries", error); } @Override public void onSuccess(RpcResult<Void> result) { if (result.isSuccessful()) { LOG.debug("NAT Service : Successfully removed the label for the prefix {} from VPN {}", externalIp, vpnName); } else { LOG.error("NAT Service : Error in removing the label for prefix {} from VPN {}, {}", externalIp, vpnName, result.getErrors()); } } }); }