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:de.tudarmstadt.ukp.dkpro.core.berkeleyparser.BerkeleyParser.java

/**
 * Creates linked constituent annotations + POS annotations
 *
 * @param aNode/*  ww  w .  j a  va 2s.c  o  m*/
 *            the source tree
 * @return the child-structure (needed for recursive call only)
 */
private Annotation createConstituentAnnotationFromTree(JCas aJCas, Tree<String> aNode, Annotation aParentFS,
        List<Token> aTokens, MutableInt aIndex) {
    // If the node is a word-level constituent node (== POS):
    // create parent link on token and (if not turned off) create POS tag
    if (aNode.isPreTerminal()) {
        Token token = aTokens.get(aIndex.intValue());

        // link token to its parent constituent
        if (aParentFS != null) {
            token.setParent(aParentFS);
        }

        // only add POS to index if we want POS-tagging
        if (writePos) {
            String typeName = aNode.getLabel();
            Type posTag = posMappingProvider.getTagType(typeName);
            POS posAnno = (POS) aJCas.getCas().createAnnotation(posTag, token.getBegin(), token.getEnd());
            posAnno.setPosValue(internTags ? typeName.intern() : typeName);
            posAnno.setCoarseValue(
                    posAnno.getClass().equals(POS.class) ? null : posAnno.getType().getShortName().intern());
            posAnno.addToIndexes();
            token.setPos(posAnno);
        }

        aIndex.add(1);

        return token;
    }
    // Check if node is a constituent node on sentence or phrase-level
    else {
        String typeName = aNode.getLabel();

        // create the necessary objects and methods
        Type constType = constituentMappingProvider.getTagType(typeName);

        Constituent constAnno = (Constituent) aJCas.getCas().createAnnotation(constType, 0, 0);
        constAnno.setConstituentType(typeName);

        // link to parent
        if (aParentFS != null) {
            constAnno.setParent(aParentFS);
        }

        // Do we have any children?
        List<Annotation> childAnnotations = new ArrayList<Annotation>();
        for (Tree<String> child : aNode.getChildren()) {
            Annotation childAnnotation = createConstituentAnnotationFromTree(aJCas, child, constAnno, aTokens,
                    aIndex);
            if (childAnnotation != null) {
                childAnnotations.add(childAnnotation);
            }
        }

        constAnno.setBegin(childAnnotations.get(0).getBegin());
        constAnno.setEnd(childAnnotations.get(childAnnotations.size() - 1).getEnd());

        // Now that we know how many children we have, link annotation of
        // current node with its children
        FSArray childArray = FSCollectionFactory.createFSArray(aJCas, childAnnotations);
        constAnno.setChildren(childArray);

        // write annotation for current node to index
        aJCas.addFsToIndexes(constAnno);

        return constAnno;
    }
}

From source file:org.wso2.andes.kernel.slot.SlotManagerClusterMode.java

/**
 * Update the slot assignment when a slot is assigned for a node
 *
 * @param queueName     Name of the queue
 * @param allocatedSlot Slot object which is allocated to a particular node
 * @param nodeId        ID of the node to which slot is Assigned
 *//* w  ww.jav a2s. c  o m*/
private void updateSlotAssignmentMap(String queueName, Slot allocatedSlot, String nodeId)
        throws AndesException {
    //Lock is used because this method will be called by multiple nodes at the same time
    String lockKey = nodeId + SlotManagerClusterMode.class;
    synchronized (lockKey.intern()) {
        //Update assigned node, assigned queue and set state to assigned
        slotAgent.updateSlotAssignment(nodeId, queueName, allocatedSlot);
    }
}

From source file:org.opennms.netmgt.config.datacollection.SnmpCollection.java

/**
 * Sets the value of field 'name'. The field 'name' has the
 * following description: collector name
 * //from w  ww .  j  a  v  a  2 s. c  om
 * @param name the value of field 'name'.
 */
public void setName(final String name) {
    m_name = name.intern();
}

From source file:org.wso2.andes.kernel.slot.SlotManagerClusterMode.java

/**
 * Get an overlapped slot by nodeId and the queue name. These are slots
 * which are overlapped with some slots that were acquired by given node
 *
 * @param nodeId    id of the node/*  w  w w  .j  av  a  2 s .  co m*/
 * @param queueName name of the queue slot is required
 * @return slot or null if not found
 */
private Slot getOverlappedSlot(String nodeId, String queueName) throws AndesException {
    Slot slotToBeAssigned;
    String lockKey = queueName + SlotManagerClusterMode.class;
    synchronized (lockKey.intern()) {
        //get oldest overlapped slot from database
        slotToBeAssigned = slotAgent.getOverlappedSlot(nodeId, queueName);
        if (log.isDebugEnabled()) {
            if (null != slotToBeAssigned) {
                log.debug(
                        " Giving overlapped slot id=" + slotToBeAssigned.getId() + " queue name= " + queueName);
            }
        }
    }
    return slotToBeAssigned;
}

