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:com.app.server.EARDeployer.java

public static void getClassList(FileObject jarFile, CopyOnWriteArrayList classList,
        StandardFileSystemManager fsManager) throws FileSystemException {
    // log.info(jarFile);
    FileObject nestedFS = null;//from w ww  .ja v  a 2  s.c  o  m
    FileObject[] children = null;
    if (jarFile.getURL().toString().trim().endsWith(".jar")) {
        nestedFS = fsManager.createFileSystem(jarFile);
        children = nestedFS.resolveFile("/").getChildren();
    } else if (jarFile.getType() == FileType.FOLDER) {
        children = jarFile.getChildren();
    }
    // log.info();
    // log.info( "Children of " + jarFile.getName().getURI() );
    if (children == null)
        return;
    for (int i = 0; i < children.length; i++) {
        // log.info(children[i].+" "+
        // children[i].getName().getBaseName() );
        if (children[i].getType() == FileType.FILE && children[i].getName().getBaseName().endsWith(".class"))
            classList.add(children[i].toString().substring(children[i].toString().lastIndexOf('!') + 2));
        getClassList(children[i], classList, fsManager);
    }
}

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

/**
 * This method parses the messagingclass.xml which is obtained after deploying the War file and metadata is constructed and kept in HashMap 
 * @param messagedigester/*  w  w w . ja v a 2  s .  co  m*/
 * @param configFile
 * @param customClassLoader
 * @param messagingClassMap
 * @throws ClassNotFoundException
 * @throws FileNotFoundException
 * @throws IOException
 * @throws SAXException
 */
public void getMessagingClass(Digester messagedigester, File configFile, WebClassLoader customClassLoader,
        Hashtable messagingClassMap)
        throws ClassNotFoundException, FileNotFoundException, IOException, SAXException {
    MessagingClasses messagingClasses = (MessagingClasses) messagedigester
            .parse(new InputSource(new FileInputStream(configFile)));

    for (MessagingClass messagingclass : messagingClasses.messagingClasses) {
        Class messagingClass = customClassLoader.loadClass(messagingclass.getMessagingclass());
        messagingclass.setMessageClass(messagingClass);
        if (messagingclass.getMessagetype().equals("RandomQueue")) {
            ConcurrentHashMap randomqueuemap = (ConcurrentHashMap) messagingClassMap.get("RandomQueue");
            //System.out.println("MessageElemName="+messagingclass.getMessageelemname().trim());
            if (randomqueuemap == null) {
                System.out.print("No RandomQueue Available");
            } else {
                CopyOnWriteArrayList queueclassList = (CopyOnWriteArrayList) randomqueuemap
                        .get(messagingclass.getMessageelemname().trim());
                if (queueclassList != null) {
                    queueclassList.add(messagingclass);
                } else {
                    System.out.print("No RandomQueue Available");
                }
            }
        } else if (messagingclass.getMessagetype().equals("RoundRobinQueue")) {
            ConcurrentHashMap roundrobinqueuemap = (ConcurrentHashMap) messagingClassMap.get("RoundRobinQueue");
            if (roundrobinqueuemap == null) {
                System.out.print("No RoundRobinQueue Available");
            } else {
                CopyOnWriteArrayList queueclassList = (CopyOnWriteArrayList) roundrobinqueuemap
                        .get(messagingclass.getMessageelemname().trim());
                if (queueclassList != null) {
                    queueclassList.add(messagingclass);
                } else {
                    System.out.print("No RoundRobinQueue Available");
                }
            }
        } else if (messagingclass.getMessagetype().equals("Topic")) {
            ConcurrentHashMap topicmap = (ConcurrentHashMap) messagingClassMap.get("Topic");
            if (topicmap == null) {
                System.out.print("No Topic Available");
            } else {
                CopyOnWriteArrayList topicclassList = (CopyOnWriteArrayList) topicmap
                        .get(messagingclass.getMessageelemname().trim());
                if (topicclassList != null) {
                    topicclassList.add(messagingclass);
                } else {
                    System.out.print("No Topic Available");
                }
            }
        }
    }
    //System.out.println(messagingClassMap);
}

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

public void getMessagingClass(Digester messagedigester, File configFile, WebClassLoader customClassLoader,
        Hashtable messagingClassMap)
        throws ClassNotFoundException, FileNotFoundException, IOException, SAXException {
    MessagingClasses messagingClasses = (MessagingClasses) messagedigester
            .parse(new InputSource(new FileInputStream(configFile)));

    for (MessagingClass messagingclass : messagingClasses.messagingClasses) {
        Class messagingClass = customClassLoader.loadClass(messagingclass.getMessagingclass());
        messagingclass.setMessageClass(messagingClass);
        if (messagingclass.getMessagetype().equals("RandomQueue")) {
            ConcurrentHashMap randomqueuemap = (ConcurrentHashMap) messagingClassMap.get("RandomQueue");
            //System.out.println("MessageElemName="+messagingclass.getMessageelemname().trim());
            if (randomqueuemap == null) {
                System.out.print("No RandomQueue Available");
            } else {
                CopyOnWriteArrayList queueclassList = (CopyOnWriteArrayList) randomqueuemap
                        .get(messagingclass.getMessageelemname().trim());
                if (queueclassList != null) {
                    queueclassList.add(messagingclass);
                } else {
                    System.out.print("No RandomQueue Available");
                }/*from  w ww  .  j a va 2 s  .  c o  m*/
            }
        } else if (messagingclass.getMessagetype().equals("RoundRobinQueue")) {
            ConcurrentHashMap roundrobinqueuemap = (ConcurrentHashMap) messagingClassMap.get("RoundRobinQueue");
            if (roundrobinqueuemap == null) {
                System.out.print("No RoundRobinQueue Available");
            } else {
                CopyOnWriteArrayList queueclassList = (CopyOnWriteArrayList) roundrobinqueuemap
                        .get(messagingclass.getMessageelemname().trim());
                if (queueclassList != null) {
                    queueclassList.add(messagingclass);
                } else {
                    System.out.print("No RoundRobinQueue Available");
                }
            }
        } else if (messagingclass.getMessagetype().equals("Topic")) {
            ConcurrentHashMap topicmap = (ConcurrentHashMap) messagingClassMap.get("Topic");
            if (topicmap == null) {
                System.out.print("No Topic Available");
            } else {
                CopyOnWriteArrayList topicclassList = (CopyOnWriteArrayList) topicmap
                        .get(messagingclass.getMessageelemname().trim());
                if (topicclassList != null) {
                    topicclassList.add(messagingclass);
                } else {
                    System.out.print("No Topic Available");
                }
            }
        }
    }
    //System.out.println(messagingClassMap);
}

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

public void getUsersJars(File dir, CopyOnWriteArrayList jarList) {
    if (dir.isDirectory()) {
        File[] children = dir.listFiles();
        for (int i = 0; i < children.length; i++) {
            System.out.println(children[i]);
            getUsersJars(children[i], jarList);
            if (children[i].isFile() && children[i].getName().endsWith(".jar"))
                jarList.add(children[i].getAbsolutePath());
        }/*from  w  w  w. j a va 2  s  . c om*/
    }

}

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

public void getUsersJars(File dir, CopyOnWriteArrayList jarList) {
    if (dir.isDirectory()) {
        File[] children = dir.listFiles();
        for (int i = 0; i < children.length; i++) {
            log.info(children[i]);//from w w w. j a v a  2  s. c  o  m
            getUsersJars(children[i], jarList);
            if (children[i].isFile() && children[i].getName().endsWith(".jar"))
                jarList.add(children[i].getAbsolutePath());
        }
    }

}

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

public static void getClassList(FileObject jarFile, CopyOnWriteArrayList classList,
        StandardFileSystemManager fsManager) throws FileSystemException {
    // System.out.println(jarFile);
    FileObject nestedFS = null;//from  w w w.  ja  va2s .  co  m
    FileObject[] children = null;
    if (jarFile.getURL().toString().trim().endsWith(".jar")) {
        nestedFS = fsManager.createFileSystem(jarFile);
        children = nestedFS.resolveFile("/").getChildren();
    } else if (jarFile.getType() == FileType.FOLDER) {
        children = jarFile.getChildren();
    }
    // System.out.println();
    // System.out.println( "Children of " + jarFile.getName().getURI() );
    if (children == null)
        return;
    for (int i = 0; i < children.length; i++) {
        // System.out.println(children[i].+" "+
        // children[i].getName().getBaseName() );
        if (children[i].getType() == FileType.FILE && children[i].getName().getBaseName().endsWith(".class"))
            classList.add(children[i].toString().substring(children[i].toString().lastIndexOf('!') + 2));
        getClassList(children[i], classList, fsManager);
    }
}

