Gaea是支持跨平台具有高并发、高性能、高可靠性,并提供异步、多协议、事件驱动的中间层服务框架

Gaea是支持跨平台具有高并发、高性能、高可靠性,并提供异步、多协议、事件驱动的中间层服务框架

Gaea:58同城开源的中间层服务框架 https://github.com/58code/Gaea

中间件

Gaea是支持跨平台具有高并发、高性能、高可靠性,并提供异步、多协议、事件驱动的中间层服务框架。相对于其它重量级的中间件,比如淘宝的dubbo,Gaea只做一件事,因此没有过多的项目依赖。

 

在学校的时候学过CORBA,因此对中间件有所了解。在CORBA中,接口通过IDL描述,然后分别生成本地存根(stub)和服务器端骨架(skeleton)。服务器端对这些接口进行实现,当客户端调用时,本地将调用的相关信息(方法、参数)通过消息发送到服务器端,服务器端执行完后返回结果。

 




Gaea也提供了同样的服务。在公司内部,各个系统之间可能需要相互调用,通过Gaea对外提供服务实现跨平台,跨语言调用。

 

部署服务器端

Gaea提供了一个demo(Gaea/demo目录下),客户端虽然提供了一个gaeaDemo.jar,但实际上只需要里面的INewsService.java以及News.java。

 

部署服务端时使用的目录结构参照gaea.tar.gz,服务是放在service目录下,service/deploy/{serviceName} 放配置文件,serveice/lib放依赖的jar包。

[root@localhost gaea]# pwd
/opt/test/gaea
[root@localhost gaea]# ls -l
总计 36
drwxr-xr-x 2 root root 4096 2012-09-10 bin
drwxr-xr-x 2 root root 4096 2012-09-10 conf
-rw-r--r-- 1 root root   52 2012-09-10 COPYRIGHT
drwxr-xr-x 2 root root 4096 2012-09-10 docs
drwxr-xr-x 2 root root 4096 2012-09-10 lib
drwxr-xr-x 2 root root 4096 2012-09-10 log
-rw-r--r-- 1 root root  247 2012-09-10 README
drwxr-xr-x 4 root root 4096 2012-09-10 service
drwxr-xr-x 3 root root 4096 2012-09-10 tmp

 

如果需要修改服务器的监听端口,修改service/deploy/{serviceName}/gaea_config.xml

<!-- socket server listent port -->
<property>
<name>gaea.server.tcp.listenPort</name>
<value>9090</value>
</property>

 

启动时执行startup.sh,参数参考demo_run.sh

[root@localhost bin]# pwd
/opt/test/gaea/bin
[root@localhost bin]# ls -l
总计 20
-rw-r--r-- 1 root root  164 2012-08-16 demo_run.sh
-rw-r--r-- 1 root root 2065 2012-09-04 restart.sh
-rw-r--r-- 1 root root    0 2010-12-28 shutdown.bat
-rw-r--r-- 1 root root  809 2012-08-16 shutdown.sh
-rw-r--r-- 1 root root 2115 2012-09-07 startup.bat
-rwxr-xr-x 1 root root 2967 2012-08-16 startup.sh
[root@localhost bin]# chmod +x demo_run.sh 
[root@localhost bin]# ./demo_run.sh 

no GAEA_HOME path
pid:6118
[root@localhost bin]# [06-21 16:03:41,073 INFO ] [main] bootstrap.Main - +++++++++++++++++++++ staring +++++++++++++++++++++


[06-21 16:03:41,074 INFO ] [main] bootstrap.Main - user.dir: /opt/test/gaea/bin
[06-21 16:03:41,074 INFO ] [main] bootstrap.Main - rootPath: /opt/test/gaea/bin/../
[06-21 16:03:41,074 INFO ] [main] bootstrap.Main - service gaea_config.xml: /opt/test/gaea/bin/../service/deploy/demo/gaea_config.xml
[06-21 16:03:41,074 INFO ] [main] bootstrap.Main - default gaea_config.xml: /opt/test/gaea/bin/../conf/gaea_config.xml
[06-21 16:03:41,075 INFO ] [main] bootstrap.Main - service gaea_log4j.xml: /opt/test/gaea/bin/../service/deploy/demo/gaea_log4j.xml
[06-21 16:03:41,075 INFO ] [main] bootstrap.Main - default gaea_log4j.xml: /opt/test/gaea/bin/../conf/gaea_log4j.xml
[06-21 16:03:41,075 INFO ] [main] bootstrap.Main - load service config...
[06-21 16:03:41,328 INFO ] [main] bootstrap.Main - gaea.service.name: demo
[06-21 16:03:41,329 INFO ] [main] bootstrap.Main - -----------------loading global jars------------------
[06-21 16:03:41,337 INFO ] [main] hotdeploy.GlobalClassLoader - append jar to classpath:file:/opt/test/gaea/service/deploy/demo/demo.jar
[06-21 16:03:41,337 INFO ] [main] hotdeploy.GlobalClassLoader - append jar to classpath:file:/opt/test/gaea/service/lib/antlr-runtime-3.3.jar