From source file:org.wso2.andes.kernel.slot.SlotManagerClusterMode.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 ww.  j  a  v a 2  s .co m
public void reAssignSlotWhenNoSubscribers(String nodeId, String queueName) throws AndesException {
    String lockKeyForNodeId = nodeId + SlotManagerClusterMode.class;
    synchronized (lockKeyForNodeId.intern()) {
        slotAgent.deleteSlotAssignmentByQueueName(nodeId, queueName);
        if (log.isDebugEnabled()) {
            log.debug("Cleared assigned slots of queue " + queueName + " Assigned to node " + nodeId);
        }
    }
}

From source file:org.wso2.andes.kernel.slot.SlotManagerClusterMode.java

/**
 * Get an unassigned slot (slots dropped by sudden subscription closes)
 *
 * @param queueName name of the queue slot is required
 * @return slot or null if cannot find//from  www  . jav a  2s.  c  o m
 */
private Slot getUnassignedSlot(String queueName) throws AndesException {
    Slot slotToBeAssigned;
    String lockKey = queueName + SlotManagerClusterMode.class;
    synchronized (lockKey.intern()) {
        //get oldest unassigned slot from database
        slotToBeAssigned = slotAgent.getUnAssignedSlot(queueName);

        if (log.isDebugEnabled()) {
            if (null != slotToBeAssigned) {
                log.debug("Giving a slot from unassigned slots. Slot: " + slotToBeAssigned + " to queue: "
                        + queueName);
            }
        }
    }
    return slotToBeAssigned;
}

From source file:org.wso2.andes.kernel.slot.SlotManagerClusterMode.java

/**
 * {@inheritDoc}/*  ww  w  .jav a 2s.  c  om*/
 */
@Override
public long getSafeZoneLowerBoundId(String queueName) throws AndesException {
    long lowerBoundId = -1;
    String lockKey = queueName + SlotManagerClusterMode.class;
    synchronized (lockKey.intern()) {
        //get the upper bound messageID for each unassigned slots as a set for the specific queue
        TreeSet<Long> messageIDSet = slotAgent.getSlotBasedMessageIds(queueName);

        if (messageIDSet.size() >= safetySlotCount) {
            lowerBoundId = messageIDSet.toArray(new Long[messageIDSet.size()])[safetySlotCount - 1] + 1;
            // Inform the slot manager regarding the current expiry deletion range and queue
            setDeletionTaskState(queueName, lowerBoundId);
        }
    }
    return lowerBoundId;
}

From source file:org.wso2.andes.kernel.slot.SlotManagerClusterMode.java

/**
 * Remove slot entry from slot assignment
 *
 * @param storageQueueName name of the queue which is owned by the slot to be deleted
 * @param emptySlot        reference of the slot to be deleted
 *//*from w  w w .  j ava  2 s .c  o m*/
public boolean deleteSlot(String storageQueueName, Slot emptySlot, String nodeId) throws AndesException {
    boolean slotDeleted = 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 + SlotManagerClusterMode.class;
        synchronized (lockKey.intern()) {
            slotDeleted = slotAgent.deleteNonOverlappingSlot(nodeId, storageQueueName, startMsgId, endMsgId);
            if (log.isDebugEnabled()) {
                log.debug(" Deleted slot id = " + emptySlot.getId() + " queue name = " + storageQueueName
                        + " deleteSuccess: " + slotDeleted);
            }
        }
    } else {
        if (log.isDebugEnabled()) {
            log.debug("Cannot delete slot as it is within safe zone " + "startMsgID= " + startMsgId
                    + " safeZone= " + slotDeleteSafeZone + " endMsgId= " + endMsgId + " slotToDelete= "
                    + emptySlot);
        }
    }
    return slotDeleted;
}

From source file:org.wso2.andes.kernel.slot.SlotManagerClusterMode.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  w  w .  jav a  2s  .  c  om
 * @return Slot object
 */
public Slot getSlot(String queueName, String nodeId) throws AndesException {

    Slot slotToBeAssigned;

    /**
     *First look in the unassigned slots pool for free slots. These slots are previously own by
     * other nodes
     */
    String lockKey = queueName + SlotManagerClusterMode.class;
    synchronized (lockKey.intern()) {
        slotToBeAssigned = getUnassignedSlot(queueName);

        if (null == slotToBeAssigned) {
            slotToBeAssigned = getOverlappedSlot(nodeId, queueName);
        }
        if (null == slotToBeAssigned) {
            slotToBeAssigned = getFreshSlot(queueName, nodeId);
        }

        if (null != slotToBeAssigned) {
            updateSlotAssignmentMap(queueName, slotToBeAssigned, nodeId);
            if (log.isDebugEnabled()) {
                log.debug("Assigning slot for node : " + nodeId + " | " + slotToBeAssigned);
            }
        }
    }

    return slotToBeAssigned;

}

