List of usage examples for java.util TreeSet last
public E last()
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. *///w w w . jav a 2 s . com 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.wso2.andes.kernel.slot.SlotManagerClusterMode.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. * @param localSafeZone Local safe zone of the requesting node. *//* ww w . jav a 2 s.c om*/ public void updateMessageID(String queueName, String nodeId, long startMessageIdInTheSlot, long lastMessageIdInTheSlot, long localSafeZone) throws AndesException { //setting up first message id of the slot if (firstMessageId > startMessageIdInTheSlot || firstMessageId == -1) { firstMessageId = startMessageIdInTheSlot; } if (slotRecoveryScheduled.get()) { queuesToRecover.remove(queueName); } // Read message Id set for slots from store TreeSet<Long> messageIdSet; messageIdSet = slotAgent.getSlotBasedMessageIds(queueName); String lockKey = queueName + SlotManagerClusterMode.class; synchronized (lockKey.intern()) { //Get last assigned message id from database long lastAssignedMessageId = slotAgent.getQueueToLastAssignedId(queueName); // Check if input slot's start message ID is less than last assigned message ID if (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.isEmpty())) { 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("Left Extra 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. slotAgent.addMessageId(queueName, lastMessageIdInTheSlot); if (log.isDebugEnabled()) { log.debug(lastMessageIdInTheSlot + " added to store " + "(RightExtraSlot). Current values in " + "store " + messageIdSet); } } } else { /* * The fact that the slot ended up in this condition means that, all previous slots within this * range have been already processed and deleted. This is a very rare scenario. */ if (log.isDebugEnabled()) { log.debug("A submit slot request has come from the past after deletion of any " + "possible overlapping slots. nodeId : " + nodeId + " StartMessageID : " + startMessageIdInTheSlot + " EndMessageID : " + lastMessageIdInTheSlot); } slotAgent.addMessageId(queueName, lastMessageIdInTheSlot); } } else { //Update the store only if the last assigned message ID is less than the new start message ID slotAgent.addMessageId(queueName, lastMessageIdInTheSlot); if (log.isDebugEnabled()) { log.debug("No overlapping slots found during slot submit " + startMessageIdInTheSlot + " to : " + lastMessageIdInTheSlot + ". Added msgID " + lastMessageIdInTheSlot + " to store"); } } //record local safe zone slotAgent.setLocalSafeZoneOfNode(nodeId, localSafeZone); } }
From source file:pku.sei.checkedcoverage.slicing.Slicer.java
/** * select the last location that was not checked, and create new slice criterion for it. * remove the relative lines from unchecked lines, until all location are sliced. * @return the new created slice location for every class. *///from w ww .ja va2 s .c o m public static HashMap<String, TreeSet<Long>> sliceForUnchecked() { System.out.println("Trying to add checks"); HashMap<String, TreeSet<Long>> sliceCreated = new HashMap<String, TreeSet<Long>>(); HashMap<String, HashSet<Instruction>> uncheckedMap = getUncheckedMap(); Iterator<String> it = uncheckedMap.keySet().iterator(); List<String> cris = new ArrayList<String>(); int crisNr = 0; while (it.hasNext()) { String key = it.next(); sliceCreated.put(key, new TreeSet<Long>()); HashSet<Instruction> insts = uncheckedMap.get(key); TreeSet<Integer> unchecked = new TreeSet<Integer>(); HashMap<Integer, String> critInfoMap = new HashMap<Integer, String>(); HashMap<Integer, HashSet<String>> varsMap = new HashMap<Integer, HashSet<String>>(); for (Instruction inst : insts) { if (inst.getType().equals(InstructionType.FIELD) || inst.getType().equals(InstructionType.VAR)) { unchecked.add(inst.getLineNumber()); if (!critInfoMap.containsKey(inst.getLineNumber())) { critInfoMap.put(inst.getLineNumber(), inst.getMethod().getReadClass().getName() + "." + inst.getMethod().getName()); } if (!varsMap.containsKey(inst.getLineNumber())) { varsMap.put(inst.getLineNumber(), new HashSet<String>()); } if (inst.getType().equals(InstructionType.FIELD)) { FieldInstruction fieldinst = (FieldInstruction) inst; varsMap.get(inst.getLineNumber()).add(fieldinst.getFieldName()); } else if (inst.getType().equals(InstructionType.VAR)) { VarInstruction varinst = (VarInstruction) inst; if (varinst.getOpcode() == Opcodes.DSTORE || varinst.getOpcode() == Opcodes.ASTORE || varinst.getOpcode() == Opcodes.LSTORE || varinst.getOpcode() == Opcodes.ISTORE || varinst.getOpcode() == Opcodes.FSTORE || varinst.getOpcode() == Opcodes.RET) { String varname = inst.getMethod().getLocalVariables()[varinst.getLocalVarIndex()] .getName(); varsMap.get(inst.getLineNumber()).add(varname); } } } } while (!unchecked.isEmpty()) { int last = unchecked.last(); String cri = critInfoMap.get(last) + ":" + last + ":*"; cris.add(cri); System.out.println(++crisNr + " new check(s) added!" + cri); unchecked.removeAll(sliceUnchecked(cri)); sliceCreated.get(key).add((long) last); unchecked.remove(last); } } System.out.println("Done!"); return sliceCreated; }
From source file:pt.scanner.server.data.Line.java
public Line expandedLine(Size size) { Coordinate left = lineIntersection(new Line(0, 0, 0, size.height())); Coordinate right = lineIntersection(new Line(size.width(), 0, size.width(), size.height())); Coordinate top = lineIntersection(new Line(0, 0, size.width(), 0)); Coordinate bottom = lineIntersection(new Line(0, size.height(), size.width(), size.height())); TreeSet<Coordinate> coords = new TreeSet<>(); if (left != null && Utils.between(0.0, (double) FastMath.round(left.x), (double) size.width()) && Utils.between(0.0, (double) FastMath.round(left.y), (double) size.height())) { coords.add(new Coordinate(FastMath.round(left.x), FastMath.round(left.y))); }/*from w ww . ja v a 2s . com*/ if (right != null && Utils.between(0.0, (double) FastMath.round(right.x), (double) size.width()) && Utils.between(0.0, (double) FastMath.round(right.y), (double) size.height())) { coords.add(new Coordinate(FastMath.round(right.x), FastMath.round(right.y))); } if (top != null && Utils.between(0.0, (double) FastMath.round(top.x), (double) size.width()) && Utils.between(0.0, (double) FastMath.round(top.y), (double) size.height())) { coords.add(new Coordinate(FastMath.round(top.x), FastMath.round(top.y))); } if (bottom != null && Utils.between(0.0, (double) FastMath.round(bottom.x), (double) size.width()) && Utils.between(0.0, (double) FastMath.round(bottom.y), (double) size.height())) { coords.add(new Coordinate(FastMath.round(bottom.x), FastMath.round(bottom.y))); } Line newLine = new Line(coords.first(), coords.last()); return newLine; }