Example usage for java.util.concurrent ConcurrentHashMap keySet

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

Introduction

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

Prototype

KeySetView keySet

To view the source code for java.util.concurrent ConcurrentHashMap keySet.

Click Source Link

Usage

From source file:org.wso2.carbon.event.input.adaptor.wso2event.WSO2EventEventAdaptorType.java

public String subscribe(InputEventAdaptorMessageConfiguration inputEventAdaptorMessageConfiguration,
        InputEventAdaptorListener inputEventAdaptorListener,
        InputEventAdaptorConfiguration inputEventAdaptorConfiguration, AxisConfiguration axisConfiguration) {
    String subscriptionId = UUID.randomUUID().toString();
    int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
    EventAdaptorConf eventAdaptorConf = new EventAdaptorConf(inputEventAdaptorListener, tenantId,
            PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain());

    ConcurrentHashMap<InputEventAdaptorMessageConfiguration, ConcurrentHashMap<String, EventAdaptorConf>> tenantSpecificAdaptorListenerMap = inputEventAdaptorListenerMap
            .get(tenantId);//from www. ja  v  a 2 s  .c o m
    if (tenantSpecificAdaptorListenerMap == null) {
        tenantSpecificAdaptorListenerMap = new ConcurrentHashMap<InputEventAdaptorMessageConfiguration, ConcurrentHashMap<String, EventAdaptorConf>>();
        inputEventAdaptorListenerMap.put(tenantId, tenantSpecificAdaptorListenerMap);
    }

    if (!tenantSpecificAdaptorListenerMap.keySet().contains(inputEventAdaptorMessageConfiguration)) {
        ConcurrentHashMap<String, EventAdaptorConf> map = new ConcurrentHashMap<String, WSO2EventEventAdaptorType.EventAdaptorConf>();
        map.put(subscriptionId, eventAdaptorConf);
        tenantSpecificAdaptorListenerMap.put(inputEventAdaptorMessageConfiguration, map);
    } else {
        tenantSpecificAdaptorListenerMap.get(inputEventAdaptorMessageConfiguration).put(subscriptionId,
                eventAdaptorConf);
        ConcurrentHashMap<InputEventAdaptorMessageConfiguration, StreamDefinition> tenantSpecificInputStreamDefinitionMap = inputStreamDefinitionMap
                .get(tenantId);
        if (tenantSpecificInputStreamDefinitionMap != null) {
            StreamDefinition streamDefinition = tenantSpecificInputStreamDefinitionMap
                    .get(inputEventAdaptorMessageConfiguration);
            if (streamDefinition != null) {
                inputEventAdaptorListener.addEventDefinitionCall(streamDefinition);
            }
        }

    }

    return subscriptionId;
}

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

@Override
public void fileDeleted(FileChangeEvent arg0) throws Exception {
    FileObject baseFile = arg0.getFile();
    if (baseFile.getName().getURI().endsWith(".jar")) {
        System.out.println(jarEJBMap.get(baseFile.getName().getURI()));
        EJBContext ejbContext = jarEJBMap.get(baseFile.getName().getURI());
        if (ejbContext != null) {
            HashMap<String, Class> bindings = ejbContext.getRemoteBindings();
            Set<String> remoteBindings = bindings.keySet();
            Iterator<String> remoteBinding = remoteBindings.iterator();
            while (remoteBinding.hasNext()) {
                String binding = (String) remoteBinding.next();
                registry.unbind(binding);
                System.out.println("unregistering the class" + bindings.get(binding));
            }/*w  w w  .  java2s .  c  om*/
            jarEJBMap.remove(baseFile.getName().getURI());
        }
        ConcurrentHashMap<String, MDBContext> mdbContexts = jarMDBMap.get(baseFile.getName().getURI());
        MDBContext mdbContext;
        if (mdbContexts != null) {
            Iterator<String> mdbnames = mdbContexts.keySet().iterator();
            while (mdbnames.hasNext()) {
                String mdbname = mdbnames.next();
                mdbContext = mdbContexts.get(mdbname);
                if (mdbContext.getConsumer() != null) {
                    mdbContext.getConsumer().setMessageListener(null);
                    mdbContext.getConsumer().close();
                }
                if (mdbContext.getSession() != null)
                    mdbContext.getSession().close();
                if (mdbContext.getConnection() != null)
                    mdbContext.getConnection().close();
                mdbContexts.remove(mdbname);
            }
            jarMDBMap.remove(baseFile.getName().getURI());
        }
    }
    System.out.println(baseFile.getName().getURI() + " UnDeployed");
}

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

/**
 * This method removes the executor services from the executor services
 * map./*www .  j a v a2  s .  c  o m*/
 * 
 * @param jarFile
 * @param classList
 * @throws FileSystemException
 */
public void deleteExecutorServicesEar(String fileName, StandardFileSystemManager fsManager)
        throws FileSystemException {
    try {
        synchronized (urlClassLoaderMap) {
            ConcurrentHashMap map = (ConcurrentHashMap) filesMap.get(fileName);
            if (map != null) {
                //log.info("ClassLoader Map=\n\n\n\n"+urlClassLoaderMap);
                Set keysinclassloadermap = map.keySet();
                System.out.println(keysinclassloadermap.size());
                Iterator classloaders = keysinclassloadermap.iterator();
                while (classloaders.hasNext()) {
                    String classloader = (String) classloaders.next();
                    System.out.println("ClassLoader=" + classloader);
                    ClassLoader webClassLoader = (ClassLoader) this.urlClassLoaderMap.get(map.get(classloader));
                    this.urlClassLoaderMap.remove(map.get(classloader));
                    ClassLoaderUtil.cleanupJarFileFactory(ClassLoaderUtil.closeClassLoader(webClassLoader));
                    urlClassLoaderMap.remove(map.get(classloader));
                    try {
                        if (webClassLoader instanceof WebClassLoader)
                            ((WebClassLoader) webClassLoader).close();
                        else if (webClassLoader instanceof VFSClassLoader) {
                            FileObject[] fObj = ((VFSClassLoader) webClassLoader).getFileObjects();
                            for (FileObject obj : fObj) {
                                obj.close();
                            }
                        }
                    } catch (Throwable e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    /*if (classloader.contains(deployDirectory +"/"+ fileName)) {
                       System.out.println("removing classloader" + deployDirectory
                      + classloader);
                          File warDir=new File(fileName);
                          if(warDir.exists()){                                    
                      warDeployer.deleteDir(warDir);
                          }
                          //System.out.println("Before Remove class loader\n\n\n\n"+this.urlClassLoaderMap);                           
                          //System.out.println("Remove class loader\n\n\n\n"+this.urlClassLoaderMap);
                    }*/
                }
                System.gc();
                classloaders = keysinclassloadermap.iterator();
                while (classloaders.hasNext()) {
                    String classloader = (String) classloaders.next();
                    if (classloader.endsWith(".war")) {
                        warDeployer.removeServlets((String) map.get(classloader), classloader);
                        File warDir = new File((String) map.get(classloader));
                        if (warDir.exists()) {
                            warDeployer.deleteDir(warDir);
                        }
                    }
                }
                log.info(this.urlClassLoaderMap);
            }
            filesMap.remove(fileName);
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:org.wso2.andes.kernel.OnflightMessageTracker.java

/**
 * Clear all tracking when orphan slot situation i.e. call when no active subscription but buffered messages are
 * sent to subscription/*from  w  w w.  j  a  va2 s .co  m*/
 *
 * @param slot slot to release
 */
public void clearAllTrackingWhenSlotOrphaned(Slot slot) {
    if (log.isDebugEnabled()) {
        log.debug("Orphan slot situation and clear tracking of messages for slot = " + slot);
    }
    String slotID = slot.getId();
    ConcurrentHashMap<Long, MsgData> messagesOfSlot = messageBufferingTracker.remove(slotID);
    if (messagesOfSlot != null) {
        for (Long messageId : messagesOfSlot.keySet()) {
            msgId2MsgData.remove(messageId);
        }
    }
    subscriptionSlotTracker.remove(slot);
}

From source file:org.wso2.andes.kernel.OnflightMessageTracker.java

/**
 * Release tracking of all messages belonging to a slot. i.e called when slot is removed.
 * This will remove all buffering tracking of messages and tracking objects.
 * But tracking objects will remain until delivery cycle completed
 *
 * @param slot slot to release/*from   w w  w  .jav a  2 s.  co  m*/
 */
public void releaseAllMessagesOfSlotFromTracking(Slot slot) {
    //remove all actual msgData objects
    if (log.isDebugEnabled()) {
        log.debug("Releasing tracking of messages for slot " + slot.toString());
    }
    String slotID = slot.getId();
    ConcurrentHashMap<Long, MsgData> messagesOfSlot = messageBufferingTracker.remove(slotID);
    if (messagesOfSlot != null) {
        for (Long messageId : messagesOfSlot.keySet()) {
            getTrackingData(messageId).addMessageStatus(MessageStatus.SLOT_REMOVED);
            if (checkIfReadyToRemoveFromTracking(messageId)) {
                if (log.isDebugEnabled()) {
                    log.debug("removing tracking object from memory id " + messageId);
                }
                msgId2MsgData.remove(messageId);
            }
        }
    }
}

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

public void undeploy(URL url) {
    try {//  ww  w  .j av a 2 s .  c o  m
        //System.out.println(jarEJBMap.get(url.toString()));
        Vector<Object> objs = staticObjsEjbMap.remove(url.toString());
        if (objs != null) {
            objs.clear();
        }
        Vector<EJBContext> ejbContexts = jarEJBMap.get(url.toString());
        if (ejbContexts != null && ejbContexts.size() > 0) {
            for (EJBContext ejbContext : ejbContexts) {
                if (ejbContext != null) {
                    HashMap<String, Class> bindings = ejbContext.getRemoteBindings();
                    Set<String> remoteBindings = bindings.keySet();
                    Iterator<String> remoteBinding = remoteBindings.iterator();
                    while (remoteBinding.hasNext()) {
                        String binding = (String) remoteBinding.next();
                        Object unbindstatefulObjs = ic.lookup("java:/" + binding);
                        if (unbindstatefulObjs instanceof StatefulBeanObject) {
                            Vector<Object> StatefulBeanObjects = StatefulBeanObject.statefulSessionBeanObjectMap
                                    .get(url.toString());
                            StatefulBeanObject.statefulSessionBeanObjectMap.remove(url.toString());
                            StatefulBeanObjects.clear();
                        }
                        ic.unbind("java:/" + binding);
                        System.out.println("unregistering the class" + bindings.get(binding));
                    }
                    jarEJBMap.remove(url.toString());
                }
            }
        }
        ConcurrentHashMap<String, MDBContext> mdbContexts = jarMDBMap.get(url.toString());
        MDBContext mdbContext;
        if (mdbContexts != null) {
            Iterator<String> mdbnames = mdbContexts.keySet().iterator();
            while (mdbnames.hasNext()) {
                String mdbname = mdbnames.next();
                mdbContext = mdbContexts.get(mdbname);
                if (mdbContext.getResourceAdapter() != null) {
                    mdbContext.getResourceAdapter().endpointDeactivation(mdbContext.getMessageEndPointFactory(),
                            mdbContext.getActivationSpec());
                    mdbContext.getResourceAdapter().stop();
                }
                if (mdbContext.getConsumer() != null) {
                    mdbContext.getConsumer().setMessageListener(null);
                    mdbContext.getConsumer().close();
                }
                if (mdbContext.getSession() != null)
                    mdbContext.getSession().close();
                if (mdbContext.getConnection() != null)
                    mdbContext.getConnection().close();
                mdbContexts.remove(mdbname);
            }
            jarMDBMap.remove(url.toString());
        }
        log.info(url.toString() + " UnDeployed");
    } catch (Exception ex) {
        log.error("Error in undeploying the package " + url, ex);
        //ex.printStackTrace();
    }
}

From source file:org.wso2.andes.server.cassandra.OnflightMessageTracker.java

/**
 * Release tracking of all messages belonging to a slot. i.e called when slot is removed.
 * This will remove all buffering tracking of messages and tracking objects.
 * But tracking objects will remain until delivery cycle completed
 *
 * @param slot slot to release/*from  w w  w . java  2 s.  c om*/
 */
public void releaseAllMessagesOfSlotFromTracking(Slot slot) {
    //remove all actual msgData objects
    if (log.isDebugEnabled()) {
        log.debug("Releasing tracking of messages for slot " + slot.toString());
    }
    ConcurrentHashMap<Long, MsgData> messagesOfSlot = messageBufferingTracker.remove(slot);
    if (messagesOfSlot != null) {
        for (Long messageIdOfSlot : messagesOfSlot.keySet()) {
            getTrackingData(messageIdOfSlot).addMessageStatus(MessageStatus.SLOT_REMOVED);
            if (checkIfReadyToRemoveFromTracking(messageIdOfSlot)) {
                if (log.isDebugEnabled()) {
                    log.debug("removing tracking object from memory id= " + messageIdOfSlot);
                }
                msgId2MsgData.remove(messageIdOfSlot);
            }
        }
    }
}

From source file:com.alibaba.napoli.metamorphosis.client.consumer.ConsumerZooKeeper.java

private String getTopicsString(
        final ConcurrentHashMap<String/* topic */, SubscriberInfo> topicSubcriberRegistry) {
    final StringBuilder topicSb = new StringBuilder();
    boolean wasFirst = true;
    for (final String topic : topicSubcriberRegistry.keySet()) {
        if (wasFirst) {
            wasFirst = false;//from  ww w  .j  av  a  2  s. co  m
            topicSb.append(topic);
        } else {
            topicSb.append(",").append(topic);
        }
    }
    return topicSb.toString();
}

From source file:org.wrml.runtime.format.text.html.WrmldocFormatter.java

protected ArrayNode buildReferencesArrayNode(final ObjectMapper objectMapper,
        final Map<URI, ObjectNode> schemaNodes, final Map<URI, LinkRelation> linkRelationCache,
        final Resource resource, final Prototype defaultPrototype) {

    final Context context = getContext();
    final SchemaLoader schemaLoader = context.getSchemaLoader();
    final SyntaxLoader syntaxLoader = context.getSyntaxLoader();

    final URI defaultSchemaUri = (defaultPrototype != null) ? defaultPrototype.getSchemaUri() : null;
    final String defaultSchemaName = (defaultPrototype != null)
            ? defaultPrototype.getUniqueName().getLocalName()
            : null;/*from w w w  . ja  v a  2s .  c o  m*/

    final ArrayNode referencesNode = objectMapper.createArrayNode();

    final ConcurrentHashMap<URI, LinkTemplate> referenceTemplates = resource.getReferenceTemplates();
    final Set<URI> referenceRelationUris = referenceTemplates.keySet();

    if (referenceTemplates != null && !referenceTemplates.isEmpty()) {

        String selfResponseSchemaName = null;

        List<String> resourceParameterList = null;
        final UriTemplate uriTemplate = resource.getUriTemplate();
        final String[] parameterNames = uriTemplate.getParameterNames();
        if (parameterNames != null && parameterNames.length > 0) {

            resourceParameterList = new ArrayList<>();

            for (int i = 0; i < parameterNames.length; i++) {
                final String parameterName = parameterNames[i];

                URI keyedSchemaUri = null;

                if (defaultPrototype != null) {
                    final Set<String> allKeySlotNames = defaultPrototype.getAllKeySlotNames();
                    if (allKeySlotNames != null && allKeySlotNames.contains(parameterName)) {
                        keyedSchemaUri = defaultSchemaUri;
                    }
                }

                if (keyedSchemaUri == null) {

                    final Set<URI> referenceLinkRelationUris = resource
                            .getReferenceLinkRelationUris(Method.Get);
                    if (referenceLinkRelationUris != null && !referenceLinkRelationUris.isEmpty()) {
                        for (URI linkRelationUri : referenceLinkRelationUris) {
                            final LinkTemplate referenceTemplate = referenceTemplates.get(linkRelationUri);
                            final URI responseSchemaUri = referenceTemplate.getResponseSchemaUri();
                            final Prototype responseSchemaPrototype = schemaLoader
                                    .getPrototype(responseSchemaUri);
                            if (responseSchemaPrototype != null) {
                                final Set<String> allKeySlotNames = responseSchemaPrototype
                                        .getAllKeySlotNames();
                                if (allKeySlotNames != null && allKeySlotNames.contains(parameterName)) {
                                    keyedSchemaUri = responseSchemaUri;
                                    break;
                                }
                            }
                        }
                    }
                }

                String parameterTypeString = "?";

                if (keyedSchemaUri != null) {

                    final Prototype keyedPrototype = schemaLoader.getPrototype(keyedSchemaUri);
                    final ProtoSlot keyProtoSlot = keyedPrototype.getProtoSlot(parameterName);
                    if (keyProtoSlot instanceof PropertyProtoSlot) {
                        final PropertyProtoSlot keyPropertyProtoSlot = (PropertyProtoSlot) keyProtoSlot;
                        final ValueType parameterValueType = keyPropertyProtoSlot.getValueType();
                        final Type parameterHeapType = keyPropertyProtoSlot.getHeapValueType();
                        switch (parameterValueType) {
                        case Text: {
                            if (!String.class.equals(parameterHeapType)) {
                                final Class<?> syntaxClass = (Class<?>) parameterHeapType;
                                parameterTypeString = syntaxClass.getSimpleName();
                            } else {
                                parameterTypeString = parameterValueType.name();
                            }

                            break;
                        }
                        case SingleSelect: {
                            final Class<?> choicesEnumClass = (Class<?>) parameterHeapType;

                            if (choicesEnumClass.isEnum()) {
                                parameterTypeString = choicesEnumClass.getSimpleName();
                            } else {
                                // ?
                                parameterTypeString = parameterValueType.name();
                            }

                            break;
                        }
                        default: {
                            parameterTypeString = parameterValueType.name();
                            break;
                        }
                        }
                    }

                }

                resourceParameterList.add(parameterTypeString + " " + parameterName);
            }
        }

        for (final Method method : Method.values()) {
            for (final URI linkRelationUri : referenceRelationUris) {

                final LinkTemplate referenceTemplate = referenceTemplates.get(linkRelationUri);
                final LinkRelation linkRelation = getLinkRelation(linkRelationCache, linkRelationUri);

                if (method != linkRelation.getMethod()) {
                    continue;
                }

                final ObjectNode referenceNode = objectMapper.createObjectNode();
                referencesNode.add(referenceNode);

                referenceNode.put(PropertyName.method.name(), method.getProtocolGivenName());
                referenceNode.put(PropertyName.rel.name(), syntaxLoader.formatSyntaxValue(linkRelationUri));

                final String relationTitle = linkRelation.getTitle();
                referenceNode.put(PropertyName.relationTitle.name(), relationTitle);

                final URI responseSchemaUri = referenceTemplate.getResponseSchemaUri();
                String responseSchemaName = null;
                if (responseSchemaUri != null) {
                    final ObjectNode responseSchemaNode = getSchemaNode(objectMapper, schemaNodes,
                            responseSchemaUri, schemaLoader);
                    referenceNode.put(PropertyName.responseSchema.name(), responseSchemaNode);

                    responseSchemaName = responseSchemaNode
                            .get(SchemaDesignFormatter.PropertyName.localName.name()).asText();
                }

                final URI requestSchemaUri = referenceTemplate.getRequestSchemaUri();

                String requestSchemaName = null;
                if (requestSchemaUri != null) {
                    final ObjectNode requestSchemaNode = getSchemaNode(objectMapper, schemaNodes,
                            requestSchemaUri, schemaLoader);
                    referenceNode.put(PropertyName.requestSchema.name(), requestSchemaNode);

                    requestSchemaName = requestSchemaNode
                            .get(SchemaDesignFormatter.PropertyName.localName.name()).asText();
                }

                final StringBuilder signatureBuilder = new StringBuilder();

                if (responseSchemaName != null) {
                    signatureBuilder.append(responseSchemaName);
                } else {
                    signatureBuilder.append("void");
                }

                signatureBuilder.append(" ");

                String functionName = relationTitle;

                if (SystemLinkRelation.self.getUri().equals(linkRelationUri)) {
                    functionName = "get" + responseSchemaName;
                    selfResponseSchemaName = responseSchemaName;
                } else if (SystemLinkRelation.save.getUri().equals(linkRelationUri)) {
                    functionName = "save" + responseSchemaName;
                } else if (SystemLinkRelation.delete.getUri().equals(linkRelationUri)) {
                    functionName = "delete";
                    if (defaultSchemaName != null) {
                        functionName += defaultSchemaName;
                    } else if (selfResponseSchemaName != null) {
                        functionName += selfResponseSchemaName;
                    }
                }

                signatureBuilder.append(functionName).append(" ( ");

                String parameterString = null;
                if (resourceParameterList != null) {
                    final StringBuilder parameterStringBuilder = new StringBuilder();
                    final int parameterCount = resourceParameterList.size();
                    for (int i = 0; i < parameterCount; i++) {
                        final String parameter = resourceParameterList.get(i);
                        parameterStringBuilder.append(parameter);
                        if (i < parameterCount - 1) {
                            parameterStringBuilder.append(" , ");
                        }
                    }

                    parameterString = parameterStringBuilder.toString();
                    signatureBuilder.append(parameterString);
                }

                if (requestSchemaName != null) {
                    if (StringUtils.isNotBlank(parameterString)) {
                        signatureBuilder.append(" , ");
                    }

                    signatureBuilder.append(requestSchemaName);

                    signatureBuilder.append(" ");

                    final String parameterName = Character.toLowerCase(requestSchemaName.charAt(0))
                            + requestSchemaName.substring(1);
                    signatureBuilder.append(parameterName);
                }

                signatureBuilder.append(" ) ");

                final String signature = signatureBuilder.toString();
                referenceNode.put(PropertyName.signature.name(), signature);
            }

        }

    }

    return referencesNode;
}

From source file:com.uber.tchannel.ping.PingClient.java

public void run() throws Exception {
    TChannel tchannel = new TChannel.Builder("ping-client").build();
    SubChannel subChannel = tchannel.makeSubChannel("ping-server");
    final ConcurrentHashMap<String, Integer> msgs = new ConcurrentHashMap<String, Integer>();
    final CountDownLatch done = new CountDownLatch(requests);

    for (int i = 0; i < requests; i++) {
        JsonRequest<Ping> request = new JsonRequest.Builder<Ping>("ping-server", "ping")
                .setBody(new Ping("{'key': 'ping?'}")).setHeader("some", "header").setTimeout(100 + i).build();
        TFuture<JsonResponse<Pong>> f = subChannel.send(request, InetAddress.getByName(host), port);

        f.addCallback(new TFutureCallback<JsonResponse<Pong>>() {
            @Override/*from ww w  .  j  a v  a  2 s  .c  o m*/
            public void onResponse(JsonResponse<Pong> pongResponse) {
                done.countDown();
                String msg = pongResponse.toString();
                if (msgs.containsKey(msg)) {
                    msgs.put(msg, msgs.get(msg) + 1);
                } else {
                    msgs.put(msg, 1);
                }
            }
        });
    }

    done.await();
    for (String msg : msgs.keySet()) {
        System.out.println(String.format("%s\n\tcount:%d", msg, msgs.get(msg)));
    }

    tchannel.shutdown(false);
}