Package EDU.oswego.cs.dl.util.concurrent

Examples of EDU.oswego.cs.dl.util.concurrent.Sync


     *
     * @param loader the class loader to register
     */
    private static void registerClassLoader(final ClassLoader loader) {
        // note: read lock is alreayd owned
        Sync writeLock = s_lock.writeLock();
        if (s_classLoaderSystemDefinitions.containsKey(loader)) {
            return;
        }
        try {
            writeLock.acquire();
            // recheck
            if (s_classLoaderSystemDefinitions.containsKey(loader)) {
                return;
            }

            // else - register

            // skip boot classloader and ext classloader
            if (loader == null) {
                // by defaults, there is alwasy the virtual definition, that has lowest precedence
                Set defaults = new HashSet();
                defaults.add(SystemDefinition.createVirtualDefinitionAt(loader));
                s_classLoaderSystemDefinitions.put(loader, defaults);
                s_classLoaderDefinitionLocations.put(loader, new ArrayList());
                return;
            }

            // register parents first
            registerClassLoader(loader.getParent());

            // then register -D.. if system classloader and then all META-INF/aop.xml
            try {
                final Set definitions = new HashSet();
                final List locationOfDefinitions = new ArrayList();

                // early registration to avoid recursion
                s_classLoaderSystemDefinitions.put(loader, definitions);
                s_classLoaderDefinitionLocations.put(loader, locationOfDefinitions);

                // is this system classloader ?
                if ((loader == ClassLoader.getSystemClassLoader()) && !s_disableSystemWideDefinition) {
                    // -D..file=... sysdef
                    definitions.addAll(DefinitionLoader.getDefaultDefinition(loader));
                    locationOfDefinitions.add(new File(URL_JVM_OPTION_SYSTEM).toURL());
                }
                if (loader.getResource(WEB_WEB_INF_XML_FILE) != null) {
                    Enumeration webres = loader.getResources(AOP_WEB_INF_XML_FILE);
                    while (webres.hasMoreElements()) {
                        URL def = (URL) webres.nextElement();
                        if (isDefinedBy(loader, def)) {
                            ;
                        } else {
                            definitions.addAll(XmlParser.parseNoCache(loader, def));
                            locationOfDefinitions.add(def);
                        }
                    }
                }
                Enumeration res = loader.getResources(AOP_META_INF_XML_FILE);
                while (res.hasMoreElements()) {
                    URL def = (URL) res.nextElement();
                    if (isDefinedBy(loader, def)) {
                        ;
                    } else {
                        definitions.addAll(XmlParser.parseNoCache(loader, def));
                        locationOfDefinitions.add(def);
                    }
                }

                // there is always the virtual definition, that has lowest precedence
                definitions.add(SystemDefinition.createVirtualDefinitionAt(loader));

                dump(loader);
            } catch (Throwable t) {
                t.printStackTrace();
            }
        } catch (InterruptedException e) {
            throw new WrappedRuntimeException(e);
        } finally {
            //downgrade lock by releasing directly
            writeLock.release();
        }
    }
View Full Code Here


     *
     * @param loader      ClassLoader
     * @param definitions SystemDefinitions list
     */
    public static void deployDefinitions(final ClassLoader loader, final Set definitions) {
        Sync lock = s_lock.writeLock();
        try {
            lock.acquire();

            // make sure the classloader is known
            registerClassLoader(loader);

            //unchanged: s_classLoaderDefinitionLocations

            // propagate change by flushing hierachical cache in all childs
            flushHierarchicalSystemDefinitionsBelow(loader);

            // update
            Set defs = (Set) s_classLoaderSystemDefinitions.get(loader);
            defs.addAll(definitions);
            dump(loader);
        } catch (InterruptedException e) {
            throw new WrappedRuntimeException(e);
        } finally {
            lock.release();
        }
    }
View Full Code Here

     * @param loader ClassLoader
     * @param uuid   system uuid
     * @return SystemDefinition or null if no such defined definition
     */
    public static SystemDefinition getDefinitionFor(final ClassLoader loader, final String uuid) {
        Sync lock = s_lock.readLock();
        try {
            lock.acquire();
            for (Iterator defs = getDefinitionsFor(loader).iterator(); defs.hasNext();) {
                SystemDefinition def = (SystemDefinition) defs.next();
                if (def.getUuid().equals(uuid)) {
                    return def;
                }
            }
            return null;
        } catch (InterruptedException e) {
            throw new WrappedRuntimeException(e);
        } finally {
            lock.release();
        }
    }
