本文整理汇总了Java中org.apache.helix.model.Message.setTgtName方法的典型用法代码示例。如果您正苦于以下问题:Java Message.setTgtName方法的具体用法?Java Message.setTgtName怎么用?Java Message.setTgtName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.helix.model.Message
的用法示例。
在下文中一共展示了Message.setTgtName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendNopMessage
import org.apache.helix.model.Message; //导入方法依赖的package包/类
private void sendNopMessage() {
if (_manager.isConnected()) {
try {
Message nopMsg = new Message(MessageType.NO_OP, UUID.randomUUID().toString());
nopMsg.setSrcName(_manager.getInstanceName());
HelixDataAccessor accessor = _manager.getHelixDataAccessor();
Builder keyBuilder = accessor.keyBuilder();
if (_manager.getInstanceType() == InstanceType.CONTROLLER
|| _manager.getInstanceType() == InstanceType.CONTROLLER_PARTICIPANT) {
nopMsg.setTgtName(InstanceType.CONTROLLER.name());
accessor.setProperty(keyBuilder.controllerMessage(nopMsg.getId()), nopMsg);
}
if (_manager.getInstanceType() == InstanceType.PARTICIPANT
|| _manager.getInstanceType() == InstanceType.CONTROLLER_PARTICIPANT) {
nopMsg.setTgtName(_manager.getInstanceName());
accessor.setProperty(keyBuilder.message(nopMsg.getTgtName(), nopMsg.getId()), nopMsg);
}
logger.info("Send NO_OP message to " + nopMsg.getTgtName() + ", msgId: " + nopMsg.getId());
} catch (Exception e) {
logger.error(e.toString());
}
}
}
示例2: sendMessage
import org.apache.helix.model.Message; //导入方法依赖的package包/类
void sendMessage(String msgId, String instanceName, String fromState, String toState,
String partitionKey, int partitionId) throws InterruptedException, JsonGenerationException,
JsonMappingException, IOException {
Message message = new Message(MessageType.STATE_TRANSITION, msgId);
message.setMsgId(msgId);
message.setSrcName(srcName);
message.setTgtName(instanceName);
message.setMsgState(MessageState.NEW);
message.setFromState(fromState);
message.setToState(toState);
// message.setPartitionId(partitionId);
message.setPartitionName(partitionKey);
String path = PropertyPathBuilder.instanceMessage(clusterName, instanceName, message.getId());
ObjectMapper mapper = new ObjectMapper();
StringWriter sw = new StringWriter();
mapper.writeValueUsingView(sw, message, Message.class);
System.out.println(sw.toString());
client.delete(path);
Thread.sleep(10000);
ZNRecord record = client.readData(PropertyPathBuilder.liveInstance(clusterName, instanceName));
message.setTgtSessionId(record.getSimpleField(LiveInstanceProperty.SESSION_ID.toString())
.toString());
client.createPersistent(path, message);
}
示例3: 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;
}
示例4: generateMessagesForController
import org.apache.helix.model.Message; //导入方法依赖的package包/类
private List<Message> generateMessagesForController(Message message) {
List<Message> messages = new ArrayList<Message>();
String id = UUID.randomUUID().toString();
Message newMessage = new Message(message.getRecord(), id);
newMessage.setMsgId(id);
newMessage.setSrcName(_manager.getInstanceName());
newMessage.setTgtName("Controller");
messages.add(newMessage);
return messages;
}
示例5: 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;
}
示例6: testNoRetry
import org.apache.helix.model.Message; //导入方法依赖的package包/类
@Test()
public void testNoRetry() throws InterruptedException {
// String p = "test_";
// System.out.println(p.substring(p.lastIndexOf('_')+1));
HelixTaskExecutor executor = new HelixTaskExecutor();
HelixManager manager = new MockClusterManager();
CancellableHandlerFactory factory = new CancellableHandlerFactory();
for (String type : factory.getMessageTypes()) {
executor.registerMessageHandlerFactory(type, factory);
}
NotificationContext changeContext = new NotificationContext(manager);
List<Message> msgList = new ArrayList<Message>();
int nMsgs2 = 4;
// Test the case in which retry = 0
for (int i = 0; i < nMsgs2; i++) {
Message msg = new Message(factory.getMessageTypes().get(0), UUID.randomUUID().toString());
msg.setTgtSessionId("*");
msg.setTgtName("Localhost_1123");
msg.setSrcName("127.101.1.23_2234");
msg.setExecutionTimeout((i + 1) * 600);
msgList.add(msg);
}
changeContext.setChangeType(HelixConstants.ChangeType.MESSAGE);
executor.onMessage("someInstance", msgList, changeContext);
Thread.sleep(4000);
AssertJUnit.assertTrue(factory._handlersCreated == nMsgs2);
AssertJUnit.assertEquals(factory._timedOutMsgIds.size(), 2);
// AssertJUnit.assertFalse(msgList.get(0).getRecord().getSimpleFields().containsKey("TimeOut"));
for (int i = 0; i < nMsgs2 - 2; i++) {
if (factory.getMessageTypes().contains(msgList.get(i).getMsgType())) {
AssertJUnit.assertTrue(msgList.get(i).getRecord().getSimpleFields()
.containsKey("Cancelcount"));
AssertJUnit.assertTrue(factory._timedOutMsgIds.containsKey(msgList.get(i).getId()));
}
}
}
示例7: testRetryOnce
import org.apache.helix.model.Message; //导入方法依赖的package包/类
@Test()
public void testRetryOnce() throws InterruptedException {
// Logger.getRootLogger().setLevel(Level.INFO);
// String p = "test_";
// System.out.println(p.substring(p.lastIndexOf('_')+1));
HelixTaskExecutor executor = new HelixTaskExecutor();
HelixManager manager = new MockClusterManager();
CancellableHandlerFactory factory = new CancellableHandlerFactory();
for (String type : factory.getMessageTypes()) {
executor.registerMessageHandlerFactory(type, factory);
}
NotificationContext changeContext = new NotificationContext(manager);
List<Message> msgList = new ArrayList<Message>();
// factory.reset();
// msgList.clear();
// Test the case that the message are executed for the second time
int nMsgs2 = 4;
for (int i = 0; i < nMsgs2; i++) {
Message msg = new Message(factory.getMessageTypes().get(0), UUID.randomUUID().toString());
msg.setTgtSessionId("*");
msg.setTgtName("Localhost_1123");
msg.setSrcName("127.101.1.23_2234");
msg.setExecutionTimeout((i + 1) * 600);
msg.setRetryCount(1);
msgList.add(msg);
}
changeContext.setChangeType(HelixConstants.ChangeType.MESSAGE);
executor.onMessage("someInstance", msgList, changeContext);
Thread.sleep(3500);
AssertJUnit.assertEquals(factory._processedMsgIds.size(), 3);
AssertJUnit.assertTrue(msgList.get(0).getRecord().getSimpleField("Cancelcount").equals("2"));
AssertJUnit.assertTrue(msgList.get(1).getRecord().getSimpleField("Cancelcount").equals("1"));
AssertJUnit.assertEquals(factory._timedOutMsgIds.size(), 2);
AssertJUnit.assertTrue(executor._taskMap.size() == 0);
}
示例8: createMessage
import org.apache.helix.model.Message; //导入方法依赖的package包/类
protected Message createMessage(MessageType type, String msgId, String fromState, String toState,
String resourceName, String tgtName) {
Message msg = new Message(type.toString(), msgId);
msg.setFromState(fromState);
msg.setToState(toState);
msg.getRecord().setSimpleField(Attributes.RESOURCE_NAME.toString(), resourceName);
msg.setTgtName(tgtName);
return msg;
}
示例9: post
import org.apache.helix.model.Message; //导入方法依赖的package包/类
public void post(String zkServer, Message message, String clusterName, String instanceName) {
ZkClient client = new ZkClient(zkServer);
client.setZkSerializer(new ZNRecordSerializer());
String path = PropertyPathBuilder.instanceMessage(clusterName, instanceName, message.getId());
client.delete(path);
ZNRecord record = client.readData(PropertyPathBuilder.liveInstance(clusterName, instanceName));
message.setTgtSessionId(record.getSimpleField(LiveInstanceProperty.SESSION_ID.toString()));
message.setTgtName(record.getId());
// System.out.println(message);
client.createPersistent(path, message.getRecord());
}
示例10: postTestMessage
import org.apache.helix.model.Message; //导入方法依赖的package包/类
public void postTestMessage(String zkServer, String clusterName, String instanceName) {
String msgSrc = "cm-instance-0";
String msgId = "TestMessageId-2";
Message message = new Message(MessageType.STATE_TRANSITION, msgId);
message.setMsgId(msgId);
message.setSrcName(msgSrc);
message.setTgtName(instanceName);
message.setMsgState(MessageState.NEW);
message.setFromState("Slave");
message.setToState("Master");
message.setPartitionName("EspressoDB.partition-0." + instanceName);
post(zkServer, message, clusterName, instanceName);
}
示例11: 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()));
}
示例12: testOnBecomeStandbyFromLeader
import org.apache.helix.model.Message; //导入方法依赖的package包/类
@Test()
public void testOnBecomeStandbyFromLeader() {
Message message = new Message(MessageType.STATE_TRANSITION, "0");
message.setPartitionName(clusterName);
message.setTgtName("controller_0");
stateModel.onBecomeStandbyFromLeader(message, new NotificationContext(null));
}
示例13: testReset
import org.apache.helix.model.Message; //导入方法依赖的package包/类
@Test()
public void testReset() {
Message message = new Message(MessageType.STATE_TRANSITION, "0");
message.setPartitionName(clusterName);
message.setTgtName("controller_0");
try {
stateModel.onBecomeLeaderFromStandby(message, new NotificationContext(null));
} catch (Exception e) {
LOG.error("Exception becoming leader from standby", e);
}
stateModel.reset();
}
示例14: 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;
}
示例15: newMsg
import org.apache.helix.model.Message; //导入方法依赖的package包/类
private static Message newMsg() {
Message msg = new Message(DUMMY_MSG_TYPE, UUID.randomUUID().toString());
msg.setTgtSessionId("*");
msg.setTgtName("localhost_12918");
return msg;
}