[06-21 16:03:41,344 INFO ] [main] bootstrap.Main - -------------------------end-------------------------


[06-21 16:03:41,345 INFO ] [main] bootstrap.Main - --------------------loading proxys-------------------
[06-21 16:03:41,348 INFO ] [main] bytecode.ScanClass - begin scan jar from path:/opt/test/gaea/bin/../service/deploy/demo/
[06-21 16:03:41,435 INFO ] [main] bytecode.ScanClass - finish scan jar
[06-21 16:03:41,437 INFO ] [main] bytecode.ProxyClassCreater - loading dynamic proxy v1...
[06-21 16:03:41,437 INFO ] [main] bytecode.ProxyClassCreater - loading => NewsServiceProxyStub1371801821435
[06-21 16:03:41,437 INFO ] [main] bytecode.ProxyClassCreater - class name:components.NewsService
[06-21 16:03:41,491 DEBUG] [main] bytecode.ProxyClassCreater - create method:getNewsByID
[06-21 16:03:41,545 DEBUG] [main] bytecode.ProxyClassCreater - create method:getNewsByCateID
[06-21 16:03:41,572 INFO ] [main] bytecode.ProxyClassCreater - load dynamic proxy success!!!
[06-21 16:03:41,572 INFO ] [main] bytecode.CreateManager - proxy class buffer creater finish!!!
[06-21 16:03:41,573 INFO ] [main] bytecode.ProxyFactoryCreater - begin create ProxyFactory:ProxyFactory1371801821435
[06-21 16:03:41,578 DEBUG] [main] bytecode.ProxyFactoryCreater - ProxyFactory source code:public com.bj58.spat.gaea.server.contract.context.IProxyStub getProxy(String lookup) {if(lookup.equalsIgnoreCase("NewsService")){return proxyNewsServicedemo;}return null;}}
[06-21 16:03:41,579 INFO ] [main] bytecode.ProxyFactoryCreater - create ProxyFactory success!!!
[06-21 16:03:41,580 INFO ] [main] bytecode.CreateManager - proxy factory buffer creater finish!!!
[06-21 16:03:41,581 INFO ] [main] bytecode.CreateManager - dynamic load class:NewsServiceProxyStub1371801821435
[06-21 16:03:41,582 INFO ] [main] bytecode.CreateManager - crate ProxyFactory instance!!!
[06-21 16:03:41,582 INFO ] [main] bootstrap.Main - -------------------------end-------------------------


[06-21 16:03:41,582 INFO ] [main] bootstrap.Main - -----------------loading init beans------------------
[06-21 16:03:41,582 INFO ] [main] bootstrap.Main - load: com.bj58.spat.gaea.server.contract.context.SerializerClassInit
[06-21 16:03:41,588 INFO ] [main] log.SystemPrintStream - Scan jar files begin!
[06-21 16:03:41,589 ERROR] [main] log.SystemPrintStream - 开始扫描全部引用jar包,如果扫描过程过长请在启动vm参数中设置gaea.serializer.basepakage或者设置gaea.serializer.scantype=asyn使用异步模式扫描。
[06-21 16:03:41,590 INFO ] [main] log.SystemPrintStream - scanByURLClassLoader:/opt/test/gaea/bin/
[06-21 16:03:41,591 INFO ] [main] log.SystemPrintStream - scanByURLClassLoader:/opt/jdk1.6.0_16/lib/tools.jar
[06-21 16:03:42,964 INFO ] [main] log.SystemPrintStream - scanByURLClassLoader:/opt/test/gaea/lib/antlrall-2.7.2.jar
[06-21 16:03:43,100 INFO ] [main] log.SystemPrintStream - scanByURLClassLoader:/opt/test/gaea/lib/com.bj58.spat.gaea.protocol-1.0.0.jar
[06-21 16:03:43,111 INFO ] [main] log.SystemPrintStream - scanByURLClassLoader:/opt/test/gaea/lib/com.bj58.spat.gaea.serializer-1.0.0.jar
[06-21 16:03:43,131 INFO ] [main] log.SystemPrintStream - scanByURLClassLoader:/opt/test/gaea/lib/com.bj58.spat.gaea.server-1.0.0.jar


