Example usage for com.google.common.util.concurrent JdkFutureAdapters listenInPoolThread

List of usage examples for com.google.common.util.concurrent JdkFutureAdapters listenInPoolThread

Introduction

In this page you can find the example usage for com.google.common.util.concurrent JdkFutureAdapters listenInPoolThread.

Prototype

public static <V> ListenableFuture<V> listenInPoolThread(Future<V> future) 

Source Link

Document

Assigns a thread to the given Future to provide ListenableFuture functionality.

Usage

From source file:org.opendaylight.openflowplugin.applications.frsync.impl.strategy.SyncPlanPushStrategyIncrementalImpl.java

private ListenableFuture<RpcResult<Void>> flushAddGroupPortionAndBarrier(
        final InstanceIdentifier<FlowCapableNode> nodeIdent, final ItemSyncBox<Group> groupsPortion) {
    final List<ListenableFuture<RpcResult<AddGroupOutput>>> allResults = new ArrayList<>();
    final List<ListenableFuture<RpcResult<UpdateGroupOutput>>> allUpdateResults = new ArrayList<>();

    for (Group group : groupsPortion.getItemsToPush()) {
        final KeyedInstanceIdentifier<Group, GroupKey> groupIdent = nodeIdent.child(Group.class,
                group.getKey());/*  w  w w . j ava2  s .c o  m*/
        allResults.add(JdkFutureAdapters.listenInPoolThread(groupForwarder.add(groupIdent, group, nodeIdent)));

    }

    for (ItemSyncBox.ItemUpdateTuple<Group> groupTuple : groupsPortion.getItemsToUpdate()) {
        final Group existingGroup = groupTuple.getOriginal();
        final Group group = groupTuple.getUpdated();

        final KeyedInstanceIdentifier<Group, GroupKey> groupIdent = nodeIdent.child(Group.class,
                group.getKey());
        allUpdateResults.add(JdkFutureAdapters
                .listenInPoolThread(groupForwarder.update(groupIdent, existingGroup, group, nodeIdent)));
    }

    final ListenableFuture<RpcResult<Void>> singleVoidAddResult = Futures.transform(
            Futures.allAsList(allResults), ReconcileUtil.<AddGroupOutput>createRpcResultCondenser("group add"));

    final ListenableFuture<RpcResult<Void>> singleVoidUpdateResult = Futures.transform(
            Futures.allAsList(allUpdateResults),
            ReconcileUtil.<UpdateGroupOutput>createRpcResultCondenser("group update"));

    final ListenableFuture<RpcResult<Void>> summaryResult = Futures.transform(
            Futures.allAsList(singleVoidAddResult, singleVoidUpdateResult),
            ReconcileUtil.<Void>createRpcResultCondenser("group add/update"));

    return Futures.transform(summaryResult,
            ReconcileUtil.chainBarrierFlush(PathUtil.digNodePath(nodeIdent), transactionService));
}

From source file:org.opendaylight.openflowplugin.openflow.md.core.sal.OFRpcTaskFactory.java

/**
 * Recursive helper method for {@link OFRpcTaskFactory#createAddFlowTask(OFRpcTaskContext, AddFlowInput, SwitchConnectionDistinguisher)}
 * and {@link OFRpcTaskFactory#createUpdateFlowTask(OFRpcTaskContext, UpdateFlowInput, SwitchConnectionDistinguisher, ReadWriteTransaction)} to chain results
 * of multiple flowmods.//from  w w  w.  j  av a2  s.  com
 * The next flowmod gets executed if the earlier one is successful.
 * All the flowmods should have the same xid, in-order to cross-reference
 * the notification
 * @param taskContext task context
 * @param ofFlowModInputs list of flow mod as input
 * @param index  starting index
 * @param cookie switch connection distinguisher
 * @return listenable future with update flow output
 *
 */
protected static ListenableFuture<RpcResult<UpdateFlowOutput>> chainFlowMods(
        final List<FlowModInputBuilder> ofFlowModInputs, final int index, final OFRpcTaskContext taskContext,
        final SwitchConnectionDistinguisher cookie) {

    Future<RpcResult<UpdateFlowOutput>> resultFromOFLib = createResultForFlowMod(taskContext,
            ofFlowModInputs.get(index), cookie);

    ListenableFuture<RpcResult<UpdateFlowOutput>> result = JdkFutureAdapters
            .listenInPoolThread(resultFromOFLib);

    if (ofFlowModInputs.size() > index + 1) {
        // there are more flowmods to chain
        return Futures.transform(result,
                new AsyncFunction<RpcResult<UpdateFlowOutput>, RpcResult<UpdateFlowOutput>>() {
                    @Override
                    public ListenableFuture<RpcResult<UpdateFlowOutput>> apply(
                            RpcResult<UpdateFlowOutput> input) throws Exception {
                        if (input.isSuccessful()) {
                            return chainFlowMods(ofFlowModInputs, index + 1, taskContext, cookie);
                        } else {
                            LOG.warn("Flowmod failed. Any chained flowmods are ignored. xid:{}",
                                    ofFlowModInputs.get(index).getXid());
                            return Futures.immediateFuture(input);
                        }
                    }
                });
    } else {
        return result;
    }
}

From source file:org.opendaylight.openflowplugin.applications.frsync.impl.strategy.SyncPlanPushStrategyIncrementalImpl.java

ListenableFuture<RpcResult<Void>> addMissingMeters(final NodeId nodeId,
        final InstanceIdentifier<FlowCapableNode> nodeIdent, final ItemSyncBox<Meter> syncBox,
        final SyncCrudCounters counters) {
    if (syncBox.isEmpty()) {
        LOG.trace("no meters configured for node: {} -> SKIPPING", nodeId.getValue());
        return RpcResultBuilder.<Void>success().buildFuture();
    }//from   w  w w .jav  a2  s .  c  o  m

    final CrudCounts meterCrudCounts = counters.getMeterCrudCounts();

    final List<ListenableFuture<RpcResult<AddMeterOutput>>> allResults = new ArrayList<>();
    final List<ListenableFuture<RpcResult<UpdateMeterOutput>>> allUpdateResults = new ArrayList<>();
    for (Meter meter : syncBox.getItemsToPush()) {
        final KeyedInstanceIdentifier<Meter, MeterKey> meterIdent = nodeIdent.child(Meter.class,
                meter.getKey());
        LOG.debug("adding meter {} - absent on device {}", meter.getMeterId(), nodeId);
        allResults.add(JdkFutureAdapters.listenInPoolThread(meterForwarder.add(meterIdent, meter, nodeIdent)));
        meterCrudCounts.incAdded();
    }

    for (ItemSyncBox.ItemUpdateTuple<Meter> meterTuple : syncBox.getItemsToUpdate()) {
        final Meter existingMeter = meterTuple.getOriginal();
        final Meter updated = meterTuple.getUpdated();
        final KeyedInstanceIdentifier<Meter, MeterKey> meterIdent = nodeIdent.child(Meter.class,
                updated.getKey());
        LOG.trace("meter {} - needs update on device {}", updated.getMeterId(), nodeId);
        allUpdateResults.add(JdkFutureAdapters
                .listenInPoolThread(meterForwarder.update(meterIdent, existingMeter, updated, nodeIdent)));
        meterCrudCounts.incUpdated();
    }

    final ListenableFuture<RpcResult<Void>> singleVoidAddResult = Futures.transform(
            Futures.allAsList(allResults), ReconcileUtil.<AddMeterOutput>createRpcResultCondenser("meter add"));

    final ListenableFuture<RpcResult<Void>> singleVoidUpdateResult = Futures.transform(
            Futures.allAsList(allUpdateResults),
            ReconcileUtil.<UpdateMeterOutput>createRpcResultCondenser("meter update"));

    return Futures.transform(Futures.allAsList(singleVoidUpdateResult, singleVoidAddResult),
            ReconcileUtil.<Void>createRpcResultCondenser("meter add/update"));
}