From source file:org.opendaylight.netvirt.vpnmanager.ArpNotificationHandler.java

private void addMipAdjacency(String vpnName, String vpnInterface, IpAddress srcPrefix, String mipMacAddress,
        IpAddress dstPrefix) {/*from   ww  w  .  ja v  a  2 s  .c  om*/
    LOG.trace("Adding {} adjacency to VPN Interface {} ", srcPrefix, vpnInterface);
    InstanceIdentifier<VpnInterface> vpnIfId = VpnUtil.getVpnInterfaceIdentifier(vpnInterface);
    InstanceIdentifier<Adjacencies> path = vpnIfId.augmentation(Adjacencies.class);
    synchronized (vpnInterface.intern()) {
        Optional<Adjacencies> adjacencies = VpnUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, path);
        String nextHopIpAddr = null;
        String nextHopMacAddress = null;
        String ip = srcPrefix.getIpv4Address().getValue();
        if (interfaceManager.isExternalInterface(vpnInterface)) {
            String subnetId = getSubnetId(vpnName, dstPrefix.getIpv4Address().getValue());
            if (subnetId == null) {
                LOG.trace("Can't find corresponding subnet for src IP {}, src MAC {}, dst IP {},  in VPN {}",
                        srcPrefix, mipMacAddress, dstPrefix, vpnName);
                return;
            }
            ip = VpnUtil.getIpPrefix(ip);
            AdjacencyBuilder newAdjBuilder = new AdjacencyBuilder().setIpAddress(ip)
                    .setKey(new AdjacencyKey(ip)).setPrimaryAdjacency(true).setMacAddress(mipMacAddress)
                    .setSubnetId(new Uuid(subnetId)).setPhysNetworkFunc(true);

            List<Adjacency> adjacencyList = adjacencies.isPresent() ? adjacencies.get().getAdjacency()
                    : new ArrayList<>();

            adjacencyList.add(newAdjBuilder.build());

            Adjacencies aug = VpnUtil.getVpnInterfaceAugmentation(adjacencyList);
            VpnInterface newVpnIntf = new VpnInterfaceBuilder().setKey(new VpnInterfaceKey(vpnInterface))
                    .setName(vpnInterface).setVpnInstanceName(vpnName).addAugmentation(Adjacencies.class, aug)
                    .build();
            VpnUtil.syncUpdate(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnIfId, newVpnIntf);
            LOG.debug(" Successfully stored subnetroute Adjacency into VpnInterface {}", vpnInterface);
            return;
        }

        if (adjacencies.isPresent()) {
            List<Adjacency> adjacencyList = adjacencies.get().getAdjacency();
            ip = VpnUtil.getIpPrefix(ip);
            for (Adjacency adjacs : adjacencyList) {
                if (adjacs.isPrimaryAdjacency()) {
                    nextHopIpAddr = adjacs.getIpAddress();
                    nextHopMacAddress = adjacs.getMacAddress();
                    break;
                }
            }
            if (nextHopIpAddr != null) {
                String rd = VpnUtil.getVpnRd(dataBroker, vpnName);
                long label = VpnUtil.getUniqueId(idManager, VpnConstants.VPN_IDPOOL_NAME,
                        VpnUtil.getNextHopLabelKey((rd != null) ? rd : vpnName, ip));
                if (label == 0) {
                    LOG.error("Unable to fetch label from Id Manager. Bailing out of adding MIP adjacency {} "
                            + "to vpn interface {} for vpn {}", ip, vpnInterface, vpnName);
                    return;
                }
                String nextHopIp = nextHopIpAddr.split("/")[0];
                AdjacencyBuilder newAdjBuilder = new AdjacencyBuilder().setIpAddress(ip)
                        .setKey(new AdjacencyKey(ip)).setNextHopIpList(Collections.singletonList(nextHopIp));
                if (mipMacAddress != null && !mipMacAddress.equalsIgnoreCase(nextHopMacAddress)) {
                    newAdjBuilder.setMacAddress(mipMacAddress);
                }
                adjacencyList.add(newAdjBuilder.build());
                Adjacencies aug = VpnUtil.getVpnInterfaceAugmentation(adjacencyList);
                VpnInterface newVpnIntf = new VpnInterfaceBuilder().setKey(new VpnInterfaceKey(vpnInterface))
                        .setName(vpnInterface).setVpnInstanceName(vpnName)
                        .addAugmentation(Adjacencies.class, aug).build();
                VpnUtil.syncUpdate(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnIfId, newVpnIntf);
                LOG.debug(" Successfully stored subnetroute Adjacency into VpnInterface {}", vpnInterface);
            }
        }
    }

}