Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修复若干问题 #2

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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/*
15 changes: 7 additions & 8 deletions client/c/client/src/client/CSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 5 additions & 2 deletions client/c/client/src/client/WindowData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#include <stddef.h>
#include <sys/types.h>
#include <stdio.h>
WindowData::WindowData() {
WindowData::WindowData() : ready(false) {
if (pthread_mutex_init(&mutex_, NULL) != 0) {
errno = -3;
throw std::runtime_error("pthread_mutex_init error");
Expand All @@ -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_);
}
Expand Down
1 change: 1 addition & 0 deletions client/c/client/src/client/WindowData.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class WindowData {
int dataLen;
pthread_mutex_t mutex_; //线程同步锁
pthread_cond_t cond_; //线程同步的条件变量
bool ready;
};

#endif /* WINDOWDATA_H_ */
Original file line number Diff line number Diff line change
Expand Up @@ -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!");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* Copyright Beijing 58 Information Technology Co.,Ltd.
*
* Licensed to the Apache Software Foundation (ASF) under one
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, ServiceProxy> Proxys = new HashMap<String, ServiceProxy>();
Expand All @@ -74,6 +74,8 @@ private ServiceProxy(String serviceName) throws Exception {
}

ioreconnect = serverCount - 1;

// count = max {ioreconnect, requestTime}
count = requestTime;

if(ioreconnect > requestTime){
Expand Down
1 change: 1 addition & 0 deletions demo/COPYRIGHT
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Copyright Beijing 58 Information Technology Co.,Ltd.
7 changes: 7 additions & 0 deletions demo/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
The Gaea Project
Gaea�Ƿ���ͨѶ���(Service Communication Framework)֧�ֿ�ƽ̨���и߲����������ܡ��߿ɿ��ԣ����ṩ�첽����Э�顢�¼��������м������ܡ�

WeiBo:@58code
Email:[email protected]

Copyright Beijing 58 Information Technology Co.,Ltd.
9 changes: 9 additions & 0 deletions demo/bin/demo_run.sh
Original file line number Diff line number Diff line change
@@ -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
86 changes: 86 additions & 0 deletions demo/bin/restart.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#!/bin/sh

## USAGE="Usage: reboot.sh <service-startscript> <time>"
## service-startscript:this script name is servicestartscript name
## example:
## umc_run.sh (reboot.sh umc_run 10)
## imc_start.sh (reboot.sh imc_start 10)
### ====================================================================== ###
## ##
## GAEA server reboot script ##
## ##
### ====================================================================== ###

USAGE="Usage: reboot.sh <service-name|service-startscript> <time>"

# if no args specified, show usage
if [ $# -ne 2 ]; then
echo $USAGE
exit 1
fi

# get arguments
SERVICE_STARTSCRIPT=$1
SERVICE_NAME=$1
CONTROL_TIME=$2

cd $(dirname "$0")

case x$2 in
x[0-9]*)
;;
*)
echo "please input time num"
exit 1
;;
esac

if [ "$SERVICE_STARTSCRIPT" ]; then
if [ `expr index "$SERVICE_NAME" "_"` > 0 ];then
SERVICE_NAME=$(echo "$SERVICE_STARTSCRIPT"|cut -d "_" -f 1)
if [ `expr index "$SERVICE_NAME" "."` > 0 ]; then
SERVICE_NAME=$(echo "$SERVICE_NAME"|cut -d "." -f 1)
fi
fi
else
echo "this server name is null Please input server name"
exit 1
fi


DIR=`dirname "$0"`
DIR=`cd "$bin"; pwd`
PID_FILE="$DIR"/../tmp/pid/"$SERVICE_NAME"

if [ ! -e $PID_FILE ]; then
echo "pid file($PID_FILE) not exits"
exit 1
fi

cd $(dirname "$0")

#send reboot signal
kill -12 `cat $PID_FILE`
echo "kill -12 `cat $PID_FILE`"

#sleep time
echo ""$CONTROL_TIME" seconds after restart service"
sleep `expr $CONTROL_TIME`

#shutdown this server
kill -9 `cat $PID_FILE`
echo "kill -9 `cat $PID_FILE`"
rm -rf $PID_FILE


