예제 #1
0
  /**
   * Construct upwards graph based on the nodes hierarchy
   *
   * @param hierachy the hierarchy of the nodes
   */
  public void constructUpwardsGraph(TLongIntHashMap hierarchy) {
    int count = 0;
    for (Tuple2<Long, Arc> arc : graph.adjacenyList) {
      long u = arc.a;
      long v = arc.b.getHeadNode();

      if (hierarchy.get(v) > hierarchy.get(u)) graph.setArcFlagForEdge(u, arc.b, true);
      else graph.setArcFlagForEdge(u, arc.b, false);

      count++;
      if (count % 100000 == 0) System.out.println("#arcs processed: " + count);
    }
  }
예제 #2
0
 /**
  * Store the given <code>{@link org.quartz.Trigger}</code>.
  *
  * @param newTrigger The <code>Trigger</code> to be stored.
  * @param replaceExisting If <code>true</code>, any <code>Trigger</code> existing in the <code>
  *     JobStore</code> with the same name & group should be over-written.
  * @throws org.quartz.ObjectAlreadyExistsException if a <code>Trigger</code> with the same
  *     name/group already exists, and replaceExisting is set to false.
  * @see #pauseTriggerGroup(org.quartz.core.SchedulingContext, String)
  */
 public void storeTrigger(SchedulingContext ctxt, Trigger newTrigger, boolean replaceExisting)
     throws ObjectAlreadyExistsException, JobPersistenceException {
   Pair<String, String> triggerKey = getTriggerKey(newTrigger);
   long score = scoreTrigger(ctxt, newTrigger);
   long custId = getCustomerId(ctxt, newTrigger);
   WrappedTrigger wt =
       new WrappedTrigger(
           newTrigger,
           custId,
           Trigger.STATE_NORMAL,
           newTrigger.getNextFireTime().getTime(),
           score);
   synchronized (m_triggerLock) {
     storeObject(
         ctxt, triggerKey, wt, replaceExisting, m_triggersByGroupAndName, m_triggersHierarchyMap);
     m_triggersByScore.add(wt);
     if (!m_taskCountsByCustomer.increment(custId)) {
       m_taskCountsByCustomer.put(custId, 1);
     }
   }
 }
  @Override
  public Facet reduce(List<Facet> facets) {
    if (facets.size() == 1) {
      return facets.get(0);
    }

    InternalLongTermsFacet first = null;

    TLongIntHashMap aggregated = CacheRecycler.popLongIntMap();
    long missing = 0;
    long total = 0;
    for (Facet facet : facets) {
      TermsFacet termsFacet = (TermsFacet) facet;
      // termsFacet could be of type InternalStringTermsFacet representing unmapped fields
      if (first == null && termsFacet instanceof InternalLongTermsFacet) {
        first = (InternalLongTermsFacet) termsFacet;
      }
      missing += termsFacet.getMissingCount();
      total += termsFacet.getTotalCount();
      for (Entry entry : termsFacet.getEntries()) {
        aggregated.adjustOrPutValue(((LongEntry) entry).term, entry.getCount(), entry.getCount());
      }
    }

    BoundedTreeSet<LongEntry> ordered =
        new BoundedTreeSet<LongEntry>(first.comparatorType.comparator(), first.requiredSize);
    for (TLongIntIterator it = aggregated.iterator(); it.hasNext(); ) {
      it.advance();
      ordered.add(new LongEntry(it.key(), it.value()));
    }
    first.entries = ordered;
    first.missing = missing;
    first.total = total;

    CacheRecycler.pushLongIntMap(aggregated);

    return first;
  }
예제 #4
0
  /**
   * Selects a customerId from among customers that (have a positive preferred weighting) and (have
   * pending tasks), picking according to their preferred weightings. If there are no such
   * customers, this method returns -1.
   */
  private long getPreferredCustomerId() {
    int preferredCount = m_preferredWeightsByCustomer.size();
    if (preferredCount <= 0) {
      return -1L;
    }
    final TLongArrayList custIds = new TLongArrayList(preferredCount);
    final TDoubleArrayList weights = new TDoubleArrayList(preferredCount);
    m_preferredWeightsByCustomer.forEachKey(
        new TLongProcedure() {
          public boolean execute(long value) {
            if (m_taskCountsByCustomer.get(value) > 0) {
              custIds.add(value);
              weights.add((double) m_preferredWeightsByCustomer.get(value));
            }
            return true;
          }
        });

    if (custIds.isEmpty()) {
      return -1L;
    }
    return custIds.get(WeightedRandom.selectRandomBucket(weights.toArray()));
  }
예제 #5
0
 /**
  * Remove (delete) the <code>{@link org.quartz.Trigger}</code> with the given name.
  *
  * <p>If removal of the <code>Trigger</code> results in an empty group, the group should be
  * removed from the <code>JobStore</code>'s list of known group names.
  *
  * <p>If removal of the <code>Trigger</code> results in an 'orphaned' <code>Job</code> that is not
  * 'durable', then the <code>Job</code> should be deleted also.
  *
  * @param triggerName The name of the <code>Trigger</code> to be removed.
  * @param groupName The group name of the <code>Trigger</code> to be removed.
  * @return <code>true</code> if a <code>Trigger</code> with the given name & group was found and
  *     removed from the store.
  */
 public boolean removeTrigger(SchedulingContext ctxt, String triggerName, String groupName)
     throws JobPersistenceException {
   Pair<String, String> triggerKey = getTriggerKey(groupName, triggerName);
   synchronized (m_triggerLock) {
     WrappedTrigger wt =
         removeObject(ctxt, triggerKey, m_triggersByGroupAndName, m_triggersHierarchyMap);
     if (wt != null) {
       m_triggersByScore.remove(wt);
       m_taskCountsByCustomer.adjustValue(wt.getCustomerId(), -1);
       return true;
     }
     return false;
   }
 }
예제 #6
0
  /**
   * @param numOfContractions the number of contractions to do
   * @param order the initial order in which to contract (can be updated during contracting)
   * @return the hierarchy in which the nodes where contracted
   */
  public TLongIntHashMap contractNodes(int numOfContractions, Queue<QEntry> order) {
    TLongIntHashMap hierarchy = new TLongIntHashMap();
    for (int i = 0; i < numOfContractions; i++) {
      if (i % 1000 == 0) System.out.println("#nodes contracted: " + i);

      // get node with smallest ed
      long node = order.poll().getNodeId();

      // store the level of this node
      hierarchy.put(node, i);
      finalContractionOrder.add(node);

      // contract node
      int shortcuts = contractSingleNode(node);

      // update the node ordering
      updateNodeContractionOrdering(order);

      // increment total #shortcuts
      this.numberOfShortcuts += shortcuts;
    }

    return hierarchy;
  }