示例#1
0
 private List<QueryQueue> getOrCreateQueues(
     Session session, Executor executor, List<QueryQueueDefinition> definitions) {
   ImmutableList.Builder<QueryQueue> queues = ImmutableList.builder();
   for (QueryQueueDefinition definition : definitions) {
     String expandedName = definition.getExpandedTemplate(session);
     QueueKey key = new QueueKey(definition, expandedName);
     if (!queryQueues.containsKey(key)) {
       QueryQueue queue =
           new QueryQueue(executor, definition.getMaxQueued(), definition.getMaxConcurrent());
       if (queryQueues.putIfAbsent(key, queue) == null) {
         // Export the mbean, after checking for races
         String objectName =
             ObjectNames.builder(QueryQueue.class, definition.getTemplate())
                 .withProperty("expansion", expandedName)
                 .build();
         mbeanExporter.export(objectName, queue);
       }
     }
     queues.add(queryQueues.get(key));
   }
   return queues.build();
 }
示例#2
0
  private static void checkIsDAG(List<QueryQueueRule> rules) {
    DirectedPseudograph<String, DefaultEdge> graph = new DirectedPseudograph<>(DefaultEdge.class);
    for (QueryQueueRule rule : rules) {
      String lastQueueName = null;
      for (QueryQueueDefinition queue : rule.getQueues()) {
        String currentQueueName = queue.getTemplate();
        graph.addVertex(currentQueueName);
        if (lastQueueName != null) {
          graph.addEdge(lastQueueName, currentQueueName);
        }
        lastQueueName = currentQueueName;
      }
    }

    List<String> shortestCycle = shortestCycle(graph);

    if (shortestCycle != null) {
      String s = Joiner.on(", ").join(shortestCycle);
      throw new IllegalArgumentException(
          format("Queues must not contain a cycle. The shortest cycle found is [%s]", s));
    }
  }
示例#3
0
    @Override
    public boolean equals(Object other) {
      if (this == other) {
        return true;
      }
      if (other == null || getClass() != other.getClass()) {
        return false;
      }

      QueueKey queueKey = (QueueKey) other;

      return Objects.equals(name, queueKey.name)
          && Objects.equals(queue.getTemplate(), queueKey.queue.getTemplate());
    }
示例#4
0
 @Override
 public int hashCode() {
   return Objects.hash(queue.getTemplate(), name);
 }