Search in sources :

Example 76 with CopyOnWriteArrayList

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));
}
Also used : JID(org.xmpp.packet.JID) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Workgroup(org.jivesoftware.xmpp.workgroup.Workgroup) UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException)

Example 77 with CopyOnWriteArrayList

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;
}
Also used : CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) DatabaseObject(liquibase.structure.DatabaseObject) DatabaseObjectCollection(liquibase.structure.DatabaseObjectCollection) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) DatabaseObject(liquibase.structure.DatabaseObject) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList)

Example 78 with CopyOnWriteArrayList

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);
}
Also used : ObjectJsonSerializer(jodd.json.impl.ObjectJsonSerializer) Person(jodd.json.mock.Person) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Test(org.junit.Test)

Example 79 with CopyOnWriteArrayList

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();
}
Also used : BackendConnection(io.mycat.backend.BackendConnection) GetConnectionHandler(io.mycat.backend.mysql.nio.handler.GetConnectionHandler) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList)

Example 80 with CopyOnWriteArrayList

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);
    }
}
Also used : ValidationException(com.netflix.config.validation.ValidationException) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList)

Aggregations

CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)97 CountDownLatch (java.util.concurrent.CountDownLatch)38 IOException (java.io.IOException)23 ArrayList (java.util.ArrayList)23 List (java.util.List)23 Test (org.junit.Test)20 ExecutionException (java.util.concurrent.ExecutionException)15 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)13 CyclicBarrier (java.util.concurrent.CyclicBarrier)11 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)11 BrokenBarrierException (java.util.concurrent.BrokenBarrierException)10 MockTransportService (org.elasticsearch.test.transport.MockTransportService)10 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)9 HashMap (java.util.HashMap)8 AtomicReference (java.util.concurrent.atomic.AtomicReference)7 HashSet (java.util.HashSet)6 Map (java.util.Map)6 TimeUnit (java.util.concurrent.TimeUnit)6 Settings (org.elasticsearch.common.settings.Settings)6 Config (com.hazelcast.config.Config)5