List of usage examples for org.springframework.util StopWatch StopWatch
public StopWatch(String id)
From source file:ru.anr.cmdline.base.BootstrapImpl.java
/** * {@inheritDoc}// w w w . j a v a 2 s . c om */ @Override @Transactional(propagation = Propagation.REQUIRED) public ExitShellRequest run() { StopWatch sw = new StopWatch("Shell Watch"); sw.start(); String[] commandsToExecuteAndThenQuit = commandLine.getShellCommandsToExecute(); // The shell is used JLineShellComponent shell = context.getBean("shell", JLineShellComponent.class); ExitShellRequest exitShellRequest; if (null == commandsToExecuteAndThenQuit) { shell.start(); shell.promptLoop(); exitShellRequest = shell.getExitShellRequest(); if (exitShellRequest == null) { // shouldn't really happen, but we'll fallback to this anyway exitShellRequest = ExitShellRequest.NORMAL_EXIT; } shell.waitForComplete(); } else { boolean successful = false; exitShellRequest = ExitShellRequest.FATAL_EXIT; for (String cmd : commandsToExecuteAndThenQuit) { successful = shell.executeCommand(cmd).isSuccess(); if (!successful) { break; } } // if all commands were successful, set the normal exit status if (successful) { exitShellRequest = ExitShellRequest.NORMAL_EXIT; } } sw.stop(); if (shell.isDevelopmentMode()) { logger.info("Total execution time: {} ms", sw.getLastTaskTimeMillis()); } return exitShellRequest; }
From source file:my.adam.smo.client.SocketClient.java
@Override public RpcChannel connect(final InetSocketAddress sa) { RpcChannel rpcChannel = new RpcChannel() { private Channel c = bootstrap.connect(sa).awaitUninterruptibly().getChannel(); @Override/*from w ww . j av a2 s .c om*/ public void callMethod(Descriptors.MethodDescriptor method, RpcController controller, Message request, Message responsePrototype, RpcCallback<Message> done) { StopWatch stopWatch = new StopWatch("callMethod"); stopWatch.start(); long id = seqNum.addAndGet(1); logger.trace("calling method: " + method.getFullName()); //infinit reconnection loop while (reconnect && !c.isOpen()) { logger.debug("channel closed " + sa); logger.debug("trying to reconnect"); c.disconnect().awaitUninterruptibly(); c.unbind().awaitUninterruptibly(); c = bootstrap.connect(sa).awaitUninterruptibly().getChannel(); try { Thread.sleep(reconnect_delay * 1000); } catch (InterruptedException e) { logger.error("error while sleeping", e); } } RPCommunication.Request protoRequest = RPCommunication.Request.newBuilder() .setServiceName(method.getService().getFullName()).setMethodName(method.getName()) .setMethodArgument(request.toByteString()).setRequestId(id).build(); logger.trace("request built: " + request.toString()); if (enableSymmetricEncryption) { protoRequest = getEncryptedRequest(protoRequest); logger.trace("symmetric encryption enabled, encrypted request: " + protoRequest.toString()); } if (enableAsymmetricEncryption) { protoRequest = getAsymEncryptedRequest(protoRequest); logger.trace("asymmetric encryption enabled, encrypted request: " + protoRequest.toString()); } callbackMap.put(id, done); descriptorProtoMap.put(id, responsePrototype); c.write(protoRequest); logger.trace("request sent: " + protoRequest.toString()); stopWatch.stop(); logger.trace(stopWatch.shortSummary()); } }; logger.trace("connected to address: " + sa.toString()); return rpcChannel; }
From source file:my.adam.smo.client.HTTPClient.java
@Override public RpcChannel connect(final InetSocketAddress sa) { RpcChannel rpcChannel = new RpcChannel() { private Channel c = bootstrap.connect(sa).awaitUninterruptibly().getChannel(); @Override/* w ww.ja va 2 s .c o m*/ public void callMethod(Descriptors.MethodDescriptor method, RpcController controller, Message request, Message responsePrototype, RpcCallback<Message> done) { StopWatch stopWatch = new StopWatch("callMethod"); stopWatch.start(); long id = seqNum.addAndGet(1); logger.trace("calling method: " + method.getFullName()); HttpRequest httpRequest = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "http://" + sa.getHostName() + ":" + sa.getPort()); httpRequest.setHeader(HttpHeaders.Names.CONNECTION, HttpHeaders.Values.CLOSE); httpRequest.setHeader(HttpHeaders.Names.ACCEPT_ENCODING, HttpHeaders.Values.GZIP); httpRequest.setHeader(HttpHeaders.Names.CONTENT_TYPE, HttpHeaders.Values.APPLICATION_X_WWW_FORM_URLENCODED); RPCommunication.Request protoRequest = RPCommunication.Request.newBuilder() .setServiceName(method.getService().getFullName()).setMethodName(method.getName()) .setMethodArgument(request.toByteString()).setRequestId(id).build(); logger.trace("request built: " + request.toString()); if (enableSymmetricEncryption) { protoRequest = getEncryptedRequest(protoRequest); logger.trace("symmetric encryption enabled, encrypted request: " + protoRequest.toString()); } if (enableAsymmetricEncryption) { protoRequest = getAsymEncryptedRequest(protoRequest); logger.trace("asymmetric encryption enabled, encrypted request: " + protoRequest.toString()); } byte[] arr = protoRequest.toByteArray(); ChannelBuffer s = Base64.encode(ChannelBuffers.copiedBuffer(arr), Base64Dialect.STANDARD); httpRequest.setContent(s); httpRequest.addHeader(HttpHeaders.Names.CONTENT_LENGTH, s.readableBytes()); httpRequest.setChunked(false); callbackMap.put(id, done); descriptorProtoMap.put(id, responsePrototype); c.write(httpRequest); logger.trace("request sent: " + protoRequest.toString()); stopWatch.stop(); logger.trace(stopWatch.shortSummary()); } }; logger.trace("connected to address: " + sa.toString()); return rpcChannel; }
From source file:org.dd4t.core.factories.impl.SimpleBinaryFactory.java
private SimpleBinary getBinaryFromUri(String uri, RequestContext context) throws ItemNotFoundException, NotAuthorizedException, ParseException, StorageException, NotAuthenticatedException { StopWatch stopWatch = null;//from www .ja v a2 s . c o m if (logger.isDebugEnabled()) { logger.debug("Enter getBinaryFromUri with uri: " + uri); stopWatch = new StopWatch("getBinaryFromUri"); stopWatch.start(); } SimpleBinaryImpl simpleBinary; // retrieve the SimpleComponent for this mm component ComponentFactory compFactory = new SimpleComponentFactory(); // make sure there are no filters set, we need only the simple component // factory logic itself! compFactory.setFilters(new LinkedList<Filter>()); Component mmComp = compFactory.getComponent(uri, context); simpleBinary = new SimpleBinaryImpl(); simpleBinary.setNativeMetadata(mmComp.getNativeMetadata()); simpleBinary.setFactory(this); simpleBinary.setId(TridionUtils.createUri(mmComp.getNativeMetadata()).toString()); simpleBinary.setTitle(mmComp.getNativeMetadata().getTitle()); try { doFilters(simpleBinary, context, null); } catch (FilterException e) { logger.warn("Error in filter. ", e); throw new RuntimeException(e); } finally { if (logger.isDebugEnabled()) { stopWatch.stop(); logger.debug("Exit getBinaryFromUri (" + stopWatch.getTotalTimeMillis() + " ms)"); } } return simpleBinary; }
From source file:org.dd4t.core.factories.impl.SimplePageFactory.java
private Page getSimplePage(String uri, RequestContext context) throws ItemNotFoundException, NotAuthorizedException, NotAuthenticatedException { if (context == null && securityFilterPresent()) { throw new RuntimeException("use of getPage is not allowed when a SecurityFilter is set"); }// www . j a v a 2 s . co m StopWatch stopWatch = null; if (logger.isDebugEnabled()) { logger.debug("Enter getSimplePage with uri: " + uri); stopWatch = new StopWatch("getSimplePage"); stopWatch.start(); } PageMeta pageMeta = null; Page page = null; try { TCMURI tcmUri = new TCMURI(uri); pageMeta = brokerPageProvider.getPageMetaById(tcmUri.getPublicationId(), tcmUri.getItemId()); page = (Page) getPageFromMeta(pageMeta); try { // run all filters regardless if they are allowed to be cached // or not doFilters(page, context, BaseFilter.RunPhase.Both); } catch (FilterException e) { logger.error("Error in filter. ", e); throw new RuntimeException(e); } } catch (ParseException e) { logger.error("Parse exception when searching for page: " + uri, e); throw new RuntimeException(e); } catch (StorageException e) { logger.error("Storage exception when searching for page: " + uri, e); throw new RuntimeException(e); } if (logger.isDebugEnabled()) { stopWatch.stop(); logger.debug("Exit getSimplePage (" + stopWatch.getTotalTimeMillis() + " ms)"); } return page; }
From source file:org.dd4t.core.factories.impl.GenericPageFactory.java
/** * This is just a intermediate method to avoid naming conflicts with the * simpleFactory./* w ww . j av a 2s .c o m*/ * @throws NotAuthenticatedException */ private GenericPage findGenericPageByUrl(String url, int publicationId, RequestContext context) throws ItemNotFoundException, NotAuthorizedException, NotAuthenticatedException { if (context == null && securityFilterPresent()) { throw new RuntimeException("use of findPageByUrl is not allowed when a SecurityFilter is set"); } StopWatch stopWatch = null; StopWatch subWatch = null; if (logger.isDebugEnabled()) { logger.debug("Enter findGenericPageByUrl with url:" + url + " and publicationId: " + publicationId); stopWatch = new StopWatch("findGenericPageByUrl"); stopWatch.start(); subWatch = new StopWatch("subTasks"); subWatch.start(); } String cacheKey = publicationId + "-" + url; GenericPage page = (GenericPage) getCacheProvider().loadFromLocalCache(cacheKey); if (page == null) { try { PageMeta pageMeta = getPageProvider().getPageMetaByURL(url, publicationId); page = getPageFromMeta(pageMeta); try { // run only the filters where the result is allowed to be // cached. doFilters(page, context, BaseFilter.RunPhase.BeforeCaching); } catch (FilterException e) { logger.warn("Error in filter. ", e); throw new RuntimeException(e); } getCacheProvider().storeInItemCache(cacheKey, page, pageMeta.getPublicationId(), pageMeta.getItemId()); } catch (IOException e) { logger.error("IOException when processing page: " + url, e); throw new RuntimeException(e); } catch (StorageException e) { logger.error("StorageException when searching for page: " + url, e); throw new RuntimeException(e); } } if (logger.isDebugEnabled()) { subWatch.stop(); logger.debug("Page retrieved in " + subWatch.getTotalTimeMillis() + " ms)"); subWatch = new StopWatch("again"); subWatch.start(); } try { // run only the filters where the result is not allowed to be // cached. doFilters(page, context, BaseFilter.RunPhase.AfterCaching); } catch (FilterException e) { logger.error("Error in filter. ", e); throw new RuntimeException(e); } finally { if (logger.isDebugEnabled()) { subWatch.stop(); logger.debug("Ran filters in " + subWatch.getTotalTimeMillis() + " ms)"); stopWatch.stop(); logger.debug( "Exit findGenericPageByUrl for " + url + " (" + stopWatch.getTotalTimeMillis() + " ms)"); } } return page; }
From source file:org.dd4t.core.factories.impl.GenericComponentFactory.java
/** * Get the component by the component uri and template uri. * //w w w . jav a2 s . c o m * @return the component * @throws ItemNotFoundException * if no item found NotAuthorizedException if the user is not * authorized to get the component * @throws NotAuthenticatedException */ public DynamicComponent getComponent(String componentUri, String componentTemplateUri, RequestContext context) throws ItemNotFoundException, NotAuthorizedException, NotAuthenticatedException { if (context == null && securityFilterPresent()) { throw new RuntimeException( "use of getComponent without a context is not allowed when a SecurityFilter is set"); } if (!componentUri.endsWith("-16")) { componentUri += "-16"; } StopWatch stopWatch = null; if (logger.isDebugEnabled()) { logger.debug("Enter getComponent with uri: " + componentUri); stopWatch = new StopWatch("getComponent"); stopWatch.start(); } DynamicComponent component = (DynamicComponent) getCacheProvider().loadFromLocalCache(componentUri); if (component == null) { TCMURI tcmUri; ComponentMeta componentMeta; com.tridion.dcp.ComponentPresentation dcp; try { tcmUri = new TCMURI(componentUri); componentMeta = getComponentProvider().getComponentMeta(tcmUri.getItemId(), tcmUri.getPublicationId()); if (componentMeta == null) { throw new ItemNotFoundException("Unable to find item with id " + componentUri + " in the broker. Is the item published?"); } if (componentTemplateUri != null) { TCMURI ctUri = new TCMURI(componentTemplateUri); dcp = getComponentProvider().getDynamicComponentPresentation(tcmUri.getItemId(), ctUri.getItemId(), tcmUri.getPublicationId()); } else { dcp = getComponentProvider().getDynamicComponentPresentation(tcmUri.getItemId(), 0, tcmUri.getPublicationId()); } } catch (ParseException e1) { logger.error("No item found with uri: " + componentUri + "; could not parse the URI: " + e1); throw new ItemNotFoundException( "No item found with uri: " + componentUri + "; could not parse the URI: " + e1); } catch (StorageException e2) { logger.error("No item found with uri: " + componentUri + "; broker is down."); throw new ItemNotFoundException("No item found with uri: " + componentUri + "; broker is down."); } if (dcp.getContent() == null) { logger.error( "Source is null for item: " + componentUri + " and templateUri: " + componentTemplateUri); throw new ItemNotFoundException( "No item found with uri: " + componentUri + " and templateUri: " + componentTemplateUri); } try { component = getDCPFromSource(dcp); component.setNativeMetadata(componentMeta); // Rogier Oudshoorn, 7/2/2012 // object size is roughly half the xml string size; ((BasePublishedItem) component).setSourceSize(dcp.getContent().length()); try { doFilters(component, context, BaseFilter.RunPhase.BeforeCaching); } catch (FilterException e) { logger.error("Error in filter. ", e); throw new RuntimeException(e); } getCacheProvider().storeInItemCache(componentUri, component, component.getNativeMetadata().getPublicationId(), component.getNativeMetadata().getItemId()); } catch (Exception e) { logger.error("error when deserializing component", e); throw new RuntimeException(e); } } try { doFilters(component, context, BaseFilter.RunPhase.AfterCaching); } catch (FilterException e) { logger.error("Error in filter. ", e); throw new RuntimeException(e); } if (logger.isDebugEnabled()) { stopWatch.stop(); logger.debug("Exit getComponent (" + stopWatch.getTotalTimeMillis() + " ms)"); } return component; }
From source file:org.dd4t.core.factories.impl.SimpleBinaryFactory.java
/** * Returns a BinaryMeta object or throws ItemNotFoundException if not found. * //from ww w.java2 s . com * @param pubId * @param url * @return * @throws ItemNotFoundException * @throws StorageException */ private BinaryVariant getBinaryVariantByUrl(int pubId, String url) throws ItemNotFoundException, StorageException { StopWatch stopWatch = null; if (logger.isDebugEnabled()) { logger.debug("Enter getBinaryMetaByUrl with url: " + url + " and publicationId: " + pubId); stopWatch = new StopWatch("getBinaryMetaByUrl"); stopWatch.start(); } BinaryVariantDAO binaryVariantDAO = HomeUtils.getInstance().getBinaryVariantDao(pubId); BinaryVariant binaryVariant = null; try { binaryVariant = binaryVariantDAO.findByURL(pubId, url); if (binaryVariant == null) { if (logger.isDebugEnabled()) { logger.debug("Cannot find BinaryVariant in Tridion."); } throw new ItemNotFoundException("No binary found with url :" + url); } if (logger.isDebugEnabled()) { logger.debug("Returning BinaryMeta " + binaryVariant); } } catch (StorageException e) { logger.error("StorageException caught throw runtime exception"); throw new RuntimeException(e); } finally { if (logger.isDebugEnabled()) { stopWatch.stop(); logger.debug("Exit getBinaryMetaByUrl (" + stopWatch.getTotalTimeMillis() + " ms)"); } } return binaryVariant; }
From source file:fr.acxio.tools.agia.alfresco.configuration.SimpleNodeFactoryTest.java
@Test public void testConditionalTreeGetNodes() throws Exception { FolderDefinition aDefaultNodeDefinition = NodeFactoryUtils.createFolderDefinition("test", null, null, null); FolderDefinition aFolder1NodeDefinition = NodeFactoryUtils.createFolderDefinition("s1", null, "true", null); FolderDefinition aFolder2NodeDefinition = NodeFactoryUtils.createFolderDefinition("s2", null, "false", null);/*from w w w .j av a 2s. com*/ FolderDefinition aFolder3NodeDefinition = NodeFactoryUtils.createFolderDefinition("s3", null, "true", null); aDefaultNodeDefinition.addFolder(aFolder1NodeDefinition); aDefaultNodeDefinition.addFolder(aFolder2NodeDefinition); aDefaultNodeDefinition.addFolder(aFolder3NodeDefinition); DocumentDefinition aDocument1Definition = NodeFactoryUtils.createDocumentDefinition("doc1", null, null, null, null, null); DocumentDefinition aDocument2Definition = NodeFactoryUtils.createDocumentDefinition("doc2", null, null, null, null, null); DocumentDefinition aDocument3Definition = NodeFactoryUtils.createDocumentDefinition("doc3", null, null, null, null, null); aFolder1NodeDefinition.addDocument(aDocument1Definition); aFolder1NodeDefinition.addDocument(aDocument2Definition); aFolder2NodeDefinition.addDocument(aDocument3Definition); StopWatch aStopWatch = new StopWatch("testConditionalTreeGetNodes"); aStopWatch.start("Create a node list"); SimpleNodeFactory aNodeFactory = new SimpleNodeFactory(); aNodeFactory.setNamespaceContext(namespaceContext); aNodeFactory.setNodeDefinition(aDefaultNodeDefinition); NodeList aNodeList = aNodeFactory.getNodes(evaluationContext); aStopWatch.stop(); assertEquals(5, aNodeList.size()); assertEquals("/cm:test", ((Folder) aNodeList.get(0)).getPath()); assertEquals("/cm:test/cm:s1", ((Folder) aNodeList.get(1)).getPath()); assertEquals("/cm:test/cm:s1/cm:doc1", ((Document) aNodeList.get(2)).getPath()); assertEquals("/cm:test/cm:s1/cm:doc2", ((Document) aNodeList.get(3)).getPath()); assertEquals("/cm:test/cm:s3", ((Folder) aNodeList.get(4)).getPath()); System.out.println(aStopWatch.prettyPrint()); }
From source file:org.dd4t.core.factories.impl.GenericComponentFactory.java
public DynamicComponent getDCPFromSource(com.tridion.dcp.ComponentPresentation dcp) { StopWatch stopWatch = null;/* w ww . j a v a2s . c o m*/ DynamicComponentImpl dynComp = null; if (logger.isDebugEnabled()) { stopWatch = new StopWatch("getComponentFromSource"); stopWatch.start(); } try { if (logger.isDebugEnabled()) { stopWatch.stop(); stopWatch.start(); } dynComp = (DynamicComponentImpl) this.getSerializer().deserialize(dcp.getContent(), DynamicComponentImpl.class); dynComp.setNativeDCP(dcp); } catch (Exception e) { logger.error("error when deserializing component", e); throw new RuntimeException(e); } finally { if (logger.isDebugEnabled()) { stopWatch.stop(); logger.debug("Deserialization of component took: " + stopWatch.getLastTaskTimeMillis() + " ms"); } } return dynComp; }