Search in sources :

Example 1 with CommunicationException

use of com.alibaba.otter.shared.communication.core.exception.CommunicationException in project otter by alibaba.

the class ArbitrateCommmunicationClient method callManager.

/**
     * 指定manager,进行event调用
     */
public Object callManager(final Event event) {
    CommunicationException ex = null;
    for (int i = index; i < index + managerAddress.size(); i++) {
        String address = managerAddress.get(i % managerAddress.size());
        try {
            Object result = delegate.call(address, event);
            index = i;
            return result;
        } catch (CommunicationException e) {
            ex = e;
            logger.warn("call manager [{}] event [{}] failed, maybe can try another manager.", address, event);
        }
    }
    throw ex;
}
Also used : CommunicationException(com.alibaba.otter.shared.communication.core.exception.CommunicationException)

Example 2 with CommunicationException

use of com.alibaba.otter.shared.communication.core.exception.CommunicationException in project otter by alibaba.

the class RmiCommunicationEndpoint method initial.

public void initial() {
    export = new RmiServiceExporter();
    export.setServiceName("endpoint");
    // 暴露自己
    export.setService(this);
    export.setServiceInterface(CommunicationEndpoint.class);
    export.setRegistryHost(host);
    export.setRegistryPort(port);
    // 强制创建一个
    export.setAlwaysCreateRegistry(alwaysCreateRegistry);
    try {
        export.afterPropertiesSet();
    } catch (RemoteException e) {
        throw new CommunicationException("Rmi_Create_Error", e);
    }
}
Also used : CommunicationException(com.alibaba.otter.shared.communication.core.exception.CommunicationException) RmiServiceExporter(org.springframework.remoting.rmi.RmiServiceExporter) RemoteException(java.rmi.RemoteException)

Example 3 with CommunicationException

use of com.alibaba.otter.shared.communication.core.exception.CommunicationException in project otter by alibaba.

the class DefaultCommunicationClientImpl method buildParams.

// ===================== helper method ==================
private CommunicationParam buildParams(String addr) {
    CommunicationParam params = new CommunicationParam();
    String[] strs = StringUtils.split(addr, ":");
    if (strs == null || strs.length != 2) {
        throw new IllegalArgumentException("addr example: 127.0.0.1:1099");
    }
    InetAddress address = null;
    try {
        address = InetAddress.getByName(strs[0]);
    } catch (UnknownHostException e) {
        throw new CommunicationException("addr_error", "addr[" + addr + "] is unknow!");
    }
    params.setIp(address.getHostAddress());
    params.setPort(Integer.valueOf(strs[1]));
    return params;
}
Also used : CommunicationParam(com.alibaba.otter.shared.communication.core.model.CommunicationParam) UnknownHostException(java.net.UnknownHostException) CommunicationException(com.alibaba.otter.shared.communication.core.exception.CommunicationException) InetAddress(java.net.InetAddress)

Example 4 with CommunicationException

use of com.alibaba.otter.shared.communication.core.exception.CommunicationException in project otter by alibaba.

the class NodeCommmunicationClient method callManager.

/**
     * 指定manager,进行event调用
     */
public Object callManager(final Event event) {
    CommunicationException ex = null;
    Object object = null;
    for (int i = index; i < index + managerAddress.size(); i++) {
        // 循环一次manager的所有地址
        String address = managerAddress.get(i % managerAddress.size());
        try {
            object = delegate.call(address, event);
            // 更新一下上一次成功的地址
            index = i;
            return object;
        } catch (CommunicationException e) {
            // retry next address;
            ex = e;
        }
    }
    // 走到这一步,说明肯定有出错了
    throw ex;
}
Also used : CommunicationException(com.alibaba.otter.shared.communication.core.exception.CommunicationException)

Example 5 with CommunicationException

use of com.alibaba.otter.shared.communication.core.exception.CommunicationException in project otter by alibaba.

the class CanalCommmunicationClient method callManager.

/**
     * 指定manager,进行event调用
     */
public Object callManager(final Event event) {
    CommunicationException ex = null;
    Object object = null;
    for (int i = index; i < index + managerAddress.size(); i++) {
        // 循环一次manager的所有地址
        String address = managerAddress.get(i % managerAddress.size());
        try {
            object = delegate.call(address, event);
            // 更新一下上一次成功的地址
            index = i;
            return object;
        } catch (CommunicationException e) {
            // retry next address;
            ex = e;
        }
    }
    // 走到这一步,说明肯定有出错了
    throw ex;
}
Also used : CommunicationException(com.alibaba.otter.shared.communication.core.exception.CommunicationException)

Aggregations

CommunicationException (com.alibaba.otter.shared.communication.core.exception.CommunicationException)8 UnknownHostException (java.net.UnknownHostException)3 CommunicationParam (com.alibaba.otter.shared.communication.core.model.CommunicationParam)2 ExecutionException (java.util.concurrent.ExecutionException)2 CommunicationConnection (com.alibaba.otter.shared.communication.core.impl.connection.CommunicationConnection)1 Event (com.alibaba.otter.shared.communication.core.model.Event)1 HeartEvent (com.alibaba.otter.shared.communication.core.model.heart.HeartEvent)1 Method (java.lang.reflect.Method)1 InetAddress (java.net.InetAddress)1 RemoteException (java.rmi.RemoteException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ExecutorCompletionService (java.util.concurrent.ExecutorCompletionService)1 Future (java.util.concurrent.Future)1 RmiServiceExporter (org.springframework.remoting.rmi.RmiServiceExporter)1