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.openflow.md.core.sal.OFRpcTaskFactory.java

/**
 * @param taskContext task context// w  w w  .ja v a  2  s  . c  o m
 * @param input get group statistics input
 * @param cookie switch connection distinguisher cookie value
 * @return task get group statistics task
 */
public static OFRpcTask<GetGroupStatisticsInput, RpcResult<GetGroupStatisticsOutput>> createGetGroupStatisticsTask(
        final OFRpcTaskContext taskContext, final GetGroupStatisticsInput input,
        SwitchConnectionDistinguisher cookie) {

    class OFRpcTaskImpl extends OFRpcTask<GetGroupStatisticsInput, RpcResult<GetGroupStatisticsOutput>> {

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

        @Override
        public ListenableFuture<RpcResult<GetGroupStatisticsOutput>> call() throws Exception {
            final SettableFuture<RpcResult<GetGroupStatisticsOutput>> result = SettableFuture.create();

            if (taskContext.getSession().getPrimaryConductor().getVersion() == OFConstants.OFP_VERSION_1_0) {
                RpcResult<GetGroupStatisticsOutput> rpcResult = RpcResultBuilder
                        .success(new GetGroupStatisticsOutputBuilder().build()).build();
                return Futures.immediateFuture(rpcResult);
            } else {
                final Long xid = taskContext.getSession().getNextXid();

                MultipartRequestGroupCaseBuilder caseBuilder = new MultipartRequestGroupCaseBuilder();
                MultipartRequestGroupBuilder mprGroupBuild = new MultipartRequestGroupBuilder();
                mprGroupBuild.setGroupId(new GroupId(input.getGroupId().getValue()));
                caseBuilder.setMultipartRequestGroup(mprGroupBuild.build());

                MultipartRequestInputBuilder mprInput = createMultipartHeader(MultipartType.OFPMPGROUP,
                        taskContext, xid);
                mprInput.setMultipartRequestBody(caseBuilder.build());
                Future<RpcResult<Void>> resultFromOFLib = getMessageService().multipartRequest(mprInput.build(),
                        getCookie());
                ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters
                        .listenInPoolThread(resultFromOFLib);

                Futures.addCallback(resultLib, new ResultCallback<GetGroupStatisticsOutput>(result) {
                    @Override
                    public GetGroupStatisticsOutput createResult() {
                        GetGroupStatisticsOutputBuilder groupStatisticsBuilder = new GetGroupStatisticsOutputBuilder()
                                .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
                        return groupStatisticsBuilder.build();
                    }
                });
                return result;
            }
        }
    }

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

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

/**
 * @param taskContext task context//from   w  w w .  j a  va 2 s . c o m
 * @param input get meter config statistics input
 * @param cookie switch connection distinguisher cookie value
 * @return task get all mtere config statistics task
 */
public static OFRpcTask<GetAllMeterConfigStatisticsInput, RpcResult<GetAllMeterConfigStatisticsOutput>> createGetAllMeterConfigStatisticsTask(
        final OFRpcTaskContext taskContext, final GetAllMeterConfigStatisticsInput input,
        SwitchConnectionDistinguisher cookie) {
    class OFRpcTaskImpl
            extends OFRpcTask<GetAllMeterConfigStatisticsInput, RpcResult<GetAllMeterConfigStatisticsOutput>> {

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

        @Override
        public ListenableFuture<RpcResult<GetAllMeterConfigStatisticsOutput>> call() throws Exception {
            final SettableFuture<RpcResult<GetAllMeterConfigStatisticsOutput>> result = SettableFuture.create();

            if (taskContext.getSession().getPrimaryConductor().getVersion() == OFConstants.OFP_VERSION_1_0) {
                RpcResult<GetAllMeterConfigStatisticsOutput> rpcResult = RpcResultBuilder
                        .success(new GetAllMeterConfigStatisticsOutputBuilder().build()).build();
                return Futures.immediateFuture(rpcResult);
            } else {
                final Long xid = taskContext.getSession().getNextXid();

                MultipartRequestMeterConfigCaseBuilder caseBuilder = new MultipartRequestMeterConfigCaseBuilder();
                MultipartRequestMeterConfigBuilder mprMeterConfigBuild = new MultipartRequestMeterConfigBuilder();
                mprMeterConfigBuild.setMeterId(new MeterId(BinContent.intToUnsignedLong(
                        org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.Meter.OFPMALL
                                .getIntValue())));
                caseBuilder.setMultipartRequestMeterConfig(mprMeterConfigBuild.build());

                MultipartRequestInputBuilder mprInput = createMultipartHeader(MultipartType.OFPMPMETERCONFIG,
                        taskContext, xid);
                mprInput.setMultipartRequestBody(caseBuilder.build());
                Future<RpcResult<Void>> resultFromOFLib = getMessageService().multipartRequest(mprInput.build(),
                        getCookie());
                ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters
                        .listenInPoolThread(resultFromOFLib);

                Futures.addCallback(resultLib, new ResultCallback<GetAllMeterConfigStatisticsOutput>(result) {
                    @Override
                    public GetAllMeterConfigStatisticsOutput createResult() {
                        GetAllMeterConfigStatisticsOutputBuilder allMeterConfStatBuilder = new GetAllMeterConfigStatisticsOutputBuilder()
                                .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
                        return allMeterConfStatBuilder.build();
                    }
                });
                return result;
            }
        }
    }

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

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

/**
 * @param taskContext task context//from  w  ww  . j a  v a2  s .  co m
 * @param input get all meter statistics input
 * @param cookie switch connection distinguisher cookie value
 * @return task get all meter statistics task
 */
public static OFRpcTask<GetAllMeterStatisticsInput, RpcResult<GetAllMeterStatisticsOutput>> createGetAllMeterStatisticsTask(
        final OFRpcTaskContext taskContext, final GetAllMeterStatisticsInput input,
        SwitchConnectionDistinguisher cookie) {
    class OFRpcTaskImpl extends OFRpcTask<GetAllMeterStatisticsInput, RpcResult<GetAllMeterStatisticsOutput>> {

        public OFRpcTaskImpl(OFRpcTaskContext taskContext, SwitchConnectionDistinguisher cookie,
                GetAllMeterStatisticsInput input) {
            super(taskContext, cookie, input);
            // TODO Auto-generated constructor stub
        }

        @Override
        public ListenableFuture<RpcResult<GetAllMeterStatisticsOutput>> call() throws Exception {
            final SettableFuture<RpcResult<GetAllMeterStatisticsOutput>> result = SettableFuture.create();

            if (taskContext.getSession().getPrimaryConductor().getVersion() == OFConstants.OFP_VERSION_1_0) {
                RpcResult<GetAllMeterStatisticsOutput> rpcResult = RpcResultBuilder
                        .success(new GetAllMeterStatisticsOutputBuilder().build()).build();
                return Futures.immediateFuture(rpcResult);
            } else {
                final Long xid = taskContext.getSession().getNextXid();

                MultipartRequestMeterCaseBuilder caseBuilder = new MultipartRequestMeterCaseBuilder();
                MultipartRequestMeterBuilder mprMeterBuild = new MultipartRequestMeterBuilder();
                mprMeterBuild.setMeterId(new MeterId(BinContent.intToUnsignedLong(
                        org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.Meter.OFPMALL
                                .getIntValue())));
                caseBuilder.setMultipartRequestMeter(mprMeterBuild.build());

                MultipartRequestInputBuilder mprInput = createMultipartHeader(MultipartType.OFPMPMETER,
                        taskContext, xid);
                mprInput.setMultipartRequestBody(caseBuilder.build());
                Future<RpcResult<Void>> resultFromOFLib = getMessageService().multipartRequest(mprInput.build(),
                        getCookie());
                ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters
                        .listenInPoolThread(resultFromOFLib);

                Futures.addCallback(resultLib, new ResultCallback<GetAllMeterStatisticsOutput>(result) {
                    @Override
                    public GetAllMeterStatisticsOutput createResult() {
                        GetAllMeterStatisticsOutputBuilder allMeterStatBuilder = new GetAllMeterStatisticsOutputBuilder()
                                .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
                        return allMeterStatBuilder.build();
                    }
                });
                return result;
            }
        }
    }

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

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

/**
 * @param taskContext task context//from  w ww  .  j  a  v  a 2  s.  c  o  m
 * @param input get meter features input
 * @param cookie switch connection distinguisher cookie value
 * @return task get meter feature task
 */
public static OFRpcTask<GetMeterFeaturesInput, RpcResult<GetMeterFeaturesOutput>> createGetMeterFeaturesTask(
        final OFRpcTaskContext taskContext, final GetMeterFeaturesInput input,
        SwitchConnectionDistinguisher cookie) {

    class OFRpcTaskImpl extends OFRpcTask<GetMeterFeaturesInput, RpcResult<GetMeterFeaturesOutput>> {

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

        @Override
        public ListenableFuture<RpcResult<GetMeterFeaturesOutput>> call() throws Exception {
            final SettableFuture<RpcResult<GetMeterFeaturesOutput>> result = SettableFuture.create();

            if (taskContext.getSession().getPrimaryConductor().getVersion() == OFConstants.OFP_VERSION_1_0) {
                RpcResult<GetMeterFeaturesOutput> rpcResult = RpcResultBuilder
                        .success(new GetMeterFeaturesOutputBuilder().build()).build();
                return Futures.immediateFuture(rpcResult);
            } else {
                final Long xid = taskContext.getSession().getNextXid();

                MultipartRequestMeterFeaturesCaseBuilder mprMeterFeaturesBuild = new MultipartRequestMeterFeaturesCaseBuilder();

                MultipartRequestInputBuilder mprInput = createMultipartHeader(MultipartType.OFPMPMETERFEATURES,
                        taskContext, xid);
                mprInput.setMultipartRequestBody(mprMeterFeaturesBuild.build());
                Future<RpcResult<Void>> resultFromOFLib = getMessageService().multipartRequest(mprInput.build(),
                        getCookie());
                ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters
                        .listenInPoolThread(resultFromOFLib);

                Futures.addCallback(resultLib, new ResultCallback<GetMeterFeaturesOutput>(result) {
                    @Override
                    public GetMeterFeaturesOutput createResult() {
                        GetMeterFeaturesOutputBuilder meterFeaturesBuilder = new GetMeterFeaturesOutputBuilder()
                                .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
                        return meterFeaturesBuilder.build();
                    }
                });
                return result;
            }
        }
    }

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

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

/**
 * @param taskContext task context/*from  w  w  w. j  av  a2  s. com*/
 * @param input get meter statistics input
 * @param cookie switch connection distinguisher cookie value
 * @return task get meter statistics task
 */
public static OFRpcTask<GetMeterStatisticsInput, RpcResult<GetMeterStatisticsOutput>> createGetMeterStatisticsTask(
        final OFRpcTaskContext taskContext, final GetMeterStatisticsInput input,
        SwitchConnectionDistinguisher cookie) {

    class OFRpcTaskImpl extends OFRpcTask<GetMeterStatisticsInput, RpcResult<GetMeterStatisticsOutput>> {

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

        @Override
        public ListenableFuture<RpcResult<GetMeterStatisticsOutput>> call() throws Exception {
            final SettableFuture<RpcResult<GetMeterStatisticsOutput>> result = SettableFuture.create();

            if (taskContext.getSession().getPrimaryConductor().getVersion() == OFConstants.OFP_VERSION_1_0) {
                RpcResult<GetMeterStatisticsOutput> rpcResult = RpcResultBuilder
                        .success(new GetMeterStatisticsOutputBuilder().build()).build();
                return Futures.immediateFuture(rpcResult);
            } else {
                final Long xid = taskContext.getSession().getNextXid();

                MultipartRequestMeterCaseBuilder caseBuilder = new MultipartRequestMeterCaseBuilder();
                MultipartRequestMeterBuilder mprMeterBuild = new MultipartRequestMeterBuilder();
                mprMeterBuild.setMeterId(new MeterId(input.getMeterId().getValue()));
                caseBuilder.setMultipartRequestMeter(mprMeterBuild.build());

                MultipartRequestInputBuilder mprInput = createMultipartHeader(MultipartType.OFPMPMETER,
                        taskContext, xid);
                mprInput.setMultipartRequestBody(caseBuilder.build());
                Future<RpcResult<Void>> resultFromOFLib = getMessageService().multipartRequest(mprInput.build(),
                        getCookie());
                ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters
                        .listenInPoolThread(resultFromOFLib);

                Futures.addCallback(resultLib, new ResultCallback<GetMeterStatisticsOutput>(result) {
                    @Override
                    public GetMeterStatisticsOutput createResult() {
                        GetMeterStatisticsOutputBuilder meterStatBuilder = new GetMeterStatisticsOutputBuilder()
                                .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
                        return meterStatBuilder.build();
                    }
                });
                return result;
            }
        }
    }

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

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

/**
 * @param taskContext task context//from   w  w  w  .  ja v  a2 s.c o m
 * @param input get all node connector statistics input
 * @param cookie switch connection distinguisher cookie value
 * @return task get all node connector statistics task
 */
public static OFRpcTask<GetAllNodeConnectorsStatisticsInput, RpcResult<GetAllNodeConnectorsStatisticsOutput>> createGetAllNodeConnectorsStatisticsTask(
        final OFRpcTaskContext taskContext, final GetAllNodeConnectorsStatisticsInput input,
        SwitchConnectionDistinguisher cookie) {
    class OFRpcTaskImpl extends
            OFRpcTask<GetAllNodeConnectorsStatisticsInput, RpcResult<GetAllNodeConnectorsStatisticsOutput>> {

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

        @Override
        public ListenableFuture<RpcResult<GetAllNodeConnectorsStatisticsOutput>> call() throws Exception {
            final SettableFuture<RpcResult<GetAllNodeConnectorsStatisticsOutput>> result = SettableFuture
                    .create();

            final Long xid = taskContext.getSession().getNextXid();

            MultipartRequestPortStatsCaseBuilder caseBuilder = new MultipartRequestPortStatsCaseBuilder();
            MultipartRequestPortStatsBuilder mprPortStatsBuilder = new MultipartRequestPortStatsBuilder();
            // Select all ports
            mprPortStatsBuilder.setPortNo(OFConstants.OFPP_ANY);
            caseBuilder.setMultipartRequestPortStats(mprPortStatsBuilder.build());

            MultipartRequestInputBuilder mprInput = createMultipartHeader(MultipartType.OFPMPPORTSTATS,
                    taskContext, xid);
            mprInput.setMultipartRequestBody(caseBuilder.build());
            Future<RpcResult<Void>> resultFromOFLib = getMessageService().multipartRequest(mprInput.build(),
                    getCookie());
            ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);

            Futures.addCallback(resultLib, new ResultCallback<GetAllNodeConnectorsStatisticsOutput>(result) {
                @Override
                public GetAllNodeConnectorsStatisticsOutput createResult() {
                    GetAllNodeConnectorsStatisticsOutputBuilder allNodeConnectorStatBuilder = new GetAllNodeConnectorsStatisticsOutputBuilder()
                            .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
                    return allNodeConnectorStatBuilder.build();
                }
            });
            return result;
        }
    }

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

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

/**
 * @param taskContext task context//from   www  .  j  a v a 2s. c  o  m
 * @param input get node connector statistics input
 * @param cookie switch connection distinguisher cookie value
 * @return task get node connector statistics task
 */
public static OFRpcTask<GetNodeConnectorStatisticsInput, RpcResult<GetNodeConnectorStatisticsOutput>> createGetNodeConnectorStatisticsTask(
        final OFRpcTaskContext taskContext, final GetNodeConnectorStatisticsInput input,
        SwitchConnectionDistinguisher cookie) {
    class OFRpcTaskImpl
            extends OFRpcTask<GetNodeConnectorStatisticsInput, RpcResult<GetNodeConnectorStatisticsOutput>> {

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

        @Override
        public ListenableFuture<RpcResult<GetNodeConnectorStatisticsOutput>> call() throws Exception {
            final SettableFuture<RpcResult<GetNodeConnectorStatisticsOutput>> result = SettableFuture.create();

            final Long xid = taskContext.getSession().getNextXid();

            MultipartRequestPortStatsCaseBuilder caseBuilder = new MultipartRequestPortStatsCaseBuilder();
            MultipartRequestPortStatsBuilder mprPortStatsBuilder = new MultipartRequestPortStatsBuilder();
            // Set specific port
            mprPortStatsBuilder.setPortNo(InventoryDataServiceUtil.portNumberfromNodeConnectorId(
                    OpenflowVersion.get(taskContext.getSession().getFeatures().getVersion()),
                    input.getNodeConnectorId()));
            caseBuilder.setMultipartRequestPortStats(mprPortStatsBuilder.build());

            MultipartRequestInputBuilder mprInput = createMultipartHeader(MultipartType.OFPMPPORTSTATS,
                    taskContext, xid);
            mprInput.setMultipartRequestBody(caseBuilder.build());
            Future<RpcResult<Void>> resultFromOFLib = getMessageService().multipartRequest(mprInput.build(),
                    getCookie());
            ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);

            Futures.addCallback(resultLib, new ResultCallback<GetNodeConnectorStatisticsOutput>(result) {
                @Override
                public GetNodeConnectorStatisticsOutput createResult() {
                    GetNodeConnectorStatisticsOutputBuilder allNodeConnectorStatBuilder = new GetNodeConnectorStatisticsOutputBuilder()
                            .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
                    return allNodeConnectorStatBuilder.build();
                }
            });
            return result;
        }
    }

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

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

/**
 * @param taskContext task context/*from   ww w .ja v  a 2 s.  co m*/
 * @param input get all flow statistics from flow table
 * @param cookie switch connection distinguisher cookie value
 * @return task get all flow statistics from flow table task
 */
public static OFRpcTask<GetAllFlowStatisticsFromFlowTableInput, RpcResult<GetAllFlowStatisticsFromFlowTableOutput>> createGetAllFlowStatisticsFromFlowTableTask(
        final OFRpcTaskContext taskContext, final GetAllFlowStatisticsFromFlowTableInput input,
        SwitchConnectionDistinguisher cookie) {
    class OFRpcTaskImpl extends
            OFRpcTask<GetAllFlowStatisticsFromFlowTableInput, RpcResult<GetAllFlowStatisticsFromFlowTableOutput>> {

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

        @Override
        public ListenableFuture<RpcResult<GetAllFlowStatisticsFromFlowTableOutput>> call() throws Exception {
            final SettableFuture<RpcResult<GetAllFlowStatisticsFromFlowTableOutput>> result = SettableFuture
                    .create();

            final Long xid = taskContext.getSession().getNextXid();

            MultipartRequestFlowBuilder mprFlowRequestBuilder = new MultipartRequestFlowBuilder();
            mprFlowRequestBuilder.setTableId(input.getTableId().getValue());
            mprFlowRequestBuilder.setOutPort(OFConstants.OFPP_ANY);
            mprFlowRequestBuilder.setOutGroup(OFConstants.OFPG_ANY);
            mprFlowRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE);
            mprFlowRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK);
            FlowCreatorUtil.setWildcardedFlowMatch(taskContext.getSession().getPrimaryConductor().getVersion(),
                    mprFlowRequestBuilder);

            MultipartRequestFlowCaseBuilder multipartRequestFlowCaseBuilder = new MultipartRequestFlowCaseBuilder();
            multipartRequestFlowCaseBuilder.setMultipartRequestFlow(mprFlowRequestBuilder.build());

            MultipartRequestInputBuilder mprInput = createMultipartHeader(MultipartType.OFPMPFLOW, taskContext,
                    xid);
            mprInput.setMultipartRequestBody(multipartRequestFlowCaseBuilder.build());
            Future<RpcResult<Void>> resultFromOFLib = getMessageService().multipartRequest(mprInput.build(),
                    getCookie());
            ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);

            Futures.addCallback(resultLib, new ResultCallback<GetAllFlowStatisticsFromFlowTableOutput>(result) {
                @Override
                public GetAllFlowStatisticsFromFlowTableOutput createResult() {
                    GetAllFlowStatisticsFromFlowTableOutputBuilder allFlowStatsFromFlowTableBuilder = new GetAllFlowStatisticsFromFlowTableOutputBuilder()
                            .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
                    return allFlowStatsFromFlowTableBuilder.build();
                }
            });
            return result;
        }
    }

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

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

/**
 * @param taskContext task context//from   ww  w.  ja  v a  2  s.co  m
 * @param input get all flow statistics from all flow table
 * @param cookie switch connection distinguisher cookie value
 * @return task get all flow statistics from all flow table task
 */
public static OFRpcTask<GetAllFlowsStatisticsFromAllFlowTablesInput, RpcResult<GetAllFlowsStatisticsFromAllFlowTablesOutput>> createGetAllFlowsStatisticsFromAllFlowTablesTask(
        final OFRpcTaskContext taskContext, final GetAllFlowsStatisticsFromAllFlowTablesInput input,
        SwitchConnectionDistinguisher cookie) {
    class OFRpcTaskImpl extends
            OFRpcTask<GetAllFlowsStatisticsFromAllFlowTablesInput, RpcResult<GetAllFlowsStatisticsFromAllFlowTablesOutput>> {

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

        @Override
        public ListenableFuture<RpcResult<GetAllFlowsStatisticsFromAllFlowTablesOutput>> call()
                throws Exception {
            final SettableFuture<RpcResult<GetAllFlowsStatisticsFromAllFlowTablesOutput>> result = SettableFuture
                    .create();

            final Long xid = taskContext.getSession().getNextXid();

            // Create multipart request body for fetch all the group stats
            MultipartRequestFlowCaseBuilder multipartRequestFlowCaseBuilder = new MultipartRequestFlowCaseBuilder();
            MultipartRequestFlowBuilder mprFlowRequestBuilder = new MultipartRequestFlowBuilder();
            mprFlowRequestBuilder.setTableId(OFConstants.OFPTT_ALL);
            mprFlowRequestBuilder.setOutPort(OFConstants.OFPP_ANY);
            mprFlowRequestBuilder.setOutGroup(OFConstants.OFPG_ANY);
            mprFlowRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE);
            mprFlowRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK);
            FlowCreatorUtil.setWildcardedFlowMatch(taskContext.getSession().getPrimaryConductor().getVersion(),
                    mprFlowRequestBuilder);

            MultipartRequestInputBuilder mprInput = createMultipartHeader(MultipartType.OFPMPFLOW, taskContext,
                    xid);
            multipartRequestFlowCaseBuilder.setMultipartRequestFlow(mprFlowRequestBuilder.build());
            mprInput.setMultipartRequestBody(multipartRequestFlowCaseBuilder.build());
            Future<RpcResult<Void>> resultFromOFLib = getMessageService().multipartRequest(mprInput.build(),
                    getCookie());
            ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);

            Futures.addCallback(resultLib,
                    new ResultCallback<GetAllFlowsStatisticsFromAllFlowTablesOutput>(result) {
                        @Override
                        public GetAllFlowsStatisticsFromAllFlowTablesOutput createResult() {
                            GetAllFlowsStatisticsFromAllFlowTablesOutputBuilder allFlowStatsFromAllFlowTableBuilder = new GetAllFlowsStatisticsFromAllFlowTablesOutputBuilder()
                                    .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
                            return allFlowStatsFromAllFlowTableBuilder.build();
                        }
                    });
            return result;
        }
    }

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

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

/**
 * @param taskContext task context// w w  w . j a  v  a2  s .co m
 * @param input get flow statistics from flow table
 * @param cookie switch connection distinguisher cookie value
 * @return task get flow statistics from flow table task
 */
public static OFRpcTask<GetFlowStatisticsFromFlowTableInput, RpcResult<GetFlowStatisticsFromFlowTableOutput>> createGetFlowStatisticsFromFlowTableTask(
        final OFRpcTaskContext taskContext, final GetFlowStatisticsFromFlowTableInput input,
        SwitchConnectionDistinguisher cookie) {

    class OFRpcTaskImpl extends
            OFRpcTask<GetFlowStatisticsFromFlowTableInput, RpcResult<GetFlowStatisticsFromFlowTableOutput>> {

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

        @Override
        public ListenableFuture<RpcResult<GetFlowStatisticsFromFlowTableOutput>> call() throws Exception {
            final SettableFuture<RpcResult<GetFlowStatisticsFromFlowTableOutput>> result = SettableFuture
                    .create();

            final Long xid = taskContext.getSession().getNextXid();

            // Create multipart request body for fetch all the group stats
            MultipartRequestFlowCaseBuilder multipartRequestFlowCaseBuilder = new MultipartRequestFlowCaseBuilder();
            MultipartRequestFlowBuilder mprFlowRequestBuilder = new MultipartRequestFlowBuilder();
            mprFlowRequestBuilder.setTableId(input.getTableId());

            if (input.getOutPort() != null) {
                mprFlowRequestBuilder.setOutPort(input.getOutPort().longValue());
            } else {
                mprFlowRequestBuilder.setOutPort(OFConstants.OFPP_ANY);
            }

            if (input.getOutGroup() != null) {
                mprFlowRequestBuilder.setOutGroup(input.getOutGroup());
            } else {
                mprFlowRequestBuilder.setOutGroup(OFConstants.OFPG_ANY);
            }

            if (input.getCookie() != null) {
                mprFlowRequestBuilder.setCookie(input.getCookie().getValue());
            } else {
                mprFlowRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE);
            }

            if (input.getCookieMask() != null) {
                mprFlowRequestBuilder.setCookieMask(input.getCookieMask().getValue());
            } else {
                mprFlowRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK);
            }

            // convert and inject match
            MatchReactor.getInstance().convert(input.getMatch(),
                    taskContext.getSession().getPrimaryConductor().getVersion(), mprFlowRequestBuilder,
                    taskContext.getSession().getFeatures().getDatapathId());

            // Set request body to main multipart request
            multipartRequestFlowCaseBuilder.setMultipartRequestFlow(mprFlowRequestBuilder.build());
            MultipartRequestInputBuilder mprInput = createMultipartHeader(MultipartType.OFPMPFLOW, taskContext,
                    xid);
            mprInput.setMultipartRequestBody(multipartRequestFlowCaseBuilder.build());
            Future<RpcResult<Void>> resultFromOFLib = getMessageService().multipartRequest(mprInput.build(),
                    getCookie());
            ListenableFuture<RpcResult<Void>> resultLib = JdkFutureAdapters.listenInPoolThread(resultFromOFLib);

            Futures.addCallback(resultLib, new ResultCallback<GetFlowStatisticsFromFlowTableOutput>(result) {
                @Override
                public GetFlowStatisticsFromFlowTableOutput createResult() {
                    GetFlowStatisticsFromFlowTableOutputBuilder flowStatsFromFlowTableBuilder = new GetFlowStatisticsFromFlowTableOutputBuilder()
                            .setTransactionId(new TransactionId(BigInteger.valueOf(xid)));
                    return flowStatsFromFlowTableBuilder.build();
                }
            });
            return result;
        }
    }

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