将RegistryManager改名为RegistryCenter,删除RegistryCenter中没有使用的API,以及完成RegistryCenter的切换center的功能
This commit is contained in:
parent
715effc177
commit
25dbe41aee
|
|
@ -0,0 +1,9 @@
|
|||
package com.a.eye.skywalking.registry.api;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ElementType.TYPE})
|
||||
public @interface Center {
|
||||
CenterType type() default CenterType.zookeeper;
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
package com.a.eye.skywalking.registry.api;
|
||||
|
||||
/**
|
||||
* Created by xin on 2016/11/10.
|
||||
*/
|
||||
public enum CenterType {
|
||||
zookeeper("zookeeper");
|
||||
|
||||
private String type;
|
||||
|
||||
CenterType(String typeStr) {
|
||||
this.type = typeStr;
|
||||
}
|
||||
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
|
|
@ -3,5 +3,5 @@ package com.a.eye.skywalking.registry.api;
|
|||
import java.util.List;
|
||||
|
||||
public interface NotifyListener {
|
||||
void notify(List<RegistryData> urls);
|
||||
void notify(List<String> urls);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,26 @@
|
|||
package com.a.eye.skywalking.registry.api;
|
||||
|
||||
/**
|
||||
* 主要用于注册中心的维护
|
||||
*/
|
||||
public interface RegistryCenter {
|
||||
|
||||
/**
|
||||
* 主要用于storage启动注册使用,将自身IP和端口注册到注册中心
|
||||
* 格式为:
|
||||
* /storage_list/192.168.0.1:3400 NULL
|
||||
*
|
||||
* @param path
|
||||
*/
|
||||
void register(String path);
|
||||
|
||||
/**
|
||||
* 主要用于routing节点在启动完成之后,读取和监听stroage节点列表
|
||||
* 格式
|
||||
*
|
||||
* @param path
|
||||
* @param listener
|
||||
*/
|
||||
void subscribe(String path, NotifyListener listener);
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
package com.a.eye.skywalking.registry.api;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.ServiceLoader;
|
||||
|
||||
/**
|
||||
* Created by xin on 2016/11/10.
|
||||
*/
|
||||
public class RegistryCenterFactory {
|
||||
|
||||
private Map<CenterType, RegistryCenter> registryCenter = new HashMap<CenterType, RegistryCenter>();
|
||||
|
||||
private RegistryCenterFactory() {
|
||||
ServiceLoader<RegistryCenter> loaders = ServiceLoader.load(RegistryCenter.class);
|
||||
Iterator<RegistryCenter> iterator = loaders.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
RegistryCenter center = iterator.next();
|
||||
Center centerInfo = center.getClass().getAnnotation(Center.class);
|
||||
if (centerInfo == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
registryCenter.put(centerInfo.type(), center);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public RegistryCenter getRegistryCenter(CenterType type) {
|
||||
return registryCenter.get(type);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
package com.a.eye.skywalking.registry.api;
|
||||
|
||||
/**
|
||||
* 存储注册项的数据
|
||||
* 注册项包括:注册的目录(支持多级,以"/"分割)以及注册值
|
||||
*/
|
||||
public interface RegistryData {
|
||||
|
||||
String getPath();
|
||||
|
||||
String getValue();
|
||||
}
|
||||
|
|
@ -1,40 +0,0 @@
|
|||
package com.a.eye.skywalking.registry.api;
|
||||
|
||||
/**
|
||||
* 主要用于注册中心的维护
|
||||
*/
|
||||
public interface RegistryManager {
|
||||
|
||||
/**
|
||||
* 主要用于storage启动注册使用,将自身IP和端口注册到注册中心
|
||||
* 格式为:
|
||||
* /storage_list/192.168.0.1:3400 NULL
|
||||
*
|
||||
* @param data
|
||||
*/
|
||||
void register(RegistryData data);
|
||||
|
||||
/**
|
||||
* 从注册中心移除storage宕机节点
|
||||
*
|
||||
* @param data
|
||||
*/
|
||||
void unregister(RegistryData data);
|
||||
|
||||
/**
|
||||
* 主要用于routing节点在启动完成之后,读取和监听stroage节点列表
|
||||
* 格式
|
||||
*
|
||||
* @param data
|
||||
* @param listener
|
||||
*/
|
||||
void subscribe(RegistryData data, NotifyListener listener);
|
||||
|
||||
/**
|
||||
* 移除storage节点监听
|
||||
*
|
||||
* @param data
|
||||
*/
|
||||
void unsubscribe(RegistryData data);
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue