Example usage for org.apache.commons.lang.time StopWatch StopWatch

List of usage examples for org.apache.commons.lang.time StopWatch StopWatch

Introduction

In this page you can find the example usage for org.apache.commons.lang.time StopWatch StopWatch.

Prototype

public StopWatch() 

Source Link

Document

Constructor.

Usage

From source file:com.liferay.portal.search.solr.SolrIndexSearcher.java

public long searchCount(SearchContext searchContext, Query query) throws SearchException {

    StopWatch stopWatch = new StopWatch();

    stopWatch.start();// www  . j a v  a  2s  .  co m

    try {
        QueryResponse queryResponse = search(searchContext, query, searchContext.getStart(),
                searchContext.getEnd(), true);

        SolrDocumentList solrDocumentList = queryResponse.getResults();

        return solrDocumentList.getNumFound();
    } catch (Exception e) {
        if (_log.isWarnEnabled()) {
            _log.warn(e, e);
        }

        if (!_swallowException) {
            throw new SearchException(e.getMessage());
        }

        return 0;
    } finally {
        if (_log.isInfoEnabled()) {
            stopWatch.stop();

            _log.info("Searching " + query.toString() + " took " + stopWatch.getTime() + " ms");
        }
    }
}

From source file:net.nan21.dnet.core.web.controller.data.AbstractDsWriteController.java

/**
 * Default handler for update action./*  w  w  w .ja v  a2s .c o m*/
 * 
 * @param resourceName
 * @param dataformat
 * @param dataString
 * @param paramString
 * @return
 * @throws Exception
 */
@RequestMapping(method = RequestMethod.POST, params = Constants.REQUEST_PARAM_ACTION + "="
        + Constants.DS_ACTION_UPDATE)
@ResponseBody
public String update(@PathVariable String resourceName, @PathVariable String dataFormat,
        @RequestParam(value = Constants.REQUEST_PARAM_DATA, required = false, defaultValue = "{}") String dataString,
        @RequestParam(value = Constants.REQUEST_PARAM_PARAMS, required = false, defaultValue = "{}") String paramString,
        HttpServletRequest request, HttpServletResponse response) throws Exception {

    try {

        StopWatch stopWatch = new StopWatch();
        stopWatch.start();

        if (logger.isInfoEnabled()) {
            logger.info("Processing request: {}.{} -> action = {} ",
                    new String[] { resourceName, dataFormat, Constants.DS_ACTION_UPDATE });
        }

        if (logger.isDebugEnabled()) {
            logger.debug("  --> request-data: {} ", new String[] { dataString });
            logger.debug("  --> request-params: {} ", new String[] { paramString });
        }

        this.prepareRequest(request, response);

        this.authorizeDsAction(resourceName, Constants.DS_ACTION_UPDATE, null);

        if (!dataString.startsWith("[")) {
            dataString = "[" + dataString + "]";
        }
        IDsService<M, F, P> service = this.findDsService(resourceName);
        IDsMarshaller<M, F, P> marshaller = service.createMarshaller(IDsMarshaller.JSON);

        List<M> list = marshaller.readListFromString(dataString);
        P params = marshaller.readParamsFromString(paramString);

        service.update(list, params);

        IActionResultSave result = this.packResultSave(list, params);
        stopWatch.stop();
        result.setExecutionTime(stopWatch.getTime());

        String out = null;

        if (dataFormat.equals(IDsMarshaller.XML)) {
            IDsMarshaller<M, F, P> resultMarshaller = service.createMarshaller(dataFormat);
            out = resultMarshaller.writeResultToString(result);
            response.setContentType("text/xml; charset=UTF-8");
        } else {
            out = marshaller.writeResultToString(result);
            response.setContentType("text/plain; charset=UTF-8");
        }

        return out;
    } catch (Exception e) {
        this.handleException(e, response);
        return null;
    } finally {
        this.finishRequest();
    }
}

From source file:com.liferay.portal.upgrade.util.Table.java

public String generateTempFile(Connection con) throws Exception {
    PreparedStatement ps = null;/*from   w  w  w . j a v a  2 s  .c  o m*/
    ResultSet rs = null;

    boolean empty = true;

    String tempFileName = SystemProperties.get(SystemProperties.TMP_DIR) + "/temp-db-" + _tableName + "-"
            + System.currentTimeMillis();

    StopWatch stopWatch = null;

    if (_log.isInfoEnabled()) {
        stopWatch = new StopWatch();

        stopWatch.start();

        _log.info("Starting backup of " + _tableName + " to " + tempFileName);
    }

    String selectSQL = getSelectSQL();

    UnsyncBufferedWriter unsyncBufferedWriter = new UnsyncBufferedWriter(new FileWriter(tempFileName));

    try {
        ps = con.prepareStatement(selectSQL);

        rs = ps.executeQuery();

        while (rs.next()) {
            String data = null;

            try {
                data = getExportedData(rs);

                unsyncBufferedWriter.write(data);

                _totalRows++;

                empty = false;
            } catch (StagnantRowException sre) {
                if (_log.isWarnEnabled()) {
                    _log.warn("Skipping stagnant data in " + _tableName + ": " + sre.getMessage());
                }
            }
        }

        if (_log.isInfoEnabled()) {
            _log.info("Finished backup of " + _tableName + " to " + tempFileName + " in " + stopWatch.getTime()
                    + " ms");
        }
    } catch (Exception e) {
        FileUtil.delete(tempFileName);

        throw e;
    } finally {
        DataAccess.cleanUp(null, ps, rs);

        unsyncBufferedWriter.close();
    }

    if (!empty) {
        return tempFileName;
    } else {
        FileUtil.delete(tempFileName);

        return null;
    }
}

From source file:com.google.code.jerseyclients.asynchttpclient.AsyncHttpClientJerseyClientHandler.java

/**
 * @see com.sun.jersey.api.client.ClientHandler#handle(com.sun.jersey.api.client.ClientRequest)
 *//*  w  w w. j  a  v a 2 s . com*/
public ClientResponse handle(final ClientRequest clientRequest) throws ClientHandlerException {

    final BoundRequestBuilder boundRequestBuilder = getBoundRequestBuilder(clientRequest);

    PerRequestConfig perRequestConfig = new PerRequestConfig();
    perRequestConfig.setRequestTimeoutInMs(this.jerseyHttpClientConfig.getReadTimeOut());

    if (this.jerseyHttpClientConfig.getProxyInformation() != null) {
        ProxyServer proxyServer = new ProxyServer(jerseyHttpClientConfig.getProxyInformation().getProxyHost(),
                jerseyHttpClientConfig.getProxyInformation().getProxyPort());
        perRequestConfig = new PerRequestConfig(proxyServer, this.jerseyHttpClientConfig.getReadTimeOut());
    }

    boundRequestBuilder.setPerRequestConfig(perRequestConfig);

    if (this.jerseyHttpClientConfig.getApplicationCode() != null) {
        boundRequestBuilder.addHeader(this.jerseyHttpClientConfig.getApplicationCodeHeader(),
                this.jerseyHttpClientConfig.getApplicationCode());
    }
    if (this.jerseyHttpClientConfig.getOptionnalHeaders() != null) {
        for (Entry<String, String> entry : this.jerseyHttpClientConfig.getOptionnalHeaders().entrySet()) {
            boundRequestBuilder.addHeader(entry.getKey(), entry.getValue());
        }
    }

    if (StringUtils.equalsIgnoreCase("POST", clientRequest.getMethod())) {

        if (clientRequest.getEntity() != null) {
            final RequestEntityWriter re = getRequestEntityWriter(clientRequest);

            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            try {
                re.writeRequestEntity(new CommittingOutputStream(baos) {
                    @Override
                    protected void commit() throws IOException {
                        writeOutBoundHeaders(clientRequest.getHeaders(), boundRequestBuilder);
                    }
                });
            } catch (IOException ex) {
                throw new ClientHandlerException(ex);
            }

            boundRequestBuilder.setBody(new ByteArrayInputStream(baos.toByteArray()));

        }
    } else {
        writeOutBoundHeaders(clientRequest.getHeaders(), boundRequestBuilder);
    }
    try {
        StopWatch stopWatch = new StopWatch();
        stopWatch.reset();
        stopWatch.start();
        Future<Response> futureResponse = boundRequestBuilder.execute();
        Response response = futureResponse.get();
        int httpReturnCode = response.getStatusCode();
        stopWatch.stop();
        log.info("time to call rest url " + clientRequest.getURI() + ", " + stopWatch.getTime() + " ms");
        // in case of empty content returned we returned an empty stream
        // to return a null object
        if (httpReturnCode == Status.NO_CONTENT.getStatusCode()) {
            new ClientResponse(httpReturnCode, getInBoundHeaders(response), IOUtils.toInputStream(""),
                    getMessageBodyWorkers());
        }
        return new ClientResponse(httpReturnCode, getInBoundHeaders(response),
                response.getResponseBodyAsStream() == null ? IOUtils.toInputStream("")
                        : response.getResponseBodyAsStream(),
                getMessageBodyWorkers());
    } catch (Exception e) {
        if (e.getCause() != null && (e.getCause() instanceof TimeoutException)) {
            throw new ClientHandlerException(new SocketTimeoutException());
        }
        throw new ClientHandlerException(e);
    }
}