[06-21 16:03:46,197 INFO ] [main] log.SystemPrintStream - scaning com.bj58.enterprise.entity.com.bj58.enterprise.entity.Enterprise
[06-21 16:03:46,197 INFO ] [main] log.SystemPrintStream - scaning com.bj58.enterprise.entity.com.bj58.enterprise.entity.SESUser
[06-21 16:03:46,198 INFO ] [main] log.SystemPrintStream - scaning com.bj58.enterprise.entity.com.bj58.enterprise.entity.User
[06-21 16:03:46,198 INFO ] [main] log.SystemPrintStream - scaning com.bj58.spat.gaea.server.core.communication.http.com.bj58.spat.gaea.server.core.communication.http.News
[06-21 16:03:46,199 INFO ] [main] log.SystemPrintStream - scaning com.bj58.spat.gaea.server.util.com.bj58.spat.gaea.server.util.News
[06-21 16:03:46,199 INFO ] [main] log.SystemPrintStream - scaning entity.entity.News
[06-21 16:03:46,199 INFO ] [main] log.SystemPrintStream - Scan jar files completed!
[06-21 16:03:46,200 INFO ] [main] bootstrap.Main - -------------------------end-------------------------


[06-21 16:03:46,200 INFO ] [main] bootstrap.Main - -----------loading global request filters------------
[06-21 16:03:46,200 INFO ] [main] bootstrap.Main - load: com.bj58.spat.gaea.server.filter.ProtocolParseFilter
[06-21 16:03:46,201 INFO ] [main] bootstrap.Main - load: com.bj58.spat.gaea.server.filter.HandclaspFilter
[06-21 16:03:46,202 INFO ] [main] bootstrap.Main - load: com.bj58.spat.gaea.server.filter.ExecuteMethodFilter
[06-21 16:03:46,203 INFO ] [main] bootstrap.Main - -------------------------end-------------------------


[06-21 16:03:46,203 INFO ] [main] bootstrap.Main - -----------loading global response filters-----------
[06-21 16:03:46,203 INFO ] [main] bootstrap.Main - load: com.bj58.spat.gaea.server.filter.ProtocolCreateFilter
[06-21 16:03:46,219 INFO ] [main] bootstrap.Main - load: com.bj58.spat.gaea.server.filter.ExecuteTimeFilter
[06-21 16:03:46,224 INFO ] [main] bootstrap.Main - -------------------------end-------------------------


[06-21 16:03:46,224 INFO ] [main] bootstrap.Main - -----------loading connection filters-----------
[06-21 16:03:46,224 INFO ] [main] bootstrap.Main - load: com.bj58.spat.gaea.server.filter.IPFilter
[06-21 16:03:46,225 INFO ] [main] bootstrap.Main - -------------------------end-------------------------


[06-21 16:03:46,225 INFO ] [main] bootstrap.Main - ------------------load secureKey start---------------------
[06-21 16:03:46,225 INFO ] [main] bootstrap.Main - ------------------load secureKey end----------------------


[06-21 16:03:46,226 INFO ] [main] bootstrap.Main - ------------------signal registr start---------------------
[06-21 16:03:46,226 INFO ] [main] bootstrap.Main - ------------------signal registr success----------------------


[06-21 16:03:46,226 INFO ] [main] bootstrap.Main - ------------------ starting servers -----------------
[06-21 16:03:46,227 INFO ] [main] bootstrap.Main - gaea.server.tcp is starting...
[06-21 16:03:46,263 INFO ] [main] tcp.SocketServer - loading invoker...
[06-21 16:03:46,300 INFO ] [main] proxy.AsyncInvokerHandle - async worker count:100
[06-21 16:03:46,300 INFO ] [main] tcp.SocketServer - initing server...
[06-21 16:03:46,300 INFO ] [main] tcp.SocketServer - -- socket server config --
[06-21 16:03:46,301 INFO ] [main] tcp.SocketServer - -- listen ip: 0.0.0.0
[06-21 16:03:46,301 INFO ] [main] tcp.SocketServer - -- port: 9090
[06-21 16:03:46,301 INFO ] [main] tcp.SocketServer - -- tcpNoDelay: true
[06-21 16:03:46,301 INFO ] [main] tcp.SocketServer - -- receiveBufferSize: 65536
[06-21 16:03:46,301 INFO ] [main] tcp.SocketServer - -- sendBufferSize: 65536
[06-21 16:03:46,302 INFO ] [main] tcp.SocketServer - -- frameMaxLength: 524288
[06-21 16:03:46,302 INFO ] [main] tcp.SocketServer - -- worker thread count: 32
[06-21 16:03:46,302 INFO ] [main] tcp.SocketServer - --------------------------
[06-21 16:03:46,302 INFO ] [main] tcp.SocketServer - demo SocketServer starting...
[06-21 16:03:46,345 INFO ] [main] bootstrap.Main - gaea.server.tcpstarted success!!!


