org.rx.net.nameserver.Nameserver Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of rxlib Show documentation
Show all versions of rxlib Show documentation
A set of utilities for Java
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() {
}
}