From source file:org.opendaylight.bgpcep.pcep.tunnel.provider.NodeChangedListener.java

@Override
public void onDataTreeChanged(final Collection<DataTreeModification<Node>> changes) {
    final ReadWriteTransaction trans = this.dataProvider.newReadWriteTransaction();

    final Set<InstanceIdentifier<ReportedLsp>> lsps = new HashSet<>();
    final Set<InstanceIdentifier<Node>> nodes = new HashSet<>();

    final Map<InstanceIdentifier<?>, DataObject> original = new HashMap<>();
    final Map<InstanceIdentifier<?>, DataObject> updated = new HashMap<>();
    final Map<InstanceIdentifier<?>, DataObject> created = new HashMap<>();

    for (final DataTreeModification<?> change : changes) {
        final InstanceIdentifier<?> iid = change.getRootPath().getRootIdentifier();
        final DataObjectModification<?> rootNode = change.getRootNode();
        handleChangedNode(rootNode, iid, lsps, nodes, original, updated, created);
    }//from   w  w w  . j av  a2  s .  c  om

    // Now walk all nodes, check for removals/additions and cascade them to LSPs
    for (final InstanceIdentifier<Node> iid : nodes) {
        enumerateLsps(iid, (Node) original.get(iid), lsps);
        enumerateLsps(iid, (Node) updated.get(iid), lsps);
        enumerateLsps(iid, (Node) created.get(iid), lsps);
    }

    // We now have list of all affected LSPs. Walk them create/remove them
    updateTransaction(trans, lsps, original, updated, created);

    Futures.addCallback(JdkFutureAdapters.listenInPoolThread(trans.submit()), new FutureCallback<Void>() {
        @Override
        public void onSuccess(final Void result) {
            LOG.trace("Topology change committed successfully");
        }

        @Override
        public void onFailure(final Throwable t) {
            LOG.error("Failed to propagate a topology change, target topology became inconsistent", t);
        }
    });
}

From source file:org.opendaylight.openflowplugin.openflow.md.core.sal.OFRpcTaskFactory.java

/**
 * @param taskContext taks context//w ww  .  j av a2 s  . c o  m
 * @param input group update input
 * @param cookie switch connection distinguisher cookie value
 * @return update group task
 */
public static OFRpcTask<AddGroupInput, RpcResult<UpdateGroupOutput>> createAddGroupTask(
        final OFRpcTaskContext taskContext, AddGroupInput input, final SwitchConnectionDistinguisher cookie) {
    class OFRpcTaskImpl extends OFRpcTask<AddGroupInput, RpcResult<UpdateGroupOutput>> {

        public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
                AddGroupInput input) {
            super(taskContext, cookie, input);
        }

        @Override
        public ListenableFuture<RpcResult<UpdateGroupOutput>> call() {
            ListenableFuture<RpcResult<UpdateGroupOutput>> result = SettableFuture.create();

            // Convert the AddGroupInput to GroupModInput
            GroupModInputBuilder ofGroupModInput = GroupConvertor.toGroupModInput(getInput(), getVersion(),
                    getSession().getFeatures().getDatapathId());
            final Long xId = getSession().getNextXid();
            ofGroupModInput.setXid(xId);

            Future<RpcResult<UpdateGroupOutput>> resultFromOFLib = getMessageService()
                    .groupMod(ofGroupModInput.build(), getCookie());
            result = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);

            result = OFRpcTaskUtil.chainFutureBarrier(this, result);
            OFRpcTaskUtil.hookFutureNotification(this, result, getRpcNotificationProviderService(),
                    createGroupAddedNotification(getInput()));

            return result;
        }

        @Override
        public Boolean isBarrier() {
            return getInput().isBarrier();
        }
    }
    ;

    return new OFRpcTaskImpl(taskContext, cookie, input);
}

From source file:org.opendaylight.vpnservice.VpnInterfaceManager.java

public void processArpRequest(IpAddress srcIP, PhysAddress srcMac, IpAddress targetIP, String srcInterface) {
    SendArpResponseInput input = new SendArpResponseInputBuilder().setInterface(srcInterface)
            .setIpaddress(srcIP).setSrcIpAddress(targetIP).setMacaddress(srcMac).build();
    final String msgFormat = String.format("Send ARP Response on interface %s to destination %s", srcInterface,
            srcIP);/*  w  ww  . j a v a 2  s  .c  o  m*/
    Future<RpcResult<Void>> future = arpManager.sendArpResponse(input);
    Futures.addCallback(JdkFutureAdapters.listenInPoolThread(future), new FutureCallback<RpcResult<Void>>() {
        @Override
        public void onFailure(Throwable error) {
            LOG.error("Error - {}", msgFormat, error);
        }

        @Override
        public void onSuccess(RpcResult<Void> result) {
            if (!result.isSuccessful()) {
                LOG.warn("Rpc call to {} failed", msgFormat, getErrorText(result.getErrors()));
            } else {
                LOG.debug("Successful RPC Result - {}", msgFormat);
            }
        }
    });
}

From source file:org.opendaylight.openflowplugin.openflow.md.core.sal.OFRpcTaskFactory.java

/**
 * @param taskContext task context/*from   ww w . jav a2 s . co  m*/
 * @param input meter add input
 * @param cookie switch connection distinguisher
 * @return update meter task
 */
public static OFRpcTask<AddMeterInput, RpcResult<UpdateMeterOutput>> createAddMeterTask(
        OFRpcTaskContext taskContext, AddMeterInput input, SwitchConnectionDistinguisher cookie) {
    class OFRpcTaskImpl extends OFRpcTask<AddMeterInput, RpcResult<UpdateMeterOutput>> {

        public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
                AddMeterInput input) {
            super(taskContext, cookie, input);
        }

        @Override
        public ListenableFuture<RpcResult<UpdateMeterOutput>> call() {
            ListenableFuture<RpcResult<UpdateMeterOutput>> result = SettableFuture.create();

            // Convert the AddGroupInput to GroupModInput
            MeterModInputBuilder ofMeterModInput = MeterConvertor.toMeterModInput(getInput(), getVersion());
            final Long xId = getSession().getNextXid();
            ofMeterModInput.setXid(xId);

            Future<RpcResult<UpdateMeterOutput>> resultFromOFLib = getMessageService()
                    .meterMod(ofMeterModInput.build(), getCookie());
            result = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);

            result = OFRpcTaskUtil.chainFutureBarrier(this, result);
            OFRpcTaskUtil.hookFutureNotification(this, result, getRpcNotificationProviderService(),
                    createMeterAddedNotification(getInput()));

            return result;
        }

        @Override
        public Boolean isBarrier() {
            return getInput().isBarrier();
        }
    }
    ;

    return new OFRpcTaskImpl(taskContext, cookie, input);
}

From source file:org.opendaylight.netvirt.natservice.internal.NatTunnelInterfaceStateListener.java

private boolean hndlTepAddOnNaptSwitch(BigInteger srcDpnId, String tunnelType, String srcTepIp,
        String destTepIp, String tunnelName, long routerId, Optional<Routers> routerData, String nextHopIp) {
    if (!routerData.isPresent()) {
        LOG.warn("hndlTepAddOnNaptSwitch: routerData is not present");
        return false;
    }//from  ww w .j  av  a2  s . c  o  m
    Routers router = routerData.get();
    String routerName = router.getRouterName();
    LOG.debug("NAT Service : SNAT -> Processing TEP add for the DPN {} having the router {} since "
            + "its THE NAPT switch for the TUNNEL TYPE {} b/w SRC IP {} and DST IP {} " + "and TUNNEL NAME {} ",
            srcDpnId, routerName, tunnelType, srcTepIp, destTepIp, tunnelName);

    Uuid networkId = router.getNetworkId();
    if (networkId == null) {
        LOG.warn("NAT Service : SNAT -> Ignoring TEP add since the router {} is not associated to the "
                + "external network", routerName);
        return false;
    }

    LOG.debug("NAT Service : SNAT -> Router {} is associated with Ext nw {}", routerId, networkId);
    Uuid vpnName = NatUtil.getVpnForRouter(dataBroker, routerName);
    Long vpnId;
    if (vpnName == null) {
        LOG.debug("NAT Service : SNAT -> Internal VPN associated to router {}", routerId);
        vpnId = NatUtil.getVpnId(dataBroker, routerId);
        if (vpnId == null || vpnId == NatConstants.INVALID_ID) {
            LOG.error("Invalid External VPN-ID returned for routerName {}", routerName);
            return false;
        }
        LOG.debug("NAT Service : SNAT -> Retrieved External VPN-ID {} for router {}", vpnId, routerId);
    } else {
        LOG.debug("NAT Service : SNAT -> Private BGP VPN associated to router {}", routerId);
        vpnId = NatUtil.getVpnId(dataBroker, vpnName.getValue());
        if (vpnId == null || vpnId == NatConstants.INVALID_ID) {
            LOG.error("NAT Service : Invalid vpnId returned for routerName {}", routerName);
            return false;
        }
        LOG.debug("NAT Service : SNAT -> Retrieved vpnId {} for router {}", vpnId, routerId);
    }

    /*1) Withdraw the old route to the external IP from the BGP which was having the
     next hop as the old TEP IP.
      2) Advertise to the BGP about the new route to the external IP having the
      new TEP IP as the next hop.
      3) Populate a new FIB entry with the next hop IP as the new TEP IP using the
      FIB manager.
    */

    //Withdraw the old route to the external IP from the BGP which was having the
    //next hop as the old TEP IP.
    final String externalVpnName = NatUtil.getAssociatedVPN(dataBroker, networkId, LOG);
    if (externalVpnName == null) {
        LOG.error("NAT Service :  SNAT -> No VPN associated with ext nw {} in router {}", networkId, routerId);
        return false;
    }
    List<String> externalIps = NatUtil.getExternalIpsForRouter(dataBroker, routerId);
    if (externalIps != null) {
        LOG.debug("NAT Service : Clearing the FIB entries but not the BGP routes");
        for (String externalIp : externalIps) {
            String rd = NatUtil.getVpnRd(dataBroker, externalVpnName);
            LOG.debug("NAT Service : Removing Fib entry rd {} prefix {}", rd, externalIp);
            fibManager.removeFibEntry(dataBroker, rd, externalIp, null);
        }
    }

    /*
    Advertise to the BGP about the new route to the external IP having the
    new TEP IP as the next hop.
    Populate a new FIB entry with the next hop IP as the new TEP IP using the
    FIB manager.
    */
    String rd = NatUtil.getVpnRd(dataBroker, externalVpnName);
    ProviderTypes extNwProvType = NatEvpnUtil.getExtNwProvTypeFromRouterName(dataBroker, routerName);
    if (extNwProvType == null) {
        return false;
    }
    String gwMacAddress = null;
    long l3Vni = 0;
    WriteTransaction writeTx = null;
    if (extNwProvType == ProviderTypes.VXLAN) {
        // Get the External Gateway MAC Address which is Router gateway MAC address for SNAT
        gwMacAddress = NatUtil.getExtGwMacAddFromRouterId(dataBroker, routerId);
        //get l3Vni value for external VPN
        l3Vni = NatEvpnUtil.getL3Vni(dataBroker, rd);
        //Create writeTx Object
        writeTx = dataBroker.newWriteOnlyTransaction();
    }
    if (externalIps != null) {
        for (final String externalIp : externalIps) {
            long serviceId = 0;
            if (extNwProvType == ProviderTypes.VXLAN) {
                LOG.debug("NAT Service : SNAT -> Advertise the route to the externalIp {} having nextHopIp {}",
                        externalIp, nextHopIp);
                NatEvpnUtil.addRoutesForVxLanProvType(dataBroker, bgpManager, fibManager, externalVpnName, rd,
                        externalIp, nextHopIp, l3Vni, tunnelName, gwMacAddress, writeTx, RouteOrigin.STATIC,
                        srcDpnId);
                serviceId = l3Vni;
            } else {

                Long label = externalRouterListner.checkExternalIpLabel(routerId, externalIp);
                if (label == null || label == NatConstants.INVALID_ID) {
                    LOG.debug("NAT Service : SNAT -> Unable to advertise to the DC GW since label is invalid");
                    return false;
                }
                LOG.debug("NAT Service : SNAT -> Advertise the route to the externalIp {} having nextHopIp {}",
                        externalIp, nextHopIp);
                long l3vni = 0;
                if (nvpnManager.getEnforceOpenstackSemanticsConfig()) {
                    l3vni = NatOverVxlanUtil.getInternetVpnVni(idManager, externalVpnName, l3vni).longValue();
                }
                Uuid externalSubnetId = NatUtil.getExternalSubnetForRouterExternalIp(dataBroker, externalIp,
                        router);
                NatUtil.addPrefixToBGP(dataBroker, bgpManager, fibManager, externalVpnName, rd,
                        externalSubnetId, externalIp, nextHopIp, networkId.getValue(), null /* mac-address */,
                        label, l3vni, LOG, RouteOrigin.STATIC, srcDpnId);
                serviceId = label;
            }

            LOG.debug("NAT Service : SNAT -> Install custom FIB routes "
                    + "(Table 21 -> Push MPLS label to Tunnel port");
            List<Instruction> customInstructions = new ArrayList<>();
            int customInstructionIndex = 0;
            long externalSubnetVpnId = NatUtil.getExternalSubnetVpnIdForRouterExternalIp(dataBroker, externalIp,
                    router);
            if (externalSubnetVpnId != NatConstants.INVALID_ID) {
                LOG.debug("NAT Service : Will install custom FIB router with external subnet VPN ID {}",
                        externalSubnetVpnId);
                BigInteger subnetIdMetaData = MetaDataUtil.getVpnIdMetadata(externalSubnetVpnId);
                customInstructions
                        .add(new InstructionWriteMetadata(subnetIdMetaData, MetaDataUtil.METADATA_MASK_VRFID)
                                .buildInstruction(customInstructionIndex));
                customInstructionIndex++;
            }
            customInstructions.add(new InstructionGotoTable(NwConstants.INBOUND_NAPT_TABLE)
                    .buildInstruction(customInstructionIndex));
            CreateFibEntryInput input = new CreateFibEntryInputBuilder().setVpnName(externalVpnName)
                    .setSourceDpid(srcDpnId).setInstruction(customInstructions).setIpAddress(externalIp + "/32")
                    .setServiceId(serviceId).setInstruction(customInstructions).build();
            Future<RpcResult<Void>> future = fibRpcService.createFibEntry(input);
            ListenableFuture<RpcResult<Void>> listenableFuture = JdkFutureAdapters.listenInPoolThread(future);

            Futures.addCallback(listenableFuture, new FutureCallback<RpcResult<Void>>() {

                @Override
                public void onFailure(Throwable error) {
                    LOG.error("NAT Service : SNAT -> Error in generate label or fib install process", error);
                }

                @Override
                public void onSuccess(RpcResult<Void> result) {
                    if (result.isSuccessful()) {
                        LOG.info("NAT Service : SNAT -> Successfully installed custom FIB routes for prefix {}",
                                externalIp);
                    } else {
                        LOG.error(
                                "NAT Service : SNAT -> Error in rpc call to create custom Fib entries "
                                        + "for prefix {} in DPN {}, {}",
                                externalIp, srcDpnId, result.getErrors());
                    }
                }
            });
        }
        if (writeTx != null) {
            writeTx.submit();
        }
    }
    return true;
}