From source file:edu.ucsb.eucalyptus.cloud.cluster.VmInstance.java

public VmInstance() {
    this.launchTime = new Date();
    this.state = VmState.PENDING;
    this.networkConfig = new NetworkConfigType();
    this.stopWatch = new StopWatch();
    this.stopWatch.start();
    this.consoleOutput = new StringBuffer();
    this.volumes = new ArrayList<AttachedVolume>();
}

From source file:edu.internet2.middleware.changelogconsumer.googleapps.GoogleAppsFullSync.java

/**
 * Runs a fullSync./*from www. ja v a  2  s .c om*/
 * @param dryRun indicates that this is dryRun
 */
public void process(boolean dryRun) {

    synchronized (fullSyncIsRunningLock) {
        fullSyncIsRunning.put(consumerName, Boolean.toString(true));
    }

    connector = new GoogleGrouperConnector();

    //Start with a clean cache
    GoogleCacheManager.googleGroups().clear();
    GoogleCacheManager.googleGroups().clear();

    properties = new GoogleAppsSyncProperties(consumerName);

    Pattern googleGroupFilter = Pattern.compile(properties.getGoogleGroupFilter());

    try {
        connector.initialize(consumerName, properties);

        if (properties.getprefillGoogleCachesForFullSync()) {
            connector.populateGoogleCache();
        }

    } catch (GeneralSecurityException e) {
        LOG.error("Google Apps Consume '{}' Full Sync - This consumer failed to initialize: {}", consumerName,
                e.getMessage());
    } catch (IOException e) {
        LOG.error("Google Apps Consume '{}' Full Sync - This consumer failed to initialize: {}", consumerName,
                e.getMessage());
    }

    GrouperSession grouperSession = null;

    try {
        grouperSession = GrouperSession.startRootSession();
        connector.getGoogleSyncAttribute();
        connector.cacheSyncedGroupsAndStems(true);

        // time context processing
        final StopWatch stopWatch = new StopWatch();
        stopWatch.start();

        //Populate a normalized list (google naming) of Grouper groups
        ArrayList<ComparableGroupItem> grouperGroups = new ArrayList<ComparableGroupItem>();
        for (String groupKey : connector.getSyncedGroupsAndStems().keySet()) {
            if (connector.getSyncedGroupsAndStems().get(groupKey).equalsIgnoreCase("yes")) {
                edu.internet2.middleware.grouper.Group group = connector.fetchGrouperGroup(groupKey);

                if (group != null) {
                    grouperGroups.add(new ComparableGroupItem(
                            connector.getAddressFormatter().qualifyGroupAddress(group.getName()), group));
                }
            }
        }

        //Populate a comparable list of Google groups
        ArrayList<ComparableGroupItem> googleGroups = new ArrayList<ComparableGroupItem>();
        for (String groupName : GoogleCacheManager.googleGroups().getKeySet()) {
            if (googleGroupFilter.matcher(groupName.replace("@" + properties.getGoogleDomain(), "")).find()) {
                googleGroups.add(new ComparableGroupItem(groupName));
                LOG.debug("Google Apps Consumer '{}' Full Sync - {} group matches group filter: included",
                        consumerName, groupName);
            } else {
                LOG.debug("Google Apps Consumer '{}' Full Sync - {} group does not match group filter: ignored",
                        consumerName, groupName);
            }
        }

        //Get our sets
        Collection<ComparableGroupItem> extraGroups = CollectionUtils.subtract(googleGroups, grouperGroups);
        processExtraGroups(dryRun, extraGroups);

        Collection<ComparableGroupItem> missingGroups = CollectionUtils.subtract(grouperGroups, googleGroups);
        processMissingGroups(dryRun, missingGroups);

        Collection<ComparableGroupItem> matchedGroups = CollectionUtils.intersection(grouperGroups,
                googleGroups);
        processMatchedGroups(dryRun, matchedGroups);

        // stop the timer and log
        stopWatch.stop();
        LOG.debug("Google Apps Consumer '{}' Full Sync - Processed, Elapsed time {}",
                new Object[] { consumerName, stopWatch });

    } finally {
        GrouperSession.stopQuietly(grouperSession);

        synchronized (fullSyncIsRunningLock) {
            fullSyncIsRunning.put(consumerName, Boolean.toString(true));
        }
    }

}

From source file:com.continuuity.weave.yarn.YarnWeaveController.java

@Override
protected void doShutDown() {
    if (processController == null) {
        LOG.warn("No process controller for application that is not submitted.");
        return;//from   w ww.  j  av a 2s.c om
    }

    // Wait for the stop message being processed
    try {
        Uninterruptibles.getUninterruptibly(getStopMessageFuture(), Constants.APPLICATION_MAX_STOP_SECONDS,
                TimeUnit.SECONDS);
    } catch (Exception e) {
        LOG.error("Failed to wait for stop message being processed.", e);
        // Kill the application through yarn
        kill();
    }

    // Poll application status from yarn
    try {
        StopWatch stopWatch = new StopWatch();
        stopWatch.start();
        stopWatch.split();
        long maxTime = TimeUnit.MILLISECONDS.convert(Constants.APPLICATION_MAX_STOP_SECONDS, TimeUnit.SECONDS);

        YarnApplicationReport report = processController.getReport();
        FinalApplicationStatus finalStatus = report.getFinalApplicationStatus();
        while (finalStatus == FinalApplicationStatus.UNDEFINED && stopWatch.getSplitTime() < maxTime) {
            LOG.debug("Yarn application final status for {} {}", report.getApplicationId(), finalStatus);
            TimeUnit.SECONDS.sleep(1);
            stopWatch.split();
            finalStatus = processController.getReport().getFinalApplicationStatus();
        }
        LOG.debug("Yarn application final status is {}", finalStatus);

        // Application not finished after max stop time, kill the application
        if (finalStatus == FinalApplicationStatus.UNDEFINED) {
            kill();
        }
    } catch (Exception e) {
        LOG.warn("Exception while waiting for application report: {}", e.getMessage(), e);
        kill();
    }

    super.doShutDown();
}

From source file:com.google.code.jerseyclients.httpclientfour.ApacheHttpClientFourHandler.java

