The version of Apache log4j used by SoundHelix.
Clone
HTTPS:
git clone https://vervis.peers.community/repos/aEp6o
SSH:
git clone USERNAME@vervis.peers.community:aEp6o
Branches
Tags
- 1.3alpha-7
- CHAINSAW_2_SANDBOX_MERGE
- CORE_VERSION
- LEVEL_REPLACES_PRIORITY
- PREALPHA_1_3_AS_OF_2004_05_12
- PRE_CHAINSAW_MODEL_CONVERSION
- PRE_UGLI_MOVE
- TAG_CHAINSAW2_MOVE
- log4j-1.2.17
- log4j-1.2.17-rc1
- v1.3alpha8
- v1.3alpha8-temp
- v1_2_1
- v1_2_10-recalled
- v1_2_11
- v1_2_11_rc1
- v1_2_11rc3
- v1_2_12
- v1_2_12_rc1
- v1_2_12_rc2
- v1_2_12_rc3
- v1_2_12_rc4
- v1_2_12_rc5
- v1_2_12_rc6
- v1_2_13
- v1_2_13_rc1
- v1_2_13_rc2
- v1_2_13_site_update
- v1_2_14
- v1_2_14_maven
- v1_2_14_rc1
- v1_2_14_site_update
- v1_2_15
- v1_2_15_rc1
- v1_2_15_rc2
- v1_2_15_rc3
- v1_2_15_rc4
- v1_2_15_rc5
- v1_2_15_rc6
- v1_2_16
- v1_2_16_rc1
- v1_2_16_rc2
- v1_2_17
- v1_2_17-rc1
- v1_2_17_rc1
- v1_2_17_rc2
- v1_2_17_rc3
- v1_2_2
- v1_2_3
- v1_2_4
- v1_2_6
- v1_2_7
- v1_2_9
- v1_2_alpha0
- v1_2_alpha7
- v1_2beta1
- v1_2final
- v1_3alpha_1
- v1_3alpha_6
- v_1_0
- v_1_0_1
- v_1_0_4
- v_1_1
- v_1_1_1
- v_1_1_2
- v_1_1_3
- v_1_1_b1
- v_1_1b2
- v_1_1b3
- v_1_1b5
- v_1_1b6
- v_1_1b7
- v_1_2beta3
PluginRegistry.java
/*
* Copyright 1999,2006 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.log4j.plugins;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.apache.log4j.spi.LoggerRepository;
import org.apache.log4j.spi.LoggerRepositoryEx;
import org.apache.log4j.spi.LoggerRepositoryEventListener;
/**
This is a registry for Plugin instances. It provides methods to
start and stop plugin objects individually and to stop all
plugins for a repository.
@author Mark Womack
@author Paul Smith
@since 1.3
*/
public final class PluginRegistry {
/**
* The pluginMap is keyed by plugin name and contains plugins as values.
* key=plugin.getName, value=plugin
*/
private final Map pluginMap;
private final LoggerRepositoryEx loggerRepository;
/**
* the listener used to listen for repository events.
*/
private final RepositoryListener listener = new RepositoryListener();
private final List listenerList = Collections.synchronizedList(new ArrayList());
public PluginRegistry(LoggerRepositoryEx loggerRepository) {
pluginMap = new HashMap();
this.loggerRepository = loggerRepository;
this.loggerRepository.addLoggerRepositoryEventListener(listener);
}
public LoggerRepositoryEx getLoggerRepository() {
return loggerRepository;
}
/**
* Returns true if the specified name is already taken by
* an existing Plugin registered within the scope of the specified
* LoggerRepository.
* @param name The name to check the repository for
* @return true if the name is already in use, otherwise false
*/
public boolean pluginNameExists(String name) {
synchronized (pluginMap) {
return pluginMap.containsKey(name);
}
}
/**
* Adds a plugin to the plugin registry. If a plugin with the same name exists
* already, it is shutdown and removed.
*
* @param plugin the plugin to add.
* */
public void addPlugin(Plugin plugin) {
// put plugin into the repository's reciever map
synchronized (pluginMap) {
String name = plugin.getName();
// make sure the plugin has reference to repository
plugin.setLoggerRepository(getLoggerRepository());
Plugin existingPlugin = (Plugin)pluginMap.get(name);
if (existingPlugin != null) {
existingPlugin.shutdown();
}
// put the new plugin into the map
pluginMap.put(name, plugin);
firePluginStarted(plugin);
}
}
/**
* Calls the pluginStarted method on every registered PluginListener.
*
* @param plugin The plugin that has been started.
*/
private void firePluginStarted(Plugin plugin) {
PluginEvent e = null;
synchronized(listenerList){
for (Iterator iter = listenerList.iterator(); iter.hasNext();) {
PluginListener listener = (PluginListener) iter.next();
if (e == null) {
e = new PluginEvent(plugin);
}
listener.pluginStarted(e);
}
}
}
/**
* Calls the pluginStopped method for every registered PluginListner.
*
* @param plugin The plugin that has been stopped.
*/
private void firePluginStopped(Plugin plugin) {
PluginEvent e = null;
synchronized(listenerList){
for (Iterator iter = listenerList.iterator(); iter.hasNext();) {
PluginListener listener = (PluginListener) iter.next();
if (e == null) {
e = new PluginEvent(plugin);
}
listener.pluginStopped(e);
}
}
}
/**
* Returns all the plugins for a given repository.
*
* @return List list of plugins from the repository.
*/
public List getPlugins() {
synchronized (pluginMap) {
List pluginList = new ArrayList(pluginMap.size());
Iterator iter = pluginMap.values().iterator();
while (iter.hasNext()) {
pluginList.add(iter.next());
}
return pluginList;
}
}
/**
Returns all the plugins for a given repository that are instances
of a certain class.
@param pluginClass the class the plugin must implement to be selected.
@return List list of plugins from the repository. */
public List getPlugins(Class pluginClass) {
synchronized (pluginMap) {
List pluginList = new ArrayList(pluginMap.size());
Iterator iter = pluginMap.values().iterator();
while (iter.hasNext()) {
Object plugin = iter.next();
if (pluginClass.isInstance(plugin)) {
pluginList.add(plugin);
}
}
return pluginList;
}
}
/**
Stops a plugin by plugin name and repository.
@param pluginName the name of the plugin to stop.
@return Plugin the plugin, if stopped, or null if the
the plugin was not found in the registry. */
public Plugin stopPlugin(String pluginName) {
synchronized (pluginMap) {
Plugin plugin = (Plugin)pluginMap.get(pluginName);
if (plugin == null) {
return null;
}
// shutdown the plugin
plugin.shutdown();
// remove it from the plugin map
pluginMap.remove(pluginName);
firePluginStopped(plugin);
// return it for future use
return plugin;
}
}
/**
Stops all plugins in the given logger repository.
*/
public void stopAllPlugins() {
synchronized (pluginMap) {
// remove the listener for this repository
loggerRepository.removeLoggerRepositoryEventListener(listener);
Iterator iter = pluginMap.values().iterator();
while (iter.hasNext()) {
Plugin plugin = (Plugin)iter.next();
plugin.shutdown();
firePluginStopped(plugin);
}
}
}
/**
* Adds a PluginListener to this registry to be notified
* of PluginEvents
*
* @param l PluginListener to add to this registry
*/
public final void addPluginListener(PluginListener l) {
listenerList.add(l);
}
/**
* Removes a particular PluginListener from this registry
* such that it will no longer be notified of PluginEvents
*
* @param l PluginListener to remove
*/
public final void removePluginListener(PluginListener l) {
listenerList.remove(l);
}
/**
Internal class used to handle listener events from repositories. */
private class RepositoryListener implements LoggerRepositoryEventListener {
/**
Stops all plugins associated with the repository being reset.
@param repository the repository that was reset. */
public void configurationResetEvent(LoggerRepository repository) {
PluginRegistry.this.stopAllPlugins();
}
/**
Called when the repository configuration is changed.
@param repository the repository that was changed. */
public void configurationChangedEvent(LoggerRepository repository) {
// do nothing with this event
}
/**
Stops all plugins associated with the repository being shutdown.
@param repository the repository being shutdown. */
public void shutdownEvent(LoggerRepository repository) {
PluginRegistry.this.stopAllPlugins();
}
}
}