com.nepxion.discovery.plugin.framework.adapter.ZookeeperAdapter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of discovery-plugin-framework-zookeeper Show documentation
Show all versions of discovery-plugin-framework-zookeeper Show documentation
Nepxion Discovery is an enhancement for Spring Cloud Discovery
package com.nepxion.discovery.plugin.framework.adapter;
/**
* Title: Nepxion Discovery
* Description: Nepxion Discovery
* Copyright: Copyright (c) 2017-2050
* Company: Nepxion
* @author Haojun Ren
* @version 1.0
*/
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.serviceregistry.Registration;
import org.springframework.cloud.zookeeper.discovery.ZookeeperServer;
import org.springframework.cloud.zookeeper.serviceregistry.ZookeeperRegistration;
import org.springframework.core.env.ConfigurableEnvironment;
import com.nepxion.discovery.plugin.framework.constant.PluginConstant;
import com.nepxion.discovery.plugin.framework.constant.ZookeeperConstant;
import com.nepxion.discovery.plugin.framework.exception.PluginException;
import com.netflix.loadbalancer.Server;
public class ZookeeperAdapter extends AbstractPluginAdapter {
@Autowired
private ConfigurableEnvironment environment;
@Override
public String getIpAddress(Registration registration) {
if (registration instanceof ZookeeperRegistration) {
ZookeeperRegistration zookeeperRegistration = (ZookeeperRegistration) registration;
return zookeeperRegistration.getServiceInstance().getAddress();
}
throw new PluginException("Registration instance isn't the type of ZookeeperRegistration");
}
@Override
public int getPort(Registration registration) {
if (registration instanceof ZookeeperRegistration) {
ZookeeperRegistration zookeeperRegistration = (ZookeeperRegistration) registration;
return zookeeperRegistration.getServiceInstance().getPort();
}
throw new PluginException("Registration instance isn't the type of ZookeeperRegistration");
}
@Override
public String getServerVersion(Server server) {
if (server instanceof ZookeeperServer) {
ZookeeperServer zookeeperServer = (ZookeeperServer) server;
return zookeeperServer.getInstance().getPayload().getMetadata().get(PluginConstant.VERSION);
}
throw new PluginException("Server instance isn't the type of ZookeeperServer");
}
@Override
public String getLocalVersion() {
return environment.getProperty(ZookeeperConstant.METADATA_VERSION);
}
}