From source file:org.wso2.carbon.event.input.adaptor.websocket.local.WebsocketLocalEventAdaptorType.java

@Override
public String subscribe(InputEventAdaptorMessageConfiguration inputEventAdaptorMessageConfiguration,
        InputEventAdaptorListener inputEventAdaptorListener,
        InputEventAdaptorConfiguration inputEventAdaptorConfiguration, AxisConfiguration axisConfiguration) {

    String subscriptionId = UUID.randomUUID().toString();

    int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
    String topic = inputEventAdaptorMessageConfiguration.getInputMessageProperties()
            .get(WebsocketLocalEventAdaptorConstants.ADAPTOR_MESSAGE_TOPIC);

    ConcurrentHashMap<String, ConcurrentHashMap<String, CopyOnWriteArrayList<WebsocketAdaptorListener>>> tenantSpecificListenerMap = inputEventAdaptorListenerMap
            .get(tenantId);//from w w  w  .j a  va  2 s. co  m

    if (tenantSpecificListenerMap == null) {
        tenantSpecificListenerMap = new ConcurrentHashMap<String, ConcurrentHashMap<String, CopyOnWriteArrayList<WebsocketAdaptorListener>>>();
        if (null != inputEventAdaptorListenerMap.putIfAbsent(tenantId, tenantSpecificListenerMap)) {
            tenantSpecificListenerMap = inputEventAdaptorListenerMap.get(tenantId);
        }
    }

    ConcurrentHashMap<String, CopyOnWriteArrayList<WebsocketAdaptorListener>> adaptorSpecificListeners = tenantSpecificListenerMap
            .get(inputEventAdaptorConfiguration.getName());

    if (adaptorSpecificListeners == null) {
        adaptorSpecificListeners = new ConcurrentHashMap<String, CopyOnWriteArrayList<WebsocketAdaptorListener>>();
        if (null != tenantSpecificListenerMap.putIfAbsent(inputEventAdaptorConfiguration.getName(),
                adaptorSpecificListeners)) {
            adaptorSpecificListeners = tenantSpecificListenerMap.get(inputEventAdaptorConfiguration.getName());
        }
    }

    CopyOnWriteArrayList<WebsocketAdaptorListener> topicSpecificListeners = adaptorSpecificListeners.get(topic);

    if (topicSpecificListeners == null) {
        topicSpecificListeners = new CopyOnWriteArrayList<WebsocketAdaptorListener>();
        if (null != adaptorSpecificListeners.putIfAbsent(topic, topicSpecificListeners)) {
            topicSpecificListeners = adaptorSpecificListeners.get(topic);
        }
    }
    topicSpecificListeners
            .add(new WebsocketAdaptorListener(subscriptionId, inputEventAdaptorListener, tenantId));

    return subscriptionId;
}

From source file:com.l2jfree.gameserver.model.entity.events.TvT.java

public static boolean addPlayerOk(String teamName, L2Player eventPlayer) {
    if (GlobalRestrictions.isRestricted(eventPlayer, TvTRestriction.class)) {
        // TODO: msg
        return false;
    }/*w ww  . ja  v  a2s . c om*/

    try {
        if (checkShufflePlayers(eventPlayer) || eventPlayer.isInEvent(TvTPlayerInfo.class)) {
            eventPlayer.sendMessage("You are already participating in the event!");
            return false;
        }

        for (L2Player player : _players) {
            if (player.getObjectId() == eventPlayer.getObjectId()) {
                eventPlayer.sendMessage("You are already participating in the event!");
                return false;
            } else if (player.getName() == eventPlayer.getName()) {
                eventPlayer.sendMessage("You are already participating in the event!");
                return false;
            }
        }
        if (_players.contains(eventPlayer)) {
            eventPlayer.sendMessage("You are already participating in the event!");
            return false;
        }
        if (CTF._savePlayers.contains(eventPlayer.getName())) {
            eventPlayer.sendMessage("You are already participating in another event!");
            return false;
        }
    } catch (Exception e) {
        _log.warn("TvT Engine exception: ", e);
    }

    if (Config.TVT_EVEN_TEAMS.equals("NO"))
        return true;
    else if (Config.TVT_EVEN_TEAMS.equals("BALANCE")) {
        boolean allTeamsEqual = true;
        int countBefore = -1;

        for (int playersCount : _teamPlayersCount) {
            if (countBefore == -1)
                countBefore = playersCount;

            if (countBefore != playersCount) {
                allTeamsEqual = false;
                break;
            }

            countBefore = playersCount;
        }

        if (allTeamsEqual)
            return true;

        countBefore = Integer.MAX_VALUE;

        for (int teamPlayerCount : _teamPlayersCount) {
            if (teamPlayerCount < countBefore)
                countBefore = teamPlayerCount;
        }

        CopyOnWriteArrayList<String> joinableTeams = new CopyOnWriteArrayList<String>();

        for (String team : _teams) {
            if (teamPlayersCount(team) == countBefore)
                joinableTeams.add(team);
        }

        if (joinableTeams.contains(teamName))
            return true;
    } else if (Config.TVT_EVEN_TEAMS.equals("SHUFFLE"))
        return true;

    eventPlayer.sendMessage("Too many players in team \"" + teamName + "\"");
    return false;
}

