org.zodiac.loadbalancer.ribbon.discovery.InternalDiscoveryServer Maven / Gradle / Ivy
package org.zodiac.loadbalancer.ribbon.discovery;
import com.netflix.loadbalancer.Server;
import org.zodiac.core.application.AppInstance;
import org.zodiac.core.application.metadata.GenericMetadata;
import java.util.Map;
public class InternalDiscoveryServer extends Server {
final T appInstance;
final MetaInfo metaInfo;
final Map metadata;
public InternalDiscoveryServer(T instance) {
super(instance.getAppHost(), instance.getAppPort());
this.appInstance = instance;
this.metadata = instance.getAppMetadata();
this.metaInfo = new MetaInfo() {
@Override
public String getAppName() {
return instance.getAppServiceId();
}
@Override
public String getServerGroup() {
return instance.getAppMetadata().getOrDefault(GenericMetadata.CLUSTER, "");
}
@Override
public String getServiceIdForDiscovery() {
return instance.getAppServiceId();
}
@Override
public String getInstanceId() {
return instance.getAppInstanceId();
}
};
}
@Override
public MetaInfo getMetaInfo() {
return this.metaInfo;
}
public Map getMetadata() {
return this.metadata;
}
public T getAppInstance(){
return this.appInstance;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof InternalDiscoveryServer)) {
return false;
}
InternalDiscoveryServer svc = (InternalDiscoveryServer) obj;
return svc.getId().equals(this.getId());
}
@Override
public int hashCode() {
return super.hashCode();
}
}