From source file:org.opendaylight.openflowplugin.openflow.md.core.sal.OFRpcTaskFactory.java

/**
 * @param taskContext task context/*from   w  ww  .java 2 s  . co m*/
 * @param input update group output
 * @param cookie switch connection distinguisher cookie value
 * @return UpdateFlow task
 */
public static OFRpcTask<UpdateGroupInput, RpcResult<UpdateGroupOutput>> createUpdateGroupTask(
        OFRpcTaskContext taskContext, UpdateGroupInput input, SwitchConnectionDistinguisher cookie) {
    class OFRpcTaskImpl extends OFRpcTask<UpdateGroupInput, RpcResult<UpdateGroupOutput>> {

        public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
                UpdateGroupInput input) {
            super(taskContext, cookie, input);
        }

        @Override
        public ListenableFuture<RpcResult<UpdateGroupOutput>> call() {
            ListenableFuture<RpcResult<UpdateGroupOutput>> result = null;

            // Convert the UpdateGroupInput to GroupModInput
            GroupModInputBuilder ofGroupModInput = GroupConvertor.toGroupModInput(getInput().getUpdatedGroup(),
                    getVersion(), getSession().getFeatures().getDatapathId());
            final Long xId = getSession().getNextXid();
            ofGroupModInput.setXid(xId);

            Future<RpcResult<UpdateGroupOutput>> resultFromOFLib = getMessageService()
                    .groupMod(ofGroupModInput.build(), getCookie());
            result = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);

            result = OFRpcTaskUtil.chainFutureBarrier(this, result);
            OFRpcTaskUtil.hookFutureNotification(this, result, getRpcNotificationProviderService(),
                    createGroupUpdatedNotification(getInput()));

            return result;
        }

        @Override
        public Boolean isBarrier() {
            return getInput().getUpdatedGroup().isBarrier();
        }
    }

    return new OFRpcTaskImpl(taskContext, cookie, input);
}

