本文整理汇总了Java中org.apache.helix.model.Message.setResourceName方法的典型用法代码示例。如果您正苦于以下问题:Java Message.setResourceName方法的具体用法?Java Message.setResourceName怎么用?Java Message.setResourceName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.helix.model.Message
的用法示例。
在下文中一共展示了Message.setResourceName方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: newMessage
import org.apache.helix.model.Message; //导入方法依赖的package包/类
private Message newMessage(String resourceName, String partitionName, String instanceName,
String fromState, String toState) {
String uuid = UUID.randomUUID().toString();
Message message = new Message(MessageType.STATE_TRANSITION, uuid);
message.setSrcName("controller");
message.setTgtName(instanceName);
message.setMsgState(MessageState.NEW);
message.setResourceName(resourceName);
message.setPartitionName(partitionName);
message.setFromState(fromState);
message.setToState(toState);
message.setTgtSessionId("sessionId");
message.setSrcSessionId("sessionId");
message.setStateModelDef("MasterSlave");
message.setStateModelFactoryName("DEFAULT");
message.setBucketSize(0);
return message;
}
示例2: createStateTransitionMessage
import org.apache.helix.model.Message; //导入方法依赖的package包/类
private Message createStateTransitionMessage(HelixManager manager, Resource resource, String partitionName,
String instanceName, String currentState, String nextState, String sessionId,
String stateModelDefName) {
String uuid = UUID.randomUUID().toString();
Message message = new Message(MessageType.STATE_TRANSITION, uuid);
message.setSrcName(manager.getInstanceName());
message.setTgtName(instanceName);
message.setMsgState(MessageState.NEW);
message.setPartitionName(partitionName);
message.setResourceName(resource.getResourceName());
message.setFromState(currentState);
message.setToState(nextState);
message.setTgtSessionId(sessionId);
message.setSrcSessionId(manager.getSessionId());
message.setStateModelDef(stateModelDefName);
message.setStateModelFactoryName(resource.getStateModelFactoryname());
message.setBucketSize(resource.getBucketSize());
if (resource.getResourceGroupName() != null) {
message.setResourceGroupName(resource.getResourceGroupName());
}
if (resource.getResourceTag() != null) {
message.setResourceTag(resource.getResourceTag());
}
return message;
}
示例3: createStateTransitionCancellationMessage
import org.apache.helix.model.Message; //导入方法依赖的package包/类
private Message createStateTransitionCancellationMessage(HelixManager manager, Resource resource,
String partitionName, String instanceName, String sessionId, String stateModelDefName,
String fromState, String toState, String nextState, Message cancellationMessage, boolean isCancellationEnabled,
String currentState) {
if (isCancellationEnabled && cancellationMessage == null) {
logger.info("Send cancellation message of the state transition for " + resource.getResourceName() + "."
+ partitionName + " on " + instanceName + ", currentState: " + currentState + ", nextState: "
+ (nextState == null ? "N/A" : nextState));
String uuid = UUID.randomUUID().toString();
Message message = new Message(MessageType.STATE_TRANSITION_CANCELLATION, uuid);
message.setSrcName(manager.getInstanceName());
message.setTgtName(instanceName);
message.setMsgState(MessageState.NEW);
message.setPartitionName(partitionName);
message.setResourceName(resource.getResourceName());
message.setFromState(fromState);
message.setToState(toState);
message.setTgtSessionId(sessionId);
message.setSrcSessionId(manager.getSessionId());
message.setStateModelDef(stateModelDefName);
message.setStateModelFactoryName(resource.getStateModelFactoryname());
message.setBucketSize(resource.getBucketSize());
return message;
}
return null;
}
示例4: createMessage
import org.apache.helix.model.Message; //导入方法依赖的package包/类
public static Message createMessage(String msgId, String fromState, String toState,
String tgtName, String resourceName, String partitionName) {
Message msg = new Message(MessageType.STATE_TRANSITION, msgId);
msg.setFromState(fromState);
msg.setToState(toState);
msg.setTgtName(tgtName);
msg.setResourceName(resourceName);
msg.setPartitionName(partitionName);
msg.setStateModelDef("MasterSlave");
return msg;
}
示例5: testInvocation
import org.apache.helix.model.Message; //导入方法依赖的package包/类
@Test()
public void testInvocation() throws Exception {
HelixTaskExecutor executor = new HelixTaskExecutor();
System.out.println("START TestCMTaskHandler.testInvocation()");
Message message = new Message(MessageType.STATE_TRANSITION, "Some unique id");
message.setSrcName("cm-instance-0");
message.setTgtSessionId("1234");
message.setFromState("Offline");
message.setToState("Slave");
message.setPartitionName("TestDB_0");
message.setMsgId("Some unique message id");
message.setResourceName("TestDB");
message.setTgtName("localhost");
message.setStateModelDef("MasterSlave");
message.setStateModelFactoryName(HelixConstants.DEFAULT_STATE_MODEL_FACTORY);
MockMasterSlaveStateModel stateModel = new MockMasterSlaveStateModel();
NotificationContext context;
MockManager manager = new MockManager("clusterName");
HelixDataAccessor accessor = manager.getHelixDataAccessor();
StateModelDefinition stateModelDef =
new StateModelDefinition(StateModelConfigGenerator.generateConfigForMasterSlave());
Builder keyBuilder = accessor.keyBuilder();
accessor.setProperty(keyBuilder.stateModelDef("MasterSlave"), stateModelDef);
context = new NotificationContext(manager);
CurrentState currentStateDelta = new CurrentState("TestDB");
currentStateDelta.setState("TestDB_0", "OFFLINE");
HelixStateTransitionHandler stHandler =
new HelixStateTransitionHandler(null, stateModel, message, context, currentStateDelta);
HelixTask handler;
handler = new HelixTask(message, context, stHandler, executor);
handler.call();
AssertJUnit.assertTrue(stateModel.stateModelInvoked);
System.out.println("END TestCMTaskHandler.testInvocation() at "
+ new Date(System.currentTimeMillis()));
}
示例6: testStateMismatch
import org.apache.helix.model.Message; //导入方法依赖的package包/类
@Test
public void testStateMismatch() throws InterruptedException {
// String controllerName = CONTROLLER_PREFIX + "_0";
HelixManager manager = _controller; // _startCMResultMap.get(controllerName)._manager;
HelixDataAccessor accessor = manager.getHelixDataAccessor();
Builder kb = accessor.keyBuilder();
ExternalView ev = accessor.getProperty(kb.externalView(TEST_DB));
Map<String, LiveInstance> liveinstanceMap =
accessor.getChildValuesMap(accessor.keyBuilder().liveInstances());
for (String instanceName : liveinstanceMap.keySet()) {
String sessionid = liveinstanceMap.get(instanceName).getSessionId();
for (String partition : ev.getPartitionSet()) {
if (ev.getStateMap(partition).containsKey(instanceName)) {
String uuid = UUID.randomUUID().toString();
Message message = new Message(MessageType.STATE_TRANSITION, uuid);
boolean rand = new Random().nextInt(10) > 5;
if (ev.getStateMap(partition).get(instanceName).equals("MASTER")) {
message.setSrcName(manager.getInstanceName());
message.setTgtName(instanceName);
message.setMsgState(MessageState.NEW);
message.setPartitionName(partition);
message.setResourceName(TEST_DB);
message.setFromState(rand ? "SLAVE" : "OFFLINE");
message.setToState(rand ? "MASTER" : "SLAVE");
message.setTgtSessionId(sessionid);
message.setSrcSessionId(manager.getSessionId());
message.setStateModelDef("MasterSlave");
message.setStateModelFactoryName("DEFAULT");
} else if (ev.getStateMap(partition).get(instanceName).equals("SLAVE")) {
message.setSrcName(manager.getInstanceName());
message.setTgtName(instanceName);
message.setMsgState(MessageState.NEW);
message.setPartitionName(partition);
message.setResourceName(TEST_DB);
message.setFromState(rand ? "MASTER" : "OFFLINE");
message.setToState(rand ? "SLAVE" : "SLAVE");
message.setTgtSessionId(sessionid);
message.setSrcSessionId(manager.getSessionId());
message.setStateModelDef("MasterSlave");
message.setStateModelFactoryName("DEFAULT");
}
accessor.setProperty(accessor.keyBuilder().message(instanceName, message.getMsgId()),
message);
}
}
}
Thread.sleep(3000);
ExternalView ev2 = accessor.getProperty(kb.externalView(TEST_DB));
Assert.assertTrue(ev.equals(ev2));
}
示例7: TestParticipantErrorMessageSend
import org.apache.helix.model.Message; //导入方法依赖的package包/类
@Test()
public void TestParticipantErrorMessageSend() {
String participant1 = "localhost_" + START_PORT;
String participant2 = "localhost_" + (START_PORT + 1);
Message errorMessage1 =
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);
} catch (InterruptedException e) {
LOG.error("Interrupted sleep", e);
}
boolean result =
ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR,
CLUSTER_NAME));
Assert.assertTrue(result);
Builder kb = _participants[1].getHelixDataAccessor().keyBuilder();
ExternalView externalView =
_participants[1].getHelixDataAccessor().getProperty(
kb.externalView("TestDB"));
for (String partitionName : externalView.getRecord().getMapFields().keySet()) {
for (String hostName : externalView.getRecord().getMapField(partitionName).keySet()) {
if (hostName.equals(participant1)) {
Assert.assertTrue(externalView.getRecord().getMapField(partitionName).get(hostName)
.equalsIgnoreCase("OFFLINE"));
}
}
}
Assert.assertTrue(externalView.getRecord().getMapField("TestDB_14").get(participant2)
.equalsIgnoreCase("OFFLINE"));
}
示例8: testCMTaskExecutor
import org.apache.helix.model.Message; //导入方法依赖的package包/类
@Test()
public void testCMTaskExecutor() throws Exception {
System.out.println("START TestCMTaskExecutor");
String msgId = "TestMessageId";
Message message = new Message(MessageType.TASK_REPLY, msgId);
message.setMsgId(msgId);
message.setSrcName("cm-instance-0");
message.setTgtName("cm-instance-1");
message.setTgtSessionId("1234");
message.setFromState("Offline");
message.setToState("Slave");
message.setPartitionName("TestDB_0");
message.setResourceName("TestDB");
message.setStateModelDef("MasterSlave");
MockManager manager = new MockManager("clusterName");
HelixDataAccessor accessor = manager.getHelixDataAccessor();
StateModelDefinition stateModelDef =
new StateModelDefinition(StateModelConfigGenerator.generateConfigForMasterSlave());
Builder keyBuilder = accessor.keyBuilder();
accessor.setProperty(keyBuilder.stateModelDef("MasterSlave"), stateModelDef);
MockHelixTaskExecutor executor = new MockHelixTaskExecutor();
MockMasterSlaveStateModel stateModel = new MockMasterSlaveStateModel();
executor.registerMessageHandlerFactory(MessageType.TASK_REPLY.name(),
new AsyncCallbackService());
NotificationContext context = new NotificationContext(manager);
CurrentState currentStateDelta = new CurrentState("TestDB");
currentStateDelta.setState("TestDB_0", "OFFLINE");
StateModelFactory<MockMasterSlaveStateModel> stateModelFactory = new StateModelFactory<MockMasterSlaveStateModel>() {
@Override
public MockMasterSlaveStateModel createNewStateModel(String resource, String partitionName) {
// TODO Auto-generated method stub
return new MockMasterSlaveStateModel();
}
};
HelixStateTransitionHandler handler =
new HelixStateTransitionHandler(stateModelFactory, stateModel, message, context,
currentStateDelta);
HelixTask task = new HelixTask(message, context, handler, executor);
executor.scheduleTask(task);
for (int i = 0; i < 10; i++) {
if (!executor.isDone(task.getTaskId())) {
Thread.sleep(500);
}
}
AssertJUnit.assertTrue(stateModel.stateModelInvoked);
System.out.println("END TestCMTaskExecutor");
}
示例9: testStateTransitionCancellationMsg
import org.apache.helix.model.Message; //导入方法依赖的package包/类
@Test
public void testStateTransitionCancellationMsg() throws InterruptedException {
HelixTaskExecutor executor = new HelixTaskExecutor();
HelixManager manager = new MockClusterManager();
TestStateTransitionHandlerFactory stateTransitionFactory = new TestStateTransitionHandlerFactory(Message.MessageType.STATE_TRANSITION.name());
TestStateTransitionHandlerFactory cancelFactory = new TestStateTransitionHandlerFactory(Message.MessageType.STATE_TRANSITION_CANCELLATION
.name());
executor.registerMessageHandlerFactory(Message.MessageType.STATE_TRANSITION.name(), stateTransitionFactory);
executor.registerMessageHandlerFactory(Message.MessageType.STATE_TRANSITION_CANCELLATION.name(), cancelFactory);
NotificationContext changeContext = new NotificationContext(manager);
List<Message> msgList = new ArrayList<Message>();
Message msg1 = new Message(Message.MessageType.STATE_TRANSITION, UUID.randomUUID().toString());
msg1.setTgtSessionId("*");
msg1.setPartitionName("P1");
msg1.setResourceName("R1");
msg1.setTgtName("Localhost_1123");
msg1.setSrcName("127.101.1.23_2234");
msg1.setFromState("SLAVE");
msg1.setToState("MASTER");
msgList.add(msg1);
Message msg2 = new Message(Message.MessageType.STATE_TRANSITION_CANCELLATION, UUID.randomUUID().toString());
msg2.setTgtSessionId("*");
msg2.setPartitionName("P1");
msg2.setResourceName("R1");
msg2.setTgtName("Localhost_1123");
msg2.setSrcName("127.101.1.23_2234");
msg2.setFromState("SLAVE");
msg2.setToState("MASTER");
msgList.add(msg2);
changeContext.setChangeType(HelixConstants.ChangeType.MESSAGE);
executor.onMessage("someInstance", msgList, changeContext);
Thread.sleep(3000);
AssertJUnit.assertEquals(cancelFactory._processedMsgIds.size(), 0);
AssertJUnit.assertEquals(stateTransitionFactory._processedMsgIds.size(), 0);
}
示例10: testInvocationAnnotated
import org.apache.helix.model.Message; //导入方法依赖的package包/类
@Test()
public void testInvocationAnnotated() throws Exception {
System.out.println("START TestCMTaskHandler.testInvocationAnnotated() at "
+ new Date(System.currentTimeMillis()));
HelixTaskExecutor executor = new HelixTaskExecutor();
Message message = new Message(MessageType.STATE_TRANSITION, "Some unique id");
message.setSrcName("cm-instance-0");
message.setTgtSessionId("1234");
message.setFromState("Offline");
message.setToState("Slave");
message.setPartitionName("TestDB_0");
message.setMsgId("Some unique message id");
message.setResourceName("TestDB");
message.setTgtName("localhost");
message.setStateModelDef("MasterSlave");
message.setStateModelFactoryName(HelixConstants.DEFAULT_STATE_MODEL_FACTORY);
MockStateModelAnnotated stateModel = new MockStateModelAnnotated();
NotificationContext context;
MockManager manager = new MockManager("clusterName");
HelixDataAccessor accessor = manager.getHelixDataAccessor();
StateModelDefinition stateModelDef =
new StateModelDefinition(StateModelConfigGenerator.generateConfigForMasterSlave());
Builder keyBuilder = accessor.keyBuilder();
accessor.setProperty(keyBuilder.stateModelDef("MasterSlave"), stateModelDef);
context = new NotificationContext(manager);
CurrentState currentStateDelta = new CurrentState("TestDB");
currentStateDelta.setState("TestDB_0", "OFFLINE");
StateModelFactory<MockStateModelAnnotated> stateModelFactory =
new StateModelFactory<MockStateModelAnnotated>() {
@Override
public MockStateModelAnnotated createNewStateModel(String resource, String partitionName) {
// TODO Auto-generated method stub
return new MockStateModelAnnotated();
}
};
HelixStateTransitionHandler stHandler =
new HelixStateTransitionHandler(stateModelFactory, stateModel, message, context,
currentStateDelta);
HelixTask handler = new HelixTask(message, context, stHandler, executor);
handler.call();
AssertJUnit.assertTrue(stateModel.stateModelInvoked);
System.out.println("END TestCMTaskHandler.testInvocationAnnotated() at "
+ new Date(System.currentTimeMillis()));
}