diff --git a/.gitignore b/.gitignore index 2433760..4bffe96 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,12 @@ #*.jar *.war *.ear +/client/java/client/*.classpath +/client/java/client/*.project +/client/java/client/.settings/*.prefs +/client/java/client/target +/client/java/client/* +/protocol/* +/serializer/target +/serializer/* +/server/* diff --git a/client/c/client/src/client/CSocket.cpp b/client/c/client/src/client/CSocket.cpp index b2312c0..437c562 100644 --- a/client/c/client/src/client/CSocket.cpp +++ b/client/c/client/src/client/CSocket.cpp @@ -67,15 +67,14 @@ char* CSocket::receive(int &dataLen, int sessionId, int timeout) { throw std::runtime_error("Need invoke 'registerRec' method before invoke 'receive' method!"); } WindowData *wd = windowDataMap[sessionId - 1]; - if (wd->getData() == NULL) { - int i = wd->waitOne(timeout); - if (i == ETIMEDOUT) { - errno = -1; - unregisterRec(sessionId); - gaeaLog(GAEA_WARNING, "timeout session:%d\n", sessionId); - throw std::runtime_error("Receive data timeout or error!"); - } + int i = wd->waitOne(timeout); + if (i == ETIMEDOUT) { + errno = -1; + unregisterRec(sessionId); + gaeaLog(GAEA_WARNING, "timeout session:%d\n", sessionId); + throw std::runtime_error("Receive data timeout or error!"); } + dataLen = wd->getDataLen(); char *data = wd->getData(); unregisterRec(sessionId); diff --git a/client/c/client/src/client/WindowData.cpp b/client/c/client/src/client/WindowData.cpp index c4e9880..1cd4205 100644 --- a/client/c/client/src/client/WindowData.cpp +++ b/client/c/client/src/client/WindowData.cpp @@ -33,7 +33,7 @@ #include #include #include -WindowData::WindowData() { +WindowData::WindowData() : ready(false) { if (pthread_mutex_init(&mutex_, NULL) != 0) { errno = -3; throw std::runtime_error("pthread_mutex_init error"); @@ -52,12 +52,15 @@ int WindowData::waitOne(int timeOut) { mytime.tv_sec = now.tv_sec + timeOut; mytime.tv_nsec = now.tv_usec * 1000; pthread_mutex_lock(&mutex_); - i = pthread_cond_timedwait(&cond_, &mutex_, &mytime); //等待线程调度 + if (!ready) { + i = pthread_cond_timedwait(&cond_, &mutex_, &mytime); //等待线程调度 + } pthread_mutex_unlock(&mutex_); return i; } void WindowData::set() { pthread_mutex_lock(&mutex_); + ready = true; pthread_cond_signal(&cond_); pthread_mutex_unlock(&mutex_); } diff --git a/client/c/client/src/client/WindowData.h b/client/c/client/src/client/WindowData.h index bec1048..fc8958c 100644 --- a/client/c/client/src/client/WindowData.h +++ b/client/c/client/src/client/WindowData.h @@ -47,6 +47,7 @@ class WindowData { int dataLen; pthread_mutex_t mutex_; //线程同步锁 pthread_cond_t cond_; //线程同步的条件变量 + bool ready; }; #endif /* WINDOWDATA_H_ */ diff --git a/client/java/client/src/com/bj58/spat/gaea/client/communication/socket/ScoketPool.java b/client/java/client/src/com/bj58/spat/gaea/client/communication/socket/ScoketPool.java index 9d4fcb0..076d416 100644 --- a/client/java/client/src/com/bj58/spat/gaea/client/communication/socket/ScoketPool.java +++ b/client/java/client/src/com/bj58/spat/gaea/client/communication/socket/ScoketPool.java @@ -97,10 +97,10 @@ public synchronized CSocket getSocket() throws TimeoutException, IOException, In logger.error("授权文件没有通过校验!"); throw new Exception("授权文件没有通过校验!"); } - } else { - if (queue.size() > 0) { + } else { + if (queue.size() > 0) { rSocket = queue.dequeue(); - } else { + } else { rSocket = queue.dequeue(socketPoolConfig.getWaitTimeout()); if (rSocket == null) { logger.error("socket connection pool is full!"); diff --git a/client/java/client/src/com/bj58/spat/gaea/client/configuration/ServiceConfig.java b/client/java/client/src/com/bj58/spat/gaea/client/configuration/ServiceConfig.java index 0627853..ac34899 100644 --- a/client/java/client/src/com/bj58/spat/gaea/client/configuration/ServiceConfig.java +++ b/client/java/client/src/com/bj58/spat/gaea/client/configuration/ServiceConfig.java @@ -1,4 +1,4 @@ -/* +/* * Copyright Beijing 58 Information Technology Co.,Ltd. * * Licensed to the Apache Software Foundation (ASF) under one @@ -134,15 +134,15 @@ public static ServiceConfig GetConfig(String serviceName) throws Exception { private static void printExceprion(int i, String serviceName) throws Exception{ switch (i) { case 0: - throw new Exception("gaea.config中没有发现" + serviceName + "服务节点!"); + throw new Exception(GaeaConst.CONFIG_PATH + "中没有发现" + serviceName + "服务节点!"); case 1: - throw new Exception("gaea.config服务节点" + serviceName + "没有发现Commmunication/SocketPool配置!"); + throw new Exception(GaeaConst.CONFIG_PATH + "服务节点" + serviceName + "没有发现Commmunication/SocketPool配置!"); case 2: - throw new Exception("gaea.config服务节点" + serviceName + "没有发现Commmunication/Protocol配置!"); + throw new Exception(GaeaConst.CONFIG_PATH + "服务节点" + serviceName + "没有发现Commmunication/Protocol配置!"); case 3: - throw new Exception("gaea.config服务节点" + serviceName + "没有发现Loadbalance/Server/add配置!"); + throw new Exception(GaeaConst.CONFIG_PATH + "服务节点" + serviceName + "没有发现Loadbalance/Server/add配置!"); case 4: - throw new Exception("gaea.config服务节点" + serviceName + "没有发现Service/id配置!"); + throw new Exception(GaeaConst.CONFIG_PATH + "服务节点" + serviceName + "没有发现Service/id配置!"); default: break; } diff --git a/client/java/client/src/com/bj58/spat/gaea/client/configuration/loadbalance/ServerProfile.java b/client/java/client/src/com/bj58/spat/gaea/client/configuration/loadbalance/ServerProfile.java index 59591eb..e775807 100644 --- a/client/java/client/src/com/bj58/spat/gaea/client/configuration/loadbalance/ServerProfile.java +++ b/client/java/client/src/com/bj58/spat/gaea/client/configuration/loadbalance/ServerProfile.java @@ -35,7 +35,7 @@ public class ServerProfile { private String host; private int port; private int deadTimeout; - private float weithtRate; + private float weithtRate; //FIXME:misspelling public ServerProfile(Node node) { NamedNodeMap attributes = node.getAttributes(); diff --git a/client/java/client/src/com/bj58/spat/gaea/client/loadbalance/Dispatcher.java b/client/java/client/src/com/bj58/spat/gaea/client/loadbalance/Dispatcher.java index ca51a28..3781caa 100644 --- a/client/java/client/src/com/bj58/spat/gaea/client/loadbalance/Dispatcher.java +++ b/client/java/client/src/com/bj58/spat/gaea/client/loadbalance/Dispatcher.java @@ -113,6 +113,7 @@ public Server GetServer() { } } + //? Find the least load if ((server.getCurrUserCount() < currUserCount * server.getWeightRage() || currUserCount < 0) && server.getState() == ServerState.Normal) { currUserCount = server.getCurrUserCount(); diff --git a/client/java/client/src/com/bj58/spat/gaea/client/loadbalance/Server.java b/client/java/client/src/com/bj58/spat/gaea/client/loadbalance/Server.java index 7fb6097..255c2c4 100644 --- a/client/java/client/src/com/bj58/spat/gaea/client/loadbalance/Server.java +++ b/client/java/client/src/com/bj58/spat/gaea/client/loadbalance/Server.java @@ -48,7 +48,7 @@ public class Server { private String address; private int port; private int weight; - private float weightRage; + private float weightRage; //Fixme: misspelling private ServerState state; private ScoketPool scoketpool; private int currUserCount; diff --git a/client/java/client/src/com/bj58/spat/gaea/client/proxy/ServiceProxy.java b/client/java/client/src/com/bj58/spat/gaea/client/proxy/ServiceProxy.java index 4c861ca..f18482c 100644 --- a/client/java/client/src/com/bj58/spat/gaea/client/proxy/ServiceProxy.java +++ b/client/java/client/src/com/bj58/spat/gaea/client/proxy/ServiceProxy.java @@ -58,7 +58,7 @@ public class ServiceProxy { private int sessionId = 1; private int requestTime = 0;//超时重连次数 private int ioreconnect = 0;//IO服务切换次数 - private int count = 0; + private int count = 0; //根据requestTime和ioreconnect确定 private static final ILog logger = LogFactory.getLogger(ServiceProxy.class); private static final Object locker = new Object(); private static final HashMap Proxys = new HashMap(); @@ -74,6 +74,8 @@ private ServiceProxy(String serviceName) throws Exception { } ioreconnect = serverCount - 1; + + // count = max {ioreconnect, requestTime} count = requestTime; if(ioreconnect > requestTime){ diff --git a/demo/COPYRIGHT b/demo/COPYRIGHT new file mode 100644 index 0000000..b511f04 --- /dev/null +++ b/demo/COPYRIGHT @@ -0,0 +1 @@ +Copyright Beijing 58 Information Technology Co.,Ltd. \ No newline at end of file diff --git a/demo/README b/demo/README new file mode 100644 index 0000000..f4f04b9 --- /dev/null +++ b/demo/README @@ -0,0 +1,7 @@ +The Gaea Project +GaeaǷͨѶ(Service Communication Framework)ֿ֧ƽ̨и߲ܡ߿ɿԣṩ첽Э顢¼мܡ + +WeiBo:@58code +Email:code@58.com + +Copyright Beijing 58 Information Technology Co.,Ltd. \ No newline at end of file diff --git a/demo/bin/demo_run.sh b/demo/bin/demo_run.sh new file mode 100644 index 0000000..77af09d --- /dev/null +++ b/demo/bin/demo_run.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +DIR=`dirname "$0"` +DIR=`cd "$bin"; pwd` + +export VM_XMS=2g +export VM_XMX=2g +export VM_XMN=512m +./startup.sh demo $DIR/demo_config.xml $DIR/gaea_log4j.xml diff --git a/demo/bin/restart.sh b/demo/bin/restart.sh new file mode 100644 index 0000000..7fde05a --- /dev/null +++ b/demo/bin/restart.sh @@ -0,0 +1,86 @@ +#!/bin/sh + +## USAGE="Usage: reboot.sh