Example usage for java.lang String intern

List of usage examples for java.lang String intern

Introduction

In this page you can find the example usage for java.lang String intern.

Prototype

public native String intern();

Source Link

Document

Returns a canonical representation for the string object.

Usage

From source file:org.protempa.LowLevelAbstractionValueDefinition.java

public LowLevelAbstractionValueDefinition(LowLevelAbstractionDefinition lowLevelAbstractionDefinition,
        String id) {
    if (lowLevelAbstractionDefinition == null) {
        throw new IllegalArgumentException("A low level abstraction definition must be specified");
    }//from  w  ww.  jav a 2  s. co m
    this.lowLevelAbstractionDefinition = lowLevelAbstractionDefinition;
    if (id == null) {
        throw new IllegalArgumentException("id cannot be null");
    }
    this.id = id.intern();
    this.lowLevelAbstractionDefinition.addValueDefinition(this);
    this.lowLevelAbstractionDefinition.addPropertyChangeListener("algorithmId", new PropertyChangeListener() {
        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            LowLevelAbstractionValueDefinition.this.algorithmArguments = null;
        }
    });
    this.parameterValues = new HashMap<>();
    this.parameterValueComps = new HashMap<>();
}

From source file:org.wso2.andes.server.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
 *//*w  w w  .j  a v  a  2  s  .co m*/
public void updateMessageID(String queueName, Long lastMessageIdInTheSlot) {

    boolean isMessageIdRangeOutdated = false;
    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 = slotIDMap.get(queueName).getLongTreeSet();
    }
    String lockKey = queueName + SlotManager.class;
    synchronized (lockKey.intern()) {
        /**
         *Insert the messageID only if last processed ID of this queue is less than this
         * messageID
         */
        Long lastAssignedMessageId = queueToLastAssignedIDMap.get(queueName);
        if (lastAssignedMessageId != null) {
            if (lastMessageIdInTheSlot <= lastAssignedMessageId) {
                isMessageIdRangeOutdated = true;
            }
        }

        /**
         * Update the slotIDMap only if the last assigned message ID is less than the new ID
         */
        if (!isMessageIdRangeOutdated) {
            messageIdSet.add(lastMessageIdInTheSlot);
            wrapper.setLongTreeSet(messageIdSet);
            slotIDMap.set(queueName, wrapper);
            if (log.isDebugEnabled()) {
                log.debug(lastMessageIdInTheSlot + " added to slotIdMap. Current values in " + "map "
                        + messageIdSet);
            }
        }
    }

}

From source file:org.opennms.netmgt.xml.eventconf.Maskelement.java

/**
 * Sets the value of field 'mename'. The field 'mename' has the
 * following description: The mask element name. Must be from
 * the following// w  w w . j  a  va 2 s . c  o  m
 *  subset: "uei" (the OpenNMS Universal Event Identifier),
 * "source"
 *  (source of the event; "trapd" for received SNMP traps;
 * warning:
 *  these aren't that standardized), "host" (host related to
 * the
 *  event; for SNMP traps this is the IP source address of the
 * host
 *  that sent the trap to OpenNMS, "snmphost" (SNMP host
 * related to
 *  the event; for SNMPv1 traps this is IP address reported in
 * the
 *  trap; for SNMPv2 traps and later this is the same as
 * "host"),
 *  "nodeid" (the OpenNMS node identifier for the node related
 * to this
 *  event), "interface" (interface related to the event; for
 * SNMP
 *  traps this is the same as "snmphost"), "service", "id"
 * (enterprise
 *  ID in an SNMP trap), "specific" (specific value in an SNMP
 * trap),
 *  "generic" (generic value in an SNMP trap), or "community"
 *  (community string in an SNMP trap).
 * 
 * @param mename the value of field 'mename'.
 */
public void setMename(final String mename) {
    this.m_mename = mename.intern();
}

From source file:org.wso2.andes.server.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 w w.  j  a  v  a 2 s  . co m
public void clearAllActiveSlotRelationsToQueue(String queueName) {

    if (null != unAssignedSlotMap) {
        unAssignedSlotMap.remove(queueName);
    }

    if (null != slotIDMap) {
        slotIDMap.remove(queueName);
    }

    // Clear slots assigned to the queue
    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()) {
                HashmapStringListWrapper wrapper = slotAssignmentMap.get(nodeId);
                HashMap<String, List<String>> queueToSlotMap = null;
                if (wrapper != null) {
                    queueToSlotMap = wrapper.getStringListHashMap();
                }
                if (queueToSlotMap != null) {
                    queueToSlotMap.remove(queueName);
                    wrapper.setStringListHashMap(queueToSlotMap);
                    slotAssignmentMap.set(nodeId, wrapper);
                }
            }
        }
    }

}

