Commit 9be973f9 authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gato

System properties are now updated across the cluster. ENT-235

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/trunk@9307 b35dd754-fafc-0310-a699-88a17e54d16e
parent ef60d4ce
......@@ -12,6 +12,7 @@
package org.jivesoftware.util;
import org.jivesoftware.database.DbConnectionManager;
import org.jivesoftware.util.cache.CacheFactory;
import java.sql.Connection;
import java.sql.PreparedStatement;
......@@ -154,8 +155,10 @@ public class JiveProperties implements Map<String, String> {
return properties.keySet();
}
public synchronized String remove(Object key) {
String value = properties.remove(key);
public String remove(Object key) {
String value;
synchronized (this) {
value = properties.remove(key);
// Also remove any children.
Collection<String> propNames = getPropertyNames();
for (String name : propNames) {
......@@ -164,26 +167,44 @@ public class JiveProperties implements Map<String, String> {
}
}
deleteProperty((String)key);
}
// Generate event.
Map<String, Object> params = Collections.emptyMap();
PropertyEventDispatcher.dispatchEvent((String)key, PropertyEventDispatcher.EventType.property_deleted, params);
// Send update to other cluster members.
CacheFactory.doClusterTask(PropertyClusterEventTask.createDeteleTask((String) key));
return value;
}
public synchronized String put(String key, String value) {
void localRemove(String key) {
properties.remove(key);
// Also remove any children.
Collection<String> propNames = getPropertyNames();
for (String name : propNames) {
if (name.startsWith(key)) {
properties.remove(name);
}
}
// Generate event.
Map<String, Object> params = Collections.emptyMap();
PropertyEventDispatcher.dispatchEvent(key, PropertyEventDispatcher.EventType.property_deleted, params);
}
public String put(String key, String value) {
if (key == null || value == null) {
throw new NullPointerException("Key or value cannot be null. Key=" +
key + ", value=" + value);
}
if (!(key instanceof String) || !(value instanceof String)) {
throw new IllegalArgumentException("Key and value must be of type String.");
}
if (key.endsWith(".")) {
key = key.substring(0, key.length()-1);
}
key = key.trim();
String result;
synchronized (this) {
if (properties.containsKey(key)) {
if (!properties.get(key).equals(value)) {
updateProperty(key, value);
......@@ -193,16 +214,29 @@ public class JiveProperties implements Map<String, String> {
insertProperty(key, value);
}
String result = properties.put(key, value);
result = properties.put(key, value);
}
// Generate event.
Map<String, Object> params = new HashMap<String, Object>();
params.put("value", value);
PropertyEventDispatcher.dispatchEvent(key, PropertyEventDispatcher.EventType.property_set, params);
// Send update to other cluster members.
CacheFactory.doClusterTask(PropertyClusterEventTask.createPutTask(key, value));
return result;
}
void localPut(String key, String value) {
properties.put(key, value);
// Generate event.
Map<String, Object> params = new HashMap<String, Object>();
params.put("value", value);
PropertyEventDispatcher.dispatchEvent(key, PropertyEventDispatcher.EventType.property_set, params);
}
public String getProperty(String name, String defaultValue) {
String value = properties.get(name);
if (value != null) {
......
/**
* $RCSfile$
* $Revision: $
* $Date: $
*
* Copyright (C) 2007 Jive Software. All rights reserved.
*
* This software is published under the terms of the GNU Public License (GPL),
* a copy of which is included in this distribution.
*/
package org.jivesoftware.util;
import org.jivesoftware.util.cache.ClusterTask;
import org.jivesoftware.util.cache.ExternalizableUtil;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
/**
* This task updates or deletes a property in a cluster node's property map.
* {@link PropertyEventListener} of each cluster node will be alerted of the event.
*
* @author Gaston Dombiak
*/
public class PropertyClusterEventTask implements ClusterTask {
private Type event;
private String key;
private String value;
public static PropertyClusterEventTask createPutTask(String key, String value) {
PropertyClusterEventTask task = new PropertyClusterEventTask();
task.event = Type.put;
task.key = key;
task.value = value;
return task;
}
public static PropertyClusterEventTask createDeteleTask(String key) {
PropertyClusterEventTask task = new PropertyClusterEventTask();
task.event = Type.deleted;
task.key = key;
return task;
}
public Object getResult() {
return null;
}
public void run() {
if (Type.put == event) {
JiveProperties.getInstance().localPut(key, value);
}
else if (Type.deleted == event) {
JiveProperties.getInstance().localRemove(key);
}
}
public void writeExternal(ObjectOutput out) throws IOException {
ExternalizableUtil.getInstance().writeInt(out, event.ordinal());
ExternalizableUtil.getInstance().writeSafeUTF(out, key);
ExternalizableUtil.getInstance().writeBoolean(out, value != null);
if (value != null) {
ExternalizableUtil.getInstance().writeSafeUTF(out, value);
}
}
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
event = Type.values()[ExternalizableUtil.getInstance().readInt(in)];
key = ExternalizableUtil.getInstance().readSafeUTF(in);
if (ExternalizableUtil.getInstance().readBoolean(in)) {
value = ExternalizableUtil.getInstance().readSafeUTF(in);
}
}
private static enum Type {
/**
* Event triggered when a system property was added or updated in the system.
*/
put,
/**
* Event triggered when a system property was deleted from the system.
*/
deleted
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment