|
Java example source code file (ClassLoaderRepositorySupport.java)
The ClassLoaderRepositorySupport.java Java example source code/* * Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package com.sun.jmx.mbeanserver; import static com.sun.jmx.defaults.JmxProperties.MBEANSERVER_LOGGER; import java.security.Permission; import java.util.ArrayList; import java.util.Arrays; import java.util.Hashtable; import java.util.List; import java.util.Map; import java.util.logging.Level; import javax.management.MBeanPermission; import javax.management.ObjectName; import javax.management.loading.PrivateClassLoader; import sun.reflect.misc.ReflectUtil; /** * This class keeps the list of Class Loaders registered in the MBean Server. * It provides the necessary methods to load classes using the * registered Class Loaders. * * @since 1.5 */ final class ClassLoaderRepositorySupport implements ModifiableClassLoaderRepository { /* We associate an optional ObjectName with each entry so that we can remove the correct entry when unregistering an MBean that is a ClassLoader. The same object could be registered under two different names (even though this is not recommended) so if we did not do this we could disturb the defined semantics for the order of ClassLoaders in the repository. */ private static class LoaderEntry { ObjectName name; // can be null ClassLoader loader; LoaderEntry(ObjectName name, ClassLoader loader) { this.name = name; this.loader = loader; } } private static final LoaderEntry[] EMPTY_LOADER_ARRAY = new LoaderEntry[0]; /** * List of class loaders * Only read-only actions should be performed on this object. * * We do O(n) operations on this array, e.g. when removing * a ClassLoader. The assumption is that the number of elements * is small, probably less than ten, and that the vast majority * of operations are searches (loadClass) which are by definition * linear. */ private LoaderEntry[] loaders = EMPTY_LOADER_ARRAY; /** * Same behavior as add(Object o) in {@link java.util.List}. * Replace the loader list with a new one in which the new * loader has been added. **/ private synchronized boolean add(ObjectName name, ClassLoader cl) { List<LoaderEntry> l = new ArrayList<LoaderEntry>(Arrays.asList(loaders)); l.add(new LoaderEntry(name, cl)); loaders = l.toArray(EMPTY_LOADER_ARRAY); return true; } /** * Same behavior as remove(Object o) in {@link java.util.List}. * Replace the loader list with a new one in which the old loader * has been removed. * * The ObjectName may be null, in which case the entry to * be removed must also have a null ObjectName and the ClassLoader * values must match. If the ObjectName is not null, then * the first entry with a matching ObjectName is removed, * regardless of whether ClassLoader values match. (In fact, * the ClassLoader parameter will usually be null in this case.) **/ private synchronized boolean remove(ObjectName name, ClassLoader cl) { final int size = loaders.length; for (int i = 0; i < size; i++) { LoaderEntry entry = loaders[i]; boolean match = (name == null) ? cl == entry.loader : name.equals(entry.name); if (match) { LoaderEntry[] newloaders = new LoaderEntry[size - 1]; System.arraycopy(loaders, 0, newloaders, 0, i); System.arraycopy(loaders, i + 1, newloaders, i, size - 1 - i); loaders = newloaders; return true; } } return false; } /** * List of valid search */ private final Map<String,List Other Java examples (source code examples)Here is a short list of links related to this Java ClassLoaderRepositorySupport.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.