All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.rx.net.nameserver.Nameserver Maven / Gradle / Ivy

There is a newer version: 3.0.0
Show newest version
package org.rx.net.nameserver;

import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.rx.bean.RandomList;
import org.rx.core.EventArgs;
import org.rx.core.EventPublisher;
import org.rx.core.Extends;
import org.rx.core.RxConfig;

import java.io.Serializable;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.util.List;
import java.util.Map;
import java.util.Set;

public interface Nameserver extends EventPublisher, AutoCloseable {
    @Getter
    class AppChangedEventArgs extends EventArgs {
        private static final long serialVersionUID = -398674064775226514L;
        final String appName;
        final InetAddress address;
        final boolean isUp;
        final String instanceId;
        final Map attributes;

        AppChangedEventArgs(String appName, InetAddress address, boolean isUp, Map attributes) {
            this.appName = appName;
            this.address = address;
            this.isUp = isUp;
            this.attributes = attributes;
            this.instanceId = (String) attributes.get(RxConfig.ConfigNames.APP_ID);
        }
    }

    @RequiredArgsConstructor
    @Getter
    class InstanceInfo implements Extends {
        private static final long serialVersionUID = 454367372507105015L;
        final InetAddress address;
        final String instanceId;
        final Map attributes;
    }

    /**
     * return active server endpoints of this nameserver
     */
    String EVENT_CLIENT_SYNC = "CLIENT_SYNC";
    String EVENT_APP_ADDRESS_CHANGED = "APP_ADDRESS_CHANGED";
    String EVENT_APP_ATTRS_CHANGED = "APP_ATTRS_CHANGED";
    String APP_NAME_KEY = "app.name";

    default int register(String appName, Set serverEndpoints) {
        return register(appName, RandomList.DEFAULT_WEIGHT, serverEndpoints);
    }

    /**
     * App register self, then return dns server proxy port
     *
     * @param appName
     * @param weight
     * @return dnsPort
     */
    int register(String appName, int weight, Set serverEndpoints);

    void deregister();

     void attr(String appName, String key, T value);

     T attr(String appName, String key);

     void instanceAttr(String appName, String key, T value);

     T instanceAttr(String appName, String key);

    List discover(String appName);

    List discoverAll(String appName, boolean exceptCurrent);

    List discover(String appName, List instanceAttrKeys);

    List discoverAll(String appName, boolean exceptCurrent, List instanceAttrKeys);

    default void close() {
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy