Search in sources :

Example 1 with ApplicationOfflineException

use of info.xiancloud.core.distribution.exception.ApplicationOfflineException in project xian by happyyangyuan.

the class ApplicationRouter method firstInstance.

@Override
public ApplicationInstance firstInstance(String application) throws ApplicationOfflineException, ApplicationUndefinedException {
    ApplicationInstance instance = localInstance(application);
    if (instance != null)
        return instance;
    newestDefinition(application);
    if (ApplicationDiscovery.singleton != null)
        instance = ApplicationDiscovery.singleton.firstInstance(application);
    if (instance != null)
        return instance;
    throw new ApplicationOfflineException(application);
}
Also used : ApplicationInstance(info.xiancloud.core.distribution.service_discovery.ApplicationInstance) ApplicationOfflineException(info.xiancloud.core.distribution.exception.ApplicationOfflineException)

Example 2 with ApplicationOfflineException

use of info.xiancloud.core.distribution.exception.ApplicationOfflineException in project xian by happyyangyuan.

the class ApplicationRouter method loadBalancedInstance.

public ApplicationInstance loadBalancedInstance(String application) throws ApplicationOfflineException, ApplicationUndefinedException {
    ApplicationInstance instance = localInstance(application);
    if (instance != null)
        return instance;
    newestDefinition(application);
    if (ApplicationDiscovery.singleton != null)
        instance = ApplicationDiscovery.singleton.lb(application);
    if (instance != null)
        return instance;
    throw new ApplicationOfflineException(application);
}
Also used : ApplicationInstance(info.xiancloud.core.distribution.service_discovery.ApplicationInstance) ApplicationOfflineException(info.xiancloud.core.distribution.exception.ApplicationOfflineException)

Example 3 with ApplicationOfflineException

use of info.xiancloud.core.distribution.exception.ApplicationOfflineException in project xian by happyyangyuan.

the class ApplicationRouter method allInstances.

/**
 * @return 根据目标获取相应的客户端列表, 目前本方法主要提供一致性哈希节点id列表入参;
 */
public List<ApplicationInstance> allInstances(String application) throws ApplicationOfflineException, ApplicationUndefinedException {
    newestDefinition(application);
    List<ApplicationInstance> instances;
    if (ApplicationDiscovery.singleton != null)
        instances = ApplicationDiscovery.singleton.all(application);
    else {
        instances = new ArrayList<>();
        instances.add(localInstance(application));
    }
    if (instances.isEmpty())
        throw new ApplicationOfflineException(application);
    /*instances.sort(Comparator.comparing(ApplicationInstance::getNodeId));
        we do not sort this any more, if you want to use the consistent hash, sort by yourself.*/
    return instances;
}
Also used : ApplicationInstance(info.xiancloud.core.distribution.service_discovery.ApplicationInstance) ApplicationOfflineException(info.xiancloud.core.distribution.exception.ApplicationOfflineException)

Aggregations

ApplicationOfflineException (info.xiancloud.core.distribution.exception.ApplicationOfflineException)3 ApplicationInstance (info.xiancloud.core.distribution.service_discovery.ApplicationInstance)3