Package org.springframework.util

Examples of org.springframework.util.StopWatch


  public ThreadPoolTaskExecutor(int poolSize, int maxPoolSize, int keepAliveTime) {
    threadPool = new ThreadPoolExecutor(poolSize, maxPoolSize, keepAliveTime, TimeUnit.SECONDS, queue);
  }

  public void runTask(Runnable task) {
    StopWatch watch = null;
    if (log.isDebug()) {
      watch = new StopWatch();
      watch.start();
    }   
    threadPool.execute(task);
   
    if (log.isDebug()) watch.stop();
    if (log.isDebug()) log.debug("Current size of queue is: "+queue.size()+". Running last task took (ms): "+watch.getTotalTimeMillis());
  }
View Full Code Here


   *
   * @param args
   * @return
   */
  public Object invoke() {
    StopWatch sw = null;
    if (logger.isDebugEnabled()) {
      sw = new StopWatch();
      sw.start();
    }
    Object retValue = null;
    if (bean instanceof GroovyObject) {
      retValue = ((GroovyObject) bean).invokeMethod(method.getName(), arguments);
    } else {
      retValue = ReflectionUtils.invokeMethod(method, bean, arguments);
    }

    if (logger.isDebugEnabled()) {
      sw.stop();
      List<String> argsDescr = new ArrayList<String>(arguments.length);
      for (int i = 0; i < arguments.length; i++) {
        if (arguments[i] != null && arguments[i] instanceof String) {
          argsDescr.add((String) arguments[i]);
        } else {
          argsDescr.add(arguments[i] != null ? arguments[i].getClass().getName() : "null");
        }
      }
      logger.debug("Invoking  " + methodId + " with arguments " + argsDescr + ": " + sw.getTotalTimeMillis());

    }
    return retValue;
  }
View Full Code Here

    }
  }

  @Override
  public Message<?> preSend(Message<?> message, MessageChannel channel) {
    StopWatch stopWatch = new StopWatch();
    stopWatch.start();
    this.stopWatchHolder.set(new StopWatchHolder(stopWatch, message.getPayload().getClass()));
    return super.preSend(message, channel);
  }
View Full Code Here

  public class PerformanceMonitorInterceptor implements MethodInterceptor, Serializable {

    public Object invoke(MethodInvocation invocation) throws Throwable {
      String name = invocation.getMethod().getDeclaringClass().getName() + "." + invocation.getMethod().getName();
      StopWatch sw = new StopWatch(name);
      sw.start(name);
      try {
        return invocation.proceed();
      }
      finally {
        sw.stop();

        System.out.println(sw.shortSummary());
      }
    }
View Full Code Here

  public class PerformanceMonitorInterceptor implements MethodInterceptor, Serializable {

    public Object invoke(MethodInvocation invocation) throws Throwable {
      String name = invocation.getMethod().getDeclaringClass().getName() + "." + invocation.getMethod().getName();
      StopWatch sw = new StopWatch(name);
      sw.start(name);
      try {
        return invocation.proceed();
      }
      finally {
        sw.stop();

        System.out.println(sw.shortSummary());
      }
    }
View Full Code Here

        Template template = engine.createTemplate(resource, encoding);

        long sum = 0;

        for (int i=0; i<100; i++) {
            StopWatch sw = new StopWatch();
            sw.start();
            template.generate(model);
            sw.stop();
            sum += sw.getTotalTimeMillis();
        }

        System.out.println("took average of " + ((double)sum)/100 + " millis");

    }
View Full Code Here

  }


  public Object invoke(MethodInvocation invocation) throws Throwable {
    if (this.isEnabled) {
      StopWatch sw = new StopWatch(invocation.getMethod().getName());

      sw.start("invoke");
      try {
        return invocation.proceed();
      }
      finally {
        sw.stop();
        synchronized (this) {
          this.callCount++;
          this.accumulatedCallTime += sw.getTotalTimeMillis();
        }
      }
    }

    else {
View Full Code Here

    }

    //~ Methods ========================================================================================================

    public void invokeContactManager(Authentication authentication, int nrOfCalls) {
        StopWatch stopWatch = new StopWatch(nrOfCalls + " ContactManager call(s)");
        Map<String, ContactManager> contactServices = this.beanFactory.getBeansOfType(ContactManager.class, true, true);

        SecurityContextHolder.getContext().setAuthentication(authentication);

        for (String beanName : contactServices.keySet()) {
            Object object = this.beanFactory.getBean("&" + beanName);

            try {
                System.out.println("Trying to find setUsername(String) method on: " + object.getClass().getName());

                Method method = object.getClass().getMethod("setUsername", new Class[] {String.class});
                System.out.println("Found; Trying to setUsername(String) to " + authentication.getPrincipal());
                method.invoke(object, authentication.getPrincipal());
            } catch (NoSuchMethodException ignored) {
                System.out.println("This client proxy factory does not have a setUsername(String) method");
            } catch (IllegalAccessException ignored) {
                ignored.printStackTrace();
            } catch (InvocationTargetException ignored) {
                ignored.printStackTrace();
            }

            try {
                System.out.println("Trying to find setPassword(String) method on: " + object.getClass().getName());

                Method method = object.getClass().getMethod("setPassword", new Class[] {String.class});
                method.invoke(object, authentication.getCredentials());
                System.out.println("Found; Trying to setPassword(String) to " + authentication.getCredentials());
            } catch (NoSuchMethodException ignored) {
                System.out.println("This client proxy factory does not have a setPassword(String) method");
            } catch (IllegalAccessException ignored) {}
            catch (InvocationTargetException ignored) {}

            ContactManager remoteContactManager = contactServices.get(beanName);
            System.out.println("Calling ContactManager '" + beanName + "'");

            stopWatch.start(beanName);

            List<Contact> contacts = null;

            for (int i = 0; i < nrOfCalls; i++) {
                contacts = remoteContactManager.getAll();
            }

            stopWatch.stop();

            if (contacts.size() != 0) {
                for(Contact contact : contacts) {
                    System.out.println("Contact: " + contact);
                }
            } else {
                System.out.println("No contacts found which this user has permission to");
            }

            System.out.println();
            System.out.println(stopWatch.prettyPrint());
        }

        SecurityContextHolder.clearContext();
    }
View Full Code Here

    }

    // Method for use with profiler
    @Test
    public void usingPrototypeDoesNotParsePointcutOnEachCall() {
        StopWatch sw = new StopWatch();
        sw.start();
        for (int i = 0; i < 1000; i++) {
            try {
                SessionRegistry reg = (SessionRegistry) ctx.getBean("sessionRegistryPrototype");
                reg.getAllPrincipals();
                fail("Expected AuthenticationCredentialsNotFoundException");
            } catch (AuthenticationCredentialsNotFoundException expected) {
            }
        }
        sw.stop();
//        assertTrue(sw.getTotalTimeMillis() < 1000);

    }
View Full Code Here

    /**
     * Creates data from 1 to N_AUTHORITIES in steps of 10, performing N_INVOCATIONS for each
     */
    @Test
    public void provideDataOnScalingWithNumberOfAuthoritiesUserHas() throws Exception {
        StopWatch sw = new StopWatch("Scaling with nAuthorities");
        for (int user=0; user < N_AUTHORITIES/10; user ++) {
            int nAuthorities = user == 0 ? 1 : user*10;
            SecurityContextHolder.getContext().setAuthentication(new UsernamePasswordAuthenticationToken("bob", "bobspassword", createRoles(nAuthorities)));
            session.setAttribute(HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY, SecurityContextHolder.getContext());
            SecurityContextHolder.clearContext();
            sw.start(Integer.toString(nAuthorities) + " authorities");
            runWithStack(minimalStack);
            System.out.println(sw.shortSummary());
            sw.stop();
        }
        System.out.println(sw.prettyPrint());
    }
View Full Code Here

TOP

Related Classes of org.springframework.util.StopWatch

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.