Example usage for java.util.concurrent CopyOnWriteArrayList get

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

Introduction

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

Prototype

public E get(int index) 

Source Link

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);
    }/* ww  w .  j  av a 2 s  .c  o m*/
    return new LBHttpSolrServer(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();
                }// w  ww  .  j  av  a 2  s .  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.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  w w w.j  a  va2  s .c  om*/
    return new LBHttpSolrClient(servers);
}

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);
        list[i] = expId + "_" + list[i];
        System.out.println("\nGetLogFile Request CLient " + list[i]);
    }/*from   ww w  .  jav  a 2 s. com*/

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

}

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// w w  w.  j a v  a 2 s . c om
 * @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/*ww  w. ja v  a2s .  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 ww  .  j ava2 s  .  c  o  m
 * @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  ww.jav  a 2s  .co  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();

}

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

/**
 * This method adds the url to the classloader.
 * @param warDirectory/*  www.  j  a  va  2  s . co  m*/
 * @param classLoader
 */
/*private void AddUrlToClassLoader(File warDirectory,WebClassLoader classLoader){
   File webInfDirectory=new File(warDirectory.getAbsolutePath()+"/WEB-INF/lib/");
   //logger.info(webInfDirectory.getAbsolutePath());
   if(webInfDirectory.exists()){
 File[] jarfiles=webInfDirectory.listFiles();
 for(int jarcount=0;jarcount<jarfiles.length;jarcount++){
    //logger.info(jarfiles[jarcount]);
    if(jarfiles[jarcount].getName().endsWith(".jar")){
       try {
       //   //log.info("Adding absolute path "+jarfiles[jarcount].getAbsolutePath());
          new WebServer().addURL(new URL("file:"+jarfiles[jarcount].getAbsolutePath()),classLoader);
       } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
       }
    }
 }
   }
}*/

public void deployService(File sarFile) {
    try {
        Sar sar = (Sar) sardigester.parse(new InputSource(new FileInputStream(sarFile)));
        CopyOnWriteArrayList mbeans = sar.getMbean();
        //log.info(mbeanServer);
        ObjectName objName;
        for (int index = 0; index < mbeans.size(); index++) {
            Mbean mbean = (Mbean) mbeans.get(index);
            //log.info(mbean.getObjectname());
            //log.info(mbean.getCls());
            objName = new ObjectName(mbean.getObjectname());
            Class service = Thread.currentThread().getContextClassLoader().loadClass(mbean.getCls());
            Object obj = service.newInstance();
            if (mbeanServer.isRegistered(objName)) {
                //mbs.invoke(objName, "stopService", null, null);
                //mbs.invoke(objName, "destroy", null, null);
                mbeanServer.unregisterMBean(objName);
            }
            mbeanServer.createMBean(service.getName(), objName);
            //mbs.registerMBean(obj, objName);
            CopyOnWriteArrayList attrlist = mbean.getMbeanAttribute();
            if (attrlist != null) {
                for (int count = 0; count < attrlist.size(); count++) {
                    MBeanAttribute attr = (MBeanAttribute) attrlist.get(count);
                    Attribute mbeanattribute = new Attribute(attr.getName(), attr.getValue());
                    mbeanServer.setAttribute(objName, mbeanattribute);
                }
            }
            Attribute mbeanattribute = new Attribute("ObjectName", objName);
            mbeanServer.setAttribute(objName, mbeanattribute);
            if (((String) mbeanServer.getAttribute(objName, "Deployer")).equals("true")) {
                mbeanServer.invoke(objName, "init", new Object[] { deployerList },
                        new String[] { Vector.class.getName() });
                //this.deployerList.add(objName.getCanonicalName());

            }
            mbeanServer.invoke(objName, "init", new Object[] { serviceList, serverConfig, mbeanServer },
                    new String[] { Vector.class.getName(), ServerConfig.class.getName(),
                            MBeanServer.class.getName() });
            mbeanServer.invoke(objName, "start", null, null);
        }
    } catch (Exception ex) {
        log.error("Could not able to deploy the SAR package " + sarFile.toURI(), ex);
        //ex.printStackTrace();
    }
}

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

/**
 * This method undeployed the SAR//from w ww .  j  a  v  a2  s  .com
 * @param dir
 * @return
 */
public boolean deleteDir(File dir) {
    String fileName = dir.getName();
    //log.info("Dirname to be deleted"+fileName);
    Sar sar = null;
    fileName = fileName.substring(0, fileName.indexOf('.'));
    fileName += "sar";
    try {
        sar = (Sar) sardigester.parse(new InputSource(new FileInputStream(
                serverConfig.getDeploydirectory() + "/" + fileName + "/META-INF/" + "mbean-service.xml")));
    } catch (Exception e) {
        log.error("Could not able to parse sar " + serverConfig.getDeploydirectory() + "/" + fileName
                + "/META-INF/" + "mbean-service.xml", e);
        // TODO Auto-generated catch block
        //e.printStackTrace();
    }
    URLClassLoader sarClassLoader = (URLClassLoader) sarsMap.get(fileName);
    if (sarClassLoader != null) {
        ClassLoaderUtil.closeClassLoader(sarClassLoader);
        CopyOnWriteArrayList mbeans = sar.getMbean();
        //log.info(mbeanServer);
        ObjectName objName;
        try {
            for (int index = 0; index < mbeans.size(); index++) {
                Mbean mbean = (Mbean) mbeans.get(index);
                //log.info(mbean.getObjectname());
                //log.info(mbean.getCls());
                objName = new ObjectName(mbean.getObjectname());
                if (mbeanServer.isRegistered(objName)) {
                    if (((String) mbeanServer.getAttribute(objName, "Deployer")).equals("true")) {
                        mbeanServer.invoke(objName, "undeploy", null, null);
                    }
                    mbeanServer.invoke(objName, "stop", null, null);
                    mbeanServer.invoke(objName, "destroy", null, null);
                    //mbs.invoke(objName, "stopService", null, null);
                    //mbs.invoke(objName, "destroy", null, null);
                    mbeanServer.unregisterMBean(objName);
                }
            }
        } catch (Exception e) {
            log.error("Could not able to undeploy stop and destroy sar in " + dir.getName(), e);
            // TODO Auto-generated catch block
            //e.printStackTrace();
        }
    }
    return recursiveDelete(new File(serverConfig.getDeploydirectory() + "/" + fileName + "/"));

}