use of com.biglybt.core.config.ParameterListener in project BiglyBT by BiglySoftware.
the class ConfigurationManager method addParameterListener.
public void addParameterListener(String parameter, ParameterListener new_listener) {
if (parameter == null || new_listener == null) {
return;
}
synchronized (parameterListenerz) {
ParameterListener[] listeners = parameterListenerz.get(parameter);
if (listeners == null) {
parameterListenerz.put(parameter, new ParameterListener[] { new_listener });
} else {
ParameterListener[] new_listeners = new ParameterListener[listeners.length + 1];
if (Constants.IS_CVS_VERSION && listeners.length > 100) {
Debug.out(parameter);
}
int pos;
if (new_listener instanceof PriorityParameterListener) {
new_listeners[0] = new_listener;
pos = 1;
} else {
new_listeners[listeners.length] = new_listener;
pos = 0;
}
for (int i = 0; i < listeners.length; i++) {
ParameterListener existing_listener = listeners[i];
if (existing_listener == new_listener) {
return;
}
new_listeners[pos++] = existing_listener;
}
if (DEBUG_PARAMETER_LISTENERS) {
System.out.println(parameter + "->" + new_listeners.length);
}
parameterListenerz.put(parameter, new_listeners);
}
}
}
use of com.biglybt.core.config.ParameterListener in project BiglyBT by BiglySoftware.
the class ConfigurationManager method removeParameterListener.
public void removeParameterListener(String parameter, ParameterListener listener) {
if (parameter == null || listener == null) {
return;
}
synchronized (parameterListenerz) {
ParameterListener[] listeners = parameterListenerz.get(parameter);
if (listeners == null) {
return;
}
if (listeners.length == 1) {
if (listeners[0] == listener) {
parameterListenerz.remove(parameter);
}
} else {
ParameterListener[] new_listeners = new ParameterListener[listeners.length - 1];
int pos = 0;
for (int i = 0; i < listeners.length; i++) {
ParameterListener existing_listener = listeners[i];
if (existing_listener != listener) {
if (pos == new_listeners.length) {
return;
}
new_listeners[pos++] = existing_listener;
}
}
if (DEBUG_PARAMETER_LISTENERS) {
System.out.println(parameter + "->" + new_listeners.length);
}
parameterListenerz.put(parameter, new_listeners);
}
}
}
use of com.biglybt.core.config.ParameterListener in project BiglyBT by BiglySoftware.
the class FileLogging method initialize.
public void initialize() {
// Shorten from COConfigurationManager To make code more readable
final ConfigurationManager config = ConfigurationManager.getInstance();
boolean overrideLog = System.getProperty(SystemProperties.SYSPROP_OVERRIDELOG) != null;
for (int i = 0; i < ignoredComponents.length; i++) {
ignoredComponents[i] = new ArrayList();
}
if (!overrideLog) {
config.addListener(new COConfigurationListener() {
@Override
public void configurationSaved() {
checkLoggingConfig();
}
});
}
checkLoggingConfig();
config.addParameterListener(CFG_ENABLELOGTOFILE, new ParameterListener() {
@Override
public void parameterChanged(String parameterName) {
FileLogging.this.reloadLogToFileParam();
}
});
}
use of com.biglybt.core.config.ParameterListener in project BiglyBT by BiglySoftware.
the class LoggerImpl method init.
/**
* Must be seperate from constructor, because the code may call a Logger.*
* method, which requires a loggerImpl to be not null.
*/
public void init() {
// temporarily set to true, to log any errors between now and setting
// bEnabled properly.
bEventLoggingEnabled = true;
// Shorten from COConfigurationManager To make code more readable
final ConfigurationManager config = ConfigurationManager.getInstance();
boolean overrideLog = System.getProperty(SystemProperties.SYSPROP_OVERRIDELOG) != null;
if (overrideLog) {
bEventLoggingEnabled = true;
} else {
bEventLoggingEnabled = config.getBooleanParameter("Logger.Enabled");
config.addParameterListener("Logger.Enabled", new ParameterListener() {
@Override
public void parameterChanged(String parameterName) {
bEventLoggingEnabled = config.getBooleanParameter("Logger.Enabled");
}
});
}
}
use of com.biglybt.core.config.ParameterListener in project BiglyBT by BiglySoftware.
the class TorrentUtils method getIgnoreSetSupport.
private static synchronized Set<String> getIgnoreSetSupport(boolean force) {
if (ignore_files_set == null || force) {
Set<String> new_ignore_set = new HashSet<>();
String ignore_list = COConfigurationManager.getStringParameter("File.Torrent.IgnoreFiles", TOTorrent.DEFAULT_IGNORE_FILES);
if (ignore_files_set == null) {
// first time - add the listener
COConfigurationManager.addParameterListener("File.Torrent.IgnoreFiles", new ParameterListener() {
@Override
public void parameterChanged(String parameterName) {
getIgnoreSetSupport(true);
}
});
}
int pos = 0;
while (true) {
int p1 = ignore_list.indexOf(";", pos);
String bit;
if (p1 == -1) {
bit = ignore_list.substring(pos);
} else {
bit = ignore_list.substring(pos, p1);
pos = p1 + 1;
}
// use default locale as we're dealing with local file names
new_ignore_set.add(bit.trim().toLowerCase());
if (p1 == -1) {
break;
}
}
ignore_files_set = new_ignore_set;
}
return (ignore_files_set);
}
Aggregations