zoukankan      html  css  js  c++  java
  • tomcat源码阅读13

    StandardManager类的doLoad()方法,该方法从session文件中读取session对象,将其放入 protected Map<String, Session> sessions = new ConcurrentHashMap<String, Session>();中:

        protected void doLoad() throws ClassNotFoundException, IOException {
            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)
                return;
            if (log.isDebugEnabled())
                log.debug(sm.getString("standardManager.loading", pathname));
            FileInputStream fis = null;
            ObjectInputStream ois = null;
            Loader loader = null;
            ClassLoader classLoader = null;
            try {
                fis = new FileInputStream(file.getAbsolutePath());
                BufferedInputStream bis = new BufferedInputStream(fis);
                if (container != null)
                    loader = container.getLoader();
                if (loader != null)
                    classLoader = loader.getClassLoader();
                if (classLoader != null) {
                    if (log.isDebugEnabled())
                        log.debug("Creating custom object input stream for class loader ");
                    ois = new CustomObjectInputStream(bis, classLoader);
                } else {
                    if (log.isDebugEnabled())
                        log.debug("Creating standard object input stream");
                    ois = new ObjectInputStream(bis);
                }
            } catch (FileNotFoundException e) {
                if (log.isDebugEnabled())
                    log.debug("No persisted data file found");
                return;
            } catch (IOException e) {
                log.error(sm.getString("standardManager.loading.ioe", e), e);
                if (ois != null) {
                    try {
                        ois.close();
                    } catch (IOException f) {
                        ;
                    }
                    ois = null;
                }
                throw e;
            }

            // Load the previously unloaded active sessions
            synchronized (sessions) {
                try {
                    Integer count = (Integer) ois.readObject();
                    int n = count.intValue();
                    if (log.isDebugEnabled())
                        log.debug("Loading " + n + " persisted sessions");
                    for (int i = 0; i < n; i++) {
                        StandardSession session = getNewSession();
                        session.readObjectData(ois);
                        session.setManager(this);
                        sessions.put(session.getIdInternal(), session);
                        session.activate();
                        sessionCounter++;
                    }
                } catch (ClassNotFoundException e) {
                    log.error(sm.getString("standardManager.loading.cnfe", e), e);
                    if (ois != null) {
                        try {
                            ois.close();
                        } catch (IOException f) {
                            ;
                        }
                        ois = null;
                    }
                    throw e;
                } catch (IOException e) {
                    log.error(sm.getString("standardManager.loading.ioe", e), e);
                    if (ois != null) {
                        try {
                            ois.close();
                        } catch (IOException f) {
                            ;
                        }
                        ois = null;
                    }
                    throw e;
                } finally {
                    // Close the input stream
                    try {
                        if (ois != null)
                            ois.close();
                    } catch (IOException f) {
                        // ignored
                    }

                    // Delete the persistent storage file
                    if (file != null && file.exists() )
                        file.delete();
                }
            }

            if (log.isDebugEnabled())
                log.debug("Finish: Loading persisted sessions");
        }

    获得session文件的方法:

        protected File file() {

            if ((pathname == null) || (pathname.length() == 0))
                return (null);
            File file = new File(pathname);
            if (!file.isAbsolute()) {
                if (container instanceof Context) {
                    ServletContext servletContext =
                        ((Context) container).getServletContext();
                    File tempdir = (File)
                        servletContext.getAttribute(Globals.WORK_DIR_ATTR);
                    if (tempdir != null)
                        file = new File(tempdir, pathname);
                }
            }
    //        if (!file.isAbsolute())
    //            return (null);
            return (file);

        }

  • 相关阅读:
    神经网络-FPN 19
    机器学习
    神经网络-DenseNet 18
    神经网路骨架:各自的特点统计
    转载:一步一步制作根文件系统
    设计模式博客
    【转】PowerPC平台linux设备移植
    【收藏】自己动手写编译器、连接器
    查看pthread线程库中锁的持有者方法
    【转】深入 Linux 的进程优先级
  • 原文地址:https://www.cnblogs.com/macula7/p/1960454.html
Copyright © 2011-2022 走看看