Search in sources :

Example 6 with HostPort

use of rpc.turbo.config.HostPort in project turbo-rpc by hank-whu.

the class App method kill.

/**
 * 干掉有问题的连接
 *
 * @param connectorContext
 */
private synchronized void kill(ConnectorContext connectorContext) {
    if (connectorContext == null) {
        return;
    }
    HostPort serverAddress = connectorContext.serverAddress;
    if (logger.isWarnEnabled()) {
        logger.warn(group + "#" + app + " " + serverAddress + " is zombie, and will be killed!");
    }
    activeMap.remove(serverAddress);
    zombieMap.put(serverAddress, connectorContext);
    Collection<ConnectorContext> connectors = activeMap.values();
    int length = methodRouterMap.size();
    for (int i = 0; i < length; i++) {
        MethodRouter router = methodRouterMap.get(i);
        if (!connectorContext.isSupport(router.getServiceMethodName())) {
            continue;
        }
        router.setConnectors(connectors);
    }
    if (logger.isWarnEnabled()) {
        logger.warn(group + "#" + app + " " + serverAddress + " is zombie, and have been killed!");
    }
}
Also used : HostPort(rpc.turbo.config.HostPort)

Example 7 with HostPort

use of rpc.turbo.config.HostPort in project turbo-rpc by hank-whu.

the class App method heartbeat.

private void heartbeat() {
    if (isCloseing) {
        return;
    }
    if (logger.isDebugEnabled()) {
        logger.debug(group + "#" + app + " start heartbeat");
    }
    // 
    activeMap.entrySet().stream().parallel().forEach(kv -> {
        if (isCloseing) {
            return;
        }
        HostPort serverAddress = kv.getKey();
        ConnectorContext context = kv.getValue();
        if (!context.heartbeat()) {
            activeMap.remove(serverAddress);
            zombieMap.put(serverAddress, context);
            if (logger.isInfoEnabled()) {
                logger.info(group + "#" + app + " " + serverAddress + " is zombie");
            }
        } else {
            if (logger.isDebugEnabled()) {
                logger.debug(group + "#" + app + " " + serverAddress + " is active");
            }
        }
    });
}
Also used : HostPort(rpc.turbo.config.HostPort)

Example 8 with HostPort

use of rpc.turbo.config.HostPort in project turbo-rpc by hank-whu.

the class App method addConnect.

private synchronized void addConnect(ConnectorContext context) throws Exception {
    if (isCloseing) {
        return;
    }
    if (context == null) {
        return;
    }
    HostPort serverAddress = context.serverAddress;
    activeMap.put(serverAddress, context);
    zombieMap.remove(serverAddress);
}
Also used : HostPort(rpc.turbo.config.HostPort)

Example 9 with HostPort

use of rpc.turbo.config.HostPort in project turbo-rpc by hank-whu.

the class NettyRpcServerHandler method channelActive.

@Override
public void channelActive(ChannelHandlerContext ctx) throws Exception {
    super.channelActive(ctx);
    if (logger.isInfoEnabled()) {
        logger.info("channelActive: " + ctx.channel());
    }
    InetSocketAddress insocket = (InetSocketAddress) ctx.channel().remoteAddress();
    clientAddress = new HostPort(insocket.getAddress().getHostAddress(), 0);
    insocket = (InetSocketAddress) ctx.channel().localAddress();
    serverAddress = new HostPort(insocket.getAddress().getHostAddress(), insocket.getPort());
}
Also used : InetSocketAddress(java.net.InetSocketAddress) HostPort(rpc.turbo.config.HostPort)

Example 10 with HostPort

use of rpc.turbo.config.HostPort in project turbo-rpc by hank-whu.

the class ZooKeeperDiscover method init.

@Override
public void init(List<HostPort> hostPorts) {
    watchers = new ConcurrentArrayList<>();
    String connectString = hostPorts.stream().map(i -> i.toString()).collect(Collectors.joining(","));
    RetryPolicy retryPolicy = new ForeverRetryPolicy(1000, 60 * 1000);
    client = CuratorFrameworkFactory.newClient(connectString, 1000 * 10, 1000 * 3, retryPolicy);
    client.start();
}
Also used : CuratorFrameworkFactory(org.apache.curator.framework.CuratorFrameworkFactory) Discover(rpc.turbo.discover.Discover) ConcurrentArrayList(rpc.turbo.util.concurrent.ConcurrentArrayList) IOException(java.io.IOException) Protocol(rpc.turbo.config.server.Protocol) Collectors(java.util.stream.Collectors) PathChildrenCacheListener(org.apache.curator.framework.recipes.cache.PathChildrenCacheListener) AddressWithWeight(rpc.turbo.config.AddressWithWeight) StartMode(org.apache.curator.framework.recipes.cache.PathChildrenCache.StartMode) ForeverRetryPolicy(rpc.turbo.zk.common.ForeverRetryPolicy) ConcurrentMap(java.util.concurrent.ConcurrentMap) Objects(java.util.Objects) List(java.util.List) CuratorFramework(org.apache.curator.framework.CuratorFramework) HostPort(rpc.turbo.config.HostPort) DiscoverListener(rpc.turbo.discover.DiscoverListener) RetryPolicy(org.apache.curator.RetryPolicy) PathChildrenCacheEvent(org.apache.curator.framework.recipes.cache.PathChildrenCacheEvent) PathChildrenCache(org.apache.curator.framework.recipes.cache.PathChildrenCache) Log(org.apache.commons.logging.Log) LogFactory(org.apache.commons.logging.LogFactory) ConcurrentHashMap(org.jboss.netty.util.internal.ConcurrentHashMap) ForeverRetryPolicy(rpc.turbo.zk.common.ForeverRetryPolicy) ForeverRetryPolicy(rpc.turbo.zk.common.ForeverRetryPolicy) RetryPolicy(org.apache.curator.RetryPolicy)

Aggregations

HostPort (rpc.turbo.config.HostPort)14 List (java.util.List)6 Collectors (java.util.stream.Collectors)6 IOException (java.io.IOException)5 InetSocketAddress (java.net.InetSocketAddress)4 Config (com.typesafe.config.Config)3 Log (org.apache.commons.logging.Log)3 LogFactory (org.apache.commons.logging.LogFactory)3 TurboService (rpc.turbo.annotation.TurboService)3 ConfigUtils.getStringOrElse (rpc.turbo.config.ConfigUtils.getStringOrElse)3 Protocol (rpc.turbo.config.server.Protocol)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Map (java.util.Map)2 Objects (java.util.Objects)2 ConcurrentMap (java.util.concurrent.ConcurrentMap)2 ExecutionException (java.util.concurrent.ExecutionException)2 RetryPolicy (org.apache.curator.RetryPolicy)2 CuratorFramework (org.apache.curator.framework.CuratorFramework)2 CuratorFrameworkFactory (org.apache.curator.framework.CuratorFrameworkFactory)2 PathChildrenCache (org.apache.curator.framework.recipes.cache.PathChildrenCache)2