package com.excavator.rpc.factory;

import com.excavator.rpc.core.bootstrap.ServerBuilder;
import com.excavator.rpc.core.server.Server;
import com.excavator.rpc.core.server.impl.ServerImpl;
import lombok.Data;
import org.springframework.beans.factory.FactoryBean;

/**
 * Created by cmonkey on 3/29/17.
 */
@Data
public class ServerFactoryBean implements FactoryBean<Object>{
    private Class<?> serviceInterface;
    private Object serviceImpl;
    private String ip;
    private int port;
    private String serviceName;
    private String zkConn;

    private ServerImpl rpcServer;

    public void start(){
        Server rpcServer = ServerBuilder
                .builder()
                .serviceImpl(serviceImpl)
                .serviceName(serviceName)
                .zkConn(zkConn)
                .port(port)
                .build();
        rpcServer.start();
    }

    public void serviceOffline(){
        rpcServer.shutdown();
    }

    @Override
    public Object getObject()throws Exception{
        return this;
    }

    @Override
    public Class<?> getObjectType(){
        return this.getClass();
    }

    @Override
    public boolean isSingleton(){
        return true;
    }
}

@@ -140,73 +140,53 @@
 ort 
-com.excavator.rpc.core.server.impl.ServerImpl;%0Aimport lombok.Data
+lombok.Data;%0Aimport lombok.extern.slf4j.Slf4j
 ;%0Aim
@@ -238,16 +238,53 @@
 yBean;%0A%0A
+import javax.annotation.PreDestroy;%0A%0A
 /**%0A * C
@@ -323,16 +323,23 @@
 /%0A@Data%0A
+@Slf4j%0A
 public c
@@ -587,20 +587,16 @@
 e Server
-Impl
  rpcServ
@@ -633,23 +633,16 @@
         
-Server 
 rpcServe
@@ -886,24 +886,40 @@
 t();%0A    %7D%0A%0A
+    @PreDestroy%0A
     public v
@@ -936,24 +936,90 @@
 eOffline()%7B%0A
+        log.info(%22serviceOffline for rpcServer = %7B%7D%22, rpcServer);%0A
         rpcS

修改ServerFactoryBean 在退出applicationContext 时的处理