Example usage for java.util.concurrent ConcurrentHashMap put

List of usage examples for java.util.concurrent ConcurrentHashMap put

Introduction

In this page you can find the example usage for java.util.concurrent ConcurrentHashMap put.

Prototype

public V put(K key, V value) 

Source Link

Document

Maps the specified key to the specified value in this table.

Usage

From source file:eu.itesla_project.online.db.OnlineDbMVStore.java

@Override
public void storeState(String workflowId, Integer stateId, Network network) {
    String stateIdStr = String.valueOf(stateId);
    LOGGER.info("Storing state {} of workflow {}", stateIdStr, workflowId);
    if (network.getStateManager().getStateIds().contains(stateIdStr)) {
        network.getStateManager().setWorkingState(stateIdStr);
        Path workflowStatesFolder = getWorkflowStatesFolder(workflowId);
        Path stateFolder = Paths.get(workflowStatesFolder.toString(), STORED_STATE_PREFIX + stateId);
        if (Files.exists(stateFolder)) {
            //remove current state file, if it already exists
            for (int i = 0; i < XIIDMEXTENSIONS.length; i++) {
                Path stateFile = Paths.get(stateFolder.toString(), network.getId() + XIIDMEXTENSIONS[i]);
                try {
                    Files.deleteIfExists(stateFile);
                } catch (IOException e) {
                    String errorMessage = "online db: folder " + workflowStatesFolder + " for workflow "
                            + workflowId + " , state " + stateIdStr + " ; cannot remove existing state file: "
                            + e.getMessage();
                    LOGGER.error(errorMessage);
                    throw new RuntimeException(errorMessage);
                }/*from w  w  w . j ava  2s  .com*/
            }
        } else {
            try {
                Files.createDirectories(stateFolder);
            } catch (IOException e) {
                String errorMessage = "online db: folder " + workflowStatesFolder + " for workflow "
                        + workflowId + " and state " + stateIdStr + " cannot be created: " + e.getMessage();
                LOGGER.error(errorMessage);
                throw new RuntimeException(errorMessage);
            }
        }
        DataSource dataSource = new FileDataSource(stateFolder, network.getId());
        Properties parameters = new Properties();
        parameters.setProperty("iidm.export.xml.indent", "true");
        parameters.setProperty("iidm.export.xml.with-branch-state-variables", "true");
        parameters.setProperty("iidm.export.xml.with-breakers", "true");
        parameters.setProperty("iidm.export.xml.with-properties", "true");
        Exporters.export("XIIDM", network, parameters, dataSource);
        // store network state values, for later serialization
        Map<HistoDbAttributeId, Object> networkValues = IIDM2DB
                .extractCimValues(network, new IIDM2DB.Config(network.getId(), true, true)).getSingleValueMap();
        ConcurrentHashMap<Integer, Map<HistoDbAttributeId, Object>> workflowStates = new ConcurrentHashMap<Integer, Map<HistoDbAttributeId, Object>>();
        if (workflowsStates.containsKey(workflowId))
            workflowStates = workflowsStates.get(workflowId);
        workflowStates.put(stateId, networkValues);
        workflowsStates.put(workflowId, workflowStates);
    } else {
        String errorMessage = "online db: no state " + stateIdStr + " in network of workflow " + workflowId;
        LOGGER.error(errorMessage);
        throw new RuntimeException(errorMessage);
    }
}

From source file:ubic.gemma.analysis.preprocess.batcheffects.ComBat.java

/**
 * Multithreaded/*from   w ww . jav  a  2 s.c o  m*/
 * 
 * @param sdata
 * @param gammastar
 * @param deltastar
 */
private void runNonParametric(final DoubleMatrix2D sdata, DoubleMatrix2D gammastar, DoubleMatrix2D deltastar) {
    final ConcurrentHashMap<String, DoubleMatrix1D[]> results = new ConcurrentHashMap<String, DoubleMatrix1D[]>();
    int numThreads = Math.min(batches.size(), Runtime.getRuntime().availableProcessors());

    log.info("Runing nonparametric estimation on " + numThreads + " threads");

    Future<?>[] futures = new Future[numThreads];
    ExecutorService service = Executors.newCachedThreadPool();

    /*
     * Divvy up batches over threads.
     */

    int batchesPerThread = batches.size() / numThreads;

    final String[] batchIds = batches.keySet().toArray(new String[] {});

    for (int i = 0; i < numThreads; i++) {

        final int firstBatch = i * batchesPerThread;
        final int lastBatch = i == (numThreads - 1) ? batches.size() : firstBatch + batchesPerThread;

        futures[i] = service.submit(new Runnable() {
            @Override
            public void run() {
                for (int k = firstBatch; k < lastBatch; k++) {
                    String batchId = batchIds[k];
                    DoubleMatrix2D batchData = getBatchData(sdata, batchId);
                    DoubleMatrix1D[] batchResults = nonParametricFit(batchData, gammaHat.viewRow(k),
                            deltaHat.viewRow(k));
                    results.put(batchId, batchResults);
                }
            }
        });
    }

    service.shutdown();

    boolean allDone = false;
    do {
        for (Future<?> f : futures) {
            allDone = true;
            if (!f.isDone() && !f.isCancelled()) {
                allDone = false;
                break;
            }
        }
    } while (!allDone);

    for (int i = 0; i < batchIds.length; i++) {
        String batchId = batchIds[i];
        DoubleMatrix1D[] batchResults = results.get(batchId);
        for (int j = 0; j < batchResults[0].size(); j++) {
            gammastar.set(i, j, batchResults[0].get(j));
        }
        for (int j = 0; j < batchResults[1].size(); j++) {
            deltastar.set(i, j, batchResults[1].get(j));
        }
    }
}

From source file:org.wso2.carbon.event.output.adaptor.mqtt.MQTTEventAdaptorType.java

/**
 * @param outputEventAdaptorMessageConfiguration
 *                 - topic name to publish messages
 * @param message  - is and Object[]{Event, EventDefinition}
 * @param outputEventAdaptorConfiguration
 *                 the {@link OutputEventAdaptorConfiguration} object that will be used to
 *                 get configuration information
 * @param tenantId tenant id of the calling thread.
 *///from   ww  w.j a  v  a2 s  .  c  om
public void publish(OutputEventAdaptorMessageConfiguration outputEventAdaptorMessageConfiguration,
        Object message, OutputEventAdaptorConfiguration outputEventAdaptorConfiguration, int tenantId) {

    ConcurrentHashMap<String, ConcurrentHashMap<String, MQTTAdaptorPublisher>> clientIdSpecificEventSenderMap = publisherMap
            .get(outputEventAdaptorConfiguration.getName());
    if (null == clientIdSpecificEventSenderMap) {
        clientIdSpecificEventSenderMap = new ConcurrentHashMap<String, ConcurrentHashMap<String, MQTTAdaptorPublisher>>();
        if (null != publisherMap.putIfAbsent(outputEventAdaptorConfiguration.getName(),
                clientIdSpecificEventSenderMap)) {
            clientIdSpecificEventSenderMap = publisherMap.get(outputEventAdaptorConfiguration.getName());
        }
    }

    String clientId = outputEventAdaptorMessageConfiguration.getOutputMessageProperties()
            .get(MQTTEventAdaptorConstants.ADAPTOR_MESSAGE_CLIENTID);
    ConcurrentHashMap<String, MQTTAdaptorPublisher> topicSpecificEventPublisherMap = clientIdSpecificEventSenderMap
            .get(clientId);
    if (null == topicSpecificEventPublisherMap) {
        topicSpecificEventPublisherMap = new ConcurrentHashMap<String, MQTTAdaptorPublisher>();
        if (null != clientIdSpecificEventSenderMap.putIfAbsent(clientId, topicSpecificEventPublisherMap)) {
            topicSpecificEventPublisherMap = clientIdSpecificEventSenderMap.get(clientId);
        }
    }

    String topic = outputEventAdaptorMessageConfiguration.getOutputMessageProperties()
            .get(MQTTEventAdaptorConstants.ADAPTOR_MESSAGE_TOPIC);
    MQTTAdaptorPublisher mqttAdaptorPublisher = topicSpecificEventPublisherMap.get(topic);
    if (mqttAdaptorPublisher == null) {
        MQTTBrokerConnectionConfiguration mqttBrokerConnectionConfiguration = new MQTTBrokerConnectionConfiguration(
                outputEventAdaptorConfiguration.getOutputProperties()
                        .get(MQTTEventAdaptorConstants.ADAPTOR_CONF_URL),
                outputEventAdaptorConfiguration.getOutputProperties()
                        .get(MQTTEventAdaptorConstants.ADAPTOR_CONF_USERNAME),
                outputEventAdaptorConfiguration.getOutputProperties()
                        .get(MQTTEventAdaptorConstants.ADAPTOR_CONF_PASSWORD),
                outputEventAdaptorConfiguration.getOutputProperties()
                        .get(MQTTEventAdaptorConstants.ADAPTOR_CONF_CLEAN_SESSION),
                outputEventAdaptorConfiguration.getOutputProperties()
                        .get(MQTTEventAdaptorConstants.ADAPTOR_CONF_KEEP_ALIVE));
        mqttAdaptorPublisher = new MQTTAdaptorPublisher(mqttBrokerConnectionConfiguration,
                outputEventAdaptorMessageConfiguration.getOutputMessageProperties()
                        .get(MQTTEventAdaptorConstants.ADAPTOR_MESSAGE_TOPIC),
                outputEventAdaptorMessageConfiguration.getOutputMessageProperties()
                        .get(MQTTEventAdaptorConstants.ADAPTOR_MESSAGE_CLIENTID));
        topicSpecificEventPublisherMap.put(topic, mqttAdaptorPublisher);
    }
    String qos = outputEventAdaptorMessageConfiguration.getOutputMessageProperties()
            .get(MQTTEventAdaptorConstants.ADAPTOR_MESSAGE_QOS);

    try {
        if (qos == null) {
            mqttAdaptorPublisher.publish(message.toString());
        } else {
            mqttAdaptorPublisher.publish(Integer.parseInt(qos), message.toString());
        }
    } catch (OutputEventAdaptorEventProcessingException ex) {
        log.error(ex);
        topicSpecificEventPublisherMap.remove(topic);
        throw new OutputEventAdaptorEventProcessingException(ex);
    }
}