#start this server
STARTSCRIPT_FILE="$DIR"/"$SERVICE_STARTSCRIPT".sh
echo "$STARTSCRIPT_FILE"
if [ ! -e $STARTSCRIPT_FILE ]; then
echo "defult startup.sh"
source "$DIR"/startup.sh "$SERVICE_NAME"
else
echo "this server start script"
source "$DIR"/"$SERVICE_STARTSCRIPT".sh
fi

Empty file added demo/bin/shutdown.bat
Empty file.
34 changes: 34 additions & 0 deletions demo/bin/shutdown.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/sh

### ====================================================================== ###
## ##
## GAEA server shutdown script ##
## ##
### ====================================================================== ###


USAGE="Usage: shutdown.sh <service-name>"

# if no args specified, show usage
if [ $# -lt 1 ]; then
echo $USAGE
exit 1
fi


# get arguments
SERVICE_NAME=$1

DIR=`dirname "$0"`
DIR=`cd "$bin"; pwd`
PID_FILE="$DIR"/../tmp/pid/"$SERVICE_NAME"

if [ ! -e $PID_FILE ]; then
echo "pid file($PID_FILE) not exits"
exit 1
fi

echo "kill pid: `cat $PID_FILE`"
kill -9 `cat $PID_FILE`
rm -rf $PID_FILE

76 changes: 76 additions & 0 deletions demo/bin/startup.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
@echo off

rem ======================================================================
rem
rem GAEA server bootstrap script
rem
rem ======================================================================


set "USAGE=Usage: startup.bat <service-name> [<other-gaea-config>]"
set "SYSTEM_PROPERTY="

rem if no args specified, show usage
if not "%1" == "" goto args_ok
echo "%USAGE%"
goto end


:args_ok
rem get arguments
set "SERVICE_NAME=%1"
set "OTHER_GAEA_CONFIG=%2%3%4%5%6%7%8%9"


rem get path
set DIR=%cd%
set ROOT_PATH=%DIR%/../
set DEPLOY_PATH=%DIR%/../service/deploy
set PID_PATH=%DIR%/../tmp/pid
#set TOOLS_JAR_PATH=%ROOT_PATH/%lib/tools.jar
set TOOLS_JAR_PATH=%ROOT_PATH%/lib/tools.jar




rem check tools.jar
if "%TOOLS_JAR_PATH%" == "" (goto tools_jar_not_exist) else (goto vm_args)

:tools_jar_not_exist
echo "Can't find tools.jar in JAVA_HOME"
echo "Need a JDK to run javac"
goto end

rem java opts
:vm_args
if not "%VM_XMS%" == "" goto vm_xmx
set VM_XMS=256m

:vm_xmx
if not "%VM_XMX%" == "" goto vm_xmn
set VM_XMX=256m

:vm_xmn
if not "%VM_XMN%" == "" goto java_opts
set VM_XMN=128m

:java_opts
set JAVA_OPTS=-Xms%VM_XMS% -Xmx%VM_XMX% -Xmn%VM_XMN% -Xss1024K -XX:PermSize=64m -XX:MaxPermSize=64m -XX:ParallelGCThreads=20 -XX:+UseConcMarkSweepGC -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:+UseCMSCompactAtFullCollection -XX:SurvivorRatio=65536 -XX:MaxTenuringThreshold=0 -XX:CMSInitiatingOccupancyFraction=80


rem class path
set CLASS_PATH=.;%TOOLS_JAR_PATH%
cd %ROOT_PATH%lib/
SETLOCAL ENABLEDELAYEDEXPANSION
for /f %%i in ('dir /b /s "*.jar"') do (
set str=%%i
set str=!str:\=/!
set CLASS_PATH=!CLASS_PATH!;!str!
)

rem main class
set MAIN_CLASS=com.bj58.spat.gaea.server.bootstrap.Main

java %JAVA_OPTS% -classpath %CLASS_PATH% -Duser.dir=%DIR% %SYSTEM_PROPERTY% %MAIN_CLASS% %OTHER_GAEA_CONFIG% -Dgaea.service.name=%SERVICE_NAME%

:end
Loading