From source file:org.opendaylight.openflowplugin.openflow.md.core.sal.OFRpcTaskFactory.java

/**
 * @param taskContext task context// ww  w . j av  a  2 s  . c  o m
 * @param input update meter input
 * @param cookie switch connection distinguisher cookie value
 * @return update meter task
 */
public static OFRpcTask<UpdateMeterInput, RpcResult<UpdateMeterOutput>> createUpdateMeterTask(
        OFRpcTaskContext taskContext, UpdateMeterInput input, SwitchConnectionDistinguisher cookie) {
    class OFRpcTaskImpl extends OFRpcTask<UpdateMeterInput, RpcResult<UpdateMeterOutput>> {

        public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
                UpdateMeterInput input) {
            super(taskContext, cookie, input);
        }

        @Override
        public ListenableFuture<RpcResult<UpdateMeterOutput>> call() {
            ListenableFuture<RpcResult<UpdateMeterOutput>> result = null;

            // Convert the UpdateMeterInput to MeterModInput
            MeterModInputBuilder ofMeterModInput = MeterConvertor.toMeterModInput(getInput().getUpdatedMeter(),
                    getVersion());
            final Long xId = getSession().getNextXid();
            ofMeterModInput.setXid(xId);

            Future<RpcResult<UpdateMeterOutput>> resultFromOFLib = getMessageService()
                    .meterMod(ofMeterModInput.build(), getCookie());
            result = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);

            result = OFRpcTaskUtil.chainFutureBarrier(this, result);
            OFRpcTaskUtil.hookFutureNotification(this, result, getRpcNotificationProviderService(),
                    createMeterUpdatedNotification(getInput()));
            return result;
        }

        @Override
        public Boolean isBarrier() {
            return getInput().getUpdatedMeter().isBarrier();
        }
    }

    return new OFRpcTaskImpl(taskContext, cookie, input);
}