use of java.util.concurrent.CopyOnWriteArrayList in project Openfire by igniterealtime.
the class InterceptorManager method loadLocalInterceptors.
private void loadLocalInterceptors(String workgroupJID) throws UserNotFoundException {
Workgroup workgroup = WorkgroupManager.getInstance().getWorkgroup(new JID(workgroupJID));
int interceptorCount = 0;
String iCount = workgroup.getProperties().getProperty("jive.interceptor." + getPropertySuffix() + ".interceptorCount");
if (iCount != null) {
try {
interceptorCount = Integer.parseInt(iCount);
} catch (NumberFormatException nfe) {
/* ignore */
}
}
// Load up all intercpetors.
List<PacketInterceptor> interceptorList = new ArrayList<PacketInterceptor>(interceptorCount);
for (int i = 0; i < interceptorCount; i++) {
try {
String interceptorContext = "jive.interceptor." + getPropertySuffix() + ".interceptor" + i + ".";
String className = workgroup.getProperties().getProperty(interceptorContext + "className");
Class interceptorClass = loadClass(className);
interceptorList.add((PacketInterceptor) interceptorClass.newInstance());
// Load properties.
Map<String, String> interceptorProps = new HashMap<String, String>();
for (String key : getChildrenPropertyNames(interceptorContext + "properties", workgroup.getProperties().getPropertyNames())) {
String value = workgroup.getProperties().getProperty(key);
// Get the bean property name, which is everything after the last '.' in the
// xml property name.
interceptorProps.put(key.substring(key.lastIndexOf(".") + 1), value);
}
// Set properties on the bean
BeanUtils.setProperties(interceptorList.get(i), interceptorProps);
} catch (Exception e) {
Log.error("Error loading local interceptor " + i, e);
}
}
localInterceptors.put(workgroupJID, new CopyOnWriteArrayList<PacketInterceptor>(interceptorList));
}
use of java.util.concurrent.CopyOnWriteArrayList in project liquibase by liquibase.
the class DatabaseSnapshot method replaceObject.
private Object replaceObject(Object fieldValue) throws DatabaseException, InvalidExampleException, IllegalAccessException, InstantiationException {
if (fieldValue == null) {
return null;
}
if (fieldValue instanceof DatabaseObject) {
if (((DatabaseObject) fieldValue).getSnapshotId() != null) {
//already been replaced
return fieldValue;
}
if (!snapshotControl.shouldInclude(((DatabaseObject) fieldValue).getClass())) {
return fieldValue;
}
if (isWrongSchema(((DatabaseObject) fieldValue))) {
DatabaseObject savedFieldValue = referencedObjects.get((DatabaseObject) fieldValue, schemaComparisons);
if (savedFieldValue == null) {
savedFieldValue = (DatabaseObject) fieldValue;
savedFieldValue.setSnapshotId(SnapshotIdService.getInstance().generateId());
includeNestedObjects(savedFieldValue);
referencedObjects.add(savedFieldValue);
}
return savedFieldValue;
}
if (fieldValue instanceof Catalog && isWrongCatalog(((DatabaseObject) fieldValue))) {
DatabaseObject savedFieldValue = referencedObjects.get((DatabaseObject) fieldValue, schemaComparisons);
if (savedFieldValue == null) {
savedFieldValue = (DatabaseObject) fieldValue;
savedFieldValue.setSnapshotId(SnapshotIdService.getInstance().generateId());
referencedObjects.add(savedFieldValue);
}
return savedFieldValue;
}
if (((DatabaseObject) fieldValue).getSnapshotId() == null) {
return include((DatabaseObject) fieldValue);
} else {
return fieldValue;
}
// } else if (Set.class.isAssignableFrom(field.getType())) {
// field.setAccessible(true);
// Set fieldValue = field.get(object);
// for (Object val : fieldValue) {
//
// }
} else if (fieldValue instanceof Collection) {
Iterator fieldValueIterator = new CopyOnWriteArrayList((Collection) fieldValue).iterator();
List newValues = new ArrayList();
while (fieldValueIterator.hasNext()) {
Object obj = fieldValueIterator.next();
if (fieldValue instanceof DatabaseObject && !snapshotControl.shouldInclude(((DatabaseObject) fieldValue).getClass())) {
return fieldValue;
}
if (obj instanceof DatabaseObject && ((DatabaseObject) obj).getSnapshotId() == null) {
obj = include((DatabaseObject) obj);
}
if (obj != null) {
newValues.add(obj);
}
}
Collection newCollection = null;
try {
Class<?> collectionClass = fieldValue.getClass();
if (List.class.isAssignableFrom(collectionClass)) {
collectionClass = ArrayList.class;
}
newCollection = (Collection) collectionClass.newInstance();
} catch (InstantiationException e) {
throw e;
}
newCollection.addAll(newValues);
return newCollection;
} else if (fieldValue instanceof Map) {
Map newMap = (Map) fieldValue.getClass().newInstance();
for (Map.Entry entry : new HashSet<Map.Entry>((Set<Map.Entry>) ((Map) fieldValue).entrySet())) {
Object key = replaceObject(entry.getKey());
Object value = replaceObject(entry.getValue());
if (key != null) {
newMap.put(key, value);
}
}
return newMap;
}
return fieldValue;
}
use of java.util.concurrent.CopyOnWriteArrayList in project jodd by oblac.
the class JSONSerializationTest method testCopyOnWriteList.
@Test
public void testCopyOnWriteList() {
CopyOnWriteArrayList<Person> people = new CopyOnWriteArrayList<>();
people.add(jodder);
people.add(modesty);
String json = new JsonSerializer().serialize(people);
assertAttribute("firstname", json);
assertStringValue("Igor", json);
assertStringValue("Modesty", json);
}
use of java.util.concurrent.CopyOnWriteArrayList in project Mycat-Server by MyCATApache.
the class PhysicalDBPool method initSource.
private boolean initSource(int index, PhysicalDatasource ds) {
int initSize = ds.getConfig().getMinCon();
LOGGER.info("init backend myqsl source ,create connections total " + initSize + " for " + ds.getName() + " index :" + index);
CopyOnWriteArrayList<BackendConnection> list = new CopyOnWriteArrayList<BackendConnection>();
GetConnectionHandler getConHandler = new GetConnectionHandler(list, initSize);
for (int i = 0; i < initSize; i++) {
try {
ds.getConnection(this.schemas[i % schemas.length], true, getConHandler, null);
} catch (Exception e) {
LOGGER.warn(getMessage(index, " init connection error."), e);
}
}
long timeOut = System.currentTimeMillis() + 60 * 1000;
// waiting for finish
while (!getConHandler.finished() && (System.currentTimeMillis() < timeOut)) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
LOGGER.error("initError", e);
}
}
LOGGER.info("init result :" + getConHandler.getStatusInfo());
// }
return !list.isEmpty();
}
use of java.util.concurrent.CopyOnWriteArrayList in project archaius by Netflix.
the class DynamicPropertyUpdater method addOrChangeProperty.
/**
* Add or update the property in the underlying config depending on if it exists
*
* @param name
* @param newValue
* @param config
*/
void addOrChangeProperty(final String name, final Object newValue, final Configuration config) {
// We do not want to abort the operation due to failed validation on one property
try {
if (!config.containsKey(name)) {
logger.debug("adding property key [{}], value [{}]", name, newValue);
config.addProperty(name, newValue);
} else {
Object oldValue = config.getProperty(name);
if (newValue != null) {
Object newValueArray;
if (oldValue instanceof CopyOnWriteArrayList && AbstractConfiguration.getDefaultListDelimiter() != '\0') {
newValueArray = new CopyOnWriteArrayList();
Iterable<String> stringiterator = Splitter.on(AbstractConfiguration.getDefaultListDelimiter()).omitEmptyStrings().trimResults().split((String) newValue);
for (String s : stringiterator) {
((CopyOnWriteArrayList) newValueArray).add(s);
}
} else {
newValueArray = newValue;
}
if (!newValueArray.equals(oldValue)) {
logger.debug("updating property key [{}], value [{}]", name, newValue);
config.setProperty(name, newValue);
}
} else if (oldValue != null) {
logger.debug("nulling out property key [{}]", name);
config.setProperty(name, null);
}
}
} catch (ValidationException e) {
logger.warn("Validation failed for property " + name, e);
}
}
Aggregations