From source file:com.untangle.app.license.LicenseManagerImpl.java

/**
 * update the app to License Map//  ww w .ja v  a2  s  .  c o  m
 */
private synchronized void _mapLicenses() {
    /* Create a new map of all of the valid licenses */
    ConcurrentHashMap<String, License> newMap = new ConcurrentHashMap<String, License>();
    LinkedList<License> newList = new LinkedList<License>();
    License license = null;

    if (this.settings != null) {
        for (License lic : this.settings.getLicenses()) {
            try {
                /**
                 * Create a duplicate - we're about to fill in metadata
                 * But we don't want to mess with the original
                 */
                license = new License(lic);

                /**
                 * Complete Meta-data
                 */
                _setValidAndStatus(license);

                String identifier = license.getCurrentName();
                if (identifier == null) {
                    logger.warn("Ignoring license with no name: " + license);
                    continue;
                }

                License current = newMap.get(identifier);

                /* current license is newer and better */
                if ((current != null) && (current.getEnd() > license.getEnd()))
                    continue;

                logger.info("Adding License: " + license.getCurrentName() + " to Map. (valid: "
                        + license.getValid() + ")");

                newMap.put(identifier, license);
                newList.add(license);
            } catch (Exception e) {
                logger.warn("Failed to load license: " + license, e);
            }
        }
    }

    this.licenseMap = newMap;
    this.licenseList = newList;
}

From source file:com.cloudera.impala.catalog.CatalogServiceCatalog.java

/**
 * Resets this catalog instance by clearing all cached table and database metadata.
 *//*from   w  w w .j ava2  s  .com*/
public void reset() throws CatalogException {
    // First update the policy metadata.
    if (sentryProxy_ != null) {
        // Sentry Service is enabled.
        try {
            // Update the authorization policy, waiting for the result to complete.
            sentryProxy_.refresh();
        } catch (Exception e) {
            throw new CatalogException("Error updating authorization policy: ", e);
        }
    }

    catalogLock_.writeLock().lock();
    try {
        nextTableId_.set(0);

        // Not all Java UDFs are persisted to the metastore. The ones which aren't
        // should be restored once the catalog has been invalidated.
        Map<String, Db> oldDbCache = dbCache_.get();

        // Build a new DB cache, populate it, and replace the existing cache in one
        // step.
        ConcurrentHashMap<String, Db> newDbCache = new ConcurrentHashMap<String, Db>();
        List<TTableName> tblsToBackgroundLoad = Lists.newArrayList();
        MetaStoreClient msClient = metaStoreClientPool_.getClient();
        try {
            for (String dbName : msClient.getHiveClient().getAllDatabases()) {
                List<org.apache.hadoop.hive.metastore.api.Function> javaFns = Lists.newArrayList();
                for (String javaFn : msClient.getHiveClient().getFunctions(dbName, "*")) {
                    javaFns.add(msClient.getHiveClient().getFunction(dbName, javaFn));
                }
                org.apache.hadoop.hive.metastore.api.Database msDb = msClient.getHiveClient()
                        .getDatabase(dbName);
                Db db = new Db(dbName, this, msDb);
                // Restore UDFs that aren't persisted.
                Db oldDb = oldDbCache.get(db.getName().toLowerCase());
                if (oldDb != null) {
                    for (Function fn : oldDb.getTransientFunctions()) {
                        db.addFunction(fn);
                        fn.setCatalogVersion(incrementAndGetCatalogVersion());
                    }
                }
                loadFunctionsFromDbParams(db, msDb);
                loadJavaFunctions(db, javaFns);
                db.setCatalogVersion(incrementAndGetCatalogVersion());
                newDbCache.put(db.getName().toLowerCase(), db);

                for (String tableName : msClient.getHiveClient().getAllTables(dbName)) {
                    Table incompleteTbl = IncompleteTable.createUninitializedTable(getNextTableId(), db,
                            tableName);
                    incompleteTbl.setCatalogVersion(incrementAndGetCatalogVersion());
                    db.addTable(incompleteTbl);
                    if (loadInBackground_) {
                        tblsToBackgroundLoad.add(new TTableName(dbName.toLowerCase(), tableName.toLowerCase()));
                    }
                }
            }
        } finally {
            msClient.release();
        }
        dbCache_.set(newDbCache);
        // Submit tables for background loading.
        for (TTableName tblName : tblsToBackgroundLoad) {
            tableLoadingMgr_.backgroundLoad(tblName);
        }
    } catch (Exception e) {
        LOG.error(e);
        throw new CatalogException("Error initializing Catalog. Catalog may be empty.", e);
    } finally {
        catalogLock_.writeLock().unlock();
    }
}

From source file:edu.berkeley.compbio.phyloutils.HugenholtzTaxonomyService.java

@NotNull
public synchronized Integer findTaxidByName(String name) throws NoSuchNodeException {
    ConcurrentHashMap<String, Integer> nameToUniqueIdMap = (ConcurrentHashMap<String, Integer>) nameToUniqueIdMapStub
            .get();/*from   w  ww . ja v a  2  s.  com*/

    Integer result = nameToUniqueIdMap.get(name);

    if (result == null) {
        BasicRootedPhylogeny<Integer> theIntegerTree = (BasicRootedPhylogeny<Integer>) theIntegerTreeStub.get();

        try {
            Integer id = new Integer(name);
            theIntegerTree.getNode(id); // throws exception if not present // intToNodeMap.containsKey(id))
            result = id;
        } catch (NumberFormatException e) {
            // ok, try the next thing
        } catch (NoSuchNodeException e) {
            // ok, try the next thing
        }

        if (result == null) {
            if (!name.contains(";")) {
                try {
                    BasicRootedPhylogeny<Integer> bTree = findSubtreeByNameRelaxed(name);
                    result = bTree.getShallowestLeaf();
                } catch (NoSuchNodeException e) {
                    result = NO_VALID_ID;
                }

                //result = getUniqueNodeForName(name);

                // REVIEW for our present purposes we always want the worst-case node; but in other contexts that may be the wrong thing to do

                //   result = getDeepestNodeForName(name);
            } else {
                result = getUniqueNodeForMultilevelName(name.split("[; ]+"));
            }
        }
        nameToUniqueIdMap.put(name, result);
    }

    if (result.equals(NO_VALID_ID)) {
        throw new NoSuchNodeException("Taxon not found: " + name);
    }

    return result;
}

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

public Vector<URL> unpack(final FileObject unpackFileObject, final File outputDir,
        StandardFileSystemManager fileSystemManager, ConcurrentHashMap<String, String> jsps)
        throws IOException {
    outputDir.mkdirs();/* www . j  av  a2  s  .  c o  m*/
    URLClassLoader webClassLoader;
    Vector<URL> libraries = new Vector<URL>();
    final FileObject packFileObject = fileSystemManager.resolveFile(unpackFileObject.toString());
    try {
        FileObject outputDirFileObject = fileSystemManager.toFileObject(outputDir);
        outputDirFileObject.copyFrom(packFileObject, new AllFileSelector());
        FileObject[] jspFiles = outputDirFileObject.findFiles(new FileSelector() {

            public boolean includeFile(FileSelectInfo arg0) throws Exception {
                return arg0.getFile().getName().getBaseName().toLowerCase().endsWith(".jsp")
                        || 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 jsplibs : jspFiles) {
            // System.out.println(outputDir.getAbsolutePath());
            // System.out.println(jsp.getName().getFriendlyURI());
            if (jsplibs.getName().getBaseName().endsWith(".jar")) {
                libraries.add(new URL(jsplibs.getName().getFriendlyURI()));
            } else {
                String relJspName = jsplibs.getName().getFriendlyURI().replace(replaceString, "");
                jsps.put(relJspName, relJspName);
            }
            // System.out.println(relJspName);
        }
    } finally {
        packFileObject.close();
    }
    return libraries;
}

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

/**
 * This method deploys the war in exploded form and configures it. 
 * @param file/*from w  w  w  . ja v a2  s .co  m*/
 * @param customClassLoader
 * @param warDirectoryPath
 */
public void extractWar(File file, WebClassLoader customClassLoader) {

    StringBuffer classPath = new StringBuffer();
    int numBytes;
    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();
            //logger.info("file://"+warDirectoryPath+"/WEB-INF/classes/");
            new WebServer().addURL(new URL("file:" + scanDirectory + "/" + directoryName + "/WEB-INF/classes/"),
                    customClassLoader);
            //new WebServer().addURL(new URL("file://"+warDirectoryPath+"/"),customClassLoader);
        } catch (IOException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
        String fileDirectory;
        Enumeration<? extends ZipEntry> entries = zip.entries();
        while (entries.hasMoreElements()) {
            ze = entries.nextElement();
            // //System.out.println("Unzipping " + ze.getName());
            String filePath = scanDirectory + "/" + directoryName + "/" + 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(".jsp")) {
                    jspMap.put(ze.getName(), filePath);
                } else if (ze.getName().endsWith(".jar")) {
                    new WebServer().addURL(
                            new URL("file:///" + scanDirectory + "/" + directoryName + "/" + ze.getName()),
                            customClassLoader);
                    classPath.append(filePath);
                    classPath.append(";");
                }
            }
        }
        zip.close();
        Set jsps = jspMap.keySet();
        Iterator jspIterator = jsps.iterator();
        classPath.append(scanDirectory + "/" + directoryName + "/WEB-INF/classes/;");
        ArrayList<String> jspFiles = new ArrayList();
        //System.out.println(classPath.toString());
        if (jspIterator.hasNext())
            new WebServer().addURL(new URL("file:" + scanDirectory + "/temp/" + directoryName + "/"),
                    customClassLoader);
        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.web.server"+filepackageInternal,classPath.toString());
            synchronized (customClassLoader) {
                String fileNameInWar = filepackageInternalTmp;
                jspFiles.add(fileNameInWar.replace("/", "\\"));
                if (fileNameInWar.contains("/") || fileNameInWar.contains("\\")) {
                    customClassLoader.addURL("/" + fileNameInWar.replace("\\", "/"),
                            "com.web.server" + filepackageInternal + "." + fileNameWithoutExtension);
                } else {
                    customClassLoader.addURL("/" + fileNameInWar,
                            "com.web.server" + filepackageInternal + "." + fileNameWithoutExtension);
                }
            }
        }
        if (jspFiles.size() > 0) {
            ClassLoader oldCL = Thread.currentThread().getContextClassLoader();
            Thread.currentThread().setContextClassLoader(customClassLoader);
            try {
                JspC jspc = new JspC();
                jspc.setUriroot(scanDirectory + "/" + directoryName + "/");
                jspc.setAddWebXmlMappings(false);
                jspc.setCompile(true);
                jspc.setOutputDir(scanDirectory + "/temp/" + directoryName + "/");
                jspc.setPackage("com.web.server");
                StringBuffer buffer = new StringBuffer();
                for (String jspFile : jspFiles) {
                    buffer.append(",");
                    buffer.append(jspFile);
                }
                String jsp = buffer.toString();
                jsp = jsp.substring(1, jsp.length());
                System.out.println(jsp);
                jspc.setJspFiles(jsp);
                jspc.execute();
            } catch (Throwable je) {
                je.printStackTrace();
            } finally {
                Thread.currentThread().setContextClassLoader(oldCL);
            }
            Thread.currentThread().setContextClassLoader(customClassLoader);
        }
        try {
            new ExecutorServicesConstruct().getExecutorServices(serverdigester, executorServiceMap,
                    new File(scanDirectory + "/" + directoryName + "/WEB-INF/" + "executorservices.xml"),
                    customClassLoader);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            //e.printStackTrace();
        }
        try {
            new MessagingClassConstruct().getMessagingClass(messagedigester,
                    new File(scanDirectory + "/" + directoryName + "/WEB-INF/" + "messagingclass.xml"),
                    customClassLoader, messagingClassMap);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            //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 {
            System.out.println("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) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        //ClassLoaderUtil.closeClassLoader(customClassLoader);

    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        //e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        //e.printStackTrace();
    } catch (Exception ex) {

    }
}

From source file:com.dtolabs.rundeck.jetty.jaas.JettyCachingLdapLoginModule.java

private ConcurrentHashMap<String, List<String>> buildRoleMemberOfMap(DirContext dirContext) {
    Object[] filterArguments = { _roleObjectClass };
    SearchControls ctls = new SearchControls();
    ctls.setDerefLinkFlag(true);/*from   w ww  .  java  2s  .  co  m*/
    ctls.setSearchScope(SearchControls.SUBTREE_SCOPE);

    ConcurrentHashMap<String, List<String>> roleMemberOfMap = new ConcurrentHashMap<String, List<String>>();

    try {
        NamingEnumeration<SearchResult> results = dirContext.search(_roleBaseDn, _roleMemberFilter, ctls);
        while (results.hasMoreElements()) {
            SearchResult result = results.nextElement();
            Attributes attributes = result.getAttributes();

            if (attributes == null) {
                continue;
            }

            Attribute roleAttribute = attributes.get(_roleNameAttribute);
            Attribute memberAttribute = attributes.get(_roleMemberAttribute);

            if (roleAttribute == null || memberAttribute == null) {
                continue;
            }

            NamingEnumeration role = roleAttribute.getAll();
            NamingEnumeration members = memberAttribute.getAll();

            if (!role.hasMore() || !members.hasMore()) {
                continue;
            }

            String roleName = (String) role.next();
            if (_rolePrefix != null && !"".equalsIgnoreCase(_rolePrefix)) {
                roleName = roleName.replace(_rolePrefix, "");
            }

            while (members.hasMore()) {
                String member = (String) members.next();
                Matcher roleMatcher = rolePattern.matcher(member);
                if (!roleMatcher.find()) {
                    continue;
                }
                String roleMember = roleMatcher.group(1);
                List<String> memberOf;
                if (roleMemberOfMap.containsKey(roleMember)) {
                    memberOf = roleMemberOfMap.get(roleMember);
                } else {
                    memberOf = new ArrayList<String>();
                }

                memberOf.add(roleName);

                roleMemberOfMap.put(roleMember, memberOf);
            }

        }
    } catch (NamingException e) {
        e.printStackTrace();
    }
    return roleMemberOfMap;
}

From source file:org.apache.slider.providers.agent.AgentProviderService.java

/**
 * Process return status for component instances
 *
 * @param heartBeat/*from  w  w w. ja v  a  2 s .  c  o m*/
 * @param componentStatus
 */