View Full Code Here

     *
     * @param loader
     * @return SystemDefinitions list
     */
    public static Set getDefinitionsFor(final ClassLoader loader) {
        Sync lock = s_lock.readLock();
        try {
            lock.acquire();
            return getHierarchicalDefinitionsFor(loader);
        } catch (InterruptedException e) {
            throw new WrappedRuntimeException(e);
        } finally {
            lock.release();
        }
    }
View Full Code Here

     *
     * @param loader
     * @return SystemDefinitions list
     */
    public static Set getDefinitionsAt(final ClassLoader loader) {
        Sync lock = s_lock.readLock();
        try {
            lock.acquire();
            // make sure the classloader is registered
            registerClassLoader(loader);
            return (Set) s_classLoaderSystemDefinitions.get(loader);
        } catch (InterruptedException e) {
            throw new WrappedRuntimeException(e);
        } finally {
            lock.release();
        }
    }
View Full Code Here

     * @return set with the system definitions
     */
    private static Set getHierarchicalDefinitionsFor(final ClassLoader loader) {
        // check cache
        // note: read Lock is already acquired at this stage
        Sync writeLock = s_lock.writeLock();
        if (!s_classLoaderHierarchicalSystemDefinitions.containsKey(loader)) {
            // upgrade lock
            try {
                writeLock.acquire();
                // recheck [see JavaDoc for read / write lock
                if (!s_classLoaderHierarchicalSystemDefinitions.containsKey(loader)) {
                    // make sure the classloader is known
                    registerClassLoader(loader);

                    Set defs = new HashSet();
                    // put it in the cache now since this method is recursive
                    s_classLoaderHierarchicalSystemDefinitions.put(loader, defs);
                    if (loader == null) {
                        ; // go on to put in the cache at the end
                    } else {
                        ClassLoader parent = loader.getParent();
                        defs.addAll(getHierarchicalDefinitionsFor(parent));
                    }
                    defs.addAll((Set) s_classLoaderSystemDefinitions.get(loader));

                    return defs;
                } else {
                    return ((Set) s_classLoaderHierarchicalSystemDefinitions.get(loader));
                }
            } catch (InterruptedException e) {
                throw new WrappedRuntimeException(e);
            } finally {
                // downgrade lock
                writeLock.release(); // release write, still hold read
            }
        } else {
            return ((Set) s_classLoaderHierarchicalSystemDefinitions.get(loader));
        }
    }
View Full Code Here

     * @return the Object associated with Key Object
     */
    public Object get(Object key)
    {
        Object value = null;
        Sync sync = this.lock.readLock();
        try
        {
            sync.acquire();
            try
            {
                value = this.doGet(key);
            }
            finally
            {
                sync.release();
            }
        }
        catch (InterruptedException ignore)
        {
        }
View Full Code Here

     * @exception  IOException
     */
    public void store(Object key, Object value)
    throws IOException
    {
        Sync sync = this.lock.writeLock();
        try
        {
            sync.acquire();

            try
            {
                this.doStore(key, value);
                m_sizeInstrument.setValue( doGetSize() );
            }
            finally
            {
                sync.release();
            }
        }
        catch (InterruptedException ignore)
        {
        }
View Full Code Here

    /**
     * Frees some values of the data file.<br>
     */
    public void free()
    {
        Sync sync = this.lock.writeLock();
        try
        {
            sync.acquire();

            try
            {
                this.doFree();
                m_sizeInstrument.setValue( doGetSize() );
            }
            finally
            {
                sync.release();
            }
        }
        catch (InterruptedException ignore)
        {
        }
View Full Code Here

        if (getLogger().isDebugEnabled())
        {
            getLogger().debug("clear(): Clearing the database ");
        }

        Sync sync = this.lock.writeLock();
        try
        {
            sync.acquire();
            try
            {
                this.doClear();
                m_sizeInstrument.setValue( 0 );
            }
            finally
            {
                sync.release();
            }
        }
        catch (InterruptedException ignore)
        {
        }
View Full Code Here

TOP

Related Classes of EDU.oswego.cs.dl.util.concurrent.Sync

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.