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:org.apache.ranger.biz.SessionMgr.java

public CopyOnWriteArrayList<UserSessionBase> getActiveSessionsOnServer() {

    CopyOnWriteArrayList<HttpSession> activeHttpUserSessions = RangerHttpSessionListener
            .getActiveSessionOnServer();
    CopyOnWriteArrayList<UserSessionBase> activeRangerUserSessions = new CopyOnWriteArrayList<UserSessionBase>();

    if (CollectionUtils.isEmpty(activeHttpUserSessions)) {
        return activeRangerUserSessions;
    }/*w  w  w.  jav a  2  s.com*/

    for (HttpSession httpSession : activeHttpUserSessions) {

        if (httpSession.getAttribute(RangerSecurityContextFormationFilter.AKA_SC_SESSION_KEY) == null) {
            continue;
        }

        RangerSecurityContext securityContext = (RangerSecurityContext) httpSession
                .getAttribute(RangerSecurityContextFormationFilter.AKA_SC_SESSION_KEY);
        if (securityContext.getUserSession() != null) {
            activeRangerUserSessions.add(securityContext.getUserSession());
        }
    }

    return activeRangerUserSessions;
}

From source file:org.wso2.carbon.device.mgt.iot.output.adapter.ui.UIEventAdapter.java

/**
 * Fetches all valid web-socket sessions from the entire pool of subscribed sessions. The validity is checked
 * against any queryString provided when subscribing to the web-socket endpoint.
 *
 * @param event the current event received and that which needs to be published to subscribed sessions.
 * @return a list of all validated web-socket sessions against the queryString values.
 *///from w w w . ja  v a  2 s. co m
private CopyOnWriteArrayList<WebSocketSessionRequest> getValidSessions(Event event) {
    CopyOnWriteArrayList<WebSocketSessionRequest> validSessions = new CopyOnWriteArrayList<>();
    UIOutputCallbackControllerServiceImpl uiOutputCallbackControllerServiceImpl = UIEventAdaptorServiceDataHolder
            .getUIOutputCallbackRegisterServiceImpl();
    // get all subscribed web-socket sessions.
    CopyOnWriteArrayList<WebSocketSessionRequest> webSocketSessionUtils = uiOutputCallbackControllerServiceImpl
            .getSessions(tenantId, streamId);
    if (webSocketSessionUtils != null) {
        for (WebSocketSessionRequest webSocketSessionUtil : webSocketSessionUtils) {
            boolean isValidSession = validateEventAgainstSessionFilters(event, webSocketSessionUtil);
            if (isValidSession) {
                validSessions.add(webSocketSessionUtil);
            }
        }
    }
    return validSessions;
}

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

public static boolean addPlayerOk(String teamName, L2Player eventPlayer) {
    if (GlobalRestrictions.isRestricted(eventPlayer, CTFRestriction.class)) {
        // TODO: msg
        return false;
    }/*  ww w.j a  va 2  s  . c o m*/

    try {
        if (checkShufflePlayers(eventPlayer) || eventPlayer.isInEvent(CTFPlayerInfo.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 (TvT._savePlayers.contains(eventPlayer.getName())) {
            eventPlayer.sendMessage("You are already participating in another event!");
            return false;
        }
    } catch (Exception e) {
        _log.warn("CTF Siege Engine exception: ", e);
    }

    if (Config.CTF_EVEN_TEAMS.equals("NO"))
        return true;
    else if (Config.CTF_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.CTF_EVEN_TEAMS.equals("SHUFFLE"))
        return true;

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

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

private static boolean startEventOk() {
    if (_joining || !_teleport || _started)
        return false;

    if (Config.CTF_EVEN_TEAMS.equals("NO") || Config.CTF_EVEN_TEAMS.equals("BALANCE")) {
        if (_teamPlayersCount.contains(0))
            return false;
    } else if (Config.CTF_EVEN_TEAMS.equals("SHUFFLE")) {
        CopyOnWriteArrayList<L2Player> playersShuffleTemp = new CopyOnWriteArrayList<L2Player>();
        int loopCount = 0;

        loopCount = _playersShuffle.size();

        for (int i = 0; i < loopCount; i++) {
            if (_playersShuffle != null)
                playersShuffleTemp.add(_playersShuffle.get(i));
        }//from www  .  j  av  a2s  . co  m

        _playersShuffle = playersShuffleTemp;
        playersShuffleTemp.clear();

        //  if (_playersShuffle.size() < (_teams.size()*2)){
        //     return false;
        //  }
    }

    return true;
}

From source file:org.wso2.carbon.event.input.adaptor.websocket.WebsocketEventAdaptorType.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(WebsocketEventAdaptorConstants.ADAPTOR_MESSAGE_TOPIC);
    String socketServerUrl = inputEventAdaptorConfiguration.getInputProperties()
            .get(WebsocketEventAdaptorConstants.ADAPTER_SERVER_URL);

    if (!socketServerUrl.startsWith("ws://")) {
        throw new InputEventAdaptorEventProcessingException(
                "Provided websocket URL " + socketServerUrl + " is invalid."); //TODO: Make this exception propagate to the UI.
    }/*from www .ja va2s. c o  m*/

    if (topic != null) {
        socketServerUrl = socketServerUrl + "/" + topic;
    } else {
        topic = ""; //Using empty string to map the cases with no topic, because topic is optional
    }
    ConcurrentHashMap<String, ConcurrentHashMap<String, CopyOnWriteArrayList<ClientManagerWrapper>>> tenantSpecificAdaptorMap = inputEventAdaptorClientManagerMap
            .get(tenantId);
    if (tenantSpecificAdaptorMap == null) {
        tenantSpecificAdaptorMap = new ConcurrentHashMap<String, ConcurrentHashMap<String, CopyOnWriteArrayList<ClientManagerWrapper>>>();
        if (null != inputEventAdaptorClientManagerMap.putIfAbsent(tenantId, tenantSpecificAdaptorMap)) {
            tenantSpecificAdaptorMap = inputEventAdaptorClientManagerMap.get(tenantId);
        }
    }

    ConcurrentHashMap<String, CopyOnWriteArrayList<ClientManagerWrapper>> adaptorSpecificTopicMap = tenantSpecificAdaptorMap
            .get(inputEventAdaptorConfiguration.getName());

    if (adaptorSpecificTopicMap == null) {
        adaptorSpecificTopicMap = new ConcurrentHashMap<String, CopyOnWriteArrayList<ClientManagerWrapper>>();
        if (null != tenantSpecificAdaptorMap.put(inputEventAdaptorConfiguration.getName(),
                adaptorSpecificTopicMap)) {
            adaptorSpecificTopicMap = tenantSpecificAdaptorMap.get(inputEventAdaptorConfiguration.getName());
        }
    }

    CopyOnWriteArrayList<ClientManagerWrapper> topicSpecificClientManagers = adaptorSpecificTopicMap.get(topic);
    if (topicSpecificClientManagers == null) {
        topicSpecificClientManagers = new CopyOnWriteArrayList<ClientManagerWrapper>();
        if (null != adaptorSpecificTopicMap.putIfAbsent(topic, topicSpecificClientManagers)) {
            topicSpecificClientManagers = adaptorSpecificTopicMap.get(topic);
        }
    }

    ClientEndpointConfig clientEndpointConfig = ClientEndpointConfig.Builder.create().build();
    ClientManager client = ClientManager.createClient();
    ClientManagerWrapper clientManagerWrapper = new ClientManagerWrapper();
    clientManagerWrapper.setClientManager(client);
    clientManagerWrapper.setSubscriptionId(subscriptionId);
    try {
        client.connectToServer(new WebsocketClient(inputEventAdaptorListener), clientEndpointConfig,
                new URI(socketServerUrl)); //TODO: Handle reconnecting, in case server disconnects. Suggestion: Create a scheduler.
        topicSpecificClientManagers.add(clientManagerWrapper);
    } catch (DeploymentException e) {
        throw new InputEventAdaptorEventProcessingException(e); //TODO: These exceptions might get modified into new types, as these do not propagate to the UI.
    } catch (IOException e) {
        throw new InputEventAdaptorEventProcessingException(e);
    } catch (Throwable e) {
        throw new InputEventAdaptorEventProcessingException(e);
    }
    return subscriptionId;
}

From source file:org.wso2.carbon.device.mgt.output.adapter.websocket.WebsocketEventAdapter.java

/**
 * Fetches all valid web-socket sessions from the entire pool of subscribed sessions. The validity is checked
 * against any queryString provided when subscribing to the web-socket endpoint.
 *
 * @param event the current event received and that which needs to be published to subscribed sessions.
 * @return a list of all validated web-socket sessions against the queryString values.
 *//*from w ww .  j av  a  2 s  .c o  m*/
private CopyOnWriteArrayList<WebSocketSessionRequest> getValidSessions(Object event) {
    CopyOnWriteArrayList<WebSocketSessionRequest> validSessions = new CopyOnWriteArrayList<>();
    WebsocketOutputCallbackControllerServiceImpl websocketOutputCallbackControllerServiceImpl = WebsocketEventAdaptorServiceDataHolder
            .getUIOutputCallbackRegisterServiceImpl();
    // get all subscribed web-socket sessions.
    CopyOnWriteArrayList<WebSocketSessionRequest> webSocketSessionUtils = websocketOutputCallbackControllerServiceImpl
            .getSessions(tenantId, streamId);
    if (webSocketSessionUtils != null) {
        for (WebSocketSessionRequest webSocketSessionUtil : webSocketSessionUtils) {
            boolean isValidSession;
            if (event instanceof Event) {
                isValidSession = validateEventAgainstSessionFilters((Event) event, webSocketSessionUtil);
            } else {
                isValidSession = validateJsonMessageAgainstEventFilters(event.toString(), webSocketSessionUtil);
            }
            if (isValidSession) {
                validSessions.add(webSocketSessionUtil);
            }
        }
    }
    return validSessions;
}

From source file:com.microsoft.windowsazure.mobileservices.MobileServicePush.java

/**
 * Unregisters the client for all notifications
 * /*from w w w . j  av  a 2  s.  co m*/
 * @param pnsHandle
 *            PNS specific identifier
 * @param callback
 *            The operation callback
 */
public void unregisterAll(String pnsHandle, final UnregisterCallback callback) {
    getFullRegistrationInformation(pnsHandle, new GetFullRegistrationInformationCallback() {

        @Override
        public void onCompleted(ArrayList<Registration> registrations, Exception exception) {

            if (exception != null) {
                callback.onUnregister(exception);
                return;
            }

            final SyncState state = new SyncState();

            state.size = registrations.size();

            final CopyOnWriteArrayList<String> concurrentArray = new CopyOnWriteArrayList<String>();

            final Object syncObject = new Object();

            if (state.size == 0) {

                removeAllRegistrationsId();

                mIsRefreshNeeded = false;

                callback.onUnregister(null);
                return;
            }

            for (Registration registration : registrations) {
                deleteRegistrationInternal(registration.getName(), registration.getRegistrationId(),
                        new DeleteRegistrationInternalCallback() {

                            @Override
                            public void onDelete(String registrationId, Exception exception) {

                                concurrentArray.add(registrationId);

                                if (exception != null) {
                                    synchronized (syncObject) {
                                        if (!state.alreadyReturn) {
                                            callback.onUnregister(exception);
                                            state.alreadyReturn = true;
                                            return;
                                        }
                                    }
                                }

                                if (concurrentArray.size() == state.size && !state.alreadyReturn) {
                                    removeAllRegistrationsId();

                                    mIsRefreshNeeded = false;

                                    callback.onUnregister(null);

                                    return;
                                }
                            }
                        });
            }
        }
    });
}

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

/**
 * This method extracts the SAR archive and configures for the SAR and starts the services
 * @param file/*from w w  w. j  av  a 2 s.  c om*/
 * @param warDirectoryPath
 * @throws IOException
 */
public void extractSar(File file, String warDirectoryPath) throws IOException {
    ZipFile zip = new ZipFile(file);
    ZipEntry ze = null;
    String fileName = file.getName();
    fileName = fileName.substring(0, fileName.indexOf('.'));
    fileName += "sar";
    String fileDirectory;
    CopyOnWriteArrayList classPath = new CopyOnWriteArrayList();
    Enumeration<? extends ZipEntry> entries = zip.entries();
    int numBytes;
    while (entries.hasMoreElements()) {
        ze = entries.nextElement();
        // //System.out.println("Unzipping " + ze.getName());
        String filePath = deployDirectory + "/" + fileName + "/" + ze.getName();
        if (!ze.isDirectory()) {
            fileDirectory = filePath.substring(0, filePath.lastIndexOf('/'));
        } else {
            fileDirectory = filePath;
        }
        // //System.out.println(fileDirectory);
        createDirectory(fileDirectory);
        if (!ze.isDirectory()) {
            FileOutputStream fout = new FileOutputStream(filePath);
            byte[] inputbyt = new byte[8192];
            InputStream istream = zip.getInputStream(ze);
            while ((numBytes = istream.read(inputbyt, 0, inputbyt.length)) >= 0) {
                fout.write(inputbyt, 0, numBytes);
            }
            fout.close();
            istream.close();
            if (ze.getName().endsWith(".jar")) {
                classPath.add(filePath);
            }
        }
    }
    zip.close();
    URLClassLoader loader = (URLClassLoader) ClassLoader.getSystemClassLoader();
    URL[] urls = loader.getURLs();
    WebClassLoader sarClassLoader = new WebClassLoader(urls);
    for (int index = 0; index < classPath.size(); index++) {
        System.out.println("file:" + classPath.get(index));
        new WebServer().addURL(new URL("file:" + classPath.get(index)), sarClassLoader);
    }
    new WebServer().addURL(new URL("file:" + deployDirectory + "/" + fileName + "/"), sarClassLoader);
    sarsMap.put(fileName, sarClassLoader);
    System.out.println(sarClassLoader.geturlS());
    try {
        Sar sar = (Sar) sardigester.parse(new InputSource(
                new FileInputStream(deployDirectory + "/" + fileName + "/META-INF/" + "mbean-service.xml")));
        CopyOnWriteArrayList mbeans = sar.getMbean();
        MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
        System.out.println(mbs);
        ObjectName objName;
        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());
            Class helloWorldService = sarClassLoader.loadClass(mbean.getCls());
            Object obj = helloWorldService.newInstance();
            if (mbs.isRegistered(objName)) {
                mbs.invoke(objName, "stopService", null, null);
                //mbs.invoke(objName, "destroy", null, null);
                mbs.unregisterMBean(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());
                    mbs.setAttribute(objName, mbeanattribute);
                }
            }
            mbs.invoke(objName, "startService", null, null);
        }
    } catch (ClassNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (InstantiationException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (SAXException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (MalformedObjectNameException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (InstanceAlreadyExistsException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (MBeanRegistrationException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (NotCompliantMBeanException 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();
    } catch (InvalidAttributeValueException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (AttributeNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

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

/**
 * This method deploys the war in exploded form and configures it.
 * //  ww  w  .  j  av a  2  s .co m
 * @param file
 * @param customClassLoader
 * @param warDirectoryPath
 */
public void extractWar(File file, ClassLoader classLoader) {

    StringBuffer classPath = new StringBuffer();
    int numBytes;
    WebClassLoader customClassLoader = null;
    CopyOnWriteArrayList<URL> jarUrls = new CopyOnWriteArrayList<URL>();
    try {
        ConcurrentHashMap jspMap = new ConcurrentHashMap();
        ZipFile zip = new ZipFile(file);
        ZipEntry ze = null;
        // String fileName=file.getName();
        String directoryName = file.getName();
        directoryName = directoryName.substring(0, directoryName.indexOf('.'));
        try {
            /*ClassLoader classLoader = Thread.currentThread()
                  .getContextClassLoader();*/
            // log.info("file://"+warDirectoryPath+"/WEB-INF/classes/");
            jarUrls.add(new URL("file:" + scanDirectory + "/" + directoryName + "/WEB-INF/classes/"));
            // new WebServer().addURL(new
            // URL("file://"+warDirectoryPath+"/"),customClassLoader);
        } catch (Exception e) {
            log.error("syntax of the URL is incorrect", e);
            //e1.printStackTrace();
        }
        String fileDirectory;
        Enumeration<? extends ZipEntry> entries = zip.entries();
        while (entries.hasMoreElements()) {
            ze = entries.nextElement();
            // //log.info("Unzipping " + ze.getName());
            String filePath = scanDirectory + "/" + directoryName + "/" + ze.getName();
            if (!ze.isDirectory()) {
                fileDirectory = filePath.substring(0, filePath.lastIndexOf('/'));
            } else {
                fileDirectory = filePath;
            }
            // //log.info(fileDirectory);
            createDirectory(fileDirectory);
            if (!ze.isDirectory()) {
                FileOutputStream fout = new FileOutputStream(filePath);
                byte[] inputbyt = new byte[8192];
                InputStream istream = zip.getInputStream(ze);
                while ((numBytes = istream.read(inputbyt, 0, inputbyt.length)) >= 0) {
                    fout.write(inputbyt, 0, numBytes);
                }
                fout.close();
                istream.close();
                if (ze.getName().endsWith(".jsp")) {
                    jspMap.put(ze.getName(), filePath);
                } else if (ze.getName().endsWith(".jar")) {
                    jarUrls.add(new URL("file:///" + scanDirectory + "/" + directoryName + "/" + ze.getName()));
                    classPath.append(filePath);
                    classPath.append(";");
                }
            }
        }
        zip.close();
        Set jsps = jspMap.keySet();
        Iterator jspIterator = jsps.iterator();
        classPath.append(scanDirectory + "/" + directoryName + "/WEB-INF/classes;");
        jarUrls.add(new URL("file:" + scanDirectory + "/" + directoryName + "/WEB-INF/classes/;"));
        ArrayList<String> jspFiles = new ArrayList();
        // log.info(classPath.toString());
        if (jspIterator.hasNext()) {
            jarUrls.add(new URL("file:" + scanDirectory + "/temp/" + directoryName + "/"));
            customClassLoader = new WebClassLoader(jarUrls.toArray(new URL[jarUrls.size()]), classLoader);
            while (jspIterator.hasNext()) {
                String filepackageInternal = (String) jspIterator.next();
                String filepackageInternalTmp = filepackageInternal;
                if (filepackageInternal.lastIndexOf('/') == -1) {
                    filepackageInternal = "";
                } else {
                    filepackageInternal = filepackageInternal.substring(0, filepackageInternal.lastIndexOf('/'))
                            .replace("/", ".");
                    filepackageInternal = "." + filepackageInternal;
                }
                createDirectory(scanDirectory + "/temp/" + directoryName);
                File jspFile = new File((String) jspMap.get(filepackageInternalTmp));
                String fName = jspFile.getName();
                String fileNameWithoutExtension = fName.substring(0, fName.lastIndexOf(".jsp")) + "_jsp";
                // String fileCreated=new JspCompiler().compileJsp((String)
                // jspMap.get(filepackageInternalTmp),
                // scanDirectory+"/temp/"+fileName,
                // "com.app.server"+filepackageInternal,classPath.toString());
                synchronized (customClassLoader) {
                    String fileNameInWar = filepackageInternalTmp;
                    jspFiles.add(fileNameInWar.replace("/", "\\"));
                    if (fileNameInWar.contains("/") || fileNameInWar.contains("\\")) {
                        customClassLoader.addURL("/" + fileNameInWar.replace("\\", "/"),
                                "com.app.server" + filepackageInternal.replace("WEB-INF", "WEB_002dINF") + "."
                                        + fileNameWithoutExtension);
                    } else {
                        customClassLoader.addURL("/" + fileNameInWar,
                                "com.app.server" + filepackageInternal.replace("WEB-INF", "WEB_002dINF") + "."
                                        + fileNameWithoutExtension);
                    }
                }
            }
        } else {
            customClassLoader = new WebClassLoader(jarUrls.toArray(new URL[jarUrls.size()]), classLoader);
        }
        String filePath = file.getAbsolutePath();
        // log.info("filePath"+filePath);
        filePath = filePath.substring(0, filePath.toLowerCase().lastIndexOf(".war"));
        urlClassLoaderMap.put(filePath.replace("\\", "/"), customClassLoader);
        if (jspFiles.size() > 0) {
            ClassLoader oldCL = Thread.currentThread().getContextClassLoader();
            //Thread.currentThread().setContextClassLoader(customClassLoader);
            String classPathBefore = "";
            try {
                JspCompiler jspc = new JspCompiler();
                jspc.setUriroot(scanDirectory + "/" + directoryName);
                jspc.setAddWebXmlMappings(false);
                jspc.setListErrors(false);
                jspc.setCompile(true);
                jspc.setOutputDir(scanDirectory + "/temp/" + directoryName + "/");
                jspc.setPackage("com.app.server");
                StringBuffer buffer = new StringBuffer();
                for (String jspFile : jspFiles) {
                    buffer.append(",");
                    buffer.append(jspFile);
                }
                String jsp = buffer.toString();
                jsp = jsp.substring(1, jsp.length());
                //log.info(jsp);
                classPathBefore = System.getProperty("java.class.path");
                System.setProperty("java.class.path",
                        System.getProperty("java.class.path") + ";" + classPath.toString().replace("/", "\\"));
                //jspc.setClassPath(System.getProperty("java.class.path")+";"+classPath.toString().replace("/", "\\"));
                jspc.setJspFiles(jsp);
                jspc.initCL(customClassLoader);
                jspc.execute();
                //jspc.closeClassLoader();
                //jspc.closeClassLoader();
            } catch (Throwable je) {
                log.error("Error in compiling the jsp page", je);
                //je.printStackTrace();
            } finally {
                System.setProperty("java.class.path", classPathBefore);
                //Thread.currentThread().setContextClassLoader(oldCL);
            }
            //Thread.currentThread().setContextClassLoader(customClassLoader);
        }
        try {
            File execxml = new File(scanDirectory + "/" + directoryName + "/WEB-INF/" + "executorservices.xml");
            if (execxml.exists()) {
                new ExecutorServicesConstruct().getExecutorServices(serverdigester, executorServiceMap, execxml,
                        customClassLoader);
            }
        } catch (Exception e) {
            log.error("error in getting executor services ", e);
            // e.printStackTrace();
        }
        try {
            File messagingxml = new File(
                    scanDirectory + "/" + directoryName + "/WEB-INF/" + "messagingclass.xml");
            if (messagingxml.exists()) {
                new MessagingClassConstruct().getMessagingClass(messagedigester, messagingxml,
                        customClassLoader, messagingClassMap);
            }
        } catch (Exception e) {
            log.error("Error in getting the messaging classes ", e);
            // e.printStackTrace();
        }
        webxmldigester.setNamespaceAware(true);
        webxmldigester.setValidating(true);
        // digester.setRules(null);
        FileInputStream webxml = new FileInputStream(
                scanDirectory + "/" + directoryName + "/WEB-INF/" + "web.xml");
        InputSource is = new InputSource(webxml);
        try {
            //log.info("SCHEMA");
            synchronized (webxmldigester) {
                // webxmldigester.set("config/web-app_2_4.xsd");
                WebAppConfig webappConfig = (WebAppConfig) webxmldigester.parse(is);
                servletMapping.put(scanDirectory + "/" + directoryName.replace("\\", "/"), webappConfig);
            }
            webxml.close();
        } catch (Exception e) {
            log.error("Error in pasrsing the web.xml", e);
            //e.printStackTrace();
        }
        //customClassLoader.close();
        // ClassLoaderUtil.closeClassLoader(customClassLoader);

    } catch (Exception ex) {
        log.error("Error in Deploying war " + file.getAbsolutePath(), ex);
    }
}

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

public CopyOnWriteArrayList<String> unpack(final FileObject unpackFileObject, final File outputDir,
        StandardFileSystemManager fileSystemManager) throws IOException {
    outputDir.mkdirs();/*  w w w  .j av  a 2  s.  com*/
    URLClassLoader webClassLoader;
    CopyOnWriteArrayList<String> classPath = new CopyOnWriteArrayList<String>();
    final FileObject packFileObject = fileSystemManager
            .resolveFile("jar:" + unpackFileObject.toString() + "!/");
    try {
        FileObject outputDirFileObject = fileSystemManager.toFileObject(outputDir);
        outputDirFileObject.copyFrom(packFileObject, new AllFileSelector());
        FileObject[] libs = outputDirFileObject.findFiles(new FileSelector() {

            public boolean includeFile(FileSelectInfo arg0) throws Exception {
                return arg0.getFile().getName().getBaseName().toLowerCase().endsWith(".jar");
            }

            public boolean traverseDescendents(FileSelectInfo arg0) throws Exception {
                // TODO Auto-generated method stub
                return true;
            }

        });
        /*String replaceString="file:///"+outputDir.getAbsolutePath().replace("\\","/");
        replaceString=replaceString.endsWith("/")?replaceString:replaceString+"/";*/
        // System.out.println(replaceString);
        for (FileObject lib : libs) {
            // System.out.println(outputDir.getAbsolutePath());
            // System.out.println(jsp.getName().getFriendlyURI());
            classPath.add(lib.getName().getFriendlyURI());
            // System.out.println(relJspName);
        }
    } finally {
        packFileObject.close();
    }
    return classPath;
}