@Override
 public void dispose() {
   this.scheduledExecutorService.shutdown();
   if (this.scheduler != null) {
     try {
       this.scheduler.shutdown(true);
     } catch (final SchedulerException e) {
       log.error("Shutdown quartz scheduler failed", e);
     }
   }
   for (final ConcurrentHashMap<Integer /* partition */, MessageStore> subMap :
       MessageStoreManager.this.stores.values()) {
     if (subMap != null) {
       for (final MessageStore msgStore : subMap.values()) {
         if (msgStore != null) {
           try {
             msgStore.close();
           } catch (final Throwable e) {
             log.error(
                 "Try to run close  "
                     + msgStore.getTopic()
                     + ","
                     + msgStore.getPartition()
                     + " failed",
                 e);
           }
         }
       }
     }
   }
   this.stores.clear();
 }
Exemplo n.º 2
0
  public void testRemoveExchange() throws Exception {
    Exchange exchange = createTestExchange();
    _store.createExchange(exchange);

    _store.removeExchange(exchange);

    reopenStore();
    verify(_exchangeRecoveryHandler, never())
        .exchange(any(UUID.class), anyString(), anyString(), anyBoolean());
  }
Exemplo n.º 3
0
  private void reopenStore() throws Exception {
    if (_store != null) {
      _store.close();
    }
    _store = createStore();

    _store.configureConfigStore(_storeName, _recoveryHandler, _configuration);
    _store.configureMessageStore(
        _storeName, _messageStoreRecoveryHandler, _logRecoveryHandler, _configuration);
    _store.activate();
  }
 public long getTotalMessagesCount() {
   long rt = 0;
   for (final ConcurrentHashMap<Integer /* partition */, MessageStore> subMap :
       MessageStoreManager.this.stores.values()) {
     if (subMap != null) {
       for (final MessageStore msgStore : subMap.values()) {
         if (msgStore != null) {
           rt += msgStore.getMessageCount();
         }
       }
     }
   }
   return rt;
 }
Exemplo n.º 5
0
  public void testCreateQueueAMQQueue() throws Exception {
    AMQQueue queue = createTestQueue(getName(), getName() + "Owner", true);
    _store.createQueue(queue);

    reopenStore();
    verify(_queueRecoveryHandler).queue(_queueId, getName(), getName() + "Owner", true, null, null);
  }
Exemplo n.º 6
0
  public void testCreateExchange() throws Exception {
    Exchange exchange = createTestExchange();
    _store.createExchange(exchange);

    reopenStore();
    verify(_exchangeRecoveryHandler).exchange(_exchangeId, getName(), getName() + "Type", true);
  }
Exemplo n.º 7
0
  public void testUpdateQueueExclusivity() throws Exception {
    // create queue
    AMQQueue queue = createTestQueue(getName(), getName() + "Owner", true);
    Map<String, Object> attributes = new HashMap<String, Object>();
    attributes.put("x-qpid-dlq-enabled", Boolean.TRUE);
    attributes.put("x-qpid-maximum-delivery-count", new Integer(10));
    FieldTable arguments = FieldTable.convertToFieldTable(attributes);
    _store.createQueue(queue, arguments);

    // update the queue to have exclusive=false
    queue = createTestQueue(getName(), getName() + "Owner", false);
    _store.updateQueue(queue);

    reopenStore();
    verify(_queueRecoveryHandler)
        .queue(_queueId, getName(), getName() + "Owner", false, arguments, null);
  }
Exemplo n.º 8
0
  public DocPlan getDefaultDocPlan(MessageStore mStore) {
    DocPlan docplan = new DocPlan("Overall");

    if (mStore.query(MultipleDiveWarningMessage.class, msg -> true) != null) {

      docplan.add(mStore.query(MultipleDiveWarningMessage.class, eval -> true));
    } else {

      docplan.add(mStore.query(DiveEvaluation.class, eval -> true));
    }

    docplan.add(mStore.query(SecondDiveletDeeperMessage.class, item -> true));

    String firstSectionName = "Dive Evaluation";
    if (mStore.query(DiveletMessage.class, divelet -> divelet.getDiveletNumber() == 2) != null) {
      firstSectionName = "First " + firstSectionName;
    }

    docplan.newSection(firstSectionName);
    docplan.addAll(
        mStore.queryAll(DiveletMessage.class, divelet -> divelet.getDiveletNumber() == 1));

    docplan.newSection("Second Dive Evaluation");
    docplan.addAll(
        mStore.queryAll(DiveletMessage.class, divelet -> divelet.getDiveletNumber() == 2));

    docplan.newSection("");

    return docplan;
  }
Exemplo n.º 9
0
  public void testUnbindQueue() throws Exception {
    AMQQueue queue = createTestQueue(QUEUE_NAME, "queueOwner", false);
    Binding binding =
        new Binding(
            UUIDGenerator.generateRandomUUID(),
            ROUTING_KEY,
            queue,
            _exchange,
            FieldTable.convertToMap(_bindingArgs));
    _store.bindQueue(binding);

    _store.unbindQueue(binding);
    reopenStore();

    verify(_bindingRecoveryHandler, never())
        .binding(
            any(UUID.class), any(UUID.class), any(UUID.class), anyString(), isA(ByteBuffer.class));
  }