public ClientResponse handle(final ClientRequest clientRequest) throws ClientHandlerException {

    if (this.jerseyHttpClientConfig.getApplicationCode() != null) {
        clientRequest.getHeaders().add(this.jerseyHttpClientConfig.getApplicationCodeHeader(),
                this.jerseyHttpClientConfig.getApplicationCode());
    }//from  ww w . ja v a2s.c  om
    if (this.jerseyHttpClientConfig.getOptionnalHeaders() != null) {
        for (Entry<String, String> entry : this.jerseyHttpClientConfig.getOptionnalHeaders().entrySet()) {
            clientRequest.getHeaders().add(entry.getKey(), entry.getValue());
        }
    }
    // final Map<String, Object> props = cr.getProperties();

    final HttpRequestBase method = getHttpMethod(clientRequest);

    // Set the read timeout
    final Integer readTimeout = jerseyHttpClientConfig.getReadTimeOut();
    if (readTimeout != null) {
        HttpConnectionParams.setSoTimeout(method.getParams(), readTimeout.intValue());
    }

    // FIXME penser au header http
    // DEBUG|wire.header|>> "Cache-Control: no-cache[\r][\n]"
    // DEBUG|wire.header|>> "Pragma: no-cache[\r][\n]"
    if (method instanceof HttpEntityEnclosingRequestBase) {
        final HttpEntityEnclosingRequestBase entMethod = (HttpEntityEnclosingRequestBase) method;

        if (clientRequest.getEntity() != null) {
            final RequestEntityWriter re = getRequestEntityWriter(clientRequest);

            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            try {
                re.writeRequestEntity(new CommittingOutputStream(baos) {
                    @Override
                    protected void commit() throws IOException {
                        writeOutBoundHeaders(clientRequest.getHeaders(), method);
                    }
                });
            } catch (IOException ex) {
                throw new ClientHandlerException(ex);
            }

            final byte[] content = baos.toByteArray();
            HttpEntity httpEntity = new ByteArrayEntity(content);
            entMethod.setEntity(httpEntity);

        }
    } else {
        writeOutBoundHeaders(clientRequest.getHeaders(), method);
    }

    try {
        StopWatch stopWatch = new StopWatch();
        stopWatch.reset();
        stopWatch.start();
        HttpResponse httpResponse = client.execute(method);
        int httpReturnCode = httpResponse.getStatusLine().getStatusCode();
        stopWatch.stop();
        log.info("time to call rest url " + clientRequest.getURI() + ", " + stopWatch.getTime() + " ms");

        if (httpReturnCode == Status.NO_CONTENT.getStatusCode()) {
            return new ClientResponse(httpReturnCode, getInBoundHeaders(httpResponse),
                    IOUtils.toInputStream(""), getMessageBodyWorkers());
        }

        return new ClientResponse(httpReturnCode, getInBoundHeaders(httpResponse),
                httpResponse.getEntity() == null ? IOUtils.toInputStream("")
                        : httpResponse.getEntity().getContent(),
                getMessageBodyWorkers());
    } catch (Exception e) {
        throw new ClientHandlerException(e);
    }
}

From source file:com.mothsoft.alexis.engine.predictive.OpenNLPMaxentModelExecutorTask.java

private boolean doExecute(final Model model) {
    final StopWatch stopWatch = new StopWatch();
    stopWatch.start();/* w  w w  .j ava  2s. c  o m*/

    boolean result = false;

    try {
        logger.info(String.format("Executing model %d", model.getId()));

        // load model file
        final File userDirectory = new File(baseDirectory, "" + model.getUserId());
        final File modelFile = new File(userDirectory, model.getId() + BIN_GZ_EXT);
        final AbstractModel maxentModel = new SuffixSensitiveGISModelReader(modelFile).getModel();

        final Date now = new Date();
        final TimeUnits timeUnits = model.getTimeUnits();
        final Timestamp topOfPeriod = new Timestamp(TimeUnits.floor(now, timeUnits).getTime());
        final Timestamp endOfPeriod = new Timestamp(topOfPeriod.getTime() + timeUnits.getDuration() - 1);

        // first position: sum of changes predicted, second position: number
        // of samples--will calculate a boring old mean...
        final double[][] changeByPeriod = new double[model.getLookahead()][2];

        // initialize
        for (int i = 0; i < changeByPeriod.length; i++) {
            changeByPeriod[i][0] = 0.0d;
            changeByPeriod[i][1] = 0.0d;
        }

        // find the most recent point value
        // FIXME - some sparse data sets may require executing the model on
        // all documents since that point or applying some sort of
        // dead-reckoning logic for smoothing
        final DataSetPoint initial = this.dataSetPointDao.findLastPointBefore(model.getTrainingDataSet(),
                endOfPeriod);

        // let's get the corner cases out of the way
        if (initial == null) {
            logger.warn("Insufficient data to execute model!");
            return false;
        }

        // happy path
        // build consolidated context of events in this period
        // find current value of training data set for this period
        final double[] probs = eval(model, topOfPeriod, endOfPeriod, maxentModel);

        // predict from the last available point, adjusted for time
        // remaining in period
        final double y0 = initial.getY();

        // map outcomes to periods in the future (at least no earlier than
        // this period)
        for (int i = 0; i < probs.length; i++) {
            // in the form +nU:+/-x, where n is the number of periods, U is
            // the unit type for the period, +/- is the direction, and x is
            // a discrete value from Model.OUTCOME_ARRAY
            final String outcome = maxentModel.getOutcome(i);

            final Matcher matcher = OUTCOME_PATTERN.matcher(outcome);

            if (!matcher.matches()) {
                logger.warn("Can't process outcome: " + outcome + "; skipping");
                continue;
            }

            final int period = Integer.valueOf(matcher.group(1));
            final String units = matcher.group(2);
            final double percentChange = Double.valueOf(matcher.group(3));

            // record the observation and the count of observations
            changeByPeriod[period][0] += percentChange;
            changeByPeriod[period][1] += 1.0d;

            if (logger.isDebugEnabled()) {
                final double yi = y0 * (1 + percentChange);
                logger.debug(String.format("Outcome: %s, %s: +%d, change: %f, new value: %f, probability: %f",
                        outcome, units, period, percentChange, yi, probs[i]));
            }
        }

        // build points for predictive data set
        double yn = y0;

        // we need to track the points and remove any that were not
        // predicted by this execution of the model
        final Timestamp endOfPredictionRange = new Timestamp(
                topOfPeriod.getTime() + (changeByPeriod.length * timeUnits.getDuration()));
        final List<DataSetPoint> existingPoints = this.dataSetPointDao
                .findByTimeRange(model.getPredictionDataSet(), topOfPeriod, endOfPredictionRange);

        for (int period = 0; period < changeByPeriod.length; period++) {
            final double totalPercentChange = changeByPeriod[period][0];
            final double sampleCount = changeByPeriod[period][1];
            double percentChange;

            if (totalPercentChange == 0.0d || sampleCount == 0.0d) {
                percentChange = 0.0d;
            } else {
                percentChange = totalPercentChange / sampleCount;
            }

            // apply adjustments only if the initial point is within the
            // time period, and only for the first time period
            boolean applyAdjustment = period == 0 && topOfPeriod.before(initial.getX());

            if (applyAdjustment) {
                final double adjustmentFactor = findAdjustmentFactor(initial.getX(), timeUnits);
                percentChange = (totalPercentChange / sampleCount) * adjustmentFactor;
            }

            // figure out the next value and coerce to a sane number of
            // decimal places (2);
            final double newValue = (double) Math.round(yn * (1.0d + percentChange) * 100) / 100;

            final Timestamp timestamp = new Timestamp(
                    topOfPeriod.getTime() + (period * timeUnits.getDuration()));

            if (logger.isDebugEnabled()) {
                logger.debug(String.format("Model %d for data set %d predicted point: (%s, %f)", model.getId(),
                        model.getTrainingDataSet().getId(), DateFormat.getInstance().format(timestamp),
                        newValue));
            }

            DataSetPoint ithPoint = this.dataSetPointDao.findByTimestamp(model.getPredictionDataSet(),
                    timestamp);

            // conditionally create
            if (ithPoint == null) {
                ithPoint = new DataSetPoint(model.getPredictionDataSet(), timestamp, newValue);
                this.dataSetPointDao.add(ithPoint);
            } else {
                // or update
                ithPoint.setY(newValue);

                // updated points retained, other existing removed
                existingPoints.remove(ithPoint);
            }

            // store current and use as starting point for next iteration
            yn = newValue;
        }

        // remove stale points from an old model execution
        for (final DataSetPoint toRemove : existingPoints) {
            this.dataSetPointDao.remove(toRemove);
        }

        result = true;

    } catch (final Exception e) {
        logger.warn("Model " + model.getId() + " failed with: " + e, e);
        result = false;
    } finally {
        stopWatch.stop();
        logger.info(String.format("Executing model %d took %s", model.getId(), stopWatch.toString()));
    }

    return result;
}

