Example usage for java.util ResourceBundle clearCache

List of usage examples for java.util ResourceBundle clearCache

Introduction

In this page you can find the example usage for java.util ResourceBundle clearCache.

Prototype

public static final void clearCache(ClassLoader loader) 

Source Link

Document

Removes all resource bundles from the cache that have been loaded by the given class loader.

Usage

From source file:Main.java

public static void main(String[] args) {

    ResourceBundle bundle = ResourceBundle.getBundle("hello", Locale.US);

    System.out.println(bundle.getString("hello"));

    ClassLoader cl = ClassLoader.getSystemClassLoader();
    ResourceBundle.clearCache(cl);
}

From source file:org.nuxeo.ecm.platform.ui.web.reload.NuxeoJSFReloadHandler.java

@Override
public void handleEvent(Event event) {
    if (!Framework.isDevModeSet()) {
        log.info("Do not flush the JSF application: debug mode is not set");
        return;//from  w  w w .j  a v  a  2  s .co  m
    }
    String id = event.getId();
    if (ReloadEventNames.FLUSH_EVENT_ID.equals(id)) {
        // force i18n messages reload at the bundle level
        ResourceBundle.clearCache(Thread.currentThread().getContextClassLoader());
        // force reload of document default views.
        DocumentModelFunctions.resetDefaultViewCache();
    }
}

From source file:org.zaproxy.zap.control.AddOnLoader.java

private void removeAddOnClassLoader(AddOn addOn) {
    if (this.addOnLoaders.containsKey(addOn.getId())) {
        try (AddOnClassLoader addOnClassLoader = this.addOnLoaders.remove(addOn.getId())) {
            if (!addOn.getIdsAddOnDependencies().isEmpty()) {
                addOnClassLoader.clearDependencies();
            }//from  www  .j  a v  a2s.c  om
            ResourceBundle.clearCache(addOnClassLoader);
        } catch (Exception e) {
            logger.error("Failure while closing class loader of " + addOn.getId() + " add-on:", e);
        }
    }
}

From source file:org.zaproxy.zap.control.AddOnLoader.java

private void unloadDependentExtensions(AddOn ao) {
    boolean changed = true;
    for (Entry<String, AddOnClassLoader> entry : new HashMap<>(addOnLoaders).entrySet()) {
        AddOn runningAddOn = aoc.getAddOn(entry.getKey());
        for (Extension ext : runningAddOn.getLoadedExtensionsWithDeps()) {
            if (runningAddOn.dependsOn(ext, ao)) {
                String classname = ext.getClass().getCanonicalName();
                AddOnInstaller.uninstallAddOnExtension(runningAddOn, ext, NULL_CALLBACK);
                try (AddOnClassLoader extensionClassLoader = (AddOnClassLoader) ext.getClass()
                        .getClassLoader()) {
                    ext = null;//from  w w  w . j  a v a  2s.  co m
                    entry.getValue().removeChildClassLoader(extensionClassLoader);
                    extensionClassLoader.clearDependencies();
                    ResourceBundle.clearCache(extensionClassLoader);
                } catch (Exception e) {
                    logger.error("Failure while closing class loader of extension '" + classname + "':", e);
                }
                runnableAddOns.get(runningAddOn).remove(classname);
                changed = true;
            }
        }
    }

    if (changed) {
        saveAddOnsRunState(runnableAddOns);
    }
}

From source file:com.jaspersoft.studio.utils.jasper.JasperReportsConfiguration.java

/**
 * Return the functions extension both by resolving the property of the current project and from the commons
 * extension. If it is available instead of request the extension from the superclass it search it in the common cache
 * /*from   www  . ja v  a 2  s  . com*/
 * @return a not null functions extension
 */
private List<FunctionsBundle> getExtensionFunctions() {
    if (functionsBundles == null || refreshFunctionsBundles) {
        // We need to be sure that the resource bundles are fresh new
        // NOTE: Let's use this for now as quick solution, in case of
        // bad performances we'll have to fix this approach
        ResourceBundle.clearCache(getClassLoader());
        functionsBundles = super.getExtensions(FunctionsBundle.class);
        Set<FunctionsBundle> fBundlesSet = new LinkedHashSet<FunctionsBundle>(functionsBundles);
        functionsBundles = new ArrayList<FunctionsBundle>(fBundlesSet);
        refreshFunctionsBundles = false;
    }
    return functionsBundles;
}

From source file:gov.anl.cue.arcane.engine.matrix.MatrixModel.java

/**
 * Run the matrix model.//from   ww  w .  j a v a  2s. co m
 *
 * @return the double
 */
public Double runMatrixModel() {

    // Create a results holder.
    Double results = Double.NaN;

    // Attempt to run the model.
    try {

        // Setup a temporary class loader.
        URL[] urls = new URL[] { new File(Util.TEMP_DIR).toURI().toURL() };
        URLClassLoader classLoader = new URLClassLoader(urls, null, null);

        // Attempt to load the compiled file.
        @SuppressWarnings("rawtypes")
        Constructor constructor = classLoader
                .loadClass(MatrixModel.PACKAGE_NAME + "." + MatrixModel.CONCRETE_CLASS_NAME)
                .getDeclaredConstructor(double.class);
        constructor.setAccessible(true);
        Object object = constructor.newInstance(this.stepSize);

        // Call "matrixFormulation.step(steps)".
        Method method = object.getClass().getSuperclass().getMethod("step", int.class);
        method.invoke(object, this.stepCount);

        // Call matrixFormulation.calculateFitnessValue();
        method = object.getClass().getSuperclass().getMethod("calculateFitnessValue");
        results = (Double) method.invoke(object);

        // Clear the given class loader, which should not be
        // a child of another class loader.
        object = null;
        method = null;
        classLoader.close();
        ResourceBundle.clearCache(classLoader);
        classLoader = null;
        Introspector.flushCaches();
        System.runFinalization();
        System.gc();

        // Catch exceptions.
    } catch (Exception e) {

        // Return the default result.
        results = Double.NaN;

    }

    // Return the results.
    return results;

}