Example usage for java.util.concurrent CopyOnWriteArrayList add

List of usage examples for java.util.concurrent CopyOnWriteArrayList add

Introduction

In this page you can find the example usage for java.util.concurrent CopyOnWriteArrayList add.

Prototype

public boolean add(E e) 

Source Link

Document

Appends the specified element to the end of this list.

Usage

From source file:Main.java

/**
 * Create a {@link CopyOnWriteArrayList} with zero or more "objects".
 * @param <O>//from ww  w . j av a  2 s . com
 * @return CopyOnWriteArrayList<O>
 */
@SafeVarargs
public static <O> CopyOnWriteArrayList<O> copyOnWriteArrayList(O... objects) {
    CopyOnWriteArrayList<O> list = new CopyOnWriteArrayList<>();

    for (O object : objects) {
        list.add(object);
    }

    return list;
}

From source file:org.apache.bval.jsr.xml.ValidationParser.java

private static void applyExecutableValidation(final ValidationConfigType xmlConfig,
        final ConfigurationImpl targetConfig) {
    final CopyOnWriteArrayList<ExecutableType> executableTypes = new CopyOnWriteArrayList<ExecutableType>();
    if (xmlConfig.getExecutableValidation() != null && xmlConfig.getExecutableValidation().getEnabled()
            && xmlConfig.getExecutableValidation().getDefaultValidatedExecutableTypes() != null) {
        executableTypes.addAll(/*from   w  w  w  .j  a v  a 2  s  .  c om*/
                xmlConfig.getExecutableValidation().getDefaultValidatedExecutableTypes().getExecutableType());
    }

    if (executableTypes.contains(ExecutableType.ALL)) {
        executableTypes.clear();
        executableTypes.add(ExecutableType.CONSTRUCTORS);
        executableTypes.add(ExecutableType.NON_GETTER_METHODS);
        executableTypes.add(ExecutableType.GETTER_METHODS);
    } else if (executableTypes.contains(ExecutableType.NONE)) { // if both are present ALL gains
        executableTypes.clear();
    }

    targetConfig.setExecutableValidation(executableTypes);
}

From source file:com.app.server.JarDeployer.java

/**
 * This method obtains the class name inside the jar
 * @param jarPath/*w  w  w  .  java  2  s  . com*/
 * @param content
 * @throws IOException
 */
