Search in sources :

Example 6 with ApplicationInstance

use of info.xiancloud.core.distribution.service_discovery.ApplicationInstance 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 7 with ApplicationInstance

use of info.xiancloud.core.distribution.service_discovery.ApplicationInstance 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 8 with ApplicationInstance

use of info.xiancloud.core.distribution.service_discovery.ApplicationInstance 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

ApplicationInstance (info.xiancloud.core.distribution.service_discovery.ApplicationInstance)8 JSONObject (com.alibaba.fastjson.JSONObject)3 ApplicationOfflineException (info.xiancloud.core.distribution.exception.ApplicationOfflineException)3 JSONArray (com.alibaba.fastjson.JSONArray)2 ApplicationUndefinedException (info.xiancloud.core.distribution.exception.ApplicationUndefinedException)2 List (java.util.List)2 ApplicationInstanceOfflineException (info.xiancloud.core.distribution.exception.ApplicationInstanceOfflineException)1 Bootstrap (io.netty.bootstrap.Bootstrap)1 Channel (io.netty.channel.Channel)1 EventLoopGroup (io.netty.channel.EventLoopGroup)1 WriteBufferWaterMark (io.netty.channel.WriteBufferWaterMark)1 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)1 NioSocketChannel (io.netty.channel.socket.nio.NioSocketChannel)1 SslContext (io.netty.handler.ssl.SslContext)1