// Path: trpc-core/src/main/java/com/github/sofn/trpc/core/IRegistry.java
// public interface IRegistry {
// 
//     /**
//      * 注册
//      */
//     void registry(RegistryConfig registryConfig);
// 
//     void modify(RegistryConfig registryConfig);
// 
//     /**
//      * 取消注册
//      */
//     boolean unRegistry(String appKey, ThriftServerInfo serverInfo);
// }
// 
// Path: trpc-server/src/main/java/com/github/sofn/trpc/server/config/ServerArgs.java
// @Data
// @Builder
// public class ServerArgs {
//     @Singular
//     private List<IRegistry> registrys = Collections.emptyList();
//     @Size(min = 1, max = 100)
//     @Singular
//     private List<ServiceArgs> services = Collections.emptyList();
//     private NettyServerArgs nettyServerArgs;
//     @NotBlank
//     private String appkey;  //localAppKey
//     @NotBlank
//     private String host;
//     @NotBlank
//     private String hostName;
//     @Min(1)
//     private int port;
//     @Min(0)
//     @Max(100)
//     private int weight = 100;
// 
//     public void setWeight(int weight) {
//         services.stream().filter(s -> s.getWeight() == this.weight).forEach(s -> s.setWeight(weight));
//         this.weight = weight;
//     }
// 
//     //对象创建完成后执行此方法
//     public void afterPropertiesSet() {
//         InetAddress localAddress = NetUtils.getLocalAddress();
//         if (StringUtils.isBlank(host)) {
//             this.host = localAddress.getHostAddress();
//         }
//         services.stream().filter(s -> s.getWeight() < 0).forEach(s -> s.setWeight(weight));
//         this.hostName = localAddress.getHostName();
//         ValidationUtils.validateWithException(this);
//     }
// 
//     public RegistryConfig getRegistryConfig() {
//         return RegistryConfig.builder()
//                 .serverInfo(new ThriftServerInfo(this.host, this.port))
//                 .servers(this.services.stream().map(ServiceArgs::getServiceConfig).collect(Collectors.toList()))
//                 .appKey(this.appkey)
//                 .hostName(this.hostName)
//                 .weight(this.weight)
//                 .build();
//     }
// 
// }


import com.github.sofn.trpc.core.IRegistry;
import com.github.sofn.trpc.server.config.ServerArgs;
import org.apache.thrift.protocol.TProtocol;
import org.apache.thrift.server.ServerContext;
import org.apache.thrift.server.TServerEventHandler;
import org.apache.thrift.transport.TTransport;
package com.github.sofn.trpc.server;


/**
 * Authors: sofn
 * Version: 1.0  Created at 2016-09-25 21:36.
 */
public class TrpcRegistryEventHandler implements TServerEventHandler {
    private ServerArgs serverArgs;

// Path: trpc-core/src/main/java/com/github/sofn/trpc/core/IRegistry.java
// public interface IRegistry {
// 
//     /**
//      * 注册
//      */
//     void registry(RegistryConfig registryConfig);
// 
//     void modify(RegistryConfig registryConfig);
// 
//     /**
//      * 取消注册
//      */
//     boolean unRegistry(String appKey, ThriftServerInfo serverInfo);
// }
// 
// Path: trpc-server/src/main/java/com/github/sofn/trpc/server/config/ServerArgs.java
// @Data
// @Builder
// public class ServerArgs {
//     @Singular
//     private List<IRegistry> registrys = Collections.emptyList();
//     @Size(min = 1, max = 100)
//     @Singular
//     private List<ServiceArgs> services = Collections.emptyList();
//     private NettyServerArgs nettyServerArgs;
//     @NotBlank
//     private String appkey;  //localAppKey
//     @NotBlank
//     private String host;
//     @NotBlank
//     private String hostName;
//     @Min(1)
//     private int port;
//     @Min(0)
//     @Max(100)
//     private int weight = 100;
// 
//     public void setWeight(int weight) {
//         services.stream().filter(s -> s.getWeight() == this.weight).forEach(s -> s.setWeight(weight));
//         this.weight = weight;
//     }
// 
//     //对象创建完成后执行此方法
//     public void afterPropertiesSet() {
//         InetAddress localAddress = NetUtils.getLocalAddress();
//         if (StringUtils.isBlank(host)) {
//             this.host = localAddress.getHostAddress();
//         }
//         services.stream().filter(s -> s.getWeight() < 0).forEach(s -> s.setWeight(weight));
//         this.hostName = localAddress.getHostName();
//         ValidationUtils.validateWithException(this);
//     }
// 
//     public RegistryConfig getRegistryConfig() {
//         return RegistryConfig.builder()
//                 .serverInfo(new ThriftServerInfo(this.host, this.port))
//                 .servers(this.services.stream().map(ServiceArgs::getServiceConfig).collect(Collectors.toList()))
//                 .appKey(this.appkey)
//                 .hostName(this.hostName)
//                 .weight(this.weight)
//                 .build();
//     }
// 
// }


// Path: trpc-server/src/main/java/com/github/sofn/trpc/server/TrpcRegistryEventHandler.java
import com.github.sofn.trpc.core.IRegistry;
import com.github.sofn.trpc.server.config.ServerArgs;
import org.apache.thrift.protocol.TProtocol;
import org.apache.thrift.server.ServerContext;
import org.apache.thrift.server.TServerEventHandler;
import org.apache.thrift.transport.TTransport;

package com.github.sofn.trpc.server;


/**
 * Authors: sofn
 * Version: 1.0  Created at 2016-09-25 21:36.
 */
public class TrpcRegistryEventHandler implements TServerEventHandler {
    private ServerArgs serverArgs;

    public TrpcRegistryEventHandler(ServerArgs serverArgs) {