Exemplo n.º 10
0
  public void testCreateQueueAMQQueueWithAlternateExchange() throws Exception {
    Exchange alternateExchange = createTestAlternateExchange();

    AMQQueue queue = createTestQueue(getName(), getName() + "Owner", true, alternateExchange);
    _store.createQueue(queue);

    reopenStore();
    verify(_queueRecoveryHandler)
        .queue(_queueId, getName(), getName() + "Owner", true, null, alternateExchange.getId());
  }
Exemplo n.º 11
0
  @DELETE
  public Response delete(@PathParam("id") String id) {
    Preconditions.checkNotNull(id, "id must not be null");

    if (!store.delete(id)) {
      return Response.status(Response.Status.NOT_FOUND).build();
    }

    return Response.noContent().build();
  }
Exemplo n.º 12
0
 @Override
 public void run() {
   for (final ConcurrentHashMap<Integer, MessageStore> map :
       MessageStoreManager.this.stores.values()) {
     for (final MessageStore store : map.values()) {
       if (this.unflushInterval
           != MessageStoreManager.this
               .metaConfig
               .getTopicConfig(store.getTopic())
               .getUnflushInterval()) {
         continue;
       }
       try {
         store.flush();
       } catch (final IOException e) {
         log.error("Try to flush store failed", e);
       }
     }
   }
 }
Exemplo n.º 13
0
  public void testRemoveQueue() throws Exception {
    // create queue
    AMQQueue queue = createTestQueue(getName(), getName() + "Owner", true);
    Map<String, Object> attributes = new HashMap<String, Object>();
    attributes.put("x-qpid-dlq-enabled", Boolean.TRUE);
    attributes.put("x-qpid-maximum-delivery-count", new Integer(10));
    FieldTable arguments = FieldTable.convertToFieldTable(attributes);
    _store.createQueue(queue, arguments);

    // remove queue
    _store.removeQueue(queue);
    reopenStore();
    verify(_queueRecoveryHandler, never())
        .queue(
            any(UUID.class),
            anyString(),
            anyString(),
            anyBoolean(),
            any(FieldTable.class),
            any(UUID.class));
  }
Exemplo n.º 14
0
  @GET
  @Produces(MediaType.APPLICATION_JSON)
  public Response get(@PathParam("id") String id, @Context UriInfo uriInfo) {
    Preconditions.checkNotNull(id, "id must not be null");

    Message message = store.get(id);

    if (message == null) {
      return Response.status(Response.Status.NOT_FOUND).entity("[" + id + "]").build();
    }

    return Response.ok(from(message, uriInfo.getAbsolutePath(), true)).build();
  }
Exemplo n.º 15
0
  public void testRecordXid() throws Exception {
    Record enqueueRecord = getTestRecord(1);
    Record dequeueRecord = getTestRecord(2);
    Record[] enqueues = {enqueueRecord};
    Record[] dequeues = {dequeueRecord};
    byte[] globalId = new byte[] {1};
    byte[] branchId = new byte[] {2};

    Transaction transaction = _store.newTransaction();
    transaction.recordXid(1l, globalId, branchId, enqueues, dequeues);
    transaction.commitTran();
    reopenStore();
    verify(_dtxRecordRecoveryHandler).dtxRecord(1l, globalId, branchId, enqueues, dequeues);

    transaction = _store.newTransaction();
    transaction.removeXid(1l, globalId, branchId);
    transaction.commitTran();

    reopenStore();
    verify(_dtxRecordRecoveryHandler, times(1))
        .dtxRecord(1l, globalId, branchId, enqueues, dequeues);
  }
Exemplo n.º 16
0
 private void loadStores(List<Callable<MessageStore>> tasks)
     throws IOException, InterruptedException {
   for (Callable<MessageStore> task : tasks) {
     MessageStore messageStore;
     try {
       messageStore = task.call();
       ConcurrentHashMap<Integer /* partition */, MessageStore> map =
           this.stores.get(messageStore.getTopic());
       if (map == null) {
         map = new ConcurrentHashMap<Integer, MessageStore>();
         this.stores.put(messageStore.getTopic(), map);
       }
       map.put(messageStore.getPartition(), messageStore);
     } catch (IOException e) {
       throw e;
     } catch (InterruptedException e) {
       throw e;
     } catch (Exception e) {
       throw new IllegalStateException(e);
     }
   }
   tasks.clear();
 }
