Java Code Examples for org.apache.catalina.Loader#getClassLoader()

The following examples show how to use org.apache.catalina.Loader#getClassLoader() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ClusterManagerBase.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
public static ClassLoader[] getClassLoaders(Context context) {
    ClassLoader tccl = Thread.currentThread().getContextClassLoader();
    Loader loader = context.getLoader();
    ClassLoader classLoader = null;
    if (loader != null) {
        classLoader = loader.getClassLoader();
    }
    if (classLoader == null) {
        classLoader = tccl;
    }
    if (classLoader == tccl) {
        return new ClassLoader[] {classLoader};
    } else {
        return new ClassLoader[] {classLoader, tccl};
    }
}
 
Example 2
Source File: ReplicatedContext.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
public ClassLoader[] getClassLoaders() {
    Loader loader = null;
    ClassLoader classLoader = null;
    loader = this.getLoader();
    if (loader != null) classLoader = loader.getClassLoader();
    if ( classLoader == null ) classLoader = Thread.currentThread().getContextClassLoader();
    if ( classLoader == Thread.currentThread().getContextClassLoader() ) {
        return new ClassLoader[] {classLoader};
    } else {
        return new ClassLoader[] {classLoader,Thread.currentThread().getContextClassLoader()};
    }
}
 
Example 3
Source File: ClusterManagerBase.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
public static ClassLoader[] getClassLoaders(Container container) {
    Loader loader = null;
    ClassLoader classLoader = null;
    if (container != null) loader = container.getLoader();
    if (loader != null) classLoader = loader.getClassLoader();
    else classLoader = Thread.currentThread().getContextClassLoader();
    if ( classLoader == Thread.currentThread().getContextClassLoader() ) {
        return new ClassLoader[] {classLoader};
    } else {
        return new ClassLoader[] {classLoader,Thread.currentThread().getContextClassLoader()};
    }
}
 
Example 4
Source File: ReplicatedContext.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
public ClassLoader[] getClassLoaders() {
    Loader loader = null;
    ClassLoader classLoader = null;
    loader = this.getLoader();
    if (loader != null) classLoader = loader.getClassLoader();
    if ( classLoader == null ) classLoader = Thread.currentThread().getContextClassLoader();
    if ( classLoader == Thread.currentThread().getContextClassLoader() ) {
        return new ClassLoader[] {classLoader};
    } else {
        return new ClassLoader[] {classLoader,Thread.currentThread().getContextClassLoader()};
    }
}
 
Example 5
Source File: ClusterManagerBase.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
public static ClassLoader[] getClassLoaders(Container container) {
    Loader loader = null;
    ClassLoader classLoader = null;
    if (container != null) loader = container.getLoader();
    if (loader != null) classLoader = loader.getClassLoader();
    else classLoader = Thread.currentThread().getContextClassLoader();
    if ( classLoader == Thread.currentThread().getContextClassLoader() ) {
        return new ClassLoader[] {classLoader};
    } else {
        return new ClassLoader[] {classLoader,Thread.currentThread().getContextClassLoader()};
    }
}
 
Example 6
Source File: ReplicatedContext.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
public ClassLoader[] getClassLoaders() {
    Loader loader = null;
    ClassLoader classLoader = null;
    loader = this.getLoader();
    if (loader != null) classLoader = loader.getClassLoader();
    if ( classLoader == null ) classLoader = Thread.currentThread().getContextClassLoader();
    if ( classLoader == Thread.currentThread().getContextClassLoader() ) {
        return new ClassLoader[] {classLoader};
    } else {
        return new ClassLoader[] {classLoader,Thread.currentThread().getContextClassLoader()};
    }
}
 
Example 7
Source File: StandardManager.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
/**
 * Load any currently active sessions that were previously unloaded
 * to the appropriate persistence mechanism, if any.  If persistence is not
 * supported, this method returns without doing anything.
 *
 * @exception ClassNotFoundException if a serialized class cannot be
 *  found during the reload
 * @exception IOException if an input/output error occurs
 */
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));
    }
    Loader loader = null;
    ClassLoader classLoader = null;
    Log logger = null;
    try (FileInputStream fis = new FileInputStream(file.getAbsolutePath());
            BufferedInputStream bis = new BufferedInputStream(fis)) {
        Context c = getContext();
        loader = c.getLoader();
        logger = c.getLogger();
        if (loader != null) {
            classLoader = loader.getClassLoader();
        }
        if (classLoader == null) {
            classLoader = getClass().getClassLoader();
        }

        // Load the previously unloaded active sessions
        synchronized (sessions) {
            try (ObjectInputStream ois = new CustomObjectInputStream(bis, classLoader, logger,
                    getSessionAttributeValueClassNamePattern(),
                    getWarnOnSessionAttributeFilterFailure())) {
                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();
                    if (!session.isValidInternal()) {
                        // If session is already invalid,
                        // expire session to prevent memory leak.
                        session.setValid(true);
                        session.expire();
                    }
                    sessionCounter++;
                }
            } finally {
                // Delete the persistent storage file
                if (file.exists()) {
                    if (!file.delete()) {
                        log.warn(sm.getString("standardManager.deletePersistedFileFail", file));
                    }
                }
            }
        }
    } catch (FileNotFoundException e) {
        if (log.isDebugEnabled()) {
            log.debug("No persisted data file found");
        }
        return;
    }

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