[06-21 16:03:46,345 INFO ] [main] bootstrap.Main - gaea.server.telnet is starting...
[06-21 16:03:46,346 INFO ] [main] telnet.TelnetServer - ----------------telnet server config------------------
[06-21 16:03:46,346 INFO ] [main] telnet.TelnetServer - -- telnet server listen ip: 0.0.0.0
[06-21 16:03:46,346 INFO ] [main] telnet.TelnetServer - -- telnet server port: 7070
[06-21 16:03:46,346 INFO ] [main] telnet.TelnetServer - ------------------------------------------------------
[06-21 16:03:46,352 INFO ] [main] bootstrap.Main - gaea.server.telnetstarted success!!!


[06-21 16:03:46,352 INFO ] [main] bootstrap.Main - -------------------------end-------------------------


[06-21 16:03:46,352 INFO ] [main] bootstrap.Main - +++++++++++++++++++++ server start success!!! +++++++++++++++++++++

 

服务器启动完毕

 

客户端

启动客户端,我自己打包成了可执行文件

[root@localhost test]# java -jar client.jar 
Scan jar files begin!
开始扫描全部引用jar包,如果扫描过程过长请在启动vm参数中设置gaea.serializer.basepakage或者设置gaea.serializer.scantype=asyn使用异步模式扫描。
scanByURLClassLoader:/opt/test/client.jar
scaning com.bj58.spat.gaea.serializer.component.com.bj58.spat.gaea.serializer.component.TypeMap
scaning com.bj58.spat.gaea.serializer.component.com.bj58.spat.gaea.serializer.component.ClassScaner
scaning com.bj58.spat.gaea.serializer.component.annotation.com.bj58.spat.gaea.serializer.component.annotation.GaeaSerializable
scaning com.bj58.spat.gaea.serializer.component.exception.com.bj58.spat.gaea.serializer.component.exception.DisallowedSerializeException
scaning com.bj58.spat.gaea.serializer.serializer.com.bj58.spat.gaea.serializer.serializer.ObjectSerializer
scaning com.bj58.spat.gaea.protocol.sdp.com.bj58.spat.gaea.protocol.sdp.RequestProtocol
scaning com.bj58.spat.gaea.protocol.sdp.com.bj58.spat.gaea.protocol.sdp.ResetProtocol
scaning com.bj58.spat.gaea.protocol.sdp.com.bj58.spat.gaea.protocol.sdp.ExceptionProtocol
scaning com.bj58.spat.gaea.protocol.sdp.com.bj58.spat.gaea.protocol.sdp.ResponseProtocol
scaning com.bj58.spat.gaea.protocol.sdp.com.bj58.spat.gaea.protocol.sdp.HandclaspProtocol
scaning com.bj58.spat.gaea.protocol.utility.com.bj58.spat.gaea.protocol.utility.KeyValuePair
scaning com.github.hailinzeng.gaea.com.github.hailinzeng.gaea.News
Scan jar files completed!
2013-6-21 17:13:04 com.bj58.spat.gaea.client.utility.logger.FileLog info
信息: Gaea Client v1.0.0:starting init servers
2013-6-21 17:13:04 com.bj58.spat.gaea.client.utility.logger.FileLog info
信息: Gaea Client v1.0.0:init servers end
2013-6-21 17:13:04 com.bj58.spat.gaea.client.utility.logger.FileLog info
信息: Gaea Client v1.0.0:MaxPakageSize:102400
2013-6-21 17:13:04 com.bj58.spat.gaea.client.utility.logger.FileLog info
信息: Gaea Client v1.0.0:SendBufferSize:8388608
2013-6-21 17:13:04 com.bj58.spat.gaea.client.utility.logger.FileLog info
信息: Gaea Client v1.0.0:RecvBufferSize:8388608
2013-6-21 17:13:04 com.bj58.spat.gaea.client.utility.logger.FileLog info
信息: Gaea Client v1.0.0:create a new connection :Socket[addr=/127.0.0.1,port=9090,localport=35459]
2013-6-21 17:13:04 com.bj58.spat.gaea.client.utility.logger.FileLog warn
警告: Gaea Client v1.0.0:method:getNewsByCateID invoke time :1010
ID is 58 title is 58同城一个神奇的网站

你可能感兴趣的:(事件驱动)