List of usage examples for java.lang String intern
public native String intern();
From source file:org.wso2.andes.kernel.slot.SlotManager.java
/** * Remove slot entry from slotAssignment map * * @param queueName name of the queue which is owned by the slot to be deleted * @param emptySlot reference of the slot to be deleted */// w w w . j av a 2 s . com public boolean deleteSlot(String queueName, Slot emptySlot, String nodeId) { //return false; long startMsgId = emptySlot.getStartMessageId(); long endMsgId = emptySlot.getEndMessageId(); long slotDeleteSafeZone = getSlotDeleteSafeZone(); if (log.isDebugEnabled()) { log.debug("Trying to delete slot. safeZone= " + getSlotDeleteSafeZone() + " startMsgID= " + startMsgId); } if (slotDeleteSafeZone > endMsgId) { String lockKey = nodeId + SlotManager.class; synchronized (lockKey.intern()) { HashMap<String, TreeSet<Slot>> queueToSlotMap = null; HashmapStringTreeSetWrapper wrapper = slotAssignmentMap.get(nodeId); if (wrapper != null) { queueToSlotMap = wrapper.getStringListHashMap(); } if (queueToSlotMap != null) { TreeSet<Slot> currentSlotList = queueToSlotMap.get(queueName); if (currentSlotList != null) { // com.google.gson.Gson gson = new GsonBuilder().create(); //get the actual reference of the slot to be removed Slot slotInAssignmentMap = null; //currentSlotList.ceiling(emptySlot); for (Slot slot : currentSlotList) { if (slot.getStartMessageId() == emptySlot.getStartMessageId()) { slotInAssignmentMap = slot; } } if (null != slotInAssignmentMap) { if (slotInAssignmentMap.addState(SlotState.DELETED)) { currentSlotList.remove(slotInAssignmentMap); queueToSlotMap.put(queueName, currentSlotList); wrapper.setStringListHashMap(queueToSlotMap); slotAssignmentMap.set(nodeId, wrapper); if (log.isDebugEnabled()) { log.debug( "Deleted slot from Slot Assignment Map : Slot= " + slotInAssignmentMap); } } } } } } return true; } else { if (log.isDebugEnabled()) { log.debug("Cannot delete slot as it is within safe zone startMsgID= " + startMsgId + " safeZone= " + slotDeleteSafeZone + " endMsgId= " + endMsgId + " slotToDelete= " + emptySlot); } return false; } }
From source file:org.compass.core.lucene.engine.store.DefaultLuceneSearchEngineStore.java
public DefaultLuceneSearchEngineStore(LuceneSearchEngineFactory searchEngineFactory, CompassSettings settings, CompassMapping mapping) {//from w ww .ja va 2s .c o m this.settings = settings; this.mapping = mapping; this.connectionString = settings.getSetting(CompassEnvironment.CONNECTION); this.dirs = new ConcurrentHashMap<String, Map<String, Directory>>(); this.defaultSubContext = settings.getSetting(CompassEnvironment.CONNECTION_SUB_CONTEXT, "index"); // setup the directory store String connection = settings.getSetting(CompassEnvironment.CONNECTION); if (connection.startsWith(RAMDirectoryStore.PROTOCOL)) { directoryStore = new RAMDirectoryStore(); } else if (connection.startsWith(FSDirectoryStore.PROTOCOL)) { directoryStore = new FSDirectoryStore(); } else if (connection.startsWith(MMapDirectoryStore.PROTOCOL)) { directoryStore = new MMapDirectoryStore(); } else if (connection.startsWith(NIOFSDirectoryStore.PROTOCOL)) { directoryStore = new NIOFSDirectoryStore(); } else if (connection.startsWith(JdbcDirectoryStore.PROTOCOL)) { directoryStore = new JdbcDirectoryStore(); } else if (connection.indexOf("://") > -1) { String pluggableStore = connection.substring(0, connection.indexOf("://")); InputStream is = LuceneSearchEngineStore.class .getResourceAsStream("/META-INF/compass/store-" + pluggableStore + ".properties"); Properties props; try { props = new Properties(); props.load(is); } catch (Exception e) { try { is.close(); } catch (Exception e1) { // ignore } throw new SearchEngineException("Failed to create store [" + connection + "]", e); } String className = props.getProperty("type"); try { directoryStore = (DirectoryStore) ClassUtils.forName(className, settings.getClassLoader()) .newInstance(); } catch (Exception e) { throw new SearchEngineException("Failed to create connection [" + connection + "]", e); } } else { directoryStore = new FSDirectoryStore(); } if (directoryStore instanceof CompassConfigurable) { ((CompassConfigurable) directoryStore).configure(settings); } String useCompoundFileSetting = settings.getSetting(LuceneEnvironment.SearchEngineIndex.USE_COMPOUND_FILE); if (useCompoundFileSetting == null) { useCompoundFile = directoryStore.suggestedUseCompoundFile(); } else { useCompoundFile = Boolean.valueOf(useCompoundFileSetting); } if (log.isDebugEnabled()) { log.debug("Using compound format [" + useCompoundFile + "]"); } String useConcurrentOperationsSetting = settings .getSetting(LuceneEnvironment.SearchEngineIndex.USE_CONCURRENT_OPERATIONS); if (useConcurrentOperationsSetting == null) { supportsConcurrentOperations = directoryStore.supportsConcurrentOperations(); } else { supportsConcurrentOperations = Boolean.valueOf(useConcurrentOperationsSetting); } String useConcurrentCommitsSetting = settings .getSetting(LuceneEnvironment.SearchEngineIndex.USE_CONCURRENT_COMMITS); if (useConcurrentCommitsSetting == null) { supportsConcurrentCommits = directoryStore.supportsConcurrentCommits(); } else { supportsConcurrentCommits = Boolean.valueOf(useConcurrentCommitsSetting); } if (log.isDebugEnabled()) { log.debug("Support concurrent operations [" + supportsConcurrentOperations + "] and concurrent commits [" + supportsConcurrentCommits + "]"); } // setup sub indexes and aliases subIndexesSet = new HashSet<String>(); for (ResourceMapping resourceMapping : mapping.getRootMappings()) { String alias = resourceMapping.getAlias(); String[] tempSubIndexes = resourceMapping.getSubIndexHash().getSubIndexes(); for (String subIndex : tempSubIndexes) { subIndexesSet.add(subIndex.intern()); List<String> list = subIndexesByAlias.get(alias); if (list == null) { list = new ArrayList<String>(); subIndexesByAlias.put(alias, list); } list.add(subIndex); list = aliasesBySubIndex.get(subIndex); if (aliasesBySubIndex.get(subIndex) == null) { list = new ArrayList<String>(); aliasesBySubIndex.put(subIndex, list); } list.add(alias); } } subIndexes = subIndexesSet.toArray(new String[subIndexesSet.size()]); // set up directory wrapper providers DirectoryWrapperProvider[] directoryWrapperProviders = null; Map<String, CompassSettings> dwSettingGroups = settings .getSettingGroups(LuceneEnvironment.DirectoryWrapper.PREFIX); if (dwSettingGroups.size() > 0) { ArrayList<DirectoryWrapperProvider> dws = new ArrayList<DirectoryWrapperProvider>(); for (Map.Entry<String, CompassSettings> entry : dwSettingGroups.entrySet()) { String dwName = entry.getKey(); if (log.isInfoEnabled()) { log.info("Building directory wrapper [" + dwName + "]"); } CompassSettings dwSettings = entry.getValue(); String dwType = dwSettings.getSetting(LuceneEnvironment.DirectoryWrapper.TYPE); if (dwType == null) { throw new ConfigurationException( "Directory wrapper [" + dwName + "] has no type associated with it"); } DirectoryWrapperProvider dw; try { dw = (DirectoryWrapperProvider) ClassUtils.forName(dwType, settings.getClassLoader()) .newInstance(); } catch (Exception e) { throw new ConfigurationException("Failed to create directory wrapper [" + dwName + "]", e); } if (dw instanceof CompassConfigurable) { ((CompassConfigurable) dw).configure(dwSettings); } dws.add(dw); } directoryWrapperProviders = dws.toArray(new DirectoryWrapperProvider[dws.size()]); } this.directoryWrapperProviders = directoryWrapperProviders; this.localCacheManager = new LocalCacheManager(searchEngineFactory); }
From source file:org.wso2.andes.kernel.slot.SlotManager.java
/** * Delete all slot associations with a given queue. This is required to handle a queue purge event. * * @param queueName name of destination queue *///w ww .ja v a 2 s .com public void clearAllActiveSlotRelationsToQueue(String queueName) { if (log.isDebugEnabled()) { log.debug("Clearing all slots for queue " + queueName); } if (null != unAssignedSlotMap) { unAssignedSlotMap.remove(queueName); } if (null != slotIDMap) { slotIDMap.remove(queueName); } // Clear slots assigned to the queue along with overlapped slots if (AndesContext.getInstance().isClusteringEnabled()) { String nodeId = HazelcastAgent.getInstance().getNodeId(); // The requirement here is to clear slot associations for the queue on all nodes. List<String> nodeIDs = HazelcastAgent.getInstance().getMembersNodeIDs(); for (String nodeID : nodeIDs) { String lockKey = nodeID + SlotManager.class; synchronized (lockKey.intern()) { //clear slot assignment map HashmapStringTreeSetWrapper wrapper = slotAssignmentMap.get(nodeId); HashMap<String, TreeSet<Slot>> queueToSlotMap = null; if (wrapper != null) { queueToSlotMap = wrapper.getStringListHashMap(); } if (queueToSlotMap != null) { queueToSlotMap.remove(queueName); wrapper.setStringListHashMap(queueToSlotMap); slotAssignmentMap.set(nodeId, wrapper); } //clear overlapped slot map HashmapStringTreeSetWrapper overlappedSlotsWrapper = overLappedSlotMap.get(nodeId); if (null != overlappedSlotsWrapper) { HashMap<String, TreeSet<Slot>> queueToOverlappedSlotMap = null; if (wrapper != null) { queueToOverlappedSlotMap = overlappedSlotsWrapper.getStringListHashMap(); } if (queueToSlotMap != null) { queueToOverlappedSlotMap.remove(queueName); overlappedSlotsWrapper.setStringListHashMap(queueToOverlappedSlotMap); overLappedSlotMap.set(nodeId, overlappedSlotsWrapper); } } } } } }
From source file:org.wso2.carbon.application.deployer.internal.ApplicationManager.java
/** * Add a new cApp for a particular tenant. If there are no cApps currently, create a new * ArrayList and add the new cApp.//from www. j a va 2s . co m * * @param tenantId - tenant id of the cApp * @param carbonApp - CarbonApplication instance */ public void addCarbonApp(String tenantId, CarbonApplication carbonApp) { ArrayList<CarbonApplication> cApps; synchronized (tenantId.intern()) { cApps = tenantcAppMap.get(tenantId); if (cApps == null) { cApps = new ArrayList<CarbonApplication>(); tenantcAppMap.put(tenantId, cApps); } } // don't add the cApp if it already exists for (CarbonApplication cApp : cApps) { String appNameWithVersion = cApp.getAppNameWithVersion(); if (appNameWithVersion != null && appNameWithVersion.equals(carbonApp.getAppNameWithVersion())) { return; } } cApps.add(carbonApp); }
From source file:org.wso2.andes.kernel.slot.SlotManager.java
/** * This method will reassigned slots which are owned by a node to a free slots pool * * @param nodeId node ID of the leaving node *///from ww w . j a v a 2s .c om public void reAssignSlotsWhenMemberLeaves(String nodeId) { //Remove the entry from slot assignment map HashmapStringTreeSetWrapper wrapper = slotAssignmentMap.remove(nodeId); HashMap<String, TreeSet<Slot>> queueToSlotMap = null; if (wrapper != null) { queueToSlotMap = wrapper.getStringListHashMap(); } if (queueToSlotMap != null) { for (Map.Entry<String, TreeSet<Slot>> entry : queueToSlotMap.entrySet()) { TreeSet<Slot> slotsToBeReAssigned = entry.getValue(); TreeSet<Slot> freeSlotTreeSet = new TreeSet<Slot>(); TreeSetSlotWrapper treeSetStringWrapper = new TreeSetSlotWrapper(); for (Slot slotToBeReAssigned : slotsToBeReAssigned) { //Re-assign only if the slot is not empty if (!SlotUtils.checkSlotEmptyFromMessageStore(slotToBeReAssigned)) { treeSetStringWrapper.setSlotTreeSet(freeSlotTreeSet); unAssignedSlotMap.putIfAbsent(slotToBeReAssigned.getStorageQueueName(), treeSetStringWrapper); //Lock key is queueName + SlotManager Class String lockKey = entry.getKey() + SlotManager.class; synchronized (lockKey.intern()) { if (slotToBeReAssigned.addState(SlotState.RETURNED)) { treeSetStringWrapper = unAssignedSlotMap .get(slotToBeReAssigned.getStorageQueueName()); freeSlotTreeSet = treeSetStringWrapper.getSlotTreeSet(); //String jsonSlotString = gson.toJson(slotsToBeReAssigned); freeSlotTreeSet.add(slotToBeReAssigned); treeSetStringWrapper.setSlotTreeSet(freeSlotTreeSet); unAssignedSlotMap.set(slotToBeReAssigned.getStorageQueueName(), treeSetStringWrapper); if (log.isDebugEnabled()) { log.debug("Returned slot " + slotToBeReAssigned + "from node " + nodeId + " as member left"); } } } } } } } //delete all overlapped slots for the node overLappedSlotMap.remove(nodeId); if (log.isDebugEnabled()) { log.debug("Removed all overlapped slots for node " + nodeId); } }
From source file:org.wso2.carbon.application.deployer.internal.ApplicationManager.java
/** * Add a new faulty cApp for a particular tenant. If there are no faulty cApps currently, create a new * ArrayList and add the new cApp./*ww w.j a v a 2 s .c o m*/ * * @param tenantId * @param carbonApp */ public void addFaultyCarbonApp(String tenantId, String carbonApp, Exception error) { HashMap<String, Exception> cApps; synchronized (tenantId.intern()) { cApps = tenantfaultycAppMap.get(tenantId); if (cApps == null) { cApps = new HashMap<String, Exception>(); tenantfaultycAppMap.put(tenantId, cApps); } } // don't add the cApp if it already exists for (String cApp : cApps.keySet()) { String appName = cApp; if (appName != null && appName.equals(carbonApp)) { return; } } cApps.put(carbonApp, error); }
From source file:org.wso2.andes.kernel.slot.SlotManager.java
/** * Re-assign the slot when there are no local subscribers in the node * * @param nodeId node ID of the node without subscribers * @param queueName name of the queue whose slots to be reassigned *///w w w . j av a2s . com public void reAssignSlotWhenNoSubscribers(String nodeId, String queueName) { TreeSet<Slot> assignedSlotList = null; String lockKeyForNodeId = nodeId + SlotManager.class; synchronized (lockKeyForNodeId.intern()) { //Get assigned slots from Hazelcast, delete all belonging to queue //and set back HashmapStringTreeSetWrapper wrapper = slotAssignmentMap.get(nodeId); HashMap<String, TreeSet<Slot>> queueToSlotMap = null; if (wrapper != null) { queueToSlotMap = wrapper.getStringListHashMap(); } if (queueToSlotMap != null) { assignedSlotList = queueToSlotMap.remove(queueName); wrapper.setStringListHashMap(queueToSlotMap); slotAssignmentMap.set(nodeId, wrapper); } if (log.isDebugEnabled()) { log.debug("Cleared assigned slots of queue " + queueName + " Assigned to node " + nodeId); } //Get overlapped slots from Hazelcast, delete all belonging to queue and //set back HashmapStringTreeSetWrapper overlappedSlotWrapper = overLappedSlotMap.get(nodeId); HashMap<String, TreeSet<Slot>> queueToOverlappedSlotMap = null; if (overlappedSlotWrapper != null) { queueToOverlappedSlotMap = overlappedSlotWrapper.getStringListHashMap(); } if (queueToOverlappedSlotMap != null) { assignedSlotList = queueToOverlappedSlotMap.remove(queueName); overlappedSlotWrapper.setStringListHashMap(queueToOverlappedSlotMap); overLappedSlotMap.set(nodeId, overlappedSlotWrapper); } if (log.isDebugEnabled()) { log.debug("Cleared overlapped slots of queue " + queueName + " to be assigned to " + "node " + nodeId); } } //add the deleted slots to un-assigned slot map, so that they can be assigned again. if (assignedSlotList != null && !assignedSlotList.isEmpty()) { String lockKeyForQueueName = queueName + SlotManager.class; synchronized (lockKeyForQueueName.intern()) { TreeSetSlotWrapper treeSetStringWrapper = unAssignedSlotMap.get(queueName); TreeSet<Slot> unAssignedSlotSet = new TreeSet<Slot>(); if (treeSetStringWrapper != null) { unAssignedSlotSet = treeSetStringWrapper.getSlotTreeSet(); } else { treeSetStringWrapper = new TreeSetSlotWrapper(); } if (unAssignedSlotSet == null) { unAssignedSlotSet = new TreeSet<Slot>(); } for (Slot slotToBeReAssigned : assignedSlotList) { //Reassign only if the slot is not empty if (!SlotUtils.checkSlotEmptyFromMessageStore(slotToBeReAssigned)) { if (slotToBeReAssigned.addState(SlotState.RETURNED)) { unAssignedSlotSet.add(slotToBeReAssigned); if (log.isDebugEnabled()) { log.debug("Slot is returned by node " + nodeId + " slot = " + slotToBeReAssigned); } } } } treeSetStringWrapper.setSlotTreeSet(unAssignedSlotSet); unAssignedSlotMap.set(queueName, treeSetStringWrapper); } } }
From source file:org.wso2.carbon.registry.core.caching.CacheBackedRegistry.java
private GhostResource<Resource> getGhostResourceFromCache(String path) throws RegistryException { Resource resource;//from w w w . ja va 2 s . c o m RegistryCacheKey registryCacheKey = getRegistryCacheKey(registry, path); GhostResource<Resource> ghostResource; Object ghostResourceObject; Cache<RegistryCacheKey, GhostResource> cache = getCache(); if ((ghostResourceObject = cache.get(registryCacheKey)) == null) { synchronized (path.intern()) { //Checking again as the some other previous thread might have updated the cache if ((ghostResourceObject = cache.get(registryCacheKey)) == null) { resource = registry.get(path); ghostResource = new GhostResource<Resource>(resource); if (resource.getProperty(RegistryConstants.REGISTRY_LINK) == null || resource.getProperty(RegistryConstants.REGISTRY_MOUNT) != null) { cache.put(registryCacheKey, ghostResource); } } else { ghostResource = (GhostResource<Resource>) ghostResourceObject; } } } else { ghostResource = (GhostResource<Resource>) ghostResourceObject; } return ghostResource; }
From source file:org.wso2.andes.kernel.slot.SlotManager.java
/** * Record Slot's last message ID related to a particular queue * * @param queueName name of the queue which this message ID belongs to * @param lastMessageIdInTheSlot last message ID of the slot * @param startMessageIdInTheSlot start message ID of the slot * @param nodeId Node ID of the node that is sending the request. *///from w w w.ja v a2 s .co m public void updateMessageID(String queueName, String nodeId, long startMessageIdInTheSlot, long lastMessageIdInTheSlot) { // Read message Id set for slots from hazelcast TreeSet<Long> messageIdSet = new TreeSet<Long>(); TreeSetLongWrapper wrapper = slotIDMap.get(queueName); if (wrapper == null) { wrapper = new TreeSetLongWrapper(); wrapper.setLongTreeSet(messageIdSet); slotIDMap.putIfAbsent(queueName, wrapper); } messageIdSet = wrapper.getLongTreeSet(); String lockKey = queueName + SlotManager.class; synchronized (lockKey.intern()) { Long lastAssignedMessageId = queueToLastAssignedIDMap.get(queueName); // Check if input slot's start message ID is less than last assigned message ID if ((null != lastAssignedMessageId) && startMessageIdInTheSlot < lastAssignedMessageId) { if (log.isDebugEnabled()) { log.debug("Found overlapping slots during slot submit: " + startMessageIdInTheSlot + " to : " + lastMessageIdInTheSlot + ". Comparing to lastAssignedID : " + lastAssignedMessageId); } // Find overlapping slots TreeSet<Slot> overlappingSlots = getOverlappedAssignedSlots(queueName, startMessageIdInTheSlot, lastMessageIdInTheSlot); if (overlappingSlots.size() > 0) { if (log.isDebugEnabled()) { log.debug("Found " + overlappingSlots.size() + " overlapping slots."); } // Following means that we have a piece of the slot exceeding the earliest // assigned slot. breaking that piece and adding it as a new,unassigned slot. if (startMessageIdInTheSlot < overlappingSlots.first().getStartMessageId()) { Slot leftExtraSlot = new Slot(startMessageIdInTheSlot, overlappingSlots.first().getStartMessageId() - 1, queueName); if (log.isDebugEnabled()) { log.debug("LeftExtra Slot in overlapping slots : " + leftExtraSlot); } } // This means that we have a piece of the slot exceeding the latest assigned slot. // breaking that piece and adding it as a new,unassigned slot. if (lastMessageIdInTheSlot > overlappingSlots.last().getEndMessageId()) { Slot rightExtraSlot = new Slot(overlappingSlots.last().getEndMessageId() + 1, lastMessageIdInTheSlot, queueName); if (log.isDebugEnabled()) { log.debug("RightExtra in overlapping slot : " + rightExtraSlot); } //Update last message ID - expand ongoing slot to cater this leftover part. messageIdSet.add(lastMessageIdInTheSlot); wrapper.setLongTreeSet(messageIdSet); slotIDMap.set(queueName, wrapper); if (log.isDebugEnabled()) { log.debug(lastMessageIdInTheSlot + " added to slotIdMap " + "(RightExtraSlot). Current values in " + "map " + messageIdSet); } //record last published message id nodeToLastPublishedIDMap.set(nodeId, lastMessageIdInTheSlot); } } } else { /** * Update the slotIDMap only if the last assigned message ID is less than the new start message ID */ messageIdSet.add(lastMessageIdInTheSlot); wrapper.setLongTreeSet(messageIdSet); slotIDMap.set(queueName, wrapper); if (log.isDebugEnabled()) { log.debug("No overlapping slots found during slot submit " + startMessageIdInTheSlot + " to : " + lastMessageIdInTheSlot + ". Added msgID " + lastMessageIdInTheSlot + " to slotIDMap"); } //record last published message ID nodeToLastPublishedIDMap.set(nodeId, lastMessageIdInTheSlot); } } }
From source file:org.protempa.proposition.AbstractProposition.java
public final void addReference(String name, UniqueId ref) { if (name == null) { throw new IllegalArgumentException("name cannot be null"); }// w ww . j a v a2s .c o m if (ref == null) { throw new IllegalArgumentException("ref cannot be null"); } initializeReferences(); List<UniqueId> refs = this.references.get(name); if (refs == null) { refs = new ArrayList<>(DEFAULT_REFERENCE_LIST_SIZE); refs.add(ref); this.references.put(name.intern(), refs); } else { refs.add(ref); } }