Package org.apache.helix

Examples of org.apache.helix.Criteria


    Message msg = new Message(factory.getMessageType(), "Template");
    msg.setTgtSessionId("*");
    msg.setMsgState(MessageState.NEW);

    // Criteria to send individual messages
    Criteria cr = new Criteria();
    cr.setInstanceName("localhost_%");
    cr.setRecipientInstanceType(InstanceType.PARTICIPANT);
    cr.setSessionSpecific(false);
    cr.setResource("%");
    cr.setPartition("%");

    ObjectMapper mapper = new ObjectMapper();
    SerializationConfig serializationConfig = mapper.getSerializationConfig();
    serializationConfig.set(SerializationConfig.Feature.INDENT_OUTPUT, true);

    StringWriter sw = new StringWriter();
    mapper.writeValue(sw, cr);

    String crString = sw.toString();

    schedulerMessage.getRecord().setSimpleField("Criteria", crString);
    schedulerMessage.getRecord().setMapField("MessageTemplate", msg.getRecord().getSimpleFields());
    schedulerMessage.getRecord().setSimpleField("TIMEOUT", "-1");
    schedulerMessage.getRecord().setSimpleField("WAIT_ALL", "true");
    schedulerMessage.getRecord().setSimpleField(
        DefaultSchedulerMessageHandlerFactory.SCHEDULER_TASK_QUEUE, "TestSchedulerMsgContraints");

    Criteria cr2 = new Criteria();
    cr2.setRecipientInstanceType(InstanceType.CONTROLLER);
    cr2.setInstanceName("*");
    cr2.setSessionSpecific(false);

    MockAsyncCallback callback = new MockAsyncCallback();
    mapper = new ObjectMapper();
    serializationConfig = mapper.getSerializationConfig();
    serializationConfig.set(SerializationConfig.Feature.INDENT_OUTPUT, true);
