/** * Detect possible the JVMRoute change at cluster backup node.. * * @param request * tomcat request being processed * @param response * tomcat response being processed * @exception IOException * if an input/output error has occurred * @exception ServletException * if a servlet error has occurred */ @Override public void invoke(Request request, Response response) throws IOException, ServletException { if (getEnabled() && request.getContext() != null && request.getContext().getDistributable() && !request.isAsyncDispatching()) { // valve cluster can access manager - other cluster handle turnover // at host level - hopefully! Manager manager = request.getContext().getManager(); if (manager != null && ( (manager instanceof ClusterManager && getCluster() != null && getCluster().getManager(((ClusterManager)manager).getName()) != null) || (manager instanceof PersistentManager))) handlePossibleTurnover(request); } // Pass this request on to the next valve in our pipeline getNext().invoke(request, response); }
/** * Detect possible the JVMRoute change at cluster backup node.. * * @param request * tomcat request being processed * @param response * tomcat response being processed * @exception IOException * if an input/output error has occurred * @exception ServletException * if a servlet error has occurred */ @Override public void invoke(Request request, Response response) throws IOException, ServletException { if (getEnabled() && request.getContext() != null && request.getContext().getDistributable() && !request.isAsyncDispatching()) { // valve cluster can access manager - other cluster handle turnover // at host level - hopefully! Manager manager = request.getContext().getManager(); if (manager != null && ((manager instanceof ClusterManager && getCluster() != null && getCluster().getManager(((ClusterManager) manager).getName()) != null) || (manager instanceof PersistentManager))) handlePossibleTurnover(request); } // Pass this request on to the next valve in our pipeline getNext().invoke(request, response); }
@Bean public EmbeddedServletContainerCustomizer containerCustomizer() { return factory -> { TomcatEmbeddedServletContainerFactory containerFactory = (TomcatEmbeddedServletContainerFactory) factory; containerFactory.setTomcatContextCustomizers(Arrays.asList(context -> { final PersistentManager persistentManager = new PersistentManager(); final FileStore store = new FileStore(); final String sessionDirectory = makeSessionDirectory(); log.info("Writing sessions to " + sessionDirectory); store.setDirectory(sessionDirectory); persistentManager.setStore(store); context.setManager(persistentManager); })); }; }
private Manager getSessionManager(Context context) { // Must be set for the persistent manager to work correctly. System.setProperty("org.apache.catalina.session.StandardSession.ACTIVITY_CHECK", "true"); PersistentManager manager = new PersistentManager(); StoreBase store; // Check if Migration has run and setup JDBC persistence if( !hibernateMigrationService.hasRunSystemMigration("com.tle.tomcat.migration.CreateTomcatSessionEntity") ) { // Use filestore until JDBC setup complete LOGGER.info("Setting up temporary file session store"); FileStore fileStore = new FileStore(); fileStore.setDirectory(System.getProperty("java.io.tmpdir")); store = fileStore; } else { LOGGER.info("Setting up JDBC session store"); JDBCStore jdbcStore = new JDBCStore(); jdbcStore.setConnectionURL(dataSourceService.getSystemUrl()); jdbcStore.setConnectionName(dataSourceService.getSystemUsername()); jdbcStore.setConnectionPassword(dataSourceService.getSystemPassword()); jdbcStore.setDriverName(dataSourceService.getDriverClass()); jdbcStore.setSessionTable("tomcat_sessions"); store = jdbcStore; } manager.setContext(context); manager.setProcessExpiresFrequency(3); // Every 30 seconds manager.setStore(store); // Persist immediately but leave in memory manager.setMaxIdleBackup(0); // Don't remove from memory for 30 minutes manager.setMaxIdleSwap((int) TimeUnit.MINUTES.toSeconds(30)); return manager; }
/** * Store the specified Manager properties. * * @param writer PrintWriter to which we are storing * @param indent Number of spaces to indent this element * @param manager Object whose properties are being stored * * @exception Exception if an exception occurs while storing */ private void storeManager(PrintWriter writer, int indent, Manager manager) throws Exception { if (isDefaultManager(manager)) { return; } // Store the beginning of this element for (int i = 0; i < indent; i++) { writer.print(' '); } writer.print("<Manager"); storeAttributes(writer, manager); writer.println(">"); // Store nested <Store> element if (manager instanceof PersistentManager) { Store store = ((PersistentManager) manager).getStore(); if (store != null) { storeStore(writer, indent + 2, store); } } // Store the ending of this element for (int i = 0; i < indent; i++) { writer.print(' '); } writer.println("</Manager>"); }