protected void publishConfigAndExportGroups(HeartBeat heartBeat, ComponentInstanceState componentStatus,
        String componentName) {
    List<ComponentStatus> statuses = heartBeat.getComponentStatus();
    if (statuses != null && !statuses.isEmpty()) {
        log.info("Processing {} status reports.", statuses.size());
        for (ComponentStatus status : statuses) {
            log.info("Status report: " + status.toString());

            if (status.getConfigs() != null) {
                Application application = getMetainfo().getApplication();

                if (canAnyMasterPublishConfig() == false || canPublishConfig(componentName)) {
                    // If no Master can explicitly publish then publish if its a master
                    // Otherwise, wait till the master that can publish is ready

                    Set<String> exportedConfigs = new HashSet();
                    String exportedConfigsStr = application.getExportedConfigs();
                    boolean exportedAllConfigs = exportedConfigsStr == null || exportedConfigsStr.isEmpty();
                    if (!exportedAllConfigs) {
                        for (String exportedConfig : exportedConfigsStr.split(",")) {
                            if (exportedConfig.trim().length() > 0) {
                                exportedConfigs.add(exportedConfig.trim());
                            }
                        }
                    }

                    for (String key : status.getConfigs().keySet()) {
                        if ((!exportedAllConfigs && exportedConfigs.contains(key)) || exportedAllConfigs) {
                            Map<String, String> configs = status.getConfigs().get(key);
                            publishApplicationInstanceData(key, key, configs.entrySet());
                        }
                    }
                }

                List<ExportGroup> appExportGroups = application.getExportGroups();
                boolean hasExportGroups = appExportGroups != null && !appExportGroups.isEmpty();

                Set<String> appExports = new HashSet();
                String appExportsStr = getApplicationComponent(componentName).getAppExports();
                if (SliderUtils.isSet(appExportsStr)) {
                    for (String appExport : appExportsStr.split(",")) {
                        if (appExport.trim().length() > 0) {
                            appExports.add(appExport.trim());
                        }
                    }
                }

                if (hasExportGroups && appExports.size() > 0) {
                    String configKeyFormat = "${site.%s.%s}";
                    String hostKeyFormat = "${%s_HOST}";

                    // publish export groups if any
                    Map<String, String> replaceTokens = new HashMap<String, String>();
                    for (Map.Entry<String, Map<String, ClusterNode>> entry : getRoleClusterNodeMapping()
                            .entrySet()) {
                        String hostName = getHostsList(entry.getValue().values(), true).iterator().next();
                        replaceTokens.put(
                                String.format(hostKeyFormat, entry.getKey().toUpperCase(Locale.ENGLISH)),
                                hostName);
                    }

                    for (String key : status.getConfigs().keySet()) {
                        Map<String, String> configs = status.getConfigs().get(key);
                        for (String configKey : configs.keySet()) {
                            String lookupKey = String.format(configKeyFormat, key, configKey);
                            replaceTokens.put(lookupKey, configs.get(configKey));
                        }
                    }

                    Set<String> modifiedGroups = new HashSet<String>();
                    for (ExportGroup exportGroup : appExportGroups) {
                        List<Export> exports = exportGroup.getExports();
                        if (exports != null && !exports.isEmpty()) {
                            String exportGroupName = exportGroup.getName();
                            ConcurrentHashMap<String, List<ExportEntry>> map = (ConcurrentHashMap<String, List<ExportEntry>>) getCurrentExports(
                                    exportGroupName);
                            for (Export export : exports) {
                                if (canBeExported(exportGroupName, export.getName(), appExports)) {
                                    String value = export.getValue();
                                    // replace host names
                                    for (String token : replaceTokens.keySet()) {
                                        if (value.contains(token)) {
                                            value = value.replace(token, replaceTokens.get(token));
                                        }
                                    }
                                    ExportEntry entry = new ExportEntry();
                                    entry.setLevel(APPLICATION_TAG);
                                    entry.setValue(value);
                                    entry.setUpdatedTime(new Date().toString());
                                    // over-write, app exports are singletons
                                    map.put(export.getName(), new ArrayList(Arrays.asList(entry)));
                                    log.info("Preparing to publish. Key {} and Value {}", export.getName(),
                                            value);
                                }
                            }
                            modifiedGroups.add(exportGroupName);
                        }
                    }
                    publishModifiedExportGroups(modifiedGroups);
                }

                log.info("Received and processed config for {}", heartBeat.getHostname());
                componentStatus.setConfigReported(true);

            }
        }
    }
}