From source file:org.wso2.andes.server.slot.SlotManager.java

/**
 * Get a slot by giving the queue name. This method first lookup the free slot pool for slots
 * and if there are no slots in the free slot pool then return a newly created slot
 *
 * @param queueName name of the queue/*from   w  ww .j a v a  2s.co  m*/
 * @return Slot object
 */
public Slot getSlot(String queueName, String nodeId) {
    Slot slotToBeAssigned;
    Gson gson = new GsonBuilder().create();
    /**
     *First look in the unassigned slots pool for free slots. These slots are previously own by
     * other nodes
     */
    String lockKey = queueName + SlotManager.class;
    synchronized (lockKey.intern()) {
        TreeSetStringWrapper treeSetStringWrapper = unAssignedSlotMap.get(queueName);
        if (treeSetStringWrapper != null) {
            TreeSet<String> slotsFromUnassignedSlotMap = treeSetStringWrapper.getStringTreeSet();
            if (slotsFromUnassignedSlotMap != null && !slotsFromUnassignedSlotMap.isEmpty()) {
                slotToBeAssigned = gson.fromJson(slotsFromUnassignedSlotMap.pollFirst(), (Type) Slot.class);
                //update hazelcast map
                treeSetStringWrapper.setStringTreeSet(slotsFromUnassignedSlotMap);
                unAssignedSlotMap.set(queueName, treeSetStringWrapper);
                if (log.isDebugEnabled()) {
                    log.debug("Slot Manager - giving a slot from unAssignedSlotMap. Slot= " + slotToBeAssigned);
                }
            } else {
                slotToBeAssigned = getFreshSlot(queueName);
                if (log.isDebugEnabled()) {
                    log.debug("Slot Manager - giving a slot from fresh pool. Slot= " + slotToBeAssigned);
                }
            }
        } else {
            slotToBeAssigned = getFreshSlot(queueName);
            if (log.isDebugEnabled()) {
                log.debug("Slot Manager - giving a slot from fresh pool. Slot= " + slotToBeAssigned);
            }
        }
        if (null != slotToBeAssigned) {
            updateSlotAssignmentMap(queueName, slotToBeAssigned, nodeId);
        } else {
            if (log.isDebugEnabled()) {
                log.debug("Slot Manager - returns empty slot for the queue: " + queueName);
            }
        }
        return slotToBeAssigned;
    }

}

From source file:org.wso2.andes.server.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  a  2  s  . c om*/
public void reAssignSlotWhenNoSubscribers(String nodeId, String queueName) {
    ArrayList<String> assignedSlotList = null;
    String lockKeyForNodeId = nodeId + SlotManager.class;
    synchronized (lockKeyForNodeId.intern()) {
        HashmapStringListWrapper wrapper = slotAssignmentMap.get(nodeId);
        HashMap<String, List<String>> queueToSlotMap = null;
        if (wrapper != null) {
            queueToSlotMap = wrapper.getStringListHashMap();
        }
        if (queueToSlotMap != null) {
            assignedSlotList = (ArrayList<String>) queueToSlotMap.remove(queueName);
            wrapper.setStringListHashMap(queueToSlotMap);
            slotAssignmentMap.set(nodeId, wrapper);
        }
    }
    if (assignedSlotList != null && !assignedSlotList.isEmpty()) {
        String lockKeyForQueueName = queueName + SlotManager.class;
        synchronized (lockKeyForQueueName.intern()) {
            TreeSetStringWrapper treeSetStringWrapper = unAssignedSlotMap.get(queueName);

            TreeSet<String> unAssignedSlotSet = new TreeSet<String>();
            if (treeSetStringWrapper != null) {
                unAssignedSlotSet = treeSetStringWrapper.getStringTreeSet();
            } else {
                treeSetStringWrapper = new TreeSetStringWrapper();
            }
            if (unAssignedSlotSet == null) {
                unAssignedSlotSet = new TreeSet<String>();
            }
            for (String slotToBeReAssignedString : assignedSlotList) {
                Gson gson = new GsonBuilder().create();
                Slot slotToBeReAssigned = gson.fromJson(slotToBeReAssignedString, (Type) Slot.class);
                //Reassign only if the slot is not empty
                if (!SlotUtils.checkSlotEmptyFromMessageStore(slotToBeReAssigned)) {
                    unAssignedSlotSet.add(slotToBeReAssignedString);
                }
            }
            treeSetStringWrapper.setStringTreeSet(unAssignedSlotSet);
            unAssignedSlotMap.set(queueName, treeSetStringWrapper);
        }
    }
}