From source file:org.opendaylight.controller.sal.implementation.internal.DataPacketService.java

void setListenDataPacket(Map props, IListenDataPacket s) {
    if (this.listenDataPacket == null || this.indexDataPacket == null) {
        logger.error("data structure to store data is NULL");
        return;/*from  w w w  . j av a  2s  . com*/
    }
    logger.trace("Received setListenDataPacket request");
    for (Object e : props.entrySet()) {
        Map.Entry entry = (Map.Entry) e;
        logger.trace("Prop key:({}) value:({})", entry.getKey(), entry.getValue());
    }

    String listenerName = null;
    String listenerDependency = null;
    Match filter = null;
    Object value;
    // Read the listenerName
    value = props.get("salListenerName");
    if (value instanceof String) {
        listenerName = (String) value;
    }

    if (listenerName == null) {
        logger.error("Trying to set a listener without a Name");
        return;
    }

    //Read the dependency
    value = props.get("salListenerDependency");
    if (value instanceof String) {
        listenerDependency = (String) value;
    }

    //Read match filter if any
    value = props.get("salListenerFilter");
    if (value instanceof Match) {
        filter = (Match) value;
    }

    DataPacketListener l = new DataPacketListener(listenerName, s, listenerDependency, filter);

    DataPacketListener lDependency = new DataPacketListener(listenerDependency, null, null, null);

    // Now let see if there is any dependency
    if (listenerDependency == null) {
        logger.debug("listener without any dependency");
        if (this.indexDataPacket.contains(l)) {
            logger.error("trying to add an existing element");
        } else {
            logger.debug("adding listener: {}", listenerName);
            CopyOnWriteArrayList<DataPacketListener> serialListeners = new CopyOnWriteArrayList<DataPacketListener>();
            serialListeners.add(l);
            this.listenDataPacket.add(serialListeners);
            this.indexDataPacket.add(l);
        }
    } else {
        logger.debug("listener with dependency");
        // Now search for the dependency and put things in order
        if (this.indexDataPacket.contains(l)) {
            logger.error("trying to add an existing element");
        } else {
            logger.debug("adding listener: {}", listenerName);
            // Lets find the set with the dependency in it, if we
            // find it lets just add our dependency at the end of
            // the list.
            for (List<DataPacketListener> serialListeners : this.listenDataPacket) {
                int i = 0;
                boolean done = false;
                if (serialListeners.contains(lDependency)) {
                    serialListeners.add(l);
                    done = true;
                }
                // If we did fine the element, lets break early
                if (done) {
                    break;
                }
            }

            this.indexDataPacket.add(l);
        }
    }
}

From source file:io.github.minecraftgui.models.network.UserConnection.java

public void addOnGuiOpenListener(OnGuiListener plugin, OnGuiListener.OnGuiOpen onGuiOpen) {
    CopyOnWriteArrayList<OnGuiListener.OnGuiOpen> onGuiOpens = onGuiOpenListeners.get(plugin);

    if (onGuiOpens == null) {
        onGuiOpens = new CopyOnWriteArrayList<>();
        onGuiOpenListeners.put(plugin, onGuiOpens);
    }/*from w w w . ja  v  a 2 s.co m*/

    onGuiOpens.add(onGuiOpen);
}