├── fishchat-api ├── user │ ├── src │ │ ├── main │ │ │ ├── resources │ │ │ │ └── application.yaml │ │ │ └── java │ │ │ │ └── org │ │ │ │ └── miaohong │ │ │ │ └── fishchat │ │ │ │ └── api │ │ │ │ └── user │ │ │ │ └── UserApp.java │ │ └── test │ │ │ └── java │ │ │ └── org │ │ │ └── miaohong │ │ │ └── fishchat │ │ │ └── api │ │ │ └── user │ │ │ └── Test.java │ └── pom.xml ├── group │ ├── src │ │ ├── main │ │ │ ├── resources │ │ │ │ └── application.yaml │ │ │ └── java │ │ │ │ └── org │ │ │ │ └── miaohong │ │ │ │ └── fishchat │ │ │ │ └── api │ │ │ │ └── group │ │ │ │ └── GroupApp.java │ │ └── test │ │ │ └── java │ │ │ └── org │ │ │ └── miaohong │ │ │ └── fishchat │ │ │ └── api │ │ │ └── group │ │ │ └── Test.java │ └── pom.xml └── pom.xml ├── fishchat-server ├── access │ ├── src │ │ └── main │ │ │ ├── resources │ │ │ └── application.yaml │ │ │ └── java │ │ │ └── org │ │ │ └── miaohong │ │ │ └── fishchat │ │ │ └── server │ │ │ └── access │ │ │ ├── config │ │ │ ├── Config.java │ │ │ └── prop │ │ │ │ └── AccessServerProperties.java │ │ │ └── AccessApp.java │ └── pom.xml ├── notify │ ├── src │ │ ├── main │ │ │ ├── resources │ │ │ │ └── application.yaml │ │ │ └── java │ │ │ │ └── org │ │ │ │ └── miaohong │ │ │ │ └── fishchat │ │ │ │ └── server │ │ │ │ └── notify │ │ │ │ ├── config │ │ │ │ ├── Config.java │ │ │ │ └── prop │ │ │ │ │ └── NotifyServerProperties.java │ │ │ │ └── NotifyApp.java │ │ └── test │ │ │ └── java │ │ │ └── org │ │ │ └── miaohong │ │ │ └── fishchat │ │ │ └── server │ │ │ └── notify │ │ │ └── Test.java │ └── pom.xml ├── gateway │ ├── src │ │ ├── main │ │ │ ├── resources │ │ │ │ ├── server.yaml │ │ │ │ ├── application.yaml │ │ │ │ └── bootstrap.properties │ │ │ └── java │ │ │ │ └── org │ │ │ │ └── miaohong │ │ │ │ └── fishchat │ │ │ │ └── server │ │ │ │ └── gateway │ │ │ │ ├── config │ │ │ │ ├── Config.java │ │ │ │ └── prop │ │ │ │ │ └── GateWayServerProperties.java │ │ │ │ ├── GateWayApp.java │ │ │ │ └── server │ │ │ │ └── GateWayServer.java │ │ └── test │ │ │ └── java │ │ │ └── org │ │ │ └── miaohong │ │ │ └── fishchat │ │ │ └── server │ │ │ └── gateway │ │ │ └── Test.java │ └── pom.xml ├── manager │ ├── src │ │ ├── main │ │ │ ├── resources │ │ │ │ └── application.yaml │ │ │ └── java │ │ │ │ └── org │ │ │ │ └── miaohong │ │ │ │ └── fishchat │ │ │ │ └── server │ │ │ │ └── manager │ │ │ │ ├── config │ │ │ │ ├── Config.java │ │ │ │ └── prop │ │ │ │ │ └── ManagerServerProperties.java │ │ │ │ └── ManagerApp.java │ │ └── test │ │ │ └── java │ │ │ └── org │ │ │ └── miaohong │ │ │ └── fishchat │ │ │ └── server │ │ │ └── manager │ │ │ └── Test.java │ └── pom.xml ├── register │ ├── src │ │ ├── main │ │ │ ├── resources │ │ │ │ └── application.yaml │ │ │ └── java │ │ │ │ └── org │ │ │ │ └── miaohong │ │ │ │ └── fishchat │ │ │ │ └── server │ │ │ │ └── register │ │ │ │ └── RegisterApp.java │ │ └── test │ │ │ └── java │ │ │ └── org │ │ │ └── miaohong │ │ │ └── fishchat │ │ │ └── server │ │ │ └── register │ │ │ └── Test.java │ └── pom.xml ├── logic │ ├── src │ │ └── main │ │ │ ├── resources │ │ │ └── application.yaml │ │ │ └── java │ │ │ └── org │ │ │ └── miaohong │ │ │ └── fishchat │ │ │ └── server │ │ │ └── logic │ │ │ ├── config │ │ │ ├── Config.java │ │ │ └── prop │ │ │ │ └── LogicServerProperties.java │ │ │ └── LogicApp.java │ └── pom.xml ├── discovery │ ├── src │ │ ├── main │ │ │ ├── resources │ │ │ │ ├── application.yaml │ │ │ │ ├── application-peer1.yaml │ │ │ │ └── application-peer2.yaml │ │ │ └── java │ │ │ │ └── org │ │ │ │ └── miaohong │ │ │ │ └── fishchat │ │ │ │ └── server │ │ │ │ └── discovery │ │ │ │ └── DiscoveryApp.java │ │ └── test │ │ │ └── java │ │ │ └── org │ │ │ └── miaohong │ │ │ └── fishchat │ │ │ └── server │ │ │ └── discovery │ │ │ └── Test.java │ └── pom.xml ├── config │ ├── src │ │ ├── test │ │ │ └── java │ │ │ │ └── org │ │ │ │ └── miaohong │ │ │ │ └── fishchat │ │ │ │ └── server │ │ │ │ └── config │ │ │ │ └── Test.java │ │ └── main │ │ │ ├── resources │ │ │ └── application.yaml │ │ │ └── java │ │ │ └── org │ │ │ └── miaohong │ │ │ └── fishchat │ │ │ └── server │ │ │ └── config │ │ │ └── ConfigApp.java │ └── pom.xml └── pom.xml ├── README.md ├── fishchat-core ├── transport-common │ ├── src │ │ ├── main │ │ │ ├── resources │ │ │ │ └── application.yaml │ │ │ └── java │ │ │ │ └── org │ │ │ │ └── miaohong │ │ │ │ └── fishchat │ │ │ │ └── transport │ │ │ │ └── common │ │ │ │ ├── exception │ │ │ │ ├── TransportException.java │ │ │ │ └── TransportAbstractException.java │ │ │ │ ├── constant │ │ │ │ └── Constants.java │ │ │ │ ├── server │ │ │ │ ├── Server.java │ │ │ │ ├── Channel.java │ │ │ │ └── AbstractServer.java │ │ │ │ ├── state │ │ │ │ └── ChannelState.java │ │ │ │ └── url │ │ │ │ ├── URLParamType.java │ │ │ │ └── URL.java │ │ └── test │ │ │ └── java │ │ │ └── org │ │ │ └── miaohong │ │ │ └── fishchat │ │ │ └── transport │ │ │ └── common │ │ │ └── Test.java │ └── pom.xml ├── transport-netty │ ├── src │ │ ├── main │ │ │ ├── resources │ │ │ │ └── application.yaml │ │ │ └── java │ │ │ │ └── org │ │ │ │ └── miaohong │ │ │ │ └── fishchat │ │ │ │ └── transport │ │ │ │ └── netty │ │ │ │ ├── client │ │ │ │ └── NettyClient.java │ │ │ │ └── server │ │ │ │ ├── NettyServerChannelManage.java │ │ │ │ └── NettyServer.java │ │ └── test │ │ │ └── java │ │ │ └── org │ │ │ └── miaohong │ │ │ └── fishchat │ │ │ └── transport │ │ │ └── netty │ │ │ └── Test.java │ └── pom.xml └── pom.xml ├── configrepo └── gateway-server-dev.yaml ├── .gitignore └── pom.xml /fishchat-api/user/src/main/resources/application.yaml: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /fishchat-api/group/src/main/resources/application.yaml: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /fishchat-server/access/src/main/resources/application.yaml: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /fishchat-server/notify/src/main/resources/application.yaml: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # FishChatServerJava 2 | FishChatServer的Java版本 3 | -------------------------------------------------------------------------------- /fishchat-server/gateway/src/main/resources/server.yaml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /fishchat-server/manager/src/main/resources/application.yaml: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /fishchat-core/transport-common/src/main/resources/application.yaml: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /fishchat-core/transport-netty/src/main/resources/application.yaml: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /fishchat-server/register/src/main/resources/application.yaml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /fishchat-server/gateway/src/main/resources/application.yaml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /configrepo/gateway-server-dev.yaml: -------------------------------------------------------------------------------- 1 | 2 | 3 | server: 4 | name: gateway 5 | url: tcp://0.0.0.0:17001 -------------------------------------------------------------------------------- /fishchat-server/logic/src/main/resources/application.yaml: -------------------------------------------------------------------------------- 1 | 2 | 3 | eureka: 4 | client: 5 | serviceUrl: 6 | defaultZone: http://localhost:1001/eureka/ 7 | -------------------------------------------------------------------------------- /fishchat-server/gateway/src/test/java/org/miaohong/fishchat/server/gateway/Test.java: -------------------------------------------------------------------------------- 1 | package org.miaohong.fishchat.server.gateway; 2 | 3 | public class Test { 4 | } 5 | -------------------------------------------------------------------------------- /fishchat-core/transport-netty/src/test/java/org/miaohong/fishchat/transport/netty/Test.java: -------------------------------------------------------------------------------- 1 | package org.miaohong.fishchat.transport.netty; 2 | 3 | public class Test { 4 | } 5 | -------------------------------------------------------------------------------- /fishchat-core/transport-common/src/test/java/org/miaohong/fishchat/transport/common/Test.java: -------------------------------------------------------------------------------- 1 | package org.miaohong.fishchat.transport.common; 2 | 3 | public class Test { 4 | } 5 | -------------------------------------------------------------------------------- /fishchat-server/discovery/src/main/resources/application.yaml: -------------------------------------------------------------------------------- 1 | 2 | 3 | eureka: 4 | instance: 5 | hostname: localhost 6 | client: 7 | register-with-eureka: false 8 | fetch-registry: false -------------------------------------------------------------------------------- /fishchat-api/group/src/test/java/org/miaohong/fishchat/api/group/Test.java: -------------------------------------------------------------------------------- 1 | package org.miaohong.fishchat.api.group; 2 | 3 | /** 4 | * Created by miaohong on 2017/11/27. 5 | */ 6 | public class Test { 7 | } 8 | -------------------------------------------------------------------------------- /fishchat-api/user/src/test/java/org/miaohong/fishchat/api/user/Test.java: -------------------------------------------------------------------------------- 1 | package org.miaohong.fishchat.api.user; 2 | 3 | /** 4 | * Created by miaohong on 2017/11/27. 5 | */ 6 | public class Test { 7 | } 8 | -------------------------------------------------------------------------------- /fishchat-api/user/src/main/java/org/miaohong/fishchat/api/user/UserApp.java: -------------------------------------------------------------------------------- 1 | package org.miaohong.fishchat.api.user; 2 | 3 | /** 4 | * Created by miaohong on 2017/11/27. 5 | */ 6 | public class UserApp { 7 | } 8 | -------------------------------------------------------------------------------- /fishchat-api/group/src/main/java/org/miaohong/fishchat/api/group/GroupApp.java: -------------------------------------------------------------------------------- 1 | package org.miaohong.fishchat.api.group; 2 | 3 | /** 4 | * Created by miaohong on 2017/11/27. 5 | */ 6 | public class GroupApp { 7 | } 8 | -------------------------------------------------------------------------------- /fishchat-server/config/src/test/java/org/miaohong/fishchat/server/config/Test.java: -------------------------------------------------------------------------------- 1 | package org.miaohong.fishchat.server.config; 2 | 3 | /** 4 | * Created by miaohong on 2017/11/27. 5 | */ 6 | public class Test { 7 | } 8 | -------------------------------------------------------------------------------- /fishchat-server/manager/src/test/java/org/miaohong/fishchat/server/manager/Test.java: -------------------------------------------------------------------------------- 1 | package org.miaohong.fishchat.server.manager; 2 | 3 | /** 4 | * Created by miaohong on 2017/11/27. 5 | */ 6 | public class Test { 7 | } 8 | -------------------------------------------------------------------------------- /fishchat-server/notify/src/test/java/org/miaohong/fishchat/server/notify/Test.java: -------------------------------------------------------------------------------- 1 | package org.miaohong.fishchat.server.notify; 2 | 3 | /** 4 | * Created by miaohong on 2017/11/27. 5 | */ 6 | public class Test { 7 | } 8 | -------------------------------------------------------------------------------- /fishchat-server/discovery/src/test/java/org/miaohong/fishchat/server/discovery/Test.java: -------------------------------------------------------------------------------- 1 | package org.miaohong.fishchat.server.discovery; 2 | 3 | /** 4 | * Created by miaohong on 2017/11/28. 5 | */ 6 | public class Test { 7 | } 8 | -------------------------------------------------------------------------------- /fishchat-server/register/src/test/java/org/miaohong/fishchat/server/register/Test.java: -------------------------------------------------------------------------------- 1 | package org.miaohong.fishchat.server.register; 2 | 3 | /** 4 | * Created by miaohong on 2017/11/27. 5 | */ 6 | public class Test { 7 | } 8 | -------------------------------------------------------------------------------- /fishchat-server/access/src/main/java/org/miaohong/fishchat/server/access/config/Config.java: -------------------------------------------------------------------------------- 1 | package org.miaohong.fishchat.server.access.config; 2 | 3 | /** 4 | * Created by miaohong on 2017/11/27. 5 | */ 6 | public class Config { 7 | } 8 | -------------------------------------------------------------------------------- /fishchat-server/logic/src/main/java/org/miaohong/fishchat/server/logic/config/Config.java: -------------------------------------------------------------------------------- 1 | package org.miaohong.fishchat.server.logic.config; 2 | 3 | /** 4 | * Created by miaohong on 2017/11/27. 5 | */ 6 | public class Config { 7 | } 8 | -------------------------------------------------------------------------------- /fishchat-server/notify/src/main/java/org/miaohong/fishchat/server/notify/config/Config.java: -------------------------------------------------------------------------------- 1 | package org.miaohong.fishchat.server.notify.config; 2 | 3 | /** 4 | * Created by miaohong on 2017/11/27. 5 | */ 6 | public class Config { 7 | } 8 | -------------------------------------------------------------------------------- /fishchat-server/manager/src/main/java/org/miaohong/fishchat/server/manager/config/Config.java: -------------------------------------------------------------------------------- 1 | package org.miaohong.fishchat.server.manager.config; 2 | 3 | /** 4 | * Created by miaohong on 2017/11/27. 5 | */ 6 | public class Config { 7 | } 8 | -------------------------------------------------------------------------------- /fishchat-server/discovery/src/main/resources/application-peer1.yaml: -------------------------------------------------------------------------------- 1 | 2 | 3 | server: 4 | port: 1111 5 | 6 | eureka: 7 | instance: 8 | hostname: peer1 9 | client: 10 | register-with-eureka: false 11 | fetch-registry: false -------------------------------------------------------------------------------- /fishchat-server/discovery/src/main/resources/application-peer2.yaml: -------------------------------------------------------------------------------- 1 | 2 | 3 | server: 4 | port: 1112 5 | 6 | eureka: 7 | instance: 8 | hostname: peer2 9 | client: 10 | register-with-eureka: false 11 | fetch-registry: false -------------------------------------------------------------------------------- /fishchat-server/gateway/src/main/java/org/miaohong/fishchat/server/gateway/config/Config.java: -------------------------------------------------------------------------------- 1 | package org.miaohong.fishchat.server.gateway.config; 2 | 3 | /** 4 | * @author miaohong 5 | * @date 2017/11/16 6 | */ 7 | public class Config { 8 | } 9 | -------------------------------------------------------------------------------- /fishchat-server/gateway/src/main/resources/bootstrap.properties: -------------------------------------------------------------------------------- 1 | 2 | 3 | spring.application.name=gateway-server 4 | spring.cloud.config.label=master 5 | spring.cloud.config.profile=dev 6 | spring.cloud.config.uri= http://localhost:9999/ 7 | server.port=8881 8 | -------------------------------------------------------------------------------- /fishchat-core/transport-netty/src/main/java/org/miaohong/fishchat/transport/netty/client/NettyClient.java: -------------------------------------------------------------------------------- 1 | package org.miaohong.fishchat.transport.netty.client; 2 | 3 | /** 4 | * @author miaohong 5 | * @date 2017/11/16 6 | */ 7 | public class NettyClient { 8 | } 9 | -------------------------------------------------------------------------------- /fishchat-server/logic/src/main/java/org/miaohong/fishchat/server/logic/config/prop/LogicServerProperties.java: -------------------------------------------------------------------------------- 1 | package org.miaohong.fishchat.server.logic.config.prop; 2 | 3 | /** 4 | * Created by miaohong on 2017/11/27. 5 | */ 6 | public class LogicServerProperties { 7 | } 8 | -------------------------------------------------------------------------------- /fishchat-server/notify/src/main/java/org/miaohong/fishchat/server/notify/config/prop/NotifyServerProperties.java: -------------------------------------------------------------------------------- 1 | package org.miaohong.fishchat.server.notify.config.prop; 2 | 3 | /** 4 | * Created by miaohong on 2017/11/27. 5 | */ 6 | public class NotifyServerProperties { 7 | } 8 | -------------------------------------------------------------------------------- /fishchat-server/manager/src/main/java/org/miaohong/fishchat/server/manager/config/prop/ManagerServerProperties.java: -------------------------------------------------------------------------------- 1 | package org.miaohong.fishchat.server.manager.config.prop; 2 | 3 | /** 4 | * Created by miaohong on 2017/11/27. 5 | */ 6 | public class ManagerServerProperties { 7 | } 8 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | #folder 2 | target/ 3 | .vagrant/ 4 | 5 | #fixed file 6 | .class 7 | .exe 8 | .log 9 | .prefs 10 | .classpath 11 | .metadata 12 | .settings 13 | .DS_Store 14 | Thumbs.db 15 | .project 16 | *.iml 17 | *.ipr 18 | *.iws 19 | *.tar.gz 20 | *.bak 21 | .idea 22 | *.log 23 | *.swp 24 | *.swo 25 | -------------------------------------------------------------------------------- /fishchat-core/transport-common/src/main/java/org/miaohong/fishchat/transport/common/exception/TransportException.java: -------------------------------------------------------------------------------- 1 | package org.miaohong.fishchat.transport.common.exception; 2 | 3 | /** 4 | * @author miaohong 5 | * @date 2017/11/16 6 | */ 7 | public class TransportException extends TransportAbstractException { 8 | 9 | 10 | } 11 | -------------------------------------------------------------------------------- /fishchat-server/config/src/main/resources/application.yaml: -------------------------------------------------------------------------------- 1 | 2 | server: 3 | port: 9999 4 | 5 | 6 | spring: 7 | application: 8 | name: config 9 | cloud: 10 | config: 11 | server: 12 | git: 13 | uri: https://github.com/oikomi/FishChatServerJava/ 14 | searchPaths: configrepo 15 | label: master 16 | 17 | -------------------------------------------------------------------------------- /fishchat-server/access/src/main/java/org/miaohong/fishchat/server/access/config/prop/AccessServerProperties.java: -------------------------------------------------------------------------------- 1 | package org.miaohong.fishchat.server.access.config.prop; 2 | 3 | import org.springframework.context.annotation.Configuration; 4 | 5 | /** 6 | * Created by miaohong on 2017/11/27. 7 | */ 8 | @Configuration 9 | public class AccessServerProperties { 10 | } 11 | -------------------------------------------------------------------------------- /fishchat-core/transport-common/src/main/java/org/miaohong/fishchat/transport/common/constant/Constants.java: -------------------------------------------------------------------------------- 1 | package org.miaohong.fishchat.transport.common.constant; 2 | 3 | /** 4 | * @author miaohong 5 | * @date 2017/11/16 6 | */ 7 | public class Constants { 8 | public static final String PROTOCOL_DEFAULT = "fixlen"; 9 | public static final String DEFAULT_VERSION = "1.0.0"; 10 | } 11 | -------------------------------------------------------------------------------- /fishchat-core/transport-common/src/main/java/org/miaohong/fishchat/transport/common/exception/TransportAbstractException.java: -------------------------------------------------------------------------------- 1 | package org.miaohong.fishchat.transport.common.exception; 2 | 3 | /** 4 | * @author miaohong 5 | * @date 2017/11/16 6 | */ 7 | public abstract class TransportAbstractException extends RuntimeException { 8 | 9 | private static final long serialVersionUID = -4252430669486252004L; 10 | 11 | 12 | } 13 | -------------------------------------------------------------------------------- /fishchat-server/access/src/main/java/org/miaohong/fishchat/server/access/AccessApp.java: -------------------------------------------------------------------------------- 1 | package org.miaohong.fishchat.server.access; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | /** 7 | * Created by miaohong on 2017/11/27. 8 | */ 9 | @SpringBootApplication 10 | public class AccessApp { 11 | 12 | public static void main(String[] args) { 13 | 14 | SpringApplication app = new SpringApplication(AccessApp.class); 15 | app.run(args); 16 | 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /fishchat-server/gateway/src/main/java/org/miaohong/fishchat/server/gateway/GateWayApp.java: -------------------------------------------------------------------------------- 1 | package org.miaohong.fishchat.server.gateway; 2 | 3 | 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | 7 | /** 8 | * @author miaohong 9 | * @date 2017/11/16 10 | */ 11 | @SpringBootApplication 12 | public class GateWayApp { 13 | 14 | public static void main(String[] args) { 15 | SpringApplication app = new SpringApplication(GateWayApp.class); 16 | app.run(args); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /fishchat-api/user/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | fishchat-api 7 | org.miaohong.fishcat 8 | 1.0.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | user 13 | 14 | 15 | -------------------------------------------------------------------------------- /fishchat-api/group/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | fishchat-api 7 | org.miaohong.fishcat 8 | 1.0.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | group 13 | 14 | 15 | -------------------------------------------------------------------------------- /fishchat-server/register/src/main/java/org/miaohong/fishchat/server/register/RegisterApp.java: -------------------------------------------------------------------------------- 1 | package org.miaohong.fishchat.server.register; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | /** 7 | * 8 | * @author miaohong 9 | * @date 2017/11/27 10 | */ 11 | @SpringBootApplication 12 | public class RegisterApp { 13 | public static void main(String[] args) { 14 | 15 | SpringApplication app = new SpringApplication(RegisterApp.class); 16 | app.run(args); 17 | 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /fishchat-server/manager/src/main/java/org/miaohong/fishchat/server/manager/ManagerApp.java: -------------------------------------------------------------------------------- 1 | package org.miaohong.fishchat.server.manager; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | /** 7 | * 8 | * @author miaohong 9 | * @date 2017/11/27 10 | */ 11 | @SpringBootApplication 12 | public class ManagerApp { 13 | 14 | public static void main(String[] args) { 15 | 16 | SpringApplication app = new SpringApplication(ManagerApp.class); 17 | app.run(args); 18 | 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /fishchat-server/config/src/main/java/org/miaohong/fishchat/server/config/ConfigApp.java: -------------------------------------------------------------------------------- 1 | package org.miaohong.fishchat.server.config; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.config.server.EnableConfigServer; 6 | 7 | /** 8 | * @author miaohong 9 | * @date 2017/11/18 10 | */ 11 | 12 | @SpringBootApplication 13 | @EnableConfigServer 14 | public class ConfigApp { 15 | 16 | public static void main(String[] args) { 17 | SpringApplication app = new SpringApplication(ConfigApp.class); 18 | app.run(args); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /fishchat-server/logic/src/main/java/org/miaohong/fishchat/server/logic/LogicApp.java: -------------------------------------------------------------------------------- 1 | package org.miaohong.fishchat.server.logic; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 6 | 7 | /** 8 | * 9 | * @author miaohong 10 | * @date 2017/11/27 11 | */ 12 | @SpringBootApplication 13 | @EnableDiscoveryClient 14 | public class LogicApp { 15 | 16 | public static void main(String[] args) { 17 | 18 | SpringApplication app = new SpringApplication(LogicApp.class); 19 | app.run(args); 20 | 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /fishchat-server/notify/src/main/java/org/miaohong/fishchat/server/notify/NotifyApp.java: -------------------------------------------------------------------------------- 1 | package org.miaohong.fishchat.server.notify; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; 6 | 7 | /** 8 | * 9 | * @author miaohong 10 | * @date 2017/11/27 11 | */ 12 | @SpringBootApplication 13 | @EnableEurekaServer 14 | public class NotifyApp { 15 | public static void main(String[] args) { 16 | 17 | SpringApplication app = new SpringApplication(NotifyApp.class); 18 | app.run(args); 19 | 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /fishchat-server/gateway/src/main/java/org/miaohong/fishchat/server/gateway/config/prop/GateWayServerProperties.java: -------------------------------------------------------------------------------- 1 | package org.miaohong.fishchat.server.gateway.config.prop; 2 | 3 | import lombok.Getter; 4 | import lombok.Setter; 5 | import org.springframework.beans.factory.annotation.Value; 6 | import org.springframework.context.annotation.Configuration; 7 | 8 | /** 9 | * @author miaohong 10 | * @date 2017/11/16 11 | */ 12 | @Configuration 13 | public class GateWayServerProperties { 14 | 15 | @Getter 16 | @Setter 17 | @Value("${server.name}") 18 | private String name; 19 | 20 | 21 | @Getter 22 | @Setter 23 | @Value("${server.url}") 24 | private String url; 25 | 26 | } 27 | -------------------------------------------------------------------------------- /fishchat-server/discovery/src/main/java/org/miaohong/fishchat/server/discovery/DiscoveryApp.java: -------------------------------------------------------------------------------- 1 | package org.miaohong.fishchat.server.discovery; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; 6 | 7 | /** 8 | * 9 | * @author miaohong 10 | * @date 2017/11/28 11 | */ 12 | @SpringBootApplication 13 | @EnableEurekaServer 14 | public class DiscoveryApp { 15 | 16 | public static void main(String[] args) { 17 | 18 | SpringApplication app = new SpringApplication(DiscoveryApp.class); 19 | app.run(args); 20 | 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /fishchat-api/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | fishchat 7 | org.miaohong.fishcat 8 | 1.0.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | fishchat-api 13 | pom 14 | 15 | user 16 | group 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /fishchat-core/transport-common/src/main/java/org/miaohong/fishchat/transport/common/server/Server.java: -------------------------------------------------------------------------------- 1 | package org.miaohong.fishchat.transport.common.server; 2 | 3 | import java.net.InetSocketAddress; 4 | import java.util.Collection; 5 | 6 | /** 7 | * @author miaohong 8 | * @date 2017/11/16 9 | */ 10 | public interface Server extends Channel { 11 | 12 | /** 13 | * isActive 14 | * 15 | * @return 16 | */ 17 | boolean isActive(); 18 | 19 | /** 20 | * get channels. 21 | * 22 | * @return channels 23 | */ 24 | Collection getChannels(); 25 | 26 | /** 27 | * get channel. 28 | * 29 | * @param remoteAddress 30 | * @return channel 31 | */ 32 | Channel getChannel(InetSocketAddress remoteAddress); 33 | 34 | } 35 | -------------------------------------------------------------------------------- /fishchat-core/transport-common/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | fishchat-core 7 | org.miaohong.fishcat 8 | 1.0.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | transport-common 13 | 14 | 15 | 16 | org.apache.commons 17 | commons-lang3 18 | 19 | 20 | org.projectlombok 21 | lombok 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /fishchat-server/config/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | fishchat-server 7 | org.miaohong.fishcat 8 | 1.0.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | config 13 | jar 14 | 15 | 16 | 17 | org.springframework.boot 18 | spring-boot-starter 19 | 20 | 21 | 22 | org.springframework.cloud 23 | spring-cloud-config-server 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /fishchat-core/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | fishchat 7 | org.miaohong.fishcat 8 | 1.0.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | fishchat-core 13 | pom 14 | 15 | transport-netty 16 | transport-common 17 | 18 | 19 | 20 | 21 | 22 | io.netty 23 | netty-all 24 | 4.1.17.Final 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /fishchat-server/gateway/src/main/java/org/miaohong/fishchat/server/gateway/server/GateWayServer.java: -------------------------------------------------------------------------------- 1 | package org.miaohong.fishchat.server.gateway.server; 2 | 3 | 4 | import org.miaohong.fishchat.server.gateway.config.prop.GateWayServerProperties; 5 | import org.miaohong.fishchat.transport.common.url.URL; 6 | import org.miaohong.fishchat.transport.netty.server.NettyServer; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.boot.CommandLineRunner; 9 | import org.springframework.stereotype.Component; 10 | 11 | import java.util.Optional; 12 | 13 | /** 14 | * @author miaohong 15 | * @date 2017/11/16 16 | */ 17 | @Component 18 | public class GateWayServer implements CommandLineRunner { 19 | 20 | @Autowired 21 | private GateWayServerProperties gwsProperties; 22 | 23 | private NettyServer nettyServer; 24 | 25 | @Override 26 | public void run(String... args) throws Exception { 27 | Optional.ofNullable(gwsProperties.getUrl()).ifPresent((url) -> { 28 | nettyServer = new NettyServer(URL.valueOf(url)); 29 | nettyServer.open(); 30 | }); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /fishchat-core/transport-common/src/main/java/org/miaohong/fishchat/transport/common/state/ChannelState.java: -------------------------------------------------------------------------------- 1 | package org.miaohong.fishchat.transport.common.state; 2 | 3 | /** 4 | * @author miaohong 5 | * @date 2017/11/16 6 | */ 7 | public enum ChannelState { 8 | /** 9 | * 未初始化状态 10 | **/ 11 | UNINIT(0), 12 | /** 13 | * 初始化完成 14 | **/ 15 | INIT(1), 16 | /** 17 | * 存活可用状态 18 | **/ 19 | ALIVE(2), 20 | /** 21 | * 不存活可用状态 22 | **/ 23 | UNALIVE(3), 24 | /** 25 | * 关闭状态 26 | **/ 27 | CLOSE(4); 28 | 29 | public final int value; 30 | 31 | ChannelState(int value) { 32 | this.value = value; 33 | } 34 | 35 | public boolean isAliveState() { 36 | return this == ALIVE; 37 | } 38 | 39 | public boolean isUnAliveState() { 40 | return this == UNALIVE; 41 | } 42 | 43 | public boolean isCloseState() { 44 | return this == CLOSE; 45 | } 46 | 47 | public boolean isInitState() { 48 | return this == INIT; 49 | } 50 | 51 | public boolean isUnInitState() { 52 | return this == UNINIT; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /fishchat-core/transport-common/src/main/java/org/miaohong/fishchat/transport/common/server/Channel.java: -------------------------------------------------------------------------------- 1 | package org.miaohong.fishchat.transport.common.server; 2 | 3 | import java.net.InetSocketAddress; 4 | 5 | /** 6 | * @author miaohong 7 | * @date 2017/11/16 8 | */ 9 | public interface Channel { 10 | 11 | /** 12 | * get local socket address. 13 | * 14 | * @return local address. 15 | */ 16 | InetSocketAddress getLocalAddress(); 17 | 18 | /** 19 | * get remote socket address 20 | * 21 | * @return 22 | */ 23 | InetSocketAddress getRemoteAddress(); 24 | 25 | 26 | /** 27 | * open the channel 28 | * 29 | * @return 30 | */ 31 | boolean open(); 32 | 33 | /** 34 | * close the channel. 35 | */ 36 | void close(); 37 | 38 | /** 39 | * close the channel gracefully. 40 | */ 41 | void close(int timeout); 42 | 43 | /** 44 | * is closed. 45 | * 46 | * @return closed 47 | */ 48 | boolean isClosed(); 49 | 50 | /** 51 | * the node available status 52 | * 53 | * @return 54 | */ 55 | boolean isAvailable(); 56 | 57 | } 58 | -------------------------------------------------------------------------------- /fishchat-core/transport-netty/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | fishchat-core 7 | org.miaohong.fishcat 8 | 1.0.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | transport-netty 13 | 14 | 15 | org.miaohong.fishcat 16 | transport-common 17 | 1.0.0-SNAPSHOT 18 | 19 | 20 | io.netty 21 | netty-all 22 | 23 | 24 | org.springframework.boot 25 | spring-boot-starter 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /fishchat-server/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | fishchat 7 | org.miaohong.fishcat 8 | 1.0.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | fishchat-server 13 | pom 14 | 15 | gateway 16 | config 17 | access 18 | manager 19 | logic 20 | notify 21 | register 22 | discovery 23 | 24 | 25 | 26 | 27 | 28 | io.netty 29 | netty-all 30 | 4.1.17.Final 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /fishchat-core/transport-common/src/main/java/org/miaohong/fishchat/transport/common/server/AbstractServer.java: -------------------------------------------------------------------------------- 1 | package org.miaohong.fishchat.transport.common.server; 2 | 3 | import org.miaohong.fishchat.transport.common.state.ChannelState; 4 | 5 | import java.net.InetSocketAddress; 6 | import java.util.Collection; 7 | 8 | /** 9 | * @author miaohong 10 | * @date 2017/11/16 11 | */ 12 | public abstract class AbstractServer implements Server { 13 | 14 | protected InetSocketAddress localAddress; 15 | protected InetSocketAddress remoteAddress; 16 | 17 | protected volatile ChannelState state = ChannelState.UNINIT; 18 | 19 | public AbstractServer() { 20 | } 21 | 22 | 23 | @Override 24 | public InetSocketAddress getLocalAddress() { 25 | return localAddress; 26 | } 27 | 28 | public void setLocalAddress(InetSocketAddress localAddress) { 29 | this.localAddress = localAddress; 30 | } 31 | 32 | @Override 33 | public InetSocketAddress getRemoteAddress() { 34 | return remoteAddress; 35 | } 36 | 37 | public void setRemoteAddress(InetSocketAddress remoteAddress) { 38 | this.remoteAddress = remoteAddress; 39 | } 40 | 41 | @Override 42 | public Collection getChannels() { 43 | // throw new MotanFrameworkException(this.getClass().getName() + " getChannels() method unsupport " + url); 44 | return null; 45 | } 46 | 47 | @Override 48 | public Channel getChannel(InetSocketAddress remoteAddress) { 49 | // throw new MotanFrameworkException(this.getClass().getName() + " getChannel(InetSocketAddress) method unsupport " + url); 50 | return null; 51 | 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /fishchat-core/transport-common/src/main/java/org/miaohong/fishchat/transport/common/url/URLParamType.java: -------------------------------------------------------------------------------- 1 | package org.miaohong.fishchat.transport.common.url; 2 | 3 | import org.miaohong.fishchat.transport.common.constant.Constants; 4 | 5 | /** 6 | * @author miaohong 7 | * @date 2017/11/16 8 | */ 9 | public enum URLParamType { 10 | /** 11 | * version 12 | **/ 13 | version("version", Constants.DEFAULT_VERSION), 14 | 15 | // 格式为protocol:port 16 | export("export", ""), 17 | embed("embed", ""), 18 | 19 | protocol("protocol", Constants.PROTOCOL_DEFAULT), 20 | path("path", ""), 21 | host("host", ""), 22 | port("port", 0); 23 | 24 | private String name; 25 | private String value; 26 | private long longValue; 27 | private int intValue; 28 | private boolean boolValue; 29 | 30 | URLParamType(String name, String value) { 31 | this.name = name; 32 | this.value = value; 33 | } 34 | 35 | URLParamType(String name, long longValue) { 36 | this.name = name; 37 | this.value = String.valueOf(longValue); 38 | this.longValue = longValue; 39 | } 40 | 41 | URLParamType(String name, int intValue) { 42 | this.name = name; 43 | this.value = String.valueOf(intValue); 44 | this.intValue = intValue; 45 | } 46 | 47 | URLParamType(String name, boolean boolValue) { 48 | this.name = name; 49 | this.value = String.valueOf(boolValue); 50 | this.boolValue = boolValue; 51 | } 52 | 53 | public String getName() { 54 | return name; 55 | } 56 | 57 | public String getValue() { 58 | return value; 59 | } 60 | 61 | public int getIntValue() { 62 | return intValue; 63 | } 64 | 65 | public long getLongValue() { 66 | return longValue; 67 | } 68 | 69 | public boolean getBooleanValue() { 70 | return boolValue; 71 | } 72 | 73 | } 74 | -------------------------------------------------------------------------------- /fishchat-server/manager/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | fishchat-server 7 | org.miaohong.fishcat 8 | 1.0.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | manager 13 | 14 | jar 15 | 16 | 17 | 18 | org.springframework.boot 19 | spring-boot-starter 20 | 21 | 22 | org.springframework.cloud 23 | spring-cloud-starter-config 24 | 25 | 26 | org.projectlombok 27 | lombok 28 | 29 | 30 | 31 | 32 | 33 | 34 | org.springframework.boot 35 | spring-boot-maven-plugin 36 | 37 | 38 | org.miaohong.fishchat.server.manager.ManagerApp 39 | 40 | 41 | 42 | 43 | 44 | repackage 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /fishchat-server/logic/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | fishchat-server 7 | org.miaohong.fishcat 8 | 1.0.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | logic 13 | 14 | jar 15 | 16 | 17 | 18 | org.springframework.boot 19 | spring-boot-starter 20 | 21 | 22 | org.springframework.cloud 23 | spring-cloud-starter-eureka 24 | 25 | 26 | org.springframework.cloud 27 | spring-cloud-starter-config 28 | 29 | 30 | org.projectlombok 31 | lombok 32 | 33 | 34 | 35 | 36 | 37 | 38 | org.springframework.boot 39 | spring-boot-maven-plugin 40 | 41 | 42 | org.miaohong.fishchat.server.logic.LogicApp 43 | 44 | 45 | 46 | 47 | 48 | repackage 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /fishchat-server/notify/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | fishchat-server 7 | org.miaohong.fishcat 8 | 1.0.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | notify 13 | 14 | jar 15 | 16 | 17 | 18 | org.springframework.boot 19 | spring-boot-starter 20 | 21 | 22 | org.springframework.cloud 23 | spring-cloud-starter-eureka 24 | 25 | 26 | org.springframework.cloud 27 | spring-cloud-starter-config 28 | 29 | 30 | org.projectlombok 31 | lombok 32 | 33 | 34 | 35 | 36 | 37 | 38 | org.springframework.boot 39 | spring-boot-maven-plugin 40 | 41 | 42 | org.miaohong.fishchat.server.notify.NotifyApp 43 | 44 | 45 | 46 | 47 | 48 | repackage 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /fishchat-server/register/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | fishchat-server 7 | org.miaohong.fishcat 8 | 1.0.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | register 13 | 14 | jar 15 | 16 | 17 | 18 | org.springframework.boot 19 | spring-boot-starter 20 | 21 | 22 | org.springframework.cloud 23 | spring-cloud-starter-eureka 24 | 25 | 26 | org.springframework.cloud 27 | spring-cloud-starter-config 28 | 29 | 30 | org.projectlombok 31 | lombok 32 | 33 | 34 | 35 | 36 | 37 | 38 | org.springframework.boot 39 | spring-boot-maven-plugin 40 | 41 | 42 | org.miaohong.fishchat.server.register.RegisterApp 43 | 44 | 45 | 46 | 47 | 48 | repackage 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /fishchat-server/discovery/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | fishchat-server 7 | org.miaohong.fishcat 8 | 1.0.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | discovery 13 | 14 | jar 15 | 16 | 17 | 18 | org.springframework.boot 19 | spring-boot-starter 20 | 21 | 22 | org.springframework.cloud 23 | spring-cloud-starter-eureka-server 24 | 25 | 26 | org.springframework.cloud 27 | spring-cloud-starter-config 28 | 29 | 30 | org.projectlombok 31 | lombok 32 | 33 | 34 | 35 | 36 | 37 | 38 | org.springframework.boot 39 | spring-boot-maven-plugin 40 | 41 | 42 | org.miaohong.fishchat.server.discovery.DiscoveryApp 43 | 44 | 45 | 46 | 47 | 48 | repackage 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /fishchat-server/gateway/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | fishchat-server 7 | org.miaohong.fishcat 8 | 1.0.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | gateway 13 | jar 14 | 15 | 16 | 17 | org.springframework.boot 18 | spring-boot-starter 19 | 20 | 21 | org.springframework.cloud 22 | spring-cloud-starter-config 23 | 24 | 25 | io.netty 26 | netty-all 27 | 28 | 29 | org.miaohong.fishcat 30 | transport-netty 31 | 1.0.0-SNAPSHOT 32 | 33 | 34 | org.projectlombok 35 | lombok 36 | 37 | 38 | 39 | 40 | 41 | 42 | org.springframework.boot 43 | spring-boot-maven-plugin 44 | 45 | 46 | org.miaohong.fishchat.server.gateway.GateWayApp 47 | 48 | 49 | 50 | 51 | 52 | repackage 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /fishchat-server/access/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | fishchat-server 7 | org.miaohong.fishcat 8 | 1.0.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | access 13 | 14 | jar 15 | 16 | 17 | 18 | org.springframework.boot 19 | spring-boot-starter 20 | 21 | 22 | org.springframework.cloud 23 | spring-cloud-starter-config 24 | 25 | 26 | org.springframework.cloud 27 | spring-cloud-starter-eureka 28 | 29 | 30 | io.netty 31 | netty-all 32 | 33 | 34 | org.miaohong.fishcat 35 | transport-netty 36 | 1.0.0-SNAPSHOT 37 | 38 | 39 | org.projectlombok 40 | lombok 41 | 42 | 43 | 44 | 45 | 46 | 47 | org.springframework.boot 48 | spring-boot-maven-plugin 49 | 50 | 51 | org.miaohong.fishchat.server.access.AccessApp 52 | 53 | 54 | 55 | 56 | 57 | repackage 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | -------------------------------------------------------------------------------- /fishchat-core/transport-netty/src/main/java/org/miaohong/fishchat/transport/netty/server/NettyServerChannelManage.java: -------------------------------------------------------------------------------- 1 | package org.miaohong.fishchat.transport.netty.server; 2 | 3 | import io.netty.channel.Channel; 4 | import io.netty.channel.ChannelHandlerContext; 5 | import io.netty.channel.ChannelInboundHandler; 6 | import io.netty.channel.ChannelInboundHandlerAdapter; 7 | import io.netty.channel.ChannelPipeline; 8 | import lombok.Getter; 9 | import org.slf4j.Logger; 10 | import org.slf4j.LoggerFactory; 11 | 12 | import java.net.InetSocketAddress; 13 | import java.util.Map; 14 | import java.util.concurrent.ConcurrentHashMap; 15 | import java.util.concurrent.ConcurrentMap; 16 | 17 | /** 18 | * @author miaohong 19 | * @date 2017/11/16 20 | */ 21 | public class NettyServerChannelManage extends ChannelInboundHandlerAdapter { 22 | 23 | private static final Logger LOGGER = LoggerFactory.getLogger(NettyServerChannelManage.class); 24 | 25 | @Getter 26 | private ConcurrentMap channels = new ConcurrentHashMap<>(); 27 | 28 | private int maxChannel = 0; 29 | 30 | public NettyServerChannelManage(int maxChannel) { 31 | super(); 32 | this.maxChannel = maxChannel; 33 | } 34 | 35 | 36 | @Override 37 | public void channelActive(ChannelHandlerContext ctx) throws Exception { 38 | 39 | Channel channel = ctx.channel(); 40 | 41 | String channelKey = getChannelKey((InetSocketAddress) channel.localAddress(), 42 | (InetSocketAddress) channel.remoteAddress()); 43 | 44 | if (channels.size() > maxChannel) { 45 | // 超过最大连接数限制,直接close连接 46 | LOGGER.warn("NettyServerChannelManage channelConnected channel size out of limit: limit={} current={}", 47 | maxChannel, channels.size()); 48 | 49 | channel.close(); 50 | } else { 51 | channels.put(channelKey, channel); 52 | ctx.fireChannelActive(); 53 | } 54 | } 55 | 56 | /** 57 | * Calls {@link ChannelHandlerContext#fireChannelInactive()} to forward 58 | * to the next {@link ChannelInboundHandler} in the {@link ChannelPipeline}. 59 | * 60 | * Sub-classes may override this method to change behavior. 61 | */ 62 | @Override 63 | public void channelInactive(ChannelHandlerContext ctx) throws Exception { 64 | 65 | Channel channel = ctx.channel(); 66 | 67 | String channelKey = getChannelKey((InetSocketAddress) channel.localAddress(), 68 | (InetSocketAddress) channel.remoteAddress()); 69 | 70 | channels.remove(channelKey); 71 | ctx.fireChannelInactive(); 72 | } 73 | 74 | 75 | /** 76 | * close所有的连接 77 | */ 78 | public void close() { 79 | for (Map.Entry entry : channels.entrySet()) { 80 | try { 81 | Channel channel = entry.getValue(); 82 | 83 | if (channel != null) { 84 | channel.close(); 85 | } 86 | } catch (Exception e) { 87 | LOGGER.error("NettyServerChannelManage close channel Error: " + entry.getKey(), e); 88 | } 89 | } 90 | } 91 | 92 | /** 93 | * remote address + local address 作为连接的唯一标示 94 | * 95 | * @param local 96 | * @param remote 97 | * @return 98 | */ 99 | private String getChannelKey(InetSocketAddress local, InetSocketAddress remote) { 100 | String key = ""; 101 | if (local == null || local.getAddress() == null) { 102 | key += "null-"; 103 | } else { 104 | key += local.getAddress().getHostAddress() + ":" + local.getPort() + "-"; 105 | } 106 | 107 | if (remote == null || remote.getAddress() == null) { 108 | key += "null"; 109 | } else { 110 | key += remote.getAddress().getHostAddress() + ":" + remote.getPort(); 111 | } 112 | 113 | return key; 114 | } 115 | 116 | } 117 | -------------------------------------------------------------------------------- /fishchat-core/transport-common/src/main/java/org/miaohong/fishchat/transport/common/url/URL.java: -------------------------------------------------------------------------------- 1 | package org.miaohong.fishchat.transport.common.url; 2 | 3 | 4 | import lombok.Getter; 5 | import lombok.Setter; 6 | import lombok.ToString; 7 | import org.apache.commons.lang3.StringUtils; 8 | import org.miaohong.fishchat.transport.common.exception.TransportException; 9 | 10 | import java.util.HashMap; 11 | import java.util.Map; 12 | 13 | /** 14 | * @author miaohong 15 | * @date 2017/11/16 16 | */ 17 | @ToString 18 | public class URL { 19 | 20 | @Getter 21 | @Setter 22 | private String protocol; 23 | 24 | @Getter 25 | @Setter 26 | private String host; 27 | 28 | @Getter 29 | @Setter 30 | private int port; 31 | 32 | @Getter 33 | @Setter 34 | private String path; 35 | 36 | private Map parameters; 37 | 38 | public URL(String protocol, String host, int port, String path) { 39 | this(protocol, host, port, path, new HashMap<>()); 40 | } 41 | 42 | public URL(String protocol, String host, int port, String path, Map parameters) { 43 | this.protocol = protocol; 44 | this.host = host; 45 | this.port = port; 46 | this.path = path; 47 | this.parameters = parameters; 48 | } 49 | 50 | 51 | public static URL valueOf(String url) { 52 | if (StringUtils.isBlank(url)) { 53 | throw new TransportException(); 54 | } 55 | String protocol = null; 56 | String host = null; 57 | int port = 0; 58 | String path = null; 59 | Map parameters = new HashMap<>(); 60 | // seperator between body and parameters 61 | int i = url.indexOf("?"); 62 | if (i >= 0) { 63 | String[] parts = url.substring(i + 1).split("\\&"); 64 | 65 | for (String part : parts) { 66 | part = part.trim(); 67 | if (part.length() > 0) { 68 | int j = part.indexOf('='); 69 | if (j >= 0) { 70 | parameters.put(part.substring(0, j), part.substring(j + 1)); 71 | } else { 72 | parameters.put(part, part); 73 | } 74 | } 75 | } 76 | url = url.substring(0, i); 77 | } 78 | i = url.indexOf("://"); 79 | if (i >= 0) { 80 | if (i == 0) { 81 | throw new IllegalStateException("url missing protocol: \"" + url + "\""); 82 | } 83 | protocol = url.substring(0, i); 84 | url = url.substring(i + 3); 85 | } else { 86 | i = url.indexOf(":/"); 87 | if (i >= 0) { 88 | if (i == 0) { 89 | throw new IllegalStateException("url missing protocol: \"" + url + "\""); 90 | } 91 | protocol = url.substring(0, i); 92 | url = url.substring(i + 1); 93 | } 94 | } 95 | 96 | i = url.indexOf("/"); 97 | if (i >= 0) { 98 | path = url.substring(i + 1); 99 | url = url.substring(0, i); 100 | } 101 | 102 | i = url.indexOf(":"); 103 | if (i >= 0 && i < url.length() - 1) { 104 | port = Integer.parseInt(url.substring(i + 1)); 105 | url = url.substring(0, i); 106 | } 107 | if (url.length() > 0) { 108 | host = url; 109 | } 110 | return new URL(protocol, host, port, path, parameters); 111 | } 112 | 113 | } 114 | 115 | -------------------------------------------------------------------------------- /fishchat-core/transport-netty/src/main/java/org/miaohong/fishchat/transport/netty/server/NettyServer.java: -------------------------------------------------------------------------------- 1 | package org.miaohong.fishchat.transport.netty.server; 2 | 3 | import io.netty.bootstrap.ServerBootstrap; 4 | import io.netty.channel.ChannelFuture; 5 | import io.netty.channel.ChannelHandlerContext; 6 | import io.netty.channel.ChannelInboundHandlerAdapter; 7 | import io.netty.channel.ChannelInitializer; 8 | import io.netty.channel.nio.NioEventLoopGroup; 9 | import io.netty.channel.socket.SocketChannel; 10 | import io.netty.channel.socket.nio.NioServerSocketChannel; 11 | import org.miaohong.fishchat.transport.common.server.AbstractServer; 12 | import org.miaohong.fishchat.transport.common.state.ChannelState; 13 | import org.miaohong.fishchat.transport.common.url.URL; 14 | import org.slf4j.Logger; 15 | import org.slf4j.LoggerFactory; 16 | 17 | import java.net.InetSocketAddress; 18 | 19 | 20 | /** 21 | * @author miaohong 22 | * @date 2017/11/16 23 | */ 24 | public class NettyServer extends AbstractServer { 25 | 26 | private static final Logger LOGGER = LoggerFactory.getLogger(NettyServer.class); 27 | 28 | private ServerBootstrap bootstrap; 29 | private ChannelFuture serverChannel; 30 | private URL url; 31 | 32 | public NettyServer(URL url) { 33 | this.url = url; 34 | } 35 | 36 | @Override 37 | public synchronized boolean open() { 38 | if (isAvailable()) { 39 | LOGGER.warn("NettyServer ServerChannel already Opened"); 40 | return true; 41 | } 42 | 43 | LOGGER.info("NettyServer ServerChannel start at port [{}]", url); 44 | 45 | initServerBootstrap(); 46 | 47 | serverChannel = bootstrap.bind(new InetSocketAddress(url.getHost(), url.getPort())); 48 | state = ChannelState.ALIVE; 49 | 50 | LOGGER.info("NettyServer ServerChannel finish"); 51 | 52 | return state.isAliveState(); 53 | } 54 | 55 | private synchronized void initServerBootstrap() { 56 | NioEventLoopGroup group = new NioEventLoopGroup(); 57 | 58 | try { 59 | bootstrap = new ServerBootstrap(); 60 | bootstrap.group(group).channel(NioServerSocketChannel.class) 61 | .localAddress(new InetSocketAddress(url.getHost(), url.getPort())) 62 | .childHandler(new ChannelInitializer() { 63 | @Override 64 | public void initChannel(SocketChannel ch) throws Exception { 65 | ch.pipeline().addLast( 66 | new ChannelInboundHandlerAdapter() { 67 | @Override 68 | public void channelActive(ChannelHandlerContext ctx) throws Exception { 69 | } 70 | }); 71 | } 72 | } 73 | ); 74 | ChannelFuture f = bootstrap.bind().sync(); 75 | f.channel().closeFuture().sync(); 76 | } catch (InterruptedException e) { 77 | LOGGER.error(e.getMessage(), e); 78 | } finally { 79 | try { 80 | group.shutdownGracefully().sync(); 81 | } catch (InterruptedException e) { 82 | LOGGER.error(e.getMessage(), e); 83 | } 84 | } 85 | 86 | } 87 | 88 | @Override 89 | public void close() { 90 | 91 | } 92 | 93 | @Override 94 | public void close(int timeout) { 95 | 96 | } 97 | 98 | @Override 99 | public boolean isClosed() { 100 | return state.isCloseState(); 101 | } 102 | 103 | @Override 104 | public boolean isAvailable() { 105 | return state.isAliveState(); 106 | } 107 | 108 | @Override 109 | public boolean isActive() { 110 | return this.serverChannel != null && this.serverChannel.channel().isActive(); 111 | } 112 | 113 | } 114 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | fishchat 6 | 7 | fishchat-core 8 | fishchat-server 9 | fishchat-api 10 | 11 | org.miaohong.fishcat 12 | 1.0.0-SNAPSHOT 13 | pom 14 | 15 | 16 | UTF-8 17 | 1.8 18 | UTF-8 19 | 20 | 21 | 22 | org.springframework.boot 23 | spring-boot-starter-parent 24 | 1.5.9.RELEASE 25 | 26 | 27 | 28 | 29 | 30 | org.springframework.cloud 31 | spring-cloud-dependencies 32 | Edgware.RELEASE 33 | pom 34 | import 35 | 36 | 37 | 38 | org.projectlombok 39 | lombok 40 | 1.16.18 41 | compile 42 | 43 | 44 | 45 | org.apache.commons 46 | commons-lang3 47 | 3.7 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | spring-snapshots 56 | Spring Snapshots 57 | http://repo.spring.io/libs-snapshot-local 58 | 59 | true 60 | 61 | 62 | 63 | spring-milestones 64 | Spring Milestones 65 | http://repo.spring.io/libs-milestone-local 66 | 67 | false 68 | 69 | 70 | 71 | spring-releases 72 | Spring Releases 73 | http://repo.spring.io/libs-release-local 74 | 75 | false 76 | 77 | 78 | 79 | 80 | 81 | spring-snapshots 82 | Spring Snapshots 83 | http://repo.spring.io/libs-snapshot-local 84 | 85 | true 86 | 87 | 88 | 89 | spring-milestones 90 | Spring Milestones 91 | http://repo.spring.io/libs-milestone-local 92 | 93 | false 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | org.springframework.boot 102 | spring-boot-maven-plugin 103 | 104 | 105 | 106 | org.apache.maven.plugins 107 | maven-compiler-plugin 108 | 3.7.0 109 | 110 | ${java.source.jdk} 111 | ${java.source.jdk} 112 | ${project.build.sourceEncoding} 113 | 114 | 115 | 116 | 117 | 118 | --------------------------------------------------------------------------------