Search in sources :

Example 1 with HeartEvent

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();
}
Also used : HeartEvent(com.alibaba.otter.shared.communication.core.model.heart.HeartEvent) Test(org.testng.annotations.Test)

Example 2 with HeartEvent

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);
    }
}
Also used : HeartEvent(com.alibaba.otter.shared.communication.core.model.heart.HeartEvent) CommunicationException(com.alibaba.otter.shared.communication.core.exception.CommunicationException) Event(com.alibaba.otter.shared.communication.core.model.Event) HeartEvent(com.alibaba.otter.shared.communication.core.model.heart.HeartEvent) Method(java.lang.reflect.Method) CommunicationException(com.alibaba.otter.shared.communication.core.exception.CommunicationException)

Example 3 with HeartEvent

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();
}
Also used : CommunicationConnection(com.alibaba.otter.shared.communication.core.impl.connection.CommunicationConnection) HeartEvent(com.alibaba.otter.shared.communication.core.model.heart.HeartEvent) CommunicationParam(com.alibaba.otter.shared.communication.core.model.CommunicationParam) RmiCommunicationConnectionFactory(com.alibaba.otter.shared.communication.core.impl.rmi.RmiCommunicationConnectionFactory) RmiCommunicationConnectionFactory(com.alibaba.otter.shared.communication.core.impl.rmi.RmiCommunicationConnectionFactory) CommunicationConnectionFactory(com.alibaba.otter.shared.communication.core.impl.connection.CommunicationConnectionFactory) Test(org.testng.annotations.Test)

Example 4 with HeartEvent

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();
}
Also used : HeartEvent(com.alibaba.otter.shared.communication.core.model.heart.HeartEvent) Test(org.testng.annotations.Test)

Example 5 with HeartEvent

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();
}
Also used : HeartEvent(com.alibaba.otter.shared.communication.core.model.heart.HeartEvent) Test(org.testng.annotations.Test)

Aggregations

HeartEvent (com.alibaba.otter.shared.communication.core.model.heart.HeartEvent)6 Test (org.testng.annotations.Test)5 CommunicationConnection (com.alibaba.otter.shared.communication.core.impl.connection.CommunicationConnection)2 CommunicationConnectionFactory (com.alibaba.otter.shared.communication.core.impl.connection.CommunicationConnectionFactory)2 CommunicationParam (com.alibaba.otter.shared.communication.core.model.CommunicationParam)2 CommunicationException (com.alibaba.otter.shared.communication.core.exception.CommunicationException)1 DubboCommunicationConnectionFactory (com.alibaba.otter.shared.communication.core.impl.dubbo.DubboCommunicationConnectionFactory)1 RmiCommunicationConnectionFactory (com.alibaba.otter.shared.communication.core.impl.rmi.RmiCommunicationConnectionFactory)1 Event (com.alibaba.otter.shared.communication.core.model.Event)1 Method (java.lang.reflect.Method)1