use of com.alibaba.otter.shared.communication.core.model.heart.HeartEvent in project otter by alibaba.
the class CommunicationSpringIntegrateTest method testDubboSingle.
@Test
public void testDubboSingle() {
Object result = dubboCommunicationClient.call("127.0.0.1:2088", new HeartEvent());
want.object(result).notNull();
}
use of com.alibaba.otter.shared.communication.core.model.heart.HeartEvent in project otter by alibaba.
the class AbstractCommunicationEndpoint method acceptEvent.
/**
* 处理指定的事件
*/
public Object acceptEvent(Event event) {
if (event instanceof HeartEvent) {
// 针对心跳请求,返回一个随意结果
return event;
}
try {
Object action = CommunicationRegistry.getAction(event.getType());
if (action != null) {
// 通过反射获取方法并执行
String methodName = "on" + StringUtils.capitalize(event.getType().toString());
Method method = ReflectionUtils.findMethod(action.getClass(), methodName, new Class[] { event.getClass() });
if (method == null) {
// 尝试一下默认方法
methodName = DEFAULT_METHOD;
method = ReflectionUtils.findMethod(action.getClass(), methodName, new Class[] { event.getClass() });
if (method == null) {
// 再尝试一下Event参数
method = ReflectionUtils.findMethod(action.getClass(), methodName, new Class[] { Event.class });
}
}
// 方法不为空就调用指定的方法,反之调用缺省的处理函数
if (method != null) {
try {
ReflectionUtils.makeAccessible(method);
return method.invoke(action, new Object[] { event });
} catch (Throwable e) {
throw new CommunicationException("method_invoke_error:" + methodName, e);
}
} else {
throw new CommunicationException("no_method_error for[" + StringUtils.capitalize(event.getType().toString()) + "] in Class[" + action.getClass().getName() + "]");
}
}
throw new CommunicationException("eventType_no_action", event.getType().name());
} catch (RuntimeException e) {
logger.error("endpoint_error", e);
throw e;
} catch (Exception e) {
logger.error("endpoint_error", e);
throw new CommunicationException(e);
}
}
use of com.alibaba.otter.shared.communication.core.model.heart.HeartEvent in project otter by alibaba.
the class RmiConnectionTest method testSingle.
@Test
public void testSingle() {
CommunicationConnectionFactory factory = new RmiCommunicationConnectionFactory();
CommunicationParam param = new CommunicationParam();
param.setIp("127.0.0.1");
param.setPort(1099);
CommunicationConnection connection = factory.createConnection(param);
Object result = connection.call(new HeartEvent());
want.object(result).notNull();
}
use of com.alibaba.otter.shared.communication.core.model.heart.HeartEvent in project otter by alibaba.
the class CommunicationSpringIntegrateTest method testRmiSingle.
@Test
public void testRmiSingle() {
Object result = rmiCommunicationClient.call("127.0.0.1:1099", new HeartEvent());
want.object(result).notNull();
}
use of com.alibaba.otter.shared.communication.core.model.heart.HeartEvent in project otter by alibaba.
the class CommunicationSpringIntegrateTest method testRmiPool.
@Test
public void testRmiPool() {
Object result = rmiPoolCommunicationClient.call("127.0.0.1:1099", new HeartEvent());
want.object(result).notNull();
}
Aggregations