Example usage for java.util.concurrent CopyOnWriteArrayList size

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

Introduction

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

Prototype

public int size() 

Source Link

Document

Returns the number of elements in this list.

Usage

From source file:org.springframework.data.solr.server.support.SolrServerUtils.java

private static LBHttpSolrServer cloneSolr3LBHttpServer(SolrServer solrServer, String core)
        throws MalformedURLException {
    CopyOnWriteArrayList<?> list = readField(solrServer, "aliveServers");

    String[] servers = new String[list.size()];
    for (int i = 0; i < list.size(); i++) {
        servers[i] = appendCoreToBaseUrl(list.get(i).toString(), core);
    }/*from www .  j a  v a2  s  .c  o m*/
    return new LBHttpSolrServer(servers);
}

From source file:com.frank.search.solr.server.support.SolrClientUtils.java

private static LBHttpSolrClient cloneSolr3LBHttpServer(SolrClient solrClient, String core)
        throws MalformedURLException {
    CopyOnWriteArrayList<?> list = readField(solrClient, "aliveServers");

    String[] servers = new String[list.size()];
    for (int i = 0; i < list.size(); i++) {
        servers[i] = appendCoreToBaseUrl(list.get(i).toString(), core);
    }/*from ww  w . j  a  va2  s .c  om*/
    return new LBHttpSolrClient(servers);
}

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   ww w  .  j  a va  2s  .com*/
                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.iitb.cse.Utils.java

public static int getClientListForLogRequest(int expId) {

    System.out.println("\nGetLogFile Request ExpID : " + expId);
    CopyOnWriteArrayList<String> clients = DBManager.getClientsForLogRequest(expId);

    String[] list = new String[clients.size()];

    for (int i = 0; i < clients.size(); i++) {
        list[i] = clients.get(i);//from   w w  w  . j a  v a2 s .co m
        list[i] = expId + "_" + list[i];
        System.out.println("\nGetLogFile Request CLient " + list[i]);
    }

    Utils.requestLogFiles(5, 5, list);
    return clients.size();

}

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  www.  j a va2  s  .c om*/
        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 {//from   ww w .j  a va 2s  .c  o  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);
    }
}

From source file:com.web.messaging.MessagingClassConstruct.java

/**
 * This method parses the messagingclass.xml which is obtained after undeploying the War file and metadata which is constructed in removed from the messaingclassMap 
 * @param messagedigester//from w  w w  .  j  av a  2  s .  c o m
 * @param configFile
 * @param messagingClassMap
 * @throws FileNotFoundException
 * @throws IOException
 * @throws SAXException
 */
public void removeMessagingClass(Digester messagedigester, File configFile, Hashtable messagingClassMap)
        throws FileNotFoundException, IOException, SAXException {
    try {
        MessagingClasses messagingClasses = (MessagingClasses) messagedigester
                .parse(new InputSource(new FileInputStream(configFile)));
        for (MessagingClass messagingclass : messagingClasses.messagingClasses) {
            if (messagingclass.getMessagetype().equals("RandomQueue")) {
                ConcurrentHashMap randomqueuemap = (ConcurrentHashMap) messagingClassMap.get("RandomQueue");
                //System.out.println("MessageElemName="+messagingclass.getMessageelemname().trim()+"Random Queue Map"+randomqueuemap);
                if (randomqueuemap != null) {
                    CopyOnWriteArrayList queueclassList = (CopyOnWriteArrayList) randomqueuemap
                            .get(messagingclass.getMessageelemname().trim());
                    if (queueclassList != null) {
                        for (int count = 0; count < queueclassList.size(); count++) {
                            MessagingClass messagingClassTmp = (MessagingClass) queueclassList.get(count);
                            //System.out.println(messagingClassTmp);
                            //System.out.println(messagingClassTmp.getMessageelemname()+" "+messagingclass.getMessageelemname() );
                            //System.out.println(messagingClassTmp.getMessagetype()+" "+messagingclass.getMessagetype() );
                            //System.out.println(messagingClassTmp.getMessagingclass()+" "+messagingclass.getMessagingclass() );
                            if (messagingClassTmp.getMessageelemname().trim()
                                    .equals(messagingclass.getMessageelemname().trim())
                                    && messagingClassTmp.getMessagetype().trim()
                                            .equals(messagingclass.getMessagetype().trim())
                                    && messagingClassTmp.getMessagingclass().trim()
                                            .equals(messagingclass.getMessagingclass().trim())) {
                                queueclassList.remove(messagingClassTmp);
                            }
                            //System.out.println(count);
                            //System.out.println("MessageElemName="+messagingClassTmp);
                        }
                    }
                }
            } else if (messagingclass.getMessagetype().equals("RoundRobinQueue")) {
                ConcurrentHashMap roundrobinqueuemap = (ConcurrentHashMap) messagingClassMap
                        .get("RoundRobinQueue");
                //System.out.println("RoundRobinQueueMap"+roundrobinqueuemap);
                if (roundrobinqueuemap != null) {
                    CopyOnWriteArrayList queueclassList = (CopyOnWriteArrayList) roundrobinqueuemap
                            .get(messagingclass.getMessageelemname().trim());
                    if (queueclassList != null) {
                        for (int count = 0; count < queueclassList.size(); count++) {
                            MessagingClass messagingClassTmp = (MessagingClass) queueclassList.get(count);
                            if (messagingClassTmp.getMessageelemname()
                                    .equals(messagingclass.getMessageelemname())
                                    && messagingClassTmp.getMessagetype()
                                            .equals(messagingclass.getMessagetype())
                                    && messagingClassTmp.getMessagingclass()
                                            .equals(messagingclass.getMessagingclass())) {
                                queueclassList.remove(messagingClassTmp);
                            }

                        }
                    }
                }
                //System.out.println("End RoundRobinQueueMap"+roundrobinqueuemap);
            } else if (messagingclass.getMessagetype().equals("Topic")) {
                ConcurrentHashMap topicmap = (ConcurrentHashMap) messagingClassMap.get("Topic");
                //System.out.println("TopicMap"+topicmap);
                if (topicmap != null) {
                    CopyOnWriteArrayList topicclassList = (CopyOnWriteArrayList) topicmap
                            .get(messagingclass.getMessageelemname().trim());
                    if (topicclassList != null) {
                        for (int count = 0; count < topicclassList.size(); count++) {
                            MessagingClass messagingClassTmp = (MessagingClass) topicclassList.get(count);
                            if (messagingClassTmp.getMessageelemname()
                                    .equals(messagingclass.getMessageelemname())
                                    && messagingClassTmp.getMessagetype()
                                            .equals(messagingclass.getMessagetype())
                                    && messagingClassTmp.getMessagingclass()
                                            .equals(messagingclass.getMessagingclass())) {
                                topicclassList.remove(messagingClassTmp);
                            }
                        }
                    }
                }
                //System.out.println("End TopicMap"+topicmap);
            }
        }
    } catch (Exception ex) {
        //ex.printStackTrace();
    }
    //System.out.println(messagingClassMap);
}

From source file:com.app.messaging.MessagingClassConstruct.java

/**
 * This method parses the messagingclass.xml which is obtained after undeploying the War file and metadata which is constructed in removed from the messaingclassMap 
 * @param messagedigester//from   w  w w  .  j  a  v  a  2 s  . co m
 * @param configFile
 * @param messagingClassMap
 * @throws FileNotFoundException
 * @throws IOException
 * @throws SAXException
 */
public void removeMessagingClass(Digester messagedigester, File configFile, Hashtable messagingClassMap)
        throws FileNotFoundException, IOException, SAXException {
    try {
        MessagingClasses messagingClasses = (MessagingClasses) messagedigester
                .parse(new InputSource(new FileInputStream(configFile)));
        for (MessagingClass messagingclass : messagingClasses.messagingClasses) {
            if (messagingclass.getMessagetype().equals("RandomQueue")) {
                ConcurrentHashMap randomqueuemap = (ConcurrentHashMap) messagingClassMap.get("RandomQueue");
                //System.out.println("MessageElemName="+messagingclass.getMessageelemname().trim()+"Random Queue Map"+randomqueuemap);
                if (randomqueuemap != null) {
                    CopyOnWriteArrayList queueclassList = (CopyOnWriteArrayList) randomqueuemap
                            .get(messagingclass.getMessageelemname().trim());
                    if (queueclassList != null) {
                        for (int count = 0; count < queueclassList.size(); count++) {
                            MessagingClass messagingClassTmp = (MessagingClass) queueclassList.get(count);
                            //System.out.println(messagingClassTmp);
                            //System.out.println(messagingClassTmp.getMessageelemname()+" "+messagingclass.getMessageelemname() );
                            //System.out.println(messagingClassTmp.getMessagetype()+" "+messagingclass.getMessagetype() );
                            //System.out.println(messagingClassTmp.getMessagingclass()+" "+messagingclass.getMessagingclass() );
                            if (messagingClassTmp.getMessageelemname().trim()
                                    .equals(messagingclass.getMessageelemname().trim())
                                    && messagingClassTmp.getMessagetype().trim()
                                            .equals(messagingclass.getMessagetype().trim())
                                    && messagingClassTmp.getMessagingclass().trim()
                                            .equals(messagingclass.getMessagingclass().trim())) {
                                queueclassList.remove(messagingClassTmp);
                            }
                            //System.out.println(count);
                            //System.out.println("MessageElemName="+messagingClassTmp);
                        }
                    }
                }
            } else if (messagingclass.getMessagetype().equals("RoundRobinQueue")) {
                ConcurrentHashMap roundrobinqueuemap = (ConcurrentHashMap) messagingClassMap
                        .get("RoundRobinQueue");
                //System.out.println("RoundRobinQueueMap"+roundrobinqueuemap);
                if (roundrobinqueuemap != null) {
                    CopyOnWriteArrayList queueclassList = (CopyOnWriteArrayList) roundrobinqueuemap
                            .get(messagingclass.getMessageelemname().trim());
                    if (queueclassList != null) {
                        for (int count = 0; count < queueclassList.size(); count++) {
                            MessagingClass messagingClassTmp = (MessagingClass) queueclassList.get(count);
                            if (messagingClassTmp.getMessageelemname()
                                    .equals(messagingclass.getMessageelemname())
                                    && messagingClassTmp.getMessagetype()
                                            .equals(messagingclass.getMessagetype())
                                    && messagingClassTmp.getMessagingclass()
                                            .equals(messagingclass.getMessagingclass())) {
                                queueclassList.remove(messagingClassTmp);
                            }

                        }
                    }
                }
                //System.out.println("End RoundRobinQueueMap"+roundrobinqueuemap);
            } else if (messagingclass.getMessagetype().equals("Topic")) {
                ConcurrentHashMap topicmap = (ConcurrentHashMap) messagingClassMap.get("Topic");
                //System.out.println("TopicMap"+topicmap);
                if (topicmap != null) {
                    CopyOnWriteArrayList topicclassList = (CopyOnWriteArrayList) topicmap
                            .get(messagingclass.getMessageelemname().trim());
                    if (topicclassList != null) {
                        for (int count = 0; count < topicclassList.size(); count++) {
                            MessagingClass messagingClassTmp = (MessagingClass) topicclassList.get(count);
                            if (messagingClassTmp.getMessageelemname()
                                    .equals(messagingclass.getMessageelemname())
                                    && messagingClassTmp.getMessagetype()
                                            .equals(messagingclass.getMessagetype())
                                    && messagingClassTmp.getMessagingclass()
                                            .equals(messagingclass.getMessagingclass())) {
                                topicclassList.remove(messagingClassTmp);
                            }
                        }
                    }
                }
                //System.out.println("End TopicMap"+topicmap);
            }
        }
    } catch (Exception ex) {
        log.error("Error occurred in constructing messaging classes", ex);
        //ex.printStackTrace();
    }
    //System.out.println(messagingClassMap);
}

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