Exemplo n.º 17
0
  private void loadStoresInParallel(ExecutorService executor, List<Callable<MessageStore>> tasks)
      throws InterruptedException {
    CompletionService<MessageStore> completionService =
        new ExecutorCompletionService<MessageStore>(executor);
    for (Callable<MessageStore> task : tasks) {
      completionService.submit(task);
    }
    for (int i = 0; i < tasks.size(); i++) {
      try {
        MessageStore messageStore = completionService.take().get();

        ConcurrentHashMap<Integer /* partition */, MessageStore> map =
            this.stores.get(messageStore.getTopic());
        if (map == null) {
          map = new ConcurrentHashMap<Integer, MessageStore>();
          this.stores.put(messageStore.getTopic(), map);
        }
        map.put(messageStore.getPartition(), messageStore);
      } catch (ExecutionException e) {
        throw ThreadUtils.launderThrowable(e);
      }
    }
    tasks.clear();
  }
Exemplo n.º 18
0
  public void testBindQueue() throws Exception {
    AMQQueue queue = createTestQueue(QUEUE_NAME, "queueOwner", false);
    Binding binding =
        new Binding(
            UUIDGenerator.generateRandomUUID(),
            ROUTING_KEY,
            queue,
            _exchange,
            FieldTable.convertToMap(_bindingArgs));
    _store.bindQueue(binding);

    reopenStore();

    ByteBuffer argsAsBytes = ByteBuffer.wrap(_bindingArgs.getDataAsBytes());

    verify(_bindingRecoveryHandler)
        .binding(binding.getId(), _exchange.getId(), queue.getId(), ROUTING_KEY, argsAsBytes);
  }
Exemplo n.º 19
0
 public void loadById(long id) {
   this.id = id;
   this.participantIds = ms.getChatParticipants(id);
 }
Exemplo n.º 20
0
 public List<Long> getMessageIds() {
   return ms.getMessageIdsFromChat(id);
 }
Exemplo n.º 21
0
 public void addParticipant(Long userId) {
   if (userId != 0 && !participantIds.contains(userId)) {
     participantIds.add(userId);
     ms.addUserToChat(userId, this.id);
   }
 }
  public void run() {
    SubscriptionStore subscriptionStore = MessagingEngine.getInstance().getSubscriptionStore();
    int queueWorkerWaitTime =
        ClusterResourceHolder.getInstance().getClusterConfiguration().getQueueWorkerInterval();
    int repeatedSleepingCounter = 0;

    while (true) {
      if (running) {
        try {
          /**
           * Steps
           *
           * <p>1)Poll Global queue and get chunk of messages 2) Put messages one by one to node
           * queues and delete them
           */
          QueueAddress sourceQueueAddress =
              new QueueAddress(QueueAddress.QueueType.GLOBAL_QUEUE, globalQueueName);

          List<AndesMessageMetadata> messageList =
              messageStore.getNextNMessageMetadataFromQueue(
                  sourceQueueAddress, lastProcessedMessageID, messageCountToReadFromCasssandra);
          while (messageList.size() != 0) {
            Iterator<AndesMessageMetadata> metadataIterator = messageList.iterator();
            while (metadataIterator.hasNext()) {
              AndesMessageMetadata metadata = metadataIterator.next();

              /**
               * check if the cluster has some subscriptions for that message and distribute to
               * relevant node queues
               */
              String destinationQueue = metadata.getDestination();
              Random random = new Random();
              // TODO remove this list to set conversion
              List<String> nodeQueuesHavingSubscriptionsForQueue =
                  new ArrayList<String>(
                      subscriptionStore.getNodeQueuesHavingSubscriptionsForQueue(destinationQueue));
              if (nodeQueuesHavingSubscriptionsForQueue != null
                  && nodeQueuesHavingSubscriptionsForQueue.size() > 0) {
                int index = random.nextInt(nodeQueuesHavingSubscriptionsForQueue.size());
                String nodeQueue = nodeQueuesHavingSubscriptionsForQueue.get(index);
                metadata.queueAddress =
                    new QueueAddress(QueueAddress.QueueType.QUEUE_NODE_QUEUE, nodeQueue);
                // if (log.isDebugEnabled()) {
                String msgID = (String) metadata.getMessageHeader("msgID");
                log.info(
                    "TRACING>> GQW "
                        + globalQueueName
                        + ">> copying message-"
                        + (msgID == null ? "" : msgID)
                        + " to "
                        + nodeQueue
                        + " message ID: "
                        + metadata.getMessageID());
                // }
              } else {
                // if there is no node queue to move message we skip
                metadataIterator.remove();
              }
              lastProcessedMessageID = metadata.getMessageID();
            }
            messageStore.moveMessageMetaData(sourceQueueAddress, null, messageList);
            PerformanceCounter.recordGlobalQueueMsgMove(messageList.size());
            messageList =
                messageStore.getNextNMessageMetadataFromQueue(
                    sourceQueueAddress, lastProcessedMessageID, messageCountToReadFromCasssandra);
          }

          try {
            Thread.sleep(queueWorkerWaitTime);
            repeatedSleepingCounter++;
            if (repeatedSleepingCounter > 1) {
              resetMessageReading();
            }
          } catch (InterruptedException e) {
            // ignore
          }
        } catch (Exception e) {
          log.error("Error in moving messages from global queue to node queue", e);
        }
      } else {
        try {
          Thread.sleep(2000);
        } catch (InterruptedException e) {
          // silently ignore
        }
      }
    }
  }