View Full Code Here


      Message messageTemplate = new Message(record);

      // Parse the criteria
      StringReader sr = new StringReader(_message.getRecord().getSimpleField("Criteria"));
      ObjectMapper mapper = new ObjectMapper();
      Criteria recipientCriteria;
      try {
        recipientCriteria = mapper.readValue(sr, Criteria.class);
      } catch (Exception e) {
        _logger.error("", e);
        result.setException(e);
        result.setSuccess(false);
        return result;
      }
      _logger.info("Scheduler sending message, criteria:" + recipientCriteria);

      boolean waitAll = false;
      if (_message.getRecord().getSimpleField(DefaultSchedulerMessageHandlerFactory.WAIT_ALL) != null) {
        try {
          waitAll =
              Boolean.parseBoolean(_message.getRecord().getSimpleField(
                  DefaultSchedulerMessageHandlerFactory.WAIT_ALL));
        } catch (Exception e) {
          _logger.warn("", e);
        }
      }
      boolean hasSchedulerTaskQueue =
          _message.getRecord().getSimpleFields().containsKey(SCHEDULER_TASK_QUEUE);
      // If the target is PARTICIPANT, use the ScheduledTaskQueue
      if (InstanceType.PARTICIPANT == recipientCriteria.getRecipientInstanceType()
          && hasSchedulerTaskQueue) {
        handleMessageUsingScheduledTaskQueue(recipientCriteria, messageTemplate,
            _message.getMsgId());
        result.setSuccess(true);
        result.getTaskResultMap().put(SCHEDULER_MSG_ID, _message.getMsgId());
View Full Code Here

    Message msg = new Message(_factory.getMessageType(), "Template");
    msg.setTgtSessionId("*");
    msg.setMsgState(MessageState.NEW);

    // Criteria to send individual messages
    Criteria cr = new Criteria();
    cr.setInstanceName("localhost_%");
    cr.setRecipientInstanceType(InstanceType.PARTICIPANT);
    cr.setSessionSpecific(false);
    cr.setResource("%");
    cr.setPartition("%");

    ObjectMapper mapper = new ObjectMapper();
    SerializationConfig serializationConfig = mapper.getSerializationConfig();
    serializationConfig.set(SerializationConfig.Feature.INDENT_OUTPUT, true);

View Full Code Here

        new Message(MessageType.PARTICIPANT_ERROR_REPORT, UUID.randomUUID().toString());
    errorMessage1.setTgtSessionId("*");
    errorMessage1.getRecord().setSimpleField(
        DefaultParticipantErrorMessageHandlerFactory.ACTIONKEY,
        ActionOnError.DISABLE_INSTANCE.toString());
    Criteria recipientCriteria = new Criteria();
    recipientCriteria.setRecipientInstanceType(InstanceType.CONTROLLER);
    recipientCriteria.setSessionSpecific(false);
    _participants[0].getMessagingService().send(recipientCriteria,
        errorMessage1);

    Message errorMessage2 =
        new Message(MessageType.PARTICIPANT_ERROR_REPORT, UUID.randomUUID().toString());
    errorMessage2.setTgtSessionId("*");
    errorMessage2.setResourceName("TestDB");
    errorMessage2.setPartitionName("TestDB_14");
    errorMessage2.getRecord().setSimpleField(
        DefaultParticipantErrorMessageHandlerFactory.ACTIONKEY,
        ActionOnError.DISABLE_PARTITION.toString());
    Criteria recipientCriteria2 = new Criteria();
    recipientCriteria2.setRecipientInstanceType(InstanceType.CONTROLLER);
    recipientCriteria2.setSessionSpecific(false);
    _participants[1].getMessagingService().send(recipientCriteria2,
        errorMessage2);

    try {
      Thread.sleep(1500);
View Full Code Here

    msg.setTgtSessionId("*");
    msg.setMsgState(MessageState.NEW);
    String para = "Testing messaging para";
    msg.getRecord().setSimpleField("TestMessagingPara", para);

    Criteria cr = new Criteria();
    cr.setInstanceName(hostDest);
    cr.setRecipientInstanceType(InstanceType.PARTICIPANT);
    cr.setSessionSpecific(false);

    // int nMsgs = _startCMResultMap.get(hostSrc)._manager.getMessagingService().send(cr, msg);
    int nMsgs = _participants[0].getMessagingService().send(cr, msg);
    AssertJUnit.assertTrue(nMsgs == 1);
    Thread.sleep(2500);
    // Thread.currentThread().join();
    AssertJUnit.assertTrue(TestMessagingHandlerFactory._processedMsgIds.contains(para));

    cr = new Criteria();
    cr.setInstanceName(hostDest);
    cr.setRecipientInstanceType(InstanceType.PARTICIPANT);
    cr.setSessionSpecific(false);
    cr.setDataSource(DataSource.IDEALSTATES);

    // nMsgs = _startCMResultMap.get(hostSrc)._manager.getMessagingService().send(cr, msg);
    nMsgs = _participants[0].getMessagingService().send(cr, msg);
    AssertJUnit.assertTrue(nMsgs == 1);
    Thread.sleep(2500);
View Full Code Here

    msg.setTgtSessionId("*");
    msg.setMsgState(MessageState.NEW);
    String para = "Testing messaging para";
    msg.getRecord().setSimpleField("TestMessagingPara", para);

    Criteria cr = new Criteria();
    cr.setInstanceName(hostDest);
    cr.setRecipientInstanceType(InstanceType.PARTICIPANT);
    cr.setSessionSpecific(false);

    TestAsyncCallback callback = new TestAsyncCallback(60000);

    _participants[0].getMessagingService().send(cr, msg, callback, 60000);

    Thread.sleep(2000);
    // Thread.currentThread().join();
    AssertJUnit.assertTrue(TestAsyncCallback._replyedMessageContents.contains("TestReplyMessage"));
    AssertJUnit.assertTrue(callback.getMessageReplied().size() == 1);

    TestAsyncCallback callback2 = new TestAsyncCallback(500);
    _participants[0].getMessagingService().send(cr, msg, callback2, 500);

    Thread.sleep(3000);
    // Thread.currentThread().join();
    AssertJUnit.assertTrue(callback2.isTimedOut());

    cr = new Criteria();
    cr.setInstanceName(hostDest);
    cr.setRecipientInstanceType(InstanceType.PARTICIPANT);
    cr.setSessionSpecific(false);
    cr.setDataSource(DataSource.IDEALSTATES);

    callback = new TestAsyncCallback(60000);

    _participants[0].getMessagingService().send(cr, msg, callback, 60000);

View Full Code Here

    msg.setTgtSessionId("*");
    msg.setMsgState(MessageState.NEW);
    String para = "Testing messaging para";
    msg.getRecord().setSimpleField("TestMessagingPara", para);

    Criteria cr = new Criteria();
    cr.setInstanceName(hostDest);
    cr.setRecipientInstanceType(InstanceType.PARTICIPANT);
    cr.setSessionSpecific(false);

    AsyncCallback asyncCallback = new MockAsyncCallback();
    int messagesSent =
        _participants[0].getMessagingService().sendAndWait(cr, msg, asyncCallback, 60000);

View Full Code Here

    msg.setTgtSessionId("*");
    msg.setMsgState(MessageState.NEW);
    String para = "Testing messaging para";
    msg.getRecord().setSimpleField("TestMessagingPara", para);

    Criteria cr = new Criteria();
    cr.setInstanceName("%");
    cr.setRecipientInstanceType(InstanceType.PARTICIPANT);
    cr.setSessionSpecific(false);
    AsyncCallback callback1 = new MockAsyncCallback();
    int messageSent1 =
        _participants[0].getMessagingService().sendAndWait(cr, msg, callback1, 10000);

    AssertJUnit.assertTrue(callback1.getMessageReplied().get(0).getRecord()
        .getMapField(Message.Attributes.MESSAGE_RESULT.toString()).get("ReplyMessage")
        .equals("TestReplyMessage"));
    AssertJUnit.assertTrue(callback1.getMessageReplied().size() == NODE_NR - 1);

    AsyncCallback callback2 = new MockAsyncCallback();
    int messageSent2 = _participants[0].getMessagingService().sendAndWait(cr, msg, callback2, 500);

    AssertJUnit.assertTrue(callback2.isTimedOut());

    cr.setPartition("TestDB_17");
    AsyncCallback callback3 = new MockAsyncCallback();
    int messageSent3 =
        _participants[0].getMessagingService().sendAndWait(cr, msg, callback3, 10000);
    AssertJUnit.assertTrue(callback3.getMessageReplied().size() == _replica - 1);

    cr.setPartition("TestDB_15");
    AsyncCallback callback4 = new MockAsyncCallback();
    int messageSent4 =
        _participants[0].getMessagingService().sendAndWait(cr, msg, callback4, 10000);
    AssertJUnit.assertTrue(callback4.getMessageReplied().size() == _replica);

    cr.setPartitionState("SLAVE");
    AsyncCallback callback5 = new MockAsyncCallback();
    int messageSent5 =
        _participants[0].getMessagingService().sendAndWait(cr, msg, callback5, 10000);
    AssertJUnit.assertTrue(callback5.getMessageReplied().size() == _replica - 1);

    cr.setDataSource(DataSource.IDEALSTATES);
    AsyncCallback callback6 = new MockAsyncCallback();
    int messageSent6 =
        _participants[0].getMessagingService().sendAndWait(cr, msg, callback6, 10000);
    AssertJUnit.assertTrue(callback6.getMessageReplied().size() == _replica - 1);
  }
View Full Code Here

    msg.setTgtSessionId("*");
    msg.setMsgState(MessageState.NEW);
    String para = "Testing messaging para";
    msg.getRecord().setSimpleField("TestMessagingPara", para);

    Criteria cr = new Criteria();
    cr.setInstanceName("%");
    cr.setRecipientInstanceType(InstanceType.PARTICIPANT);
    cr.setSessionSpecific(false);
    cr.setSelfExcluded(false);
    AsyncCallback callback1 = new MockAsyncCallback();
    int messageSent1 =
        _participants[0].getMessagingService().sendAndWait(cr, msg, callback1, 10000);

    AssertJUnit.assertTrue(callback1.getMessageReplied().size() == NODE_NR);
View Full Code Here

    msg.setTgtSessionId("*");
    msg.setMsgState(MessageState.NEW);
    String para = "Testing messaging para";
    msg.getRecord().setSimpleField("TestMessagingPara", para);

    Criteria cr = new Criteria();
    cr.setInstanceName("*");
    cr.setRecipientInstanceType(InstanceType.CONTROLLER);
    cr.setSessionSpecific(false);

    AsyncCallback callback1 = new MockAsyncCallback();
    int messagesSent =
        _participants[0].getMessagingService().sendAndWait(cr, msg, callback1, 10000);

    AssertJUnit.assertTrue(callback1.getMessageReplied().get(0).getRecord()
        .getMapField(Message.Attributes.MESSAGE_RESULT.toString()).get("ControllerResult")
        .indexOf(hostSrc) != -1);
    AssertJUnit.assertTrue(callback1.getMessageReplied().size() == 1);

    msgId = UUID.randomUUID().toString();
    msg.setMsgId(msgId);
    cr.setPartition("TestDB_17");
    AsyncCallback callback2 = new MockAsyncCallback();
    messagesSent = _participants[0].getMessagingService().sendAndWait(cr, msg, callback2, 10000);

    AssertJUnit.assertTrue(callback2.getMessageReplied().get(0).getRecord()
        .getMapField(Message.Attributes.MESSAGE_RESULT.toString()).get("ControllerResult")
        .indexOf(hostSrc) != -1);

    AssertJUnit.assertTrue(callback2.getMessageReplied().size() == 1);

    msgId = UUID.randomUUID().toString();
    msg.setMsgId(msgId);
    cr.setPartitionState("SLAVE");
    AsyncCallback callback3 = new MockAsyncCallback();
    messagesSent = _participants[0].getMessagingService().sendAndWait(cr, msg, callback3, 10000);
    AssertJUnit.assertTrue(callback3.getMessageReplied().get(0).getRecord()
        .getMapField(Message.Attributes.MESSAGE_RESULT.toString()).get("ControllerResult")
        .indexOf(hostSrc) != -1);
View Full Code Here

TOP

Related Classes of org.apache.helix.Criteria

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.