/** * Understands and applies the following integer properties. * * <ul> * <li>max.size - setMaximumSize * <li>max.threads - setMaximumThreads * <li>timeout.idle - setIdleTimeout * <li>timeout.transaction - setTransactionTimeout * <li>tune.size - Automatically tunes queue size when "true" and transaction timeout set. * <li>tune.threads - Automatically tunes maximum thread count. * </ul> */ public synchronized void applyProperties(PropertyMap properties) { if (properties.containsKey("max.size")) { setMaximumSize(properties.getInt("max.size")); } if (properties.containsKey("max.threads")) { setMaximumThreads(properties.getInt("max.threads")); } if (properties.containsKey("timeout.idle")) { setIdleTimeout(properties.getNumber("timeout.idle").longValue()); } if (properties.containsKey("timeout.transaction")) { setTransactionTimeout(properties.getNumber("timeout.transaction").longValue()); } if ("true".equalsIgnoreCase(properties.getString("tune.size"))) { addTransactionQueueListener(new TransactionQueueSizeTuner()); } if ("true".equalsIgnoreCase(properties.getString("tune.threads"))) { addTransactionQueueListener(new TransactionQueueThreadTuner()); } }
/** * Process the user's http get request. Process the template that maps to the URI that was hit. * * @param request the user's http request * @param response the user's http response */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { if (processStatus(request, response)) { return; } if (!isRunning()) { int errorCode = mProperties.getInt("startup.codes.error", 503); response.sendError(errorCode); return; } if (mUseSpiderableRequest) { request = new SpiderableRequest(request, mQuerySeparator, mParameterSeparator, mValueSeparator); } // start transaction TeaServletTransaction tsTrans = getEngine().createTransaction(request, response, true); // load associated request/response ApplicationRequest appRequest = tsTrans.getRequest(); ApplicationResponse appResponse = tsTrans.getResponse(); // process template processTemplate(appRequest, appResponse); appResponse.finish(); // flush the output response.flushBuffer(); }
private void createMemoryLog(Log log) { if (log != null) { // Create memory log listener. mLogEvents = Collections.synchronizedList(new LinkedList<LogEvent>()); // The maximum number of log events to store in memory. final int logEventsMax = mProperties.getInt("log.max", 100); log.addRootLogListener( new TeaLogListener() { public void logMessage(LogEvent e) { checkSize(); mLogEvents.add(e); } public void logException(LogEvent e) { checkSize(); mLogEvents.add(e); } public void logTeaStackTrace(TeaLogEvent e) { checkSize(); mLogEvents.add(e); } private void checkSize() { while (mLogEvents.size() >= logEventsMax) { mLogEvents.remove(0); } } }); logVersionInfo(TeaServlet.class, "TeaServlet", log); log.info("Copyright (C) 1999-2012 TeaTrove http://teatrove.org"); logVersionInfo(TemplateLoader.class, "Tea", log); log.info("Copyright (C) 1997-2012 TeaTrove http://teatrove.org"); } }
protected boolean processStatus(HttpServletRequest request, HttpServletResponse response) throws IOException { String path = request.getPathInfo(); // check password String adminKey = mProperties.getString("admin.key"); String adminValue = mProperties.getString("admin.value"); if (AdminApplication.adminCheck( adminKey, adminValue, request, response)) { // check if status request if ("/system/status.json".equals(path)) { printStatus(response); return true; } // once we have initialized, no need to further process if (isRunning()) { return false; } // verify our path matches the expected path String pattern = mProperties.getString("startup.path"); if (pattern != null && path.matches(pattern)) { // verify the startup file that was provided String resource = mProperties.getString("startup.file"); if (resource != null) { InputStream input = TeaServlet.class.getResourceAsStream(resource); // copy the data to the response if valid if (input != null) { int read = 0; byte[] data = new byte[512]; input = new BufferedInputStream(input); ServletOutputStream output = response.getOutputStream(); while ((read = input.read(data)) >= 0) { output.write(data, 0, read); } input.close(); response.flushBuffer(); return true; } } } } // handle error code if not yet initialized if (!isInitialized()) { // request not processed so send uninitialized error code int errorCode = mProperties.getInt("startup.codes.initializing", 503); response.sendError(errorCode); return true; } // nothing to process return false; }