当前位置: 首页>>代码示例>>Java>>正文


Java StopWatch.getTime方法代码示例

本文整理汇总了Java中org.apache.commons.lang.time.StopWatch.getTime方法的典型用法代码示例。如果您正苦于以下问题:Java StopWatch.getTime方法的具体用法?Java StopWatch.getTime怎么用?Java StopWatch.getTime使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.lang.time.StopWatch的用法示例。


在下文中一共展示了StopWatch.getTime方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: get

import org.apache.commons.lang.time.StopWatch; //导入方法依赖的package包/类
private <T> T get(final String url, final java.lang.Class<T> tClass, final Object... uriVariables) {
    setErrorHandler();
    StopWatch watch = new StopWatch();
    watch.start();
    // T object = restTemplate.getForObject(url, tClass, uriVariables);

    ResponseEntity<T> response = restTemplate.getForEntity(url, tClass, uriVariables);
    HttpHeaders headers = response.getHeaders();

    List<String> cookies = headers.get("Set-Cookie");
    if (cookies != null && cookies.size() > 0) {
        for (String cookie : cookies) {
            if (cookie.substring(0, cookie.indexOf("=")).equals(LoomClient.SESSION_COOKIE)) {
                sessionId = cookie.substring(cookie.indexOf("=") + 1, cookie.indexOf(";"));
                if (sessionId.equals("")) {
                    sessionId = null;
                }
                break;
            }
        }
    }

    watch.stop();
    if (log.isTraceEnabled()) {
        String args = "";
        for (Object arg : uriVariables) {
            args += " " + arg;
        }
        if (watch.getTime() > timewarning) {
            log.trace("GET " + url + " " + args + " WARNING: Operation took " + watch);
        } else {
            log.trace("GET " + url + " " + args + " Operation took " + watch);
        }
    }

    return response.getBody();
    // return object;
}
 
开发者ID:HewlettPackard,项目名称:loom,代码行数:39,代码来源:RestClient.java

示例2: perform

import org.apache.commons.lang.time.StopWatch; //导入方法依赖的package包/类
private <T> T perform(MockHttpServletRequestBuilder requestBuilder, String bodyStr, final java.lang.Class<T> tClass,
        final boolean noSession) throws Exception {
    if (bodyStr == null) {
        bodyStr = "";
    }
    requestBuilder = requestBuilder.content(bodyStr);

    if (noSession) {
        requestBuilder = requestBuilder.cookie(new Cookie(LoomClient.SESSION_COOKIE, ""));
    } else {
        if (sessionId != null) {
            requestBuilder = requestBuilder.cookie(new Cookie(LoomClient.SESSION_COOKIE, sessionId));
        }
    }


    StopWatch watch = new StopWatch();
    watch.start();
    MvcResult result = tClass == null
            ? mockMvc.perform(requestBuilder).andExpect(status().isOk()).andDo(PrintHandler.print()).andReturn()
            : mockMvc.perform(requestBuilder)
                    // .andExpect(status().isOk())
                    // .andExpect(content().contentType(MediaType.APPLICATION_JSON))
                    .andDo(PrintHandler.print()).andReturn();

    if (result.getResponse().getStatus() == 200) {
        T resource = tClass == null ? null : new ObjectMapper().readValue(checkResult(result), tClass);

        watch.stop();
        if (LOG.isTraceEnabled()) {
            String uri = result.getRequest().getRequestURI();
            String method = result.getRequest().getMethod();
            if (watch.getTime() > timeWarning) {
                bodyStr += " WARNING:";
            }
            LOG.trace(method + " " + uri + " " + bodyStr + " Operation took " + watch);
        }

        Cookie[] c = result.getResponse().getCookies();
        Cookie loomCookie = null;
        for (Cookie element : c) {
            if (element.getName().equals(LoomClient.SESSION_COOKIE)) {
                loomCookie = element;
            }
        }

        if (loomCookie != null) {
            if (loomCookie.getMaxAge() != 0) {
                sessionId = loomCookie.getValue();
            } else {
                sessionId = null;
            }
        } // TODO: LOOM-622 work around for cookie issue
        return resource;
    } else {
        System.out.println(result);
        System.out.println(result.getResponse().getStatus());
        System.out.println(result.getResponse().getContentAsString());
        throw new LoomClientException("", result.getResponse().getStatus());
    }
}
 
开发者ID:HewlettPackard,项目名称:loom,代码行数:62,代码来源:LoomMvcClient.java


注:本文中的org.apache.commons.lang.time.StopWatch.getTime方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。