Package com.planet_ink.coffee_web.util

Examples of com.planet_ink.coffee_web.util.RequestStats


    final ServletResponse servletResponse = new ServletResponse(); // generate a response object
    final SimpleServletSession session=getServletSession(request, servletResponse); // get or create a session object
    final SimpleServletRequest servletRequest = new ServletRequest(session, request);
    try
    {
      final RequestStats stats = config.getServletMan().getServletStats(servletClass);
      final long startTime = System.nanoTime(); // for stat keeping
      try
      {
        stats.startProcessing(); // synchronization is not required, so long as endProcessing is always called
        final SimpleServlet servletInstance = servletClass.newInstance(); // instantiate a new servlet instance!
        if(request.getMethod() == HTTPMethod.GET)
          servletInstance.doGet(servletRequest, servletResponse);
        else
        if(request.getMethod() == HTTPMethod.POST)
          servletInstance.doPost(servletRequest, servletResponse);
        servletInstance.service(request.getMethod(), servletRequest, servletResponse);
        return servletResponse.generateOutput(request); // the generated output, yea!
      }
      finally
      {
        session.touch();
        stats.endProcessing(System.nanoTime() - startTime);
        lastHttpStatusCode=servletResponse.getStatusCode();
      }
    }
    catch (final HTTPException e)
    {
View Full Code Here


   */
  @Override
  public void registerServlet(String context, Class<? extends SimpleServlet> servletClass)
  {
    servlets.put(context, servletClass);
    servletStats.put(servletClass, new RequestStats());
  }
View Full Code Here

  public void requestStatsTester()
  {
    CWConfig config=new CWConfig();
    config.setLogger(Log.instance());
    CWThreadExecutor executor = new CWThreadExecutor("test", config, 1, 5, 100, TimeUnit.SECONDS, 10, 500);
    final RequestStats stats = new RequestStats();
    int numRequests=500;
    for(int i=0;i<numRequests;i++)
    {
      executor.execute(new Runnable(){
        @Override
        public void run()
        {
          final long startTime=System.nanoTime();
          try
          {
            stats.startProcessing();
            try{Thread.sleep(random.nextInt(10));}catch(Exception e){}
          }
          finally
          {
            stats.endProcessing(System.nanoTime()-startTime);
          }
        }
      });
    }
    boolean success=false;
    for(int i=1;i<8000;i++)
    {
      if((stats.getAverageEllapsedNanos()>0)
      &&(stats.getNumberOfRequestsInProcess()>0))
      {
        success=true;
        break;
      }
      try
      {
        Thread.sleep(1);
      }
      catch (InterruptedException e1)
      {
        // TODO Auto-generated catch block
        e1.printStackTrace();
      }
    }
    if(!success)
    {
      fail("FAIL, nothing is in progress: "+stats.getAverageEllapsedNanos()+"/"+stats.getNumberOfRequestsInProcess());
    }
    while(executor.getQueue().size()>0)
      try{Thread.sleep(100);}catch(Exception e){}
    try{Thread.sleep(1000);}catch(Exception e){}
    if((stats.getAverageEllapsedNanos()==0)
    ||(stats.getNumberOfRequests()!=numRequests))
    {
      fail("FAIL, num requests = "+stats.getNumberOfRequests());
    }
    System.out.println("Stats smoke test: PASS");
  }
View Full Code Here

    {
      response.setMimeType(MIMEType.html.getType());
      final StringBuilder str = new StringBuilder("");
      str.append("<html><body>");
     
      RequestStats stats;
      for(final Class<? extends SimpleServlet> servletClass : request.getServletManager().getServlets())
      {
        stats = request.getServletManager().getServletStats(servletClass);
        str.append("<P><h2>"+servletClass.getSimpleName()+"</h2></p><br>");
        appendStats(stats, str);
View Full Code Here

   */
  @Override
  public void registerConverter(MIMEType mime, Class<? extends HTTPOutputConverter> converterClass)
  {
    converters.put(mime, converterClass);
    requestStats.put(converterClass, new RequestStats());
  }
View Full Code Here

TOP

Related Classes of com.planet_ink.coffee_web.util.RequestStats

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.