public static void getJarContent(String jarPath, CopyOnWriteArrayList content) throws IOException {
    try {
        log.info("enumer=" + jarPath);

        JarFile jarFile = new JarFile(jarPath);
        Enumeration enumer = (Enumeration) jarFile.entries();
        while (enumer.hasMoreElements()) {
            JarEntry entry = (JarEntry) enumer.nextElement();
            String name = entry.getName();
            if (name.endsWith(".class"))
                content.add(name.replace("/", "."));
        }
        log.info(content);
        jarFile.close();
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:com.web.server.JarDeployer.java

/**
 * This method obtains the class name inside the jar
 * @param jarPath/*from w w  w . jav a2s.c o  m*/
 * @param content
 * @throws IOException
 */
public static void getJarContent(String jarPath, CopyOnWriteArrayList content) throws IOException {
    try {
        System.out.println("enumer=" + jarPath);

        JarFile jarFile = new JarFile(jarPath);
        Enumeration enumer = (Enumeration) jarFile.entries();
        while (enumer.hasMoreElements()) {
            JarEntry entry = (JarEntry) enumer.nextElement();
            String name = entry.getName();
            if (name.endsWith(".class"))
                content.add(name.replace("/", "."));
        }
        System.out.println(content);
        jarFile.close();
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:com.app.server.util.ClassLoaderUtil.java

public static CopyOnWriteArrayList closeClassLoader(ClassLoader cl) {
    CopyOnWriteArrayList jars = new CopyOnWriteArrayList();
    boolean res = false;
    Class classURLClassLoader = null;
    if (cl instanceof URLClassLoader) {
        classURLClassLoader = URLClassLoader.class;
        if (cl instanceof WebClassLoader) {
            String url = "";
            CopyOnWriteArrayList webCLUrl = ((WebClassLoader) cl).geturlS();
            for (int index = 0; index < webCLUrl.size(); index++) {

                try {
                    url = ((URL) webCLUrl.get(index)).toURI().toString();
                } catch (URISyntaxException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }/*from  www .  j av  a  2s . c o m*/
                jars.add(url.replace("file:", "").replace("/", "\\").toUpperCase());
            }
        }
    } else if (cl instanceof VFSClassLoader) {
        classURLClassLoader = VFSClassLoader.class;
    }
    Field f = null;
    try {
        f = classURLClassLoader.getDeclaredField("ucp");
        //log.info(f);
    } catch (NoSuchFieldException e1) {
        // e1.printStackTrace();
        // log.info(e1.getMessage(), e1);

    }
    if (f != null) {
        f.setAccessible(true);
        Object obj = null;
        try {
            obj = f.get(cl);
        } catch (IllegalAccessException e1) {
            // e1.printStackTrace();
            // log.info(e1.getMessage(), e1);
        }
        if (obj != null) {
            final Object ucp = obj;
            f = null;
            try {
                f = ucp.getClass().getDeclaredField("loaders");
                //log.info(f);
            } catch (NoSuchFieldException e1) {
                // e1.printStackTrace();
                // log.info(e1.getMessage(), e1);
            }
            if (f != null) {
                f.setAccessible(true);
                ArrayList loaders = null;
                try {
                    loaders = (ArrayList) f.get(ucp);
                    res = true;
                } catch (IllegalAccessException e1) {
                    // e1.printStackTrace();
                }
                for (int i = 0; loaders != null && i < loaders.size(); i++) {
                    obj = loaders.get(i);
                    f = null;
                    try {
                        f = obj.getClass().getDeclaredField("jar");
                        // log.info(f);
                    } catch (NoSuchFieldException e) {
                        // e.printStackTrace();
                        // log.info(e.getMessage(), e);
                    }
                    if (f != null) {
                        f.setAccessible(true);
                        try {
                            obj = f.get(obj);
                        } catch (IllegalAccessException e1) {
                            // e1.printStackTrace();
                            // log.info(e1.getMessage(), e1);
                        }
                        if (obj instanceof JarFile) {
                            final JarFile jarFile = (JarFile) obj;
                            //log.info(jarFile.getName());
                            jars.add(jarFile.getName().replace("/", "\\").trim().toUpperCase());
                            // try {
                            // jarFile.getManifest().clear();
                            // } catch (IOException e) {
                            // // ignore
                            // }
                            try {
                                jarFile.close();
                            } catch (IOException e) {
                                e.printStackTrace();
                                // ignore
                                // log.info(e.getMessage(), e);
                            }
                        }
                    }
                }
            }
        }
    }
    return jars;
}

From source file:com.netflix.config.DynamicURLConfigurationTestWithFileURL.java

@Test
public void testFileURLWithPropertiesUpdatedDynamically() throws IOException, InterruptedException {

    File file = File.createTempFile("DynamicURLConfigurationTestWithFileURL",
            "testFileURLWithPropertiesUpdatedDynamically");
    populateFile(file, "test.host=12312,123213", "test.host1=13212");

    AbstractConfiguration.setDefaultListDelimiter(',');
    DynamicURLConfiguration config = new DynamicURLConfiguration(0, 500, false, file.toURI().toString());
    Thread.sleep(1000);/*  w w w .  jav  a  2s .  c o  m*/
    Assert.assertEquals(13212, config.getInt("test.host1"));
    Thread.sleep(1000);
    populateFile(file, "test.host=12312,123213", "test.host1=13212");
    populateFile(file, "test.host=12312,123213", "test.host1=13212");
    CopyOnWriteArrayList writeList = new CopyOnWriteArrayList();
    writeList.add("12312");
    writeList.add("123213");
    config.setProperty("sample.domain", "google,yahoo");
    Assert.assertEquals(writeList, config.getProperty("test.host"));

}

From source file:com.iitb.cse.Utils.java

public static CopyOnWriteArrayList<DeviceInfo> activeClients() {
    //   (Utils.getCurrentTimeStamp().getTime() - device.getLastHeartBeatTime().getTime())/1000 > 60 
    //        int count = 0;

    ConcurrentHashMap<String, DeviceInfo> clients = Constants.currentSession.getConnectedClients();
    Enumeration<String> macList = clients.keys();
    ConcurrentHashMap<String, DeviceInfo> connectedClients = new ConcurrentHashMap<String, DeviceInfo>();
    CopyOnWriteArrayList<DeviceInfo> activeClients = new CopyOnWriteArrayList<DeviceInfo>();

    if (clients != null) {
        while (macList.hasMoreElements()) {
            String macAddr = macList.nextElement();
            DeviceInfo device = clients.get(macAddr);
            if ((Utils.getCurrentTimeStamp().getTime() - device.getLastHeartBeatTime().getTime())
                    / 1000 <= Constants.heartBeatAlive) {
                activeClients.add(device);
                //                   count++;
            }/*w w  w .  ja  v  a 2  s . c o  m*/
        }
    }
    return activeClients;
}

From source file:org.apache.activemq.artemis.spi.core.protocol.AbstractProtocolManagerFactory.java

/**
 * This method exists because java templates won't store the type of P at runtime.
 * So it's not possible to write a generic method with having the Class Type.
 * This will serve as a tool for sub classes to filter properly* * *
 *
 * @param type/*  w  w w  . j  a  va2s.  co  m*/
 * @param listIn
 * @return
 */
protected List<P> internalFilterInterceptors(Class<P> type, List<? extends BaseInterceptor> listIn) {
    if (listIn == null) {
        return Collections.emptyList();
    } else {
        CopyOnWriteArrayList<P> listOut = new CopyOnWriteArrayList<>();
        for (BaseInterceptor<?> in : listIn) {
            if (type.isInstance(in)) {
                listOut.add((P) in);
            }
        }
        return listOut;
    }
}

From source file:edu.eci.arsw.pacm.services.PacmServicesStub.java

@Override
public void registrarJugadorAtacante(int salanum, Player p) throws ServicesException {
    if (!salasData.containsKey(salanum)) {
        throw new ServicesException("Sala " + salanum + " no ha sido registrada en el servidor.");
    } else {/*from   w  w w . java 2s .  co  m*/
        CopyOnWriteArrayList tmp = salasData.get(salanum).getAtacantes();
        int a = 64 + tmp.size();
        identifacadores.put(p.getNombre(), Character.toString((char) a));
        tmp.add(p);
        salasData.get(salanum).setAtacantes(tmp);
    }
}

From source file:edu.eci.arsw.pacm.services.PacmServicesStub.java

@Override
public void registrarJugadorProtector(int salanum, Player p) throws ServicesException {
    if (!salasData.containsKey(salanum)) {
        throw new ServicesException("Sala " + salanum + " no ha sido registrada en el servidor.");
    } else {//www .j av a2  s  .  co  m
        CopyOnWriteArrayList tmp = salasData.get(salanum).getProtectores();
        int a = 96 + tmp.size();
        identifacadores.put(p.getNombre(), Character.toString((char) a));
        tmp.add(p);
        salasData.get(salanum).setProtectores(tmp);
    }
}