Author: markt Date: Mon Jan 4 10:16:11 2016 New Revision: 1722824 URL: http://svn.apache.org/viewvc?rev=1722824&view=rev Log: Code clean-up and Javadoc fixes
Modified: tomcat/trunk/java/org/apache/catalina/session/FileStore.java tomcat/trunk/java/org/apache/catalina/session/JDBCStore.java tomcat/trunk/java/org/apache/catalina/session/StandardManager.java tomcat/trunk/java/org/apache/catalina/session/StandardSessionFacade.java Modified: tomcat/trunk/java/org/apache/catalina/session/FileStore.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/session/FileStore.java?rev=1722824&r1=1722823&r2=1722824&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/session/FileStore.java (original) +++ tomcat/trunk/java/org/apache/catalina/session/FileStore.java Mon Jan 4 10:16:11 2016 @@ -14,11 +14,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - - package org.apache.catalina.session; - import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.File; @@ -37,7 +34,6 @@ import org.apache.catalina.Loader; import org.apache.catalina.Session; import org.apache.catalina.util.CustomObjectInputStream; - /** * Concrete implementation of the <b>Store</b> interface that utilizes * a file per saved Session in a configured directory. Sessions that are @@ -47,10 +43,8 @@ import org.apache.catalina.util.CustomOb */ public final class FileStore extends StoreBase { - // ----------------------------------------------------- Constants - /** * The extension to use for serialized session filenames. */ @@ -59,7 +53,6 @@ public final class FileStore extends Sto // ----------------------------------------------------- Instance Variables - /** * The pathname of the directory in which Sessions are stored. * This may be an absolute pathname, or a relative path that is @@ -88,14 +81,11 @@ public final class FileStore extends Sto // ------------------------------------------------------------- Properties - /** - * Return the directory path for this Store. + * @return The directory path for this Store. */ public String getDirectory() { - - return (directory); - + return directory; } @@ -105,21 +95,18 @@ public final class FileStore extends Sto * @param path The new directory path */ public void setDirectory(String path) { - String oldDirectory = this.directory; this.directory = path; this.directoryFile = null; - support.firePropertyChange("directory", oldDirectory, - this.directory); - + support.firePropertyChange("directory", oldDirectory, this.directory); } /** - * Return the thread name for this Store. + * @return The thread name for this Store. */ public String getThreadName() { - return(threadName); + return threadName; } @@ -128,7 +115,7 @@ public final class FileStore extends Sto */ @Override public String getStoreName() { - return(storeName); + return storeName; } @@ -139,7 +126,6 @@ public final class FileStore extends Sto */ @Override public int getSize() throws IOException { - // Acquire the list of files in our storage directory File file = directory(); if (file == null) { @@ -157,27 +143,22 @@ public final class FileStore extends Sto } } return keycount; - } // --------------------------------------------------------- Public Methods - /** * Remove all of the Sessions in this Store. * * @exception IOException if an input/output error occurs */ @Override - public void clear() - throws IOException { - + public void clear() throws IOException { String[] keys = keys(); for (int i = 0; i < keys.length; i++) { remove(keys[i]); } - } @@ -190,7 +171,6 @@ public final class FileStore extends Sto */ @Override public String[] keys() throws IOException { - // Acquire the list of files in our storage directory File file = directory(); if (file == null) { @@ -213,7 +193,6 @@ public final class FileStore extends Sto } } return list.toArray(new String[list.size()]); - } @@ -228,9 +207,7 @@ public final class FileStore extends Sto * @exception IOException if an input/output error occurs */ @Override - public Session load(String id) - throws ClassNotFoundException, IOException { - + public Session load(String id) throws ClassNotFoundException, IOException { // Open an input stream to the specified pathname, if any File file = file(id); if (file == null) { @@ -252,10 +229,12 @@ public final class FileStore extends Sto try (FileInputStream fis = new FileInputStream(file.getAbsolutePath()); BufferedInputStream bis = new BufferedInputStream(fis)) { Context context = manager.getContext(); - if (context != null) + if (context != null) { loader = context.getLoader(); - if (loader != null) + } + if (loader != null) { classLoader = loader.getClassLoader(); + } if (classLoader != null) { Thread.currentThread().setContextClassLoader(classLoader); ois = new CustomObjectInputStream(bis, classLoader); @@ -269,9 +248,10 @@ public final class FileStore extends Sto session.setManager(manager); return (session); } catch (FileNotFoundException e) { - if (manager.getContext().getLogger().isDebugEnabled()) + if (manager.getContext().getLogger().isDebugEnabled()) { manager.getContext().getLogger().debug("No persisted data file found"); - return (null); + } + return null; } finally { if (ois != null) { // Close the input stream @@ -297,17 +277,15 @@ public final class FileStore extends Sto */ @Override public void remove(String id) throws IOException { - File file = file(id); if (file == null) { return; } if (manager.getContext().getLogger().isDebugEnabled()) { - manager.getContext().getLogger().debug(sm.getString(getStoreName()+".removing", + manager.getContext().getLogger().debug(sm.getString(getStoreName() + ".removing", id, file.getAbsolutePath())); } file.delete(); - } @@ -321,14 +299,13 @@ public final class FileStore extends Sto */ @Override public void save(Session session) throws IOException { - // Open an output stream to the specified pathname, if any File file = file(session.getIdInternal()); if (file == null) { return; } if (manager.getContext().getLogger().isDebugEnabled()) { - manager.getContext().getLogger().debug(sm.getString(getStoreName()+".saving", + manager.getContext().getLogger().debug(sm.getString(getStoreName() + ".saving", session.getIdInternal(), file.getAbsolutePath())); } @@ -341,20 +318,18 @@ public final class FileStore extends Sto // -------------------------------------------------------- Private Methods - /** * Return a File object representing the pathname to our * session persistence directory, if any. The directory will be * created if it does not already exist. */ private File directory() throws IOException { - if (this.directory == null) { - return (null); + return null; } if (this.directoryFile != null) { // NOTE: Race condition is harmless, so do not synchronize - return (this.directoryFile); + return this.directoryFile; } File file = new File(this.directory); if (!file.isAbsolute()) { @@ -365,8 +340,7 @@ public final class FileStore extends Sto servletContext.getAttribute(ServletContext.TEMPDIR); file = new File(work, this.directory); } else { - throw new IllegalArgumentException - ("Parent Container is not a Context"); + throw new IllegalArgumentException("Parent Container is not a Context"); } } if (!file.exists() || !file.isDirectory()) { @@ -380,8 +354,7 @@ public final class FileStore extends Sto } } this.directoryFile = file; - return (file); - + return file; } @@ -393,15 +366,11 @@ public final class FileStore extends Sto * used in the file naming. */ private File file(String id) throws IOException { - if (this.directory == null) { - return (null); + return null; } String filename = id + FILE_EXT; File file = new File(directory(), filename); - return (file); - + return file; } - - } Modified: tomcat/trunk/java/org/apache/catalina/session/JDBCStore.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/session/JDBCStore.java?rev=1722824&r1=1722823&r2=1722824&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/session/JDBCStore.java (original) +++ tomcat/trunk/java/org/apache/catalina/session/JDBCStore.java Mon Jan 4 10:16:11 2016 @@ -111,7 +111,8 @@ public class JDBCStore extends StoreBase */ protected DataSource dataSource = null; - // ------------------------------------------------------------- Table & cols + + // ------------------------------------------------------------ Table & cols /** * Table to use. @@ -148,7 +149,8 @@ public class JDBCStore extends StoreBase */ protected String sessionLastAccessedCol = "lastaccess"; - // ------------------------------------------------------------- SQL Variables + + // ----------------------------------------------------------- SQL Variables /** * Variable to hold the <code>getSize()</code> prepared statement. @@ -175,7 +177,8 @@ public class JDBCStore extends StoreBase */ protected PreparedStatement preparedLoadSql = null; - // ------------------------------------------------------------- Properties + + // -------------------------------------------------------------- Properties /** * @return the name for this instance (built from container name) @@ -235,7 +238,7 @@ public class JDBCStore extends StoreBase * @return the driver for this Store. */ public String getDriverName() { - return this.driverName; + return driverName; } /** @@ -287,7 +290,7 @@ public class JDBCStore extends StoreBase * @return the Connection URL for this Store. */ public String getConnectionURL() { - return this.connectionURL; + return connectionURL; } /** @@ -307,7 +310,7 @@ public class JDBCStore extends StoreBase * @return the table for this Store. */ public String getSessionTable() { - return this.sessionTable; + return sessionTable; } /** @@ -451,6 +454,7 @@ public class JDBCStore extends StoreBase return this.dataSourceName; } + // --------------------------------------------------------- Public Methods @Override @@ -841,6 +845,7 @@ public class JDBCStore extends StoreBase } } + // --------------------------------------------------------- Protected Methods /** Modified: tomcat/trunk/java/org/apache/catalina/session/StandardManager.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/session/StandardManager.java?rev=1722824&r1=1722823&r2=1722824&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/session/StandardManager.java (original) +++ tomcat/trunk/java/org/apache/catalina/session/StandardManager.java Mon Jan 4 10:16:11 2016 @@ -14,8 +14,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - - package org.apache.catalina.session; import java.io.BufferedInputStream; @@ -45,6 +43,7 @@ import org.apache.catalina.util.CustomOb import org.apache.juli.logging.Log; import org.apache.juli.logging.LogFactory; import org.apache.tomcat.util.ExceptionUtils; + /** * Standard implementation of the <b>Manager</b> interface that provides * simple session persistence across restarts of this component (such as @@ -62,6 +61,7 @@ public class StandardManager extends Man private final Log log = LogFactory.getLog(StandardManager.class); // must not be static // ---------------------------------------------------- Security Classes + private class PrivilegedDoLoad implements PrivilegedExceptionAction<Void> { @@ -118,19 +118,15 @@ public class StandardManager extends Man */ @Override public String getName() { - - return (name); - + return name; } /** - * Return the session persistence pathname, if any. + * @return The session persistence pathname, if any. */ public String getPathname() { - - return (this.pathname); - + return pathname; } @@ -141,11 +137,9 @@ public class StandardManager extends Man * @param pathname New session persistence pathname */ public void setPathname(String pathname) { - String oldPathname = this.pathname; this.pathname = pathname; support.firePropertyChange("pathname", oldPathname, this.pathname); - } @@ -167,14 +161,14 @@ public class StandardManager extends Man AccessController.doPrivileged( new PrivilegedDoLoad() ); } catch (PrivilegedActionException ex){ Exception exception = ex.getException(); - if (exception instanceof ClassNotFoundException){ + if (exception instanceof ClassNotFoundException) { throw (ClassNotFoundException)exception; - } else if (exception instanceof IOException){ + } else if (exception instanceof IOException) { throw (IOException)exception; } - if (log.isDebugEnabled()) - log.debug("Unreported exception in load() " - + exception); + if (log.isDebugEnabled()) { + log.debug("Unreported exception in load() ", exception); + } } } else { doLoad(); @@ -192,18 +186,21 @@ public class StandardManager extends Man * @exception IOException if an input/output error occurs */ protected void doLoad() throws ClassNotFoundException, IOException { - if (log.isDebugEnabled()) + if (log.isDebugEnabled()) { log.debug("Start: Loading persisted sessions"); + } // Initialize our internal data structures sessions.clear(); // Open an input stream to the specified pathname, if any File file = file(); - if (file == null) + if (file == null) { return; - if (log.isDebugEnabled()) + } + if (log.isDebugEnabled()) { log.debug(sm.getString("standardManager.loading", pathname)); + } FileInputStream fis = null; BufferedInputStream bis = null; ObjectInputStream ois = null; @@ -213,22 +210,27 @@ public class StandardManager extends Man fis = new FileInputStream(file.getAbsolutePath()); bis = new BufferedInputStream(fis); Context c = getContext(); - if (c != null) + if (c != null) { loader = c.getLoader(); - if (loader != null) + } + if (loader != null) { classLoader = loader.getClassLoader(); + } if (classLoader != null) { - if (log.isDebugEnabled()) + if (log.isDebugEnabled()) { log.debug("Creating custom object input stream for class loader "); + } ois = new CustomObjectInputStream(bis, classLoader); } else { - if (log.isDebugEnabled()) + if (log.isDebugEnabled()) { log.debug("Creating standard object input stream"); + } ois = new ObjectInputStream(bis); } } catch (FileNotFoundException e) { - if (log.isDebugEnabled()) + if (log.isDebugEnabled()) { log.debug("No persisted data file found"); + } return; } catch (IOException e) { log.error(sm.getString("standardManager.loading.ioe", e), e); @@ -285,13 +287,15 @@ public class StandardManager extends Man } // Delete the persistent storage file - if (file.exists() ) + if (file.exists()) { file.delete(); + } } } - if (log.isDebugEnabled()) + if (log.isDebugEnabled()) { log.debug("Finish: Loading persisted sessions"); + } } @@ -304,17 +308,17 @@ public class StandardManager extends Man */ @Override public void unload() throws IOException { - if (SecurityUtil.isPackageProtectionEnabled()){ - try{ - AccessController.doPrivileged( new PrivilegedDoUnload() ); + if (SecurityUtil.isPackageProtectionEnabled()) { + try { + AccessController.doPrivileged(new PrivilegedDoUnload()); } catch (PrivilegedActionException ex){ Exception exception = ex.getException(); - if (exception instanceof IOException){ + if (exception instanceof IOException) { throw (IOException)exception; } - if (log.isDebugEnabled()) - log.debug("Unreported exception in unLoad() " - + exception); + if (log.isDebugEnabled()) { + log.debug("Unreported exception in unLoad()", exception); + } } } else { doUnload(); @@ -342,10 +346,12 @@ public class StandardManager extends Man // Open an output stream to the specified pathname, if any File file = file(); - if (file == null) + if (file == null) { return; - if (log.isDebugEnabled()) + } + if (log.isDebugEnabled()) { log.debug(sm.getString("standardManager.unloading", pathname)); + } FileOutputStream fos = null; BufferedOutputStream bos = null; ObjectOutputStream oos = null; @@ -387,8 +393,9 @@ public class StandardManager extends Man // Write the number of active sessions, followed by the details ArrayList<StandardSession> list = new ArrayList<>(); synchronized (sessions) { - if (log.isDebugEnabled()) + if (log.isDebugEnabled()) { log.debug("Unloading " + sessions.size() + " sessions"); + } try { // oos can't be null here oos.writeObject(Integer.valueOf(sessions.size())); @@ -423,8 +430,9 @@ public class StandardManager extends Man } // Expire all the sessions we just wrote - if (log.isDebugEnabled()) + if (log.isDebugEnabled()) { log.debug("Expiring " + list.size() + " persisted sessions"); + } Iterator<StandardSession> expires = list.iterator(); while (expires.hasNext()) { StandardSession session = expires.next(); @@ -437,9 +445,9 @@ public class StandardManager extends Man } } - if (log.isDebugEnabled()) + if (log.isDebugEnabled()) { log.debug("Unloading complete"); - + } } @@ -477,8 +485,9 @@ public class StandardManager extends Man @Override protected synchronized void stopInternal() throws LifecycleException { - if (log.isDebugEnabled()) + if (log.isDebugEnabled()) { log.debug("Stopping"); + } setState(LifecycleState.STOPPING); @@ -514,13 +523,11 @@ public class StandardManager extends Man // ------------------------------------------------------ Protected Methods - /** * Return a File object representing the pathname to our * persistence file, if any. */ protected File file() { - if ((pathname == null) || (pathname.length() == 0)) return (null); File file = new File(pathname); @@ -536,7 +543,6 @@ public class StandardManager extends Man } // if (!file.isAbsolute()) // return (null); - return (file); - + return file; } } Modified: tomcat/trunk/java/org/apache/catalina/session/StandardSessionFacade.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/session/StandardSessionFacade.java?rev=1722824&r1=1722823&r2=1722824&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/session/StandardSessionFacade.java (original) +++ tomcat/trunk/java/org/apache/catalina/session/StandardSessionFacade.java Mon Jan 4 10:16:11 2016 @@ -14,17 +14,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - - package org.apache.catalina.session; - import java.util.Enumeration; import javax.servlet.ServletContext; import javax.servlet.http.HttpSession; - /** * Facade for the StandardSession object. * @@ -32,11 +28,12 @@ import javax.servlet.http.HttpSession; */ public class StandardSessionFacade implements HttpSession { - // ----------------------------------------------------------- Constructors /** * Construct a new session facade. + * + * @param session The session instance to wrap */ public StandardSessionFacade(HttpSession session) { this.session = session; @@ -45,7 +42,6 @@ public class StandardSessionFacade imple // ----------------------------------------------------- Instance Variables - /** * Wrapped session object. */ @@ -54,7 +50,6 @@ public class StandardSessionFacade imple // ---------------------------------------------------- HttpSession Methods - @Override public long getCreationTime() { return session.getCreationTime(); @@ -181,6 +176,4 @@ public class StandardSessionFacade imple public boolean isNew() { return session.isNew(); } - - } --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org