/**
 * This method undeployed the SAR//from w  w  w .j  a va 2  s.com
 * @param dir
 * @return
 */
public boolean deleteDir(File dir) {
    String fileName = dir.getName();
    System.out.println("Dirname to be deleted" + fileName);
    Sar sar = null;
    try {
        sar = (Sar) sardigester.parse(new InputSource(
                new FileInputStream(deployDirectory + "/" + fileName + "/META-INF/" + "mbean-service.xml")));
    } catch (IOException | SAXException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    URLClassLoader sarClassLoader = (URLClassLoader) sarsMap.get(fileName);
    if (sarClassLoader != null) {
        ClassLoaderUtil.closeClassLoader(sarClassLoader);
        CopyOnWriteArrayList mbeans = sar.getMbean();
        MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
        System.out.println(mbs);
        ObjectName objName;
        try {
            for (int index = 0; index < mbeans.size(); index++) {
                Mbean mbean = (Mbean) mbeans.get(index);
                System.out.println(mbean.getObjectname());
                System.out.println(mbean.getCls());
                objName = new ObjectName(mbean.getObjectname());
                if (mbs.isRegistered(objName)) {
                    mbs.invoke(objName, "stopService", null, null);
                    //mbs.invoke(objName, "destroy", null, null);
                    mbs.unregisterMBean(objName);
                }
            }
            sarsMap.remove(fileName);
        } catch (MalformedObjectNameException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (MBeanRegistrationException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (InstanceNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (ReflectionException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (MBeanException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    return recursiveDelete(dir);

}

From source file:com.arman.efficientqhalgoforch.SuperAwesomeCardFragment.java

public void updateChart(CopyOnWriteArrayList<DataHolder> holdder) {

    ArrayList<Entry> yVals1 = new ArrayList<Entry>();
    ArrayList<String> xVals = new ArrayList<String>();
    for (int i = 0; i < 25; i++) {
        xVals.add(i + "");
    }//from  w w  w .  ja  v  a2 s .c  o  m
    ArrayList<Entry> yValspoint = new ArrayList<Entry>();
    for (int i = 0; i < holdder.size(); i++) {

        yVals1.add(new Entry((holdder.get(i).getTime()),
                Integer.valueOf(xVals.get(xVals.indexOf(String.valueOf(holdder.get(i).getThread()))))));

    }

    ArrayList<ScatterDataSet> dataSets = new ArrayList<ScatterDataSet>();

    // create a dataset and give it a type
    ScatterDataSet set1 = new ScatterDataSet(yVals1, "Result");
    set1.setScatterShape(ScatterChart.ScatterShape.SQUARE);
    set1.setColor(ColorTemplate.COLORFUL_COLORS[0]);
    set1.setScatterShapeSize(8f);

    dataSets.add(set1); // add the datasets

    // create a data object with the datasets
    ScatterData data = new ScatterData(xVals, dataSets);
    data.setValueTypeface(tf);

    mChart.setData(data);
    mChart.invalidate();

}