From source file:edu.cornell.med.icb.learning.tools.svmlight.EvaluationMeasure.java

public double getPerformanceValueStd(final String measureName) {
    final ZScoreCalculator calc = new ZScoreCalculator();
    calc.reset();//from  w  ww . java2  s  .c o  m
    final DoubleList values = name2Values.get(measureName.intern());
    if (values == null || values.size() < 3) {
        return Double.NaN;
    }
    for (final double value : values) {
        calc.observe(value);
    }
    calc.calculateStats();
    return calc.stdDev();
}

From source file:org.wso2.andes.server.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  w  w w.j a va  2  s.c om
public void reAssignSlotsWhenMemberLeaves(String nodeId) {
    //Remove the entry from slot assignment map
    HashmapStringListWrapper wrapper = slotAssignmentMap.remove(nodeId);
    HashMap<String, List<String>> queueToSlotMap = null;
    if (wrapper != null) {
        queueToSlotMap = wrapper.getStringListHashMap();
    }
    if (queueToSlotMap != null) {
        for (Map.Entry<String, List<String>> entry : queueToSlotMap.entrySet()) {
            List<String> slotsToBeReAssigned = entry.getValue();
            TreeSet<String> freeSlotTreeSet = new TreeSet<String>();
            TreeSetStringWrapper treeSetStringWrapper = new TreeSetStringWrapper();
            for (String slotToBeReAssignedString : slotsToBeReAssigned) {
                com.google.gson.Gson gson = new GsonBuilder().create();
                Slot slotToBeReAssigned = gson.fromJson(slotToBeReAssignedString, (Type) Slot.class);
                //Re-assign only if the slot is not empty
                if (!SlotUtils.checkSlotEmptyFromMessageStore(slotToBeReAssigned)) {
                    treeSetStringWrapper.setStringTreeSet(freeSlotTreeSet);
                    unAssignedSlotMap.putIfAbsent(slotToBeReAssigned.getStorageQueueName(),
                            treeSetStringWrapper);
                    //Lock key is queuName + SlotManager Class
                    String lockKey = entry.getKey() + SlotManager.class;
                    synchronized (lockKey.intern()) {
                        treeSetStringWrapper = unAssignedSlotMap.get(slotToBeReAssigned.getStorageQueueName());
                        freeSlotTreeSet = treeSetStringWrapper.getStringTreeSet();
                        String jsonSlotString = gson.toJson(slotsToBeReAssigned);
                        freeSlotTreeSet.add(jsonSlotString);
                        treeSetStringWrapper.setStringTreeSet(freeSlotTreeSet);
                        unAssignedSlotMap.set(slotToBeReAssigned.getStorageQueueName(), treeSetStringWrapper);
                        if (log.isDebugEnabled()) {
                            log.debug("Reassigned slot " + slotToBeReAssigned.getStartMessageId() + " - "
                                    + slotToBeReAssigned.getEndMessageId() + "from node " + nodeId);
                        }
                    }
                }
            }
        }
    }
}

From source file:org.opennms.netmgt.xml.eventconf.Maskelement.java

/**
 * Sets the value of '_mevalueList' by setting it to the given
 * Vector. No type checking is performed.
 * @deprecated//from   www  .  j  a  v a 2 s  . c  o  m
 * 
 * @param mevalueList the Vector to set.
 */
public void setMevalueCollection(final List<String> mevalueList) {
    this.m_mevalueList.clear();
    for (final String value : mevalueList) {
        this.m_mevalueList.add(value.intern());
    }
}

From source file:org.opennms.netmgt.xml.eventconf.Maskelement.java

/**
 * Sets the value of '_mevalueList' by copying the given
 * Vector. All elements will be checked for type safety.
 * /* www  . j a  v  a  2  s.c om*/
 * @param vMevalueList the Vector to copy.
 */
public void setMevalue(final List<String> vMevalueList) {
    // copy vector
    this.m_mevalueList.clear();
    for (final String value : vMevalueList) {
        this.m_mevalueList.add(value.intern());
    }
}