From source file:net.nan21.dnet.core.web.controller.data.AbstractDsRpcController.java

/**
 * Default handler for remote procedure call on a list of value-objects.
 * Contributed by Jan Fockaert//from   w  w w. j  a  v a 2s.c  o  m
 * 
 * @param resourceName
 * @param dataFormat
 * @param rpcName
 * @param dataString
 * @param paramString
 * @param request
 * @param response
 * @return
 * @throws Exception
 */
@RequestMapping(params = { Constants.REQUEST_PARAM_ACTION + "=" + Constants.DS_ACTION_RPC,
        Constants.DS_ACTION_RPC + "Type=dataList" })
@ResponseBody
public String rpcDataList(@PathVariable String resourceName, @PathVariable String dataFormat,
        @RequestParam(value = Constants.REQUEST_PARAM_SERVICE_NAME_PARAM, required = true) String rpcName,
        @RequestParam(value = Constants.REQUEST_PARAM_DATA, required = false, defaultValue = "{}") String dataString,
        @RequestParam(value = Constants.REQUEST_PARAM_PARAMS, required = false, defaultValue = "{}") String paramString,
        HttpServletRequest request, HttpServletResponse response) throws Exception {

    try {
        StopWatch stopWatch = new StopWatch();
        stopWatch.start();

        if (logger.isInfoEnabled()) {
            logger.info("Processing request: {}.{} -> action = {}-dataList / {}",
                    new String[] { resourceName, dataFormat, Constants.DS_ACTION_RPC, rpcName });
        }

        if (logger.isDebugEnabled()) {

            logger.debug("  --> request-dataList: {} ", new String[] { dataString });
            logger.debug("  --> request-params: {} ", new String[] { paramString });
        }
        this.prepareRequest(request, response);

        this.authorizeDsAction(resourceName, Constants.DS_ACTION_RPC, rpcName);

        if (dataFormat.equals("stream")) {
            IDsService<M, F, P> service = this.findDsService(resourceName);
            IDsMarshaller<M, F, P> marshaller = service.createMarshaller("json");

            List<M> list = marshaller.readListFromString(dataString);
            P params = marshaller.readParamsFromString(paramString);

            InputStream s = service.rpcDataStream(rpcName, list, params);
            this.sendFile(s, response.getOutputStream());
            return "";
        } else {
            IDsService<M, F, P> service = this.findDsService(resourceName);
            IDsMarshaller<M, F, P> marshaller = service.createMarshaller(dataFormat);

            List<M> list = marshaller.readListFromString(dataString);
            P params = marshaller.readParamsFromString(paramString);

            service.rpcData(rpcName, list, params);
            IActionResultSave result = this.packRpcDataListResult(list, params);
            stopWatch.stop();
            result.setExecutionTime(stopWatch.getTime());
            return marshaller.writeResultToString(result);
        }

    } catch (Exception e) {
        return this.handleException(e, response);
    } finally {
        this.finishRequest();
    }
}