Explorar el Código

集群推送第二版修改,调整P端增删改路由关系,M端查询等操作

chengwb3 %!s(int64=8) %!d(string=hace) años
padre
commit
446c503804
Se han modificado 41 ficheros con 1295 adiciones y 347 borrados
  1. 8 9
      display-server/src/main/webapp/biz/js/more/push/PushDemo.js
  2. 16 13
      push-manager-server/src/main/java/com/ai/ipu/biz/bean/PMSMessageAction.java
  3. 1 1
      push-manager-server/src/main/java/com/ai/ipu/biz/bean/RouteBean.java
  4. 53 2
      push-manager-server/src/main/java/com/ai/ipu/biz/bean/ServerBean.java
  5. 107 25
      push-manager-server/src/main/java/com/ai/ipu/pushmanager/cache/BizDataCacheManager.java
  6. 11 11
      push-manager-server/src/main/java/com/ai/ipu/pushmanager/cache/PushRouteCacheManager.java
  7. 1 1
      push-manager-server/src/main/java/com/ai/ipu/pushmanager/loadbalancing/impl/HashLoadBalancing.java
  8. 2 2
      push-manager-server/src/main/java/com/ai/ipu/pushmanager/loadbalancing/impl/RoundLoadBalancing.java
  9. 4 2
      push-manager-server/src/main/java/com/ai/ipu/pushmanager/route/Route.java
  10. 8 7
      push-manager-server/src/main/java/com/ai/ipu/pushmanager/route/DefaultRouteManager.java
  11. 58 0
      push-manager-server/src/main/java/com/ai/ipu/pushmanager/route/impl/RouteManagerImpl.java
  12. 21 0
      push-manager-server/src/main/java/com/ai/ipu/pushmanager/usermanager/AbstractUserManager.java
  13. 25 0
      push-manager-server/src/main/java/com/ai/ipu/pushmanager/usermanager/DefaultUserManager.java
  14. 16 0
      push-manager-server/src/main/java/com/ai/ipu/pushmanager/usermanager/IUserManager.java
  15. 8 5
      push-manager-server/src/main/java/com/ai/ipu/pushmanager/util/AccountsGroup.java
  16. 10 0
      push-manager-server/src/main/java/com/ai/ipu/pushmanager/util/PushConstant.java
  17. 16 39
      push-manager-server/src/main/java/com/ai/ipu/pushmanager/util/PushUtil.java
  18. 205 0
      push-manager-server/src/main/java/com/ai/ipu/pushmanager/util/PushUtilOld.java
  19. 1 1
      push-manager-server/src/main/resources/memcache.xml
  20. 4 0
      push-manager-server/src/main/resources/server-config.xml
  21. 4 0
      push-manager-server/src/main/resources/server-data.xml
  22. 0 28
      push-manager-server/src/main/resources/server-page.xml
  23. 1 6
      push-server/.project
  24. 13 0
      push-server/etc/memcache.xml
  25. 2 2
      push-server/etc/server-data.xml
  26. BIN
      push-server/lib/ipu-basic-3.0.jar
  27. 71 0
      push-server/src/com/ai/server/PushServer.java
  28. 4 4
      push-server/src/com/ai/server/action/MessageAction.java
  29. 23 0
      push-server/src/com/ai/server/action/PushServerManagerAction.java
  30. 203 0
      push-server/src/com/ai/server/push/cache/BizDataCacheManager.java
  31. 48 0
      push-server/src/com/ai/server/push/cache/PushRouteCacheManager.java
  32. 112 104
      push-server/src/com/ai/server/push/handle/RegisterWithRouteHandler.java
  33. 41 39
      push-server/src/com/ai/server/push/handle/UnregisterWithRouteHandler.java
  34. 36 0
      push-server/src/com/ai/server/push/route/IRouteManager.java
  35. 2 2
      push-server/src/com/ai/server/push/route/Route.java
  36. 55 0
      push-server/src/com/ai/server/push/route/impl/DefaultRouteManager.java
  37. 58 0
      push-server/src/com/ai/server/push/route/impl/RouteManagerImpl.java
  38. 0 16
      push-server/src/com/ai/server/usermanager/AbstractUserManager.java
  39. 4 14
      push-server/src/com/ai/server/usermanager/DefaultUserManager.java
  40. 1 14
      push-server/src/com/ai/server/usermanager/IUserManager.java
  41. 42 0
      push-server/src/com/ai/server/util/PushConstant.java

+ 8 - 9
display-server/src/main/webapp/biz/js/more/push/PushDemo.js

@ -21,22 +21,21 @@ require(["domReady!","wadeMobile","mobile","util"],function(doc,WadeMobile,Mobil
21 21
				$("#devicePart").css("display","block"); 
22 22
				var map = new Wade.DataMap();
23 23
				map.put("account", info);
24
				// 用户权限校验的数据
25
				map.put("userName", "chengwb3");
26
				map.put("passWord", "123456");
24 27
				// 请求M,返回ip+port
25 28
				var url = "http://192.168.253.1:8080/push-manager-server/wlwdata";//也可以通过配置文件读取,获取数据库读取,待修正 add by chengwb3
26 29
				var action = "ServerBean.getBestServer";
27
				Mobile.dataRequestWithHost(url,action,null,function(data){
30
				Mobile.dataRequestWithHost(url,action,map.toString(),function(data){
28 31
					data = typeof(data) == "string" ? new Wade.DataMap(data) : data;
32
					map.put("serverId", data.get("server").get("serverId"));//serverId
29 33
					map.put("address", data.get("server").get("host"));// 请求M端获取
30 34
					map.put("port", data.get("server").get("port"));// 请求M端获取
31
					map.put("httpPort", data.get("server").get("http_port"));// http服务端端口
32
					map.put("serverName", data.get("server").get("server_name"));// 项目部署名称
33
					map.put("servletDataRequestName", data.get("server").get("servlet_data_request_name"));// 项目数据请求的serlet的名称
34
					map.put("serverId", data.get("server").get("server_id"));//serverId
35
					// 测试数据替换,因只有一个推送服务端push-server
36
					map.put("address", "192.168.253.1");
37
					map.put("port", "7070");
35
					map.put("httpPort", data.get("server").get("httpPort"));// http服务端端口
36
					map.put("serverName", data.get("server").get("serverName"));// 项目部署名称
37
					map.put("servletDataRequestName", data.get("server").get("servletDataRequestName"));// 项目数据请求的serlet的名称
38 38
					// 推送注册
39
					alert("开始注册");
40 39
					WadeMobile.registerForPush(map.toString(),function(msg){
41 40
						WadeMobile.tip(msg);
42 41
					},function(msg){

+ 16 - 13
push-manager-server/src/main/java/com/ai/ipu/biz/bean/PMSMessageAction.java

@ -1,11 +1,12 @@
1 1
package com.ai.ipu.biz.bean;
2 2

3
import java.util.Set;
4

3
import com.ai.ipu.basic.log.ILogger;
4
import com.ai.ipu.basic.log.IpuLoggerFactory;
5 5
import com.ai.ipu.basic.string.StringUtil;
6
import com.ai.ipu.basic.util.IpuUtility;
6
import com.ai.ipu.basic.util.IpuBaseException;
7 7
import com.ai.ipu.biz.core.bean.IpuAppBean;
8 8
import com.ai.ipu.pushmanager.cache.BizDataCacheManager;
9
import com.ai.ipu.pushmanager.cache.PushRouteCacheManager;
9 10
import com.ai.ipu.pushmanager.util.PushUtil;
10 11
import com.ailk.common.data.IData;
11 12
import com.ailk.common.data.IDataset;
@ -13,6 +14,8 @@ import com.ailk.common.data.impl.DataMap;
13 14
import com.ailk.common.data.impl.DatasetList;
14 15

15 16
public class PMSMessageAction extends IpuAppBean {
17
    
18
    transient protected static final ILogger log = IpuLoggerFactory.createLogger(PMSMessageAction.class);
16 19

17 20
    /**
18 21
     * 根据account列表推送消息,可以是一个或者多个account
@ -27,7 +30,7 @@ public class PMSMessageAction extends IpuAppBean {
27 30
        if (StringUtil.isJSONArray(accountSetStr)) {
28 31
            IDataset accountSet = new DatasetList(accountSetStr);
29 32
            if (accountSet == null || accountSet.size() == 0) {
30
                IpuUtility.error("is not expected json format or has no account");
33
                throw new IpuBaseException("is not expected json format or has no account");
31 34
            }
32 35
            PushUtil.pushToAccountSet(accountSet, content, false, true);
33 36
        } else {
@ -37,23 +40,23 @@ public class PMSMessageAction extends IpuAppBean {
37 40
        return null;
38 41
    }
39 42

40
    public IData sendTextMessageToAllAccounts(IData param) throws Exception {
41
        String content = param.getString("content");
42
        PushUtil.pushToAllAccount(content, false, true);
43
        return null;
44
    }
43
    // public IData sendTextMessageToAllAccounts(IData param) throws Exception {
44
    // String content = param.getString("content");
45
    // PushUtil.pushToAllAccount(content, false, true);
46
    // return null;
47
    // }
45 48

46 49
    public IData getPushServerStatus(IData param) throws Exception {
47 50
        IData result = new DataMap();
48 51
        IDataset pushServerList = BizDataCacheManager.getPushServerListCache();
49 52
        IData pushServer;
50 53
        String serverId = null;
51
        Set<String> pushServerAccountSzet;
54
        int accountSizze;
52 55
        for (int i = 0; i < pushServerList.size(); i++) {
53 56
            pushServer = pushServerList.getData(i);
54
            serverId = pushServer.getString("server_id");
55
            pushServerAccountSzet = BizDataCacheManager.getPushServerAccountsCache(serverId);
56
            result.put(BizDataCacheManager.PUSH_SERVER_ACCOUNTS_PREFIX + serverId + "_size", pushServerAccountSet.size());
57
            serverId = pushServer.getString("serverId");
58
            accountSizze = BizDataCacheManager.getPushServerAccountsSize(serverId);
59
            result.put(BizDataCacheManager.PUSH_SERVER_ACCOUNTS_SIZE_PREFIX + serverId, accountSize);
57 60
        }
58 61
        return result;
59 62
    }

+ 1 - 1
push-manager-server/src/main/java/com/ai/ipu/biz/bean/RouteBean.java

@ -1,9 +1,9 @@
1 1
package com.ai.ipu.biz.bean;
2 2

3 3
import com.ai.ipu.biz.core.bean.IpuAppBean;
4
import com.ai.ipu.pushmanager.route.DefaultRouteManager;
5 4
import com.ai.ipu.pushmanager.route.IRouteManager;
6 5
import com.ai.ipu.pushmanager.route.Route;
6
import com.ai.ipu.pushmanager.route.impl.DefaultRouteManager;
7 7
import com.ailk.common.data.IData;
8 8
import com.ailk.common.data.impl.DataMap;
9 9


+ 53 - 2
push-manager-server/src/main/java/com/ai/ipu/biz/bean/ServerBean.java

@ -1,16 +1,34 @@
1 1
package com.ai.ipu.biz.bean;
2 2

3
import com.ai.ipu.basic.util.IpuBaseException;
3 4
import com.ai.ipu.biz.core.bean.IpuAppBean;
4 5
import com.ai.ipu.pushmanager.cache.BizDataCacheManager;
5 6
import com.ai.ipu.pushmanager.loadbalancing.ILoadBalancing;
6 7
import com.ai.ipu.pushmanager.loadbalancing.impl.WeightRandomLoadBalancing;
8
import com.ai.ipu.pushmanager.usermanager.DefaultUserManager;
9
import com.ai.ipu.pushmanager.usermanager.IUserManager;
10
import com.ai.ipu.server.config.MobileConfig;
7 11
import com.ailk.common.data.IData;
8 12
import com.ailk.common.data.IDataset;
9 13
import com.ailk.common.data.impl.DataMap;
10 14

11 15
public class ServerBean extends IpuAppBean {
12
    
13
    public IData getBestServer(IData param) throws Exception{
16

17
    /**
18
     * C向M请求最佳P
19
     * 
20
     * @param param
21
     * @return
22
     * @throws Exception
23
     */
24
    public IData getBestServer(IData param) throws Exception {
25
        // 用户权限校验
26
        // 可能使用个,可能不使用。要通过配置文件注入
27
        String userPermissionsCheck = MobileConfig.getValue("userPermissionsCheck", "false");
28
        if("true".equals(userPermissionsCheck)){
29
            IUserManager userManager = new DefaultUserManager();
30
            userManager.verify(param.getString("account"), param);//用户连接权限验证
31
        }
14 32
        IData result = new DataMap();
15 33
        // 用户是否可以获取ip+port的验证
16 34
        IDataset list = BizDataCacheManager.getPushServerListCache();
@ -20,4 +38,37 @@ public class ServerBean extends IpuAppBean {
20 38
        result.put("flag", "success");
21 39
        return result;
22 40
    }
41

42
    /**
43
     * P启动时候,向M注册信息
44
     */
45
    public IData addServer(IData param) throws Exception {
46
        String serverId = param.getString("serverId");
47
        boolean containsPushServer = BizDataCacheManager.containsPushServer(serverId);
48
        if (containsPushServer) {
49
            String msg = "serverId[" + serverId + "]的push-server已经存在,请检查。";
50
            throw new IpuBaseException(msg);
51
        }
52
        IDataset pushList = BizDataCacheManager.getPushServerListCache();
53
        IData pushServerObj = new DataMap();
54
        pushServerObj.put("serverId", param.getString("serverId"));
55
        pushServerObj.put("host", param.getString("host"));
56
        pushServerObj.put("name", param.getString("name"));
57
        pushServerObj.put("port", param.getString("port"));
58
        pushServerObj.put("weight", param.getString("weight"));
59
        pushServerObj.put("httpPort", param.getString("httpPort"));
60
        pushServerObj.put("serverName", param.getString("serverName"));
61
        pushServerObj.put("servletDataRequestName", param.getString("servletDataRequestName"));
62
        pushList.add(pushServerObj);
63
        BizDataCacheManager.putPushServerListCache(pushList);
64

65
        IData result = new DataMap();
66
        result.put("flag", "success");
67
        return result;
68
    }
69

70
    public IData deleteServer(IData param) {
71
        //
72
        return null;
73
    }
23 74
}

+ 107 - 25
push-manager-server/src/main/java/com/ai/ipu/pushmanager/cache/BizDataCacheManager.java

@ -3,25 +3,22 @@ package com.ai.ipu.pushmanager.cache;
3 3
import java.util.HashSet;
4 4
import java.util.Set;
5 5

6
import org.apache.log4j.Logger;
7

8
import com.ai.ipu.basic.util.IpuLogger;
9
import com.ai.ipu.basic.util.IpuUtility;
10
import com.ai.ipu.biz.dao.ServerDao;
11
import com.ai.ipu.biz.util.Constant;
6
import com.ai.ipu.basic.log.ILogger;
7
import com.ai.ipu.basic.log.IpuLoggerFactory;
8
import com.ai.ipu.basic.util.IpuBaseException;
12 9
import com.ai.ipu.pushmanager.util.PushConstant;
13 10
import com.ai.ipu.server.cache.CacheFactory;
14 11
import com.ai.ipu.server.cache.intf.ICache;
15 12
import com.ailk.common.data.IData;
16 13
import com.ailk.common.data.IDataset;
17
import com.ailk.common.data.impl.DataMap;
14
import com.ailk.common.data.impl.DatasetList;
18 15

19 16
/**
20 17
 * 业务数据缓存管理类
21 18
 */
22 19
public class BizDataCacheManager {
23 20

24
    private static transient Logger log = Logger.getLogger(BizDataCacheManager.class);
21
    transient protected static final ILogger log = IpuLoggerFactory.createLogger(BizDataCacheManager.class);
25 22

26 23
    private static final String BIZ_DATA_CACHE = PushConstant.BIZ_DATA_CACHE;
27 24

@ -29,6 +26,10 @@ public class BizDataCacheManager {
29 26

30 27
    public static final String PUSH_SERVER_ACCOUNTS_PREFIX = PushConstant.PUSH_SERVER_ACCOUNTS_PREFIX; // value:Set<String>
31 28

29
    public static final String AVAILABLE_ACCOUNTS = PushConstant.AVAILABLE_ACCOUNTS; // 用于P端用户有效性二次验证的集合,value:Set<String>
30

31
    public static final String PUSH_SERVER_ACCOUNTS_SIZE_PREFIX = PushConstant.PUSH_SERVER_ACCOUNTS_SIZE_PREFIX; // push-server链接account的数量,value:int
32

32 33
    public static ICache getBizDataCache() throws Exception {
33 34
        return CacheFactory.getCache(BIZ_DATA_CACHE);
34 35
    }
@ -44,36 +45,64 @@ public class BizDataCacheManager {
44 45
                if (null != getBizDataCache().get(PUSH_SERVER_LIST)) {// 避免时间差
45 46
                    return (IDataset) getBizDataCache().get(PUSH_SERVER_LIST);
46 47
                }
47
                putPushServerListCache();
48
                initPushServerListCache();
48 49
            }
49 50
        }
50 51
        return (IDataset) getBizDataCache().get(PUSH_SERVER_LIST);
51 52
    }
52 53

54
    public static boolean containsPushServer(String serverId) throws Exception {
55
        if (null == serverId) {
56
            throw new IpuBaseException("serverId is null.");
57
        }
58
        IDataset list = getPushServerListCache();
59
        if (list.isEmpty()) {
60
            return false;
61
        }
62
        IData pushServer;
63
        for (int i = 0; i < list.size(); i++) {
64
            pushServer = list.getData(i);
65
            if (serverId.equals(pushServer.getString("serverId"))) {
66
                return true;
67
            }
68
        }
69
        return false;
70
    }
71

53 72
    /**
54 73
     * 读取数据库,初始化数据
55 74
     */
56
    private static void putPushServerListCache() throws Exception {
57
        ServerDao dao = new ServerDao(Constant.connName);
58
        IData param = new DataMap();
59
        param.put("STATE", Constant.Server.STATE_AVAILABLE);
60
        IDataset list = dao.getServerList(param);
61
        if (list == null || list.isEmpty()) {
62
            IpuLogger.error(log, "tab_server表未找到数据.");
63
            IpuUtility.error("tab_server表未找到数据.");
64
        }
65
        getBizDataCache().put(PUSH_SERVER_LIST, list);
75
    // private static void initPushServerListCache() throws Exception {
76
    // ServerDao dao = new ServerDao(Constant.connName);
77
    // IData param = new DataMap();
78
    // param.put("STATE", Constant.Server.STATE_AVAILABLE);
79
    // IDataset list = dao.getServerList(param);
80
    // if (list == null || list.isEmpty()) {
81
    // IpuLogger.error(log, "tab_server表未找到数据.");
82
    // IpuUtility.error("tab_server表未找到数据.");
83
    // }
84
    // getBizDataCache().put(PUSH_SERVER_LIST, list);
85
    //
86
    // IpuLogger.debug(log, "初始化" + PUSH_SERVER_LIST + "成功.");
87
    // }
66 88

67
        IpuLogger.debug(log, "初始化" + PUSH_SERVER_LIST + "成功.");
89
    /**
90
     * 初始化P的列表,应该是主动扫描P的列表
91
     */
92
    private static void initPushServerListCache() throws Exception {
93
        // 待处理。。。
94
        log.debug("待处理,初始化扫描可用的P的列表");
95
        IDataset list = new DatasetList();
96
        getBizDataCache().put(PUSH_SERVER_LIST, list);
68 97
    }
69 98

70 99
    /**
71 100
     * 主动更改缓存,用于数据库tab_server表变动
72 101
     */
73
    protected static void putPushServerListCache(IDataset list) throws Exception {
102
    public static void putPushServerListCache(IDataset list) throws Exception {
74 103
        getBizDataCache().put(PUSH_SERVER_LIST, list);
75 104

76
        IpuLogger.debug(log, "主动更改" + PUSH_SERVER_LIST + "成功.");
105
        log.debug("更改" + PUSH_SERVER_LIST + "成功.");
77 106
    }
78 107

79 108
    /**
@ -99,10 +128,10 @@ public class BizDataCacheManager {
99 128
     */
100 129
    public static void addAccountToPushServerAccountsId(String account, String serverId) throws Exception {
101 130
        Set<String> accountSet = getPushServerAccountsCache(serverId);
102
        IpuLogger.debug(log, "M add route, put before:key=" + (PUSH_SERVER_ACCOUNTS_PREFIX + serverId) + ",value=" + accountSet.toString());
131
        log.debug("M add route, put before:key=" + (PUSH_SERVER_ACCOUNTS_PREFIX + serverId) + ",value=" + accountSet.toString());
103 132
        accountSet.add(account);
104 133
        putPushServerAccountsCache(accountSet, serverId);
105
        IpuLogger.debug(log, "M add route, put after:key=" + (PUSH_SERVER_ACCOUNTS_PREFIX + serverId) + ",value=" + accountSet.toString());
134
        log.debug("M add route, put after:key=" + (PUSH_SERVER_ACCOUNTS_PREFIX + serverId) + ",value=" + accountSet.toString());
106 135

107 136
    }
108 137

@ -112,10 +141,63 @@ public class BizDataCacheManager {
112 141
    public static void removeAccountToPushServerAccountsId(String account, String serverId) throws Exception {
113 142
        Set<String> accountSet = getPushServerAccountsCache(serverId);
114 143
        if (null == accountSet || !accountSet.contains(account)) {
115
            IpuLogger.debug(log, "has not this account [" + account + "] on this " + serverId + "server");
144
            log.debug("has not this account [" + account + "] on this " + serverId + "server");
116 145
            return;
117 146
        }
118 147
        accountSet.remove(account);
119 148
        putPushServerAccountsCache(accountSet, serverId);
120 149
    }
150

151
    public static void addAvailableAccount(String account) throws Exception {
152
        if (getAvailableAccountSet().contains(account)) {
153
            // account已经存在了
154
            log.debug("account[" + account + "] already exists.");
155
        }
156
        Set<String> accountSet = getAvailableAccountSet();
157
        accountSet.add(account);
158
        putAvailableAccountSet(accountSet);
159
    }
160

161
    @SuppressWarnings("unchecked")
162
    public static Set<String> getAvailableAccountSet() throws Exception {
163
        if (null == getBizDataCache().get(AVAILABLE_ACCOUNTS)) {
164
            return new HashSet<String>();
165
        }
166
        return (Set<String>) getBizDataCache().get(AVAILABLE_ACCOUNTS);
167
    }
168

169
    public static void putAvailableAccountSet(Set<String> accountSet) throws Exception {
170
        getBizDataCache().put(AVAILABLE_ACCOUNTS, accountSet);
171
    }
172

173
    public static boolean containsAvailableAccount(String account) throws Exception {
174
        return getAvailableAccountSet().contains(account);
175
    }
176

177
    public static void increasePushServerAccountsSize(String serverId) throws Exception {
178
        int size = getPushServerAccountsSize(serverId);
179
        putPushServerAccountsSize(serverId, size + 1);
180
        log.debug("Number of server connections plus one");
181
    }
182

183
    public static void decreasePushServerAccountsSize(String serverId) throws Exception {
184
        int size = getPushServerAccountsSize(serverId);
185
        if (size < 1) {
186
            throw new IpuBaseException("The number of current connected account is less than one.");
187
        }
188
        putPushServerAccountsSize(serverId, size - 1);
189
        log.debug("Number of server connections minus one");
190
    }
191

192
    private static void putPushServerAccountsSize(String serverId, int accountsSize) throws Exception {
193
        getBizDataCache().put(PUSH_SERVER_ACCOUNTS_PREFIX + serverId, accountsSize);
194
    }
195

196
    public static int getPushServerAccountsSize(String serverId) throws Exception {
197
        if (null == getBizDataCache().get(PUSH_SERVER_ACCOUNTS_SIZE_PREFIX + serverId)) {
198
            return 0;
199
        }
200
        return (Integer) getBizDataCache().get(PUSH_SERVER_ACCOUNTS_SIZE_PREFIX + serverId);
201
    }
202

121 203
}

+ 11 - 11
push-manager-server/src/main/java/com/ai/ipu/pushmanager/cache/PushRouteCacheManager.java

@ -1,9 +1,8 @@
1 1
package com.ai.ipu.pushmanager.cache;
2 2

3
import org.apache.log4j.Logger;
4

5
import com.ai.ipu.basic.util.IpuLogger;
6
import com.ai.ipu.basic.util.IpuUtility;
3
import com.ai.ipu.basic.log.ILogger;
4
import com.ai.ipu.basic.log.IpuLoggerFactory;
5
import com.ai.ipu.basic.util.IpuBaseException;
7 6
import com.ai.ipu.pushmanager.route.Route;
8 7
import com.ai.ipu.pushmanager.util.PushConstant;
9 8
import com.ai.ipu.server.cache.CacheFactory;
@ -14,7 +13,7 @@ import com.ai.ipu.server.cache.intf.ICache;
14 13
 */
15 14
public class PushRouteCacheManager {
16 15

17
    private static transient Logger log = Logger.getLogger(PushRouteCacheManager.class);
16
    transient protected static final ILogger log = IpuLoggerFactory.createLogger(PushRouteCacheManager.class);
18 17

19 18
    private static final String PUSH_ROUTE_CACHE = PushConstant.PUSH_ROUTE_CACHE;
20 19

@ -26,23 +25,24 @@ public class PushRouteCacheManager {
26 25
        if (null == getPushRouteCache().get(account)) {
27 26
            return null;
28 27
        }
29
        return (Route) getPushRouteCache().get(account);
28
        return new Route(getPushRouteCache().get(account).toString());
30 29
    }
31 30

32 31
    public static void putRoute(String account, Route route) throws Exception {
33
        if (null == route) {
34
            IpuLogger.error(log, "route is null.");
35
            IpuUtility.error("route is null.");
32
        if (null == account || "".equals(account) || null == route) {
33
            throw new IpuBaseException("account or route is null.");
36 34
        }
37
        getPushRouteCache().put(account, route);
35
        getPushRouteCache().put(account, route.toString());
36
        log.debug("set key=[" + account + "] route success.");
38 37
    }
39 38

40 39
    public static void removeRoute(String account) throws Exception {
41 40
        if (null == getRoute(account)) {
42
            IpuLogger.debug(log, "this route account [" + account + "] is null.");
41
            log.debug("this route account [" + account + "] is null.");
43 42
            return;
44 43
        }
45 44
        getPushRouteCache().remove(account);
45
        log.debug("remove key=[" + account + "] route success.");
46 46
    }
47 47

48 48
}

+ 1 - 1
push-manager-server/src/main/java/com/ai/ipu/pushmanager/loadbalancing/impl/HashLoadBalancing.java

@ -17,7 +17,7 @@ public class HashLoadBalancing implements ILoadBalancing {
17 17
            return null;
18 18
        }
19 19
        Object obj = null;
20
        synchronized (pos) {
20
        synchronized (new Object()) {
21 21
            pos = pos > list.size() ? 0 : pos;
22 22
            obj = list.get(pos);
23 23
            pos++;

+ 2 - 2
push-manager-server/src/main/java/com/ai/ipu/pushmanager/loadbalancing/impl/RoundLoadBalancing.java

@ -2,7 +2,7 @@ package com.ai.ipu.pushmanager.loadbalancing.impl;
2 2

3 3
import java.util.List;
4 4

5
import com.ai.ipu.basic.util.IpuUtility;
5
import com.ai.ipu.basic.util.IpuBaseException;
6 6
import com.ai.ipu.pushmanager.loadbalancing.ILoadBalancing;
7 7

8 8
/**
@ -18,7 +18,7 @@ public class RoundLoadBalancing implements ILoadBalancing {
18 18
            return null;
19 19
        }
20 20
        if (null == IP) {
21
            IpuUtility.error("IP为null");
21
            throw new IpuBaseException("IP为null");
22 22
        }
23 23
        int hashCode = IP.hashCode();
24 24
        int hashPosition = hashCode % list.size();

+ 4 - 2
push-manager-server/src/main/java/com/ai/ipu/pushmanager/route/Route.java

@ -2,7 +2,9 @@ package com.ai.ipu.pushmanager.route;
2 2

3 3
import java.io.Serializable;
4 4

5
import com.ai.ipu.basic.util.IpuLogger;
5
import com.ai.ipu.basic.log.ILogger;
6
import com.ai.ipu.basic.log.IpuLoggerFactory;
7
import com.ai.ipu.basic.util.IpuBaseException;
6 8
import com.ailk.common.data.impl.DataMap;
7 9

8 10
/**
@ -210,7 +212,7 @@ public class Route extends DataMap implements Serializable {
210 212
                }
211 213
            }
212 214
        } else {
213
            IpuLogger.debug("无法解析,不是自定义解析格式。");
215
            throw new IpuBaseException("无法解析,不是自定义解析格式。");
214 216
        }
215 217
    }
216 218


+ 8 - 7
push-manager-server/src/main/java/com/ai/ipu/pushmanager/route/DefaultRouteManager.java

@ -1,15 +1,16 @@
1
package com.ai.ipu.pushmanager.route;
1
package com.ai.ipu.pushmanager.route.impl;
2 2

3
import org.apache.log4j.Logger;
4

5
import com.ai.ipu.basic.util.IpuLogger;
3
import com.ai.ipu.basic.log.ILogger;
4
import com.ai.ipu.basic.log.IpuLoggerFactory;
6 5
import com.ai.ipu.pushmanager.cache.BizDataCacheManager;
7 6
import com.ai.ipu.pushmanager.cache.PushRouteCacheManager;
7
import com.ai.ipu.pushmanager.route.IRouteManager;
8
import com.ai.ipu.pushmanager.route.Route;
8 9
import com.ai.ipu.server.cache.intf.ICache;
9 10

10 11
public class DefaultRouteManager implements IRouteManager {
11 12

12
    private static transient Logger log = Logger.getLogger(DefaultRouteManager.class);
13
    transient protected static final ILogger log = IpuLoggerFactory.createLogger(DefaultRouteManager.class);
13 14

14 15
    @Override
15 16
    public void addRoute(String account, Route route) throws Exception {
@ -36,10 +37,10 @@ public class DefaultRouteManager implements IRouteManager {
36 37
    public void removeRoute(String account) throws Exception {
37 38
        Route route = PushRouteCacheManager.getRoute(account);
38 39
        if (null == route) {
39
            IpuLogger.debug(log, "Not found this designated account of the Route.");
40
            log.debug("Not found this designated account of the Route.");
40 41
            return;
41 42
        }
42
        BizDataCacheManager.removeAccountToPushServerAccountsId(account, route.getServerId());
43
        BizDataCacheManager.decreasePushServerAccountsSize(route.getServerId());
43 44
        PushRouteCacheManager.removeRoute(account);
44 45
    }
45 46


+ 58 - 0
push-manager-server/src/main/java/com/ai/ipu/pushmanager/route/impl/RouteManagerImpl.java

@ -0,0 +1,58 @@
1
package com.ai.ipu.pushmanager.route.impl;
2

3
import com.ai.ipu.basic.log.ILogger;
4
import com.ai.ipu.basic.log.IpuLoggerFactory;
5
import com.ai.ipu.pushmanager.cache.BizDataCacheManager;
6
import com.ai.ipu.pushmanager.cache.PushRouteCacheManager;
7
import com.ai.ipu.pushmanager.route.IRouteManager;
8
import com.ai.ipu.pushmanager.route.Route;
9
import com.ai.ipu.server.cache.intf.ICache;
10

11
/**
12
 * 路由关系管理实现类。 注:不保存push-server对象的account列表,只保存account的数量。
13
 */
14
public class RouteManagerImpl implements IRouteManager {
15

16
    transient protected static final ILogger log = IpuLoggerFactory.createLogger(RouteManagerImpl.class);
17

18
    @Override
19
    public void addRoute(String account, Route route) throws Exception {
20
        PushRouteCacheManager.putRoute(account, route);
21
        BizDataCacheManager.increasePushServerAccountsSize(route.getServerId());
22
    }
23

24
    @Override
25
    public Route getRoute(String account) throws Exception {
26
        return PushRouteCacheManager.getRoute(account);
27
    }
28

29
    @Override
30
    public ICache getRoutes() throws Exception {
31
        return PushRouteCacheManager.getPushRouteCache();
32
    }
33

34
    @Override
35
    public void removeRoute(Route route) throws Exception {
36
        removeRoute(route.getAccount());
37
    }
38

39
    @Override
40
    public void removeRoute(String account) throws Exception {
41
        Route route = PushRouteCacheManager.getRoute(account);
42
        if (null == route) {
43
            log.debug("Not found this designated account of the Route.");
44
            return;
45
        }
46
        BizDataCacheManager.decreasePushServerAccountsSize(route.getServerId());
47
        PushRouteCacheManager.removeRoute(account);
48
    }
49

50
    @Override
51
    public boolean containsRoute(Route route) throws Exception {
52
        if (null != PushRouteCacheManager.getPushRouteCache().get(route.getAccount())) {
53
            return true;
54
        }
55
        return false;
56
    }
57

58
}

+ 21 - 0
push-manager-server/src/main/java/com/ai/ipu/pushmanager/usermanager/AbstractUserManager.java

@ -0,0 +1,21 @@
1
package com.ai.ipu.pushmanager.usermanager;
2

3
import java.util.Map;
4

5
import com.ai.ipu.basic.util.IpuBaseException;
6
import com.ai.ipu.pushmanager.cache.BizDataCacheManager;
7

8
public abstract class AbstractUserManager implements IUserManager {
9

10
    @Override
11
    public boolean verify(String account, Map<String, Object> map) throws Exception {
12
        if (account == null || "".equals(account)) {
13
            throw new IpuBaseException("account为空。");
14
        }
15
        if(customVerify(account, map)){
16
            // 把tokenId即account保存到memcache里面,用于P端的二次验证
17
            BizDataCacheManager.addAvailableAccount(account);
18
        }
19
        return false;
20
    }
21
}

+ 25 - 0
push-manager-server/src/main/java/com/ai/ipu/pushmanager/usermanager/DefaultUserManager.java

@ -0,0 +1,25 @@
1
package com.ai.ipu.pushmanager.usermanager;
2

3
import java.util.Map;
4

5
import com.ai.ipu.basic.log.ILogger;
6
import com.ai.ipu.basic.log.IpuLoggerFactory;
7
import com.ai.ipu.basic.util.IpuBaseException;
8

9
public class DefaultUserManager extends AbstractUserManager{
10
    
11
    transient protected final static ILogger log = IpuLoggerFactory.createLogger(DefaultUserManager.class);
12
    
13
    @Override
14
    public boolean customVerify(String account, Map<String, Object> map) throws Exception{
15
        // 用户名和密码的校验
16
        String user = (String) map.get("userName");
17
        String passwd = (String) map.get("passWord");
18
        if(user!=null&&passwd!=null){
19
            log.debug("用户连接权限校验通过.");
20
            return true;
21
        }
22
        throw new IpuBaseException("用户连接权限校验失败.");
23
    }
24

25
}

+ 16 - 0
push-manager-server/src/main/java/com/ai/ipu/pushmanager/usermanager/IUserManager.java

@ -0,0 +1,16 @@
1
package com.ai.ipu.pushmanager.usermanager;
2

3
import java.util.Map;
4

5
public interface IUserManager {
6

7
    /**
8
     * 验证account有效性
9
     */
10
    public boolean verify(String account, Map<String, Object> map) throws Exception;
11

12
    /**
13
     * 自定义校验map
14
     */
15
    public boolean customVerify(String account, Map<String, Object> map) throws Exception;
16
}

+ 8 - 5
push-manager-server/src/main/java/com/ai/ipu/pushmanager/util/AccountsGroup.java

@ -1,6 +1,6 @@
1 1
package com.ai.ipu.pushmanager.util;
2 2

3
import com.ai.ipu.basic.util.IpuUtility;
3
import com.ai.ipu.basic.util.IpuBaseException;
4 4
import com.ai.ipu.pushmanager.route.Route;
5 5
import com.ailk.common.data.IDataset;
6 6
import com.ailk.common.data.impl.DatasetList;
@ -13,7 +13,11 @@ public class AccountsGroup {
13 13
    private String serverId;
14 14

15 15
    private IDataset accountSet = new DatasetList();
16
    
16

17
    public AccountsGroup(String serverId) {
18
        this.serverId = serverId;
19
    }
20

17 21
    public String getServerId() {
18 22
        return serverId;
19 23
    }
@ -29,7 +33,7 @@ public class AccountsGroup {
29 33
    public void setAccountSet(IDataset accountSet) {
30 34
        this.accountSet = accountSet;
31 35
    }
32
    
36

33 37
    /**
34 38
     * 添加account
35 39
     */
@ -38,12 +42,11 @@ public class AccountsGroup {
38 42
            return;
39 43
        }
40 44
        if (serverId == null) {
41
            IpuUtility.error("serverId is null");
45
            throw new IpuBaseException("serverId is null");
42 46
        }
43 47
        if (serverId.equals(route.getServerId())) {
44 48
            accountSet.add(route.getAccount());
45 49
        }
46 50
    }
47 51

48
    
49 52
}

+ 10 - 0
push-manager-server/src/main/java/com/ai/ipu/pushmanager/util/PushConstant.java

@ -16,6 +16,16 @@ public class PushConstant {
16 16
     * 业务数据缓存之一的前缀,+serverId即key,单个push-server的链接accounts列表
17 17
     */
18 18
    public static final String PUSH_SERVER_ACCOUNTS_PREFIX = "PUSH_SERVER_ACCOUNTS_"; // value:Set<String>
19
    
20
    /**
21
     * 业务数据缓存之一的前缀,+serverId即key,单个push-server链接account的数量
22
     */
23
    public static final String PUSH_SERVER_ACCOUNTS_SIZE_PREFIX = "PUSH_SERVER_ACCOUNTS_SIZE_"; // value:int
24
    
25
    /**
26
     * 业务数据缓存之一,是account的Set集合
27
     */
28
    public static final String AVAILABLE_ACCOUNTS = "AVAILABLE_ACCOUNTS"; // value:Set<String>
19 29

20 30
    /**
21 31
     * 路由缓存key,memcache.xml的cluster name

+ 16 - 39
push-manager-server/src/main/java/com/ai/ipu/pushmanager/util/PushUtil.java

@ -6,19 +6,17 @@ import java.util.Iterator;
6 6
import java.util.Map;
7 7
import java.util.Set;
8 8

9
import org.apache.log4j.Logger;
10

9
import com.ai.ipu.basic.log.ILogger;
10
import com.ai.ipu.basic.log.IpuLoggerFactory;
11 11
import com.ai.ipu.basic.net.http.HttpTool;
12
import com.ai.ipu.basic.util.IpuLogger;
13
import com.ai.ipu.basic.util.IpuUtility;
14
import com.ai.ipu.pushmanager.cache.BizDataCacheManager;
15
import com.ai.ipu.pushmanager.route.DefaultRouteManager;
12
import com.ai.ipu.basic.util.IpuBaseException;
16 13
import com.ai.ipu.pushmanager.route.IRouteManager;
17 14
import com.ai.ipu.pushmanager.route.Route;
15
import com.ai.ipu.pushmanager.route.impl.DefaultRouteManager;
16
import com.ai.ipu.pushmanager.route.impl.RouteManagerImpl;
18 17
import com.ailk.common.data.IData;
19 18
import com.ailk.common.data.IDataset;
20 19
import com.ailk.common.data.impl.DataMap;
21
import com.ailk.common.data.impl.DatasetList;
22 20

23 21
/**
24 22
 * 推送工具类
@ -28,7 +26,7 @@ import com.ailk.common.data.impl.DatasetList;
28 26
 */
29 27
public class PushUtil {
30 28

31
    private static transient Logger log = Logger.getLogger(PushUtil.class);
29
    transient protected final static ILogger log = IpuLoggerFactory.createLogger(PushUtil.class);
32 30

33 31
    /**
34 32
     * 推送给单个account
@ -42,7 +40,7 @@ public class PushUtil {
42 40
     * @throws Exception
43 41
     */
44 42
    public static void pushToAccount(String account, String content, boolean isEncrypt) throws Exception {
45
        IRouteManager routeManager = new DefaultRouteManager();
43
        IRouteManager routeManager = new RouteManagerImpl();
46 44
        Route route = routeManager.getRoute(account);
47 45
        String ip = route.getHost();
48 46
        String httpPort = route.getHttpPort();
@ -51,11 +49,10 @@ public class PushUtil {
51 49
        String url = "http://" + ip + ":" + httpPort + "/" + serverName + "/" + servletDataRequestName;
52 50

53 51
        IData dataParam = new DataMap();
54
        dataParam.put("CONTENT", content);
52
        dataParam.put("content", content);
55 53
        dataParam.put("accountSet", account);
56 54
        dataParam.put("SENDER", "system");
57 55
        Map<String, String> postData = new HashMap<String, String>();
58
        isEncrypt = false;
59 56
        if (isEncrypt) {
60 57
            /* 参数加密处理 */
61 58
            postData.put("action", "MessageAction.sendTextMessageToAccountSet");
@ -78,9 +75,9 @@ public class PushUtil {
78 75
        }
79 76
        IData resultData = new DataMap(resultStr);
80 77
        if ("success".equals(resultData.getString("flag"))) {
81
            IpuLogger.debug("发送成功!");
78
            log.debug("单个account推送成功!");
82 79
        } else {
83
            IpuLogger.debug("发送失败!");
80
            log.debug("单个account推送失败!");
84 81
        }
85 82
    }
86 83

@ -116,8 +113,7 @@ public class PushUtil {
116 113
            AccountsGroup ag;
117 114
            Iterator<String> it = serverIdSet.iterator();
118 115
            while (it.hasNext()) {
119
                ag = new AccountsGroup();
120
                ag.setServerId(it.next());
116
                ag = new AccountsGroup(it.next());
121 117
                for (int i = 0; i < accountSet.size(); i++) {
122 118
                    route = routeManager.getRoute(accountSet.get(i).toString());
123 119
                    ag.addRoute(route);
@ -141,9 +137,8 @@ public class PushUtil {
141 137
     */
142 138
    public static void pushToAccountSetByServerId(IDataset accountSet, String content, boolean isEncrypt) throws Exception {
143 139
        if (accountSet == null || accountSet.isEmpty()) {
144
            IpuLogger.error(log, "not found effective accountSet : " + accountSet);
145
            IpuUtility.error("not found effective accountSet : " + accountSet);
146
            return;
140
            log.error("not found effective accountSet : " + accountSet);
141
            throw new IpuBaseException("not found effective accountSet : " + accountSet);
147 142
        }
148 143
        IRouteManager routeManager = new DefaultRouteManager();
149 144
        Route route = routeManager.getRoute(accountSet.get(0).toString());
@ -154,7 +149,7 @@ public class PushUtil {
154 149
        String url = "http://" + ip + ":" + httpPort + "/" + serverName + "/" + servletDataRequestName;
155 150

156 151
        IData dataParam = new DataMap();
157
        dataParam.put("CONTENT", content);
152
        dataParam.put("content", content);
158 153
        dataParam.put("accountSet", accountSet.toString());
159 154
        dataParam.put("SENDER", "system");
160 155
        Map<String, String> postData = new HashMap<String, String>();
@ -181,27 +176,9 @@ public class PushUtil {
181 176
        }
182 177
        IData resultData = new DataMap(resultStr);
183 178
        if ("success".equals(resultData.getString("flag"))) {
184
            IpuLogger.debug("发送成功!");
179
            log.debug("发送成功!");
185 180
        } else {
186
            IpuLogger.debug("发送失败!");
187
        }
188
    }
189

190
    /**
191
     * 推送所有account
192
     */
193
    public static void pushToAllAccount(String content, boolean isEncrypt, boolean isMerge) throws Exception {
194
        IDataset pushServerList = BizDataCacheManager.getPushServerListCache();
195
        IData pushServer;
196
        String serverId = null;
197
        Set<String> accountSet;
198
        IDataset accountDataset;
199
        for (int i = 0; i < pushServerList.size(); i++) {
200
            pushServer = pushServerList.getData(i);
201
            serverId = pushServer.getString("server_id");
202
            accountSet = BizDataCacheManager.getPushServerAccountsCache(serverId);
203
            accountDataset = new DatasetList(accountSet.toString());
204
            pushToAccountSetByServerId(accountDataset, content, false);
181
            log.debug("发送失败!");
205 182
        }
206 183
    }
207 184


+ 205 - 0
push-manager-server/src/main/java/com/ai/ipu/pushmanager/util/PushUtilOld.java

@ -0,0 +1,205 @@
1
package com.ai.ipu.pushmanager.util;
2

3
import java.util.HashMap;
4
import java.util.HashSet;
5
import java.util.Iterator;
6
import java.util.Map;
7
import java.util.Set;
8

9
import com.ai.ipu.basic.log.ILogger;
10
import com.ai.ipu.basic.log.IpuLoggerFactory;
11
import com.ai.ipu.basic.net.http.HttpTool;
12
import com.ai.ipu.basic.util.IpuBaseException;
13
import com.ai.ipu.pushmanager.cache.BizDataCacheManager;
14
import com.ai.ipu.pushmanager.route.IRouteManager;
15
import com.ai.ipu.pushmanager.route.Route;
16
import com.ai.ipu.pushmanager.route.impl.DefaultRouteManager;
17
import com.ailk.common.data.IData;
18
import com.ailk.common.data.IDataset;
19
import com.ailk.common.data.impl.DataMap;
20
import com.ailk.common.data.impl.DatasetList;
21

22
/**
23
 * 推送工具类
24
 * 
25
 * @author Administrator
26
 *
27
 */
28
public class PushUtilOld {
29

30
    transient protected final static ILogger log = IpuLoggerFactory.createLogger(PushUtilOld.class);
31

32
    /**
33
     * 推送给单个account
34
     * 
35
     * @param account
36
     *            账号
37
     * @param content
38
     *            推送内容
39
     * @param isEncrypt
40
     *            是否加密传输
41
     * @throws Exception
42
     */
43
    public static void pushToAccount(String account, String content, boolean isEncrypt) throws Exception {
44
        IRouteManager routeManager = new DefaultRouteManager();
45
        Route route = routeManager.getRoute(account);
46
        String ip = route.getHost();
47
        String httpPort = route.getHttpPort();
48
        String serverName = route.getServerName();
49
        String servletDataRequestName = route.getServletDataRequestName();
50
        String url = "http://" + ip + ":" + httpPort + "/" + serverName + "/" + servletDataRequestName;
51

52
        IData dataParam = new DataMap();
53
        dataParam.put("CONTENT", content);
54
        dataParam.put("accountSet", account);
55
        dataParam.put("SENDER", "system");
56
        Map<String, String> postData = new HashMap<String, String>();
57
        isEncrypt = false;
58
        if (isEncrypt) {
59
            /* 参数加密处理 */
60
            postData.put("action", "MessageAction.sendTextMessageToAccountSet");
61
            // postData.put("key", MobileSecurity.getDesKey());
62
            String encryptData = "";// 加密后的数据
63
            postData.put("data", encryptData);
64
        } else {
65
            postData.put("action", "MessageAction.sendTextMessageToAccountSet");
66
            postData.put("data", dataParam.toString());
67
        }
68
        String data = HttpTool.toQueryStringWithEncode(postData);
69

70
        String resultStr = HttpTool.httpRequest(url, data, "POST");
71
        if (isEncrypt) {
72
            /* 解密 */
73
            // result = MobileSecurity.responseDecrypt(resultStr);
74
        }
75
        if (resultStr.endsWith("\r")) {
76
            resultStr = resultStr.substring(0, resultStr.lastIndexOf("\r")); // 待测试,之前尾部没有“\r”???????????
77
        }
78
        IData resultData = new DataMap(resultStr);
79
        if ("success".equals(resultData.getString("flag"))) {
80
            log.debug("发送成功!");
81
        } else {
82
            log.debug("发送失败!");
83
        }
84
    }
85

86
    /**
87
     * 按照account的列表推送
88
     * 
89
     * @param accounts
90
     *            账号数据
91
     * @param content
92
     *            消息内容
93
     * @param isEncrypt
94
     *            是否加密传输
95
     * @param isMerge
96
     *            是否合并发送到推送端
97
     * @throws Exception
98
     */
99
    public static void pushToAccountSet(IDataset accountSet, String content, boolean isEncrypt, boolean isMerge) throws Exception {
100
        if (!isMerge) {// 不合并,单个发送
101
            for (int i = 0; i < accountSet.size(); i++) {
102
                pushToAccount(accountSet.get(i).toString(), content, isEncrypt);
103
            }
104
        } else {
105
            // accounts经过分类,分为多个accounts
106
            IRouteManager routeManager = new DefaultRouteManager();
107
            Route route;
108
            Set<String> serverIdSet = new HashSet<String>();
109
            for (int i = 0; i < accountSet.size(); i++) {
110
                route = routeManager.getRoute(accountSet.get(i).toString());
111
                if (!serverIdSet.contains(route.getServerId())) {
112
                    serverIdSet.add(route.getServerId());
113
                }
114
            }
115
            AccountsGroup ag;
116
            Iterator<String> it = serverIdSet.iterator();
117
            while (it.hasNext()) {
118
                ag = new AccountsGroup(it.next());
119
                for (int i = 0; i < accountSet.size(); i++) {
120
                    route = routeManager.getRoute(accountSet.get(i).toString());
121
                    ag.addRoute(route);
122
                }
123
                pushToAccountSetByServerId(ag.getAccountSet(), content, isEncrypt);
124
            }
125
        }
126

127
    }
128

129
    /**
130
     * 给指定服务端的指定account集合推送消息
131
     * 
132
     * @param accountSet
133
     *            account集合
134
     * @param content
135
     *            推送内容
136
     * @param isEncrypt
137
     *            是否加密
138
     * @throws Exception
139
     */
140
    public static void pushToAccountSetByServerId(IDataset accountSet, String content, boolean isEncrypt) throws Exception {
141
        if (accountSet == null || accountSet.isEmpty()) {
142
            log.error("not found effective accountSet : " + accountSet);
143
            throw new IpuBaseException("not found effective accountSet : " + accountSet);
144
        }
145
        IRouteManager routeManager = new DefaultRouteManager();
146
        Route route = routeManager.getRoute(accountSet.get(0).toString());
147
        String ip = route.getHost();
148
        String httpPort = route.getHttpPort();
149
        String serverName = route.getServerName();
150
        String servletDataRequestName = route.getServletDataRequestName();
151
        String url = "http://" + ip + ":" + httpPort + "/" + serverName + "/" + servletDataRequestName;
152

153
        IData dataParam = new DataMap();
154
        dataParam.put("CONTENT", content);
155
        dataParam.put("accountSet", accountSet.toString());
156
        dataParam.put("SENDER", "system");
157
        Map<String, String> postData = new HashMap<String, String>();
158
        isEncrypt = false;
159
        if (isEncrypt) {
160
            /* 参数加密处理 */
161
            postData.put("action", "MessageAction.sendTextMessageToAccountSet");
162
            // postData.put("key", MobileSecurity.getDesKey());
163
            String encryptData = "";// 加密后的数据
164
            postData.put("data", encryptData);
165
        } else {
166
            postData.put("action", "MessageAction.sendTextMessageToAccountSet");
167
            postData.put("data", dataParam.toString());
168
        }
169
        String data = HttpTool.toQueryStringWithEncode(postData);
170

171
        String resultStr = HttpTool.httpRequest(url, data, "POST");
172
        if (isEncrypt) {
173
            /* 解密 */
174
            // result = MobileSecurity.responseDecrypt(resultStr);
175
        }
176
        if (resultStr.endsWith("\r")) {
177
            resultStr = resultStr.substring(0, resultStr.lastIndexOf("\r")); // 待测试,之前尾部没有“\r”???????????
178
        }
179
        IData resultData = new DataMap(resultStr);
180
        if ("success".equals(resultData.getString("flag"))) {
181
            log.debug("发送成功!");
182
        } else {
183
            log.debug("发送失败!");
184
        }
185
    }
186

187
    /**
188
     * 推送所有account
189
     */
190
    public static void pushToAllAccount(String content, boolean isEncrypt, boolean isMerge) throws Exception {
191
        IDataset pushServerList = BizDataCacheManager.getPushServerListCache();
192
        IData pushServer;
193
        String serverId = null;
194
        Set<String> accountSet;
195
        IDataset accountDataset;
196
        for (int i = 0; i < pushServerList.size(); i++) {
197
            pushServer = pushServerList.getData(i);
198
            serverId = pushServer.getString("serverId");
199
            accountSet = BizDataCacheManager.getPushServerAccountsCache(serverId);
200
            accountDataset = new DatasetList(accountSet.toString());
201
            pushToAccountSetByServerId(accountDataset, content, false);
202
        }
203
    }
204

205
}

+ 1 - 1
push-manager-server/src/main/resources/memcache.xml

@ -10,7 +10,7 @@
10 10
            <address master="127.0.0.1:11211" />
11 11
        </cluster>
12 12
        
13
		<!-- 数据缓存列表 -->
13
        <!-- 数据缓存列表 -->
14 14
		<cluster name="biz_data_cache">
15 15
			<heartbeat-second>2</heartbeat-second>
16 16
			<pool-size>16</pool-size>

+ 4 - 0
push-manager-server/src/main/resources/server-config.xml

@ -4,6 +4,10 @@
4 4
	<config name="engine" value="beetl"/>
5 5
	<config name="encode" value="UTF-8"/>
6 6
	<config name="indexPage" value="SendMessage"/>
7
	
8
	<!-- add by chengwb3 M端是否进行用户权限校验 -->
9
	<config name="userPermissionsCheck" value="true"/>
10
	
7 11
	<!-- 缓存类型,目前支持mem和jvm -->
8 12
	<config name="cache" value="mem"/>
9 13
	<!-- 文件是否加密 -->

+ 4 - 0
push-manager-server/src/main/resources/server-data.xml

@ -3,6 +3,10 @@
3 3
   	<!-- add by chengwb3 -->
4 4
	<!-- 通过负载均衡,获取其中一个ip+port -->
5 5
	<action name="ServerBean.getBestServer" class="com.ai.ipu.biz.bean.ServerBean" method="getBestServer" verify="false"></action>
6
	
7
	<!-- P向M注册服务端列表信息 -->
8
	<action name="ServerBean.addServer" class="com.ai.ipu.biz.bean.ServerBean" method="addServer" verify="false"/>
9
	
6 10
	<!-- 增加路由关系 -->
7 11
	<action name="RouteBean.addRoute" class="com.ai.ipu.biz.bean.RouteBean" method="addRoute" verify="false"></action>
8 12
	<!-- 删除路由关系 -->

+ 0 - 28
push-manager-server/src/main/resources/server-page.xml

@ -1,32 +1,4 @@
1 1
<?xml version="1.0" encoding="UTF-8"?>
2 2
<pages>
3
    <!-- 首页 -->
4
    <action name="Home" 		template="template/home/index.html"/>
5
    <action name="Index" template="template/home/index_forward.html"> </action>
6
 	<action name="Prod" 		template="template/home/prod.html"/>
7
 	<action name="Case" 		template="template/home/case.html"/>
8
 	<action name="CaseDetail" 	template="template/home/case-detail.html" data="CaseDetail"/>
9
 	<action name="Touch" 		template="template/home/touch-us.html"/>
10
 	<action name="ppt" template="ppt.html"/>
11
 	<!-- 文档 -->
12
 	<action name="Doc" 	template="template/doc/Index.html" data="MenuData"/>
13
 	<!-- 市场 -->
14
 	<action name="Appstore" 	template="template/appstore/index.html" data="appStore.appList"/>
15
 	<action name="AppDetail" 		template="template/appstore/app_detail.html" data="appStore.appDetail"/>
16
17
 	<!-- 众包 -->
18
 	<action name="zongbao.Index" template="template/zongbao/index.html" />
19
 	<action name="zongbao.Detail" template="template/zongbao/detail.html" />
20
 	<action name="zongbao.Mine" template="template/zongbao/mine.html" />
21
 	
22
 	<!-- IPU手机版 -->
23
    <action name="MobileHome" template="template/ipumobile/index.html" />
24
 	<action name="MobileProd" template="template/ipumobile/prod.html" />
25
 	<action name="MobileDoc" template="template/ipumobile/doc.html" />
26
 	<action name="MobileCase" template="template/ipumobile/case.html" />
27
 	<action name="MobileTouch" template="template/ipumobile/touch.html" />
28
 	<action name="MobileCaseDetail" template="template/ipumobile/case-detail.html" data="CaseDetail" />
29
 	
30 3
    <action name="SendMessage" template="template/webapp/SendMessage.html"/>
31
    
32 4
</pages>

+ 1 - 6
push-server/.project

@ -11,11 +11,6 @@
11 11
			</arguments>
12 12
		</buildCommand>
13 13
		<buildCommand>
14
			<name>org.eclipse.wst.jsdt.core.javascriptValidator</name>
15
			<arguments>
16
			</arguments>
17
		</buildCommand>
18
		<buildCommand>
19 14
			<name>com.genuitec.eclipse.j2eedt.core.WebClasspathBuilder</name>
20 15
			<arguments>
21 16
			</arguments>
@ -51,8 +46,8 @@
51 46
		<nature>com.genuitec.eclipse.ast.deploy.core.deploymentnature</nature>
52 47
		<nature>com.genuitec.eclipse.j2eedt.core.webnature</nature>
53 48
		<nature>org.eclipse.jdt.core.javanature</nature>
54
		<nature>org.eclipse.wst.jsdt.core.jsNature</nature>
55 49
		<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
56 50
		<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
51
		<nature>com.sysdeo.eclipse.tomcat.tomcatnature</nature>
57 52
	</natures>
58 53
</projectDescription>

+ 13 - 0
push-server/etc/memcache.xml

@ -10,5 +10,18 @@
10 10
            <address master="127.0.0.1:11211" />
11 11
        </cluster>
12 12
        
13
        <!-- 数据缓存列表 -->
14
		<cluster name="biz_data_cache">
15
			<heartbeat-second>2</heartbeat-second>
16
			<pool-size>16</pool-size>
17
			<address master="127.0.0.1:11211" />
18
		</cluster>
19
		
20
		<!-- 路由缓存 -->
21
		<cluster name="push_route_cache">
22
			<heartbeat-second>2</heartbeat-second>
23
			<pool-size>16</pool-size>
24
			<address master="127.0.0.1:11211" />
25
		</cluster>
13 26
    </datacenter>
14 27
</memcache>

+ 2 - 2
push-server/etc/server-data.xml

@ -6,7 +6,7 @@
6 6
 	<action name="OfflineSession" class="com.ai.server.action.SessionAction" method="offlineSession" verify="false"/>
7 7
 	<action name="getLRUSession" class="com.ai.server.action.SessionAction" method="getLRUSession" verify="false"/>
8 8

9
	<!-- C向M请求P的地址 -->
10
	<action name="get" class="com.ai.server.action.SessionAction" method="getLRUSession" verify="false"/>
9
	<!-- 手动注册P -->
10
	<action name="main" class="com.ai.server.action.PushServerManagerAction" method="startMain" verify="false"/>
11 11
	
12 12
</datas>

BIN
push-server/lib/ipu-basic-3.0.jar


+ 71 - 0
push-server/src/com/ai/server/PushServer.java

@ -0,0 +1,71 @@
1
package com.ai.server;
2

3
import java.util.HashMap;
4
import java.util.Map;
5

6
import com.ai.ipu.basic.log.ILogger;
7
import com.ai.ipu.basic.log.IpuLoggerFactory;
8
import com.ai.ipu.basic.net.http.HttpTool;
9
import com.ailk.common.data.IData;
10
import com.ailk.common.data.impl.DataMap;
11

12

13
public class PushServer {
14
    
15
    transient protected static final ILogger log = IpuLoggerFactory.createLogger(PushServer.class);
16
    
17
    public static void main(String[] args) {
18
//        args = new String[8];
19
//        //args应该读取配置文件
20
//        args[0] = "1";//server_id
21
//        args[1] = "192.168.253.1";//host
22
//        args[2] = "服务器1";//name
23
//        args[3] = "7070";//port
24
//        args[4] = "1";//weight
25
//        args[5] = "8080";//http_port
26
//        args[6] = "push-server";//server_name
27
//        args[7] = "mobiledata";//servlet_data_request_name
28
        
29
        String url = "http://localhost:8080/push-manager-server/wlwdata";//push-manager-server的url
30
        // 自动发送http请求到M端注册
31
        IData pushServerObj = new DataMap();
32
        pushServerObj.put("serverId", args[0]);
33
        pushServerObj.put("host", args[1]);
34
        pushServerObj.put("name", args[2]);
35
        pushServerObj.put("port", args[3]);
36
        pushServerObj.put("weight", args[4]);
37
        pushServerObj.put("httpPort", args[5]);
38
        pushServerObj.put("serverName", args[6]);
39
        pushServerObj.put("servletDataRequestName", args[7]);
40
        Map<String, String> postData = new HashMap<String, String>();
41
        boolean isEncrypt = false;// 默认不加密传输
42
        if (isEncrypt ) {
43
            /* 参数加密处理 */
44
            postData.put("action", "ServerBean.addServer");
45
            // postData.put("key", MobileSecurity.getDesKey());
46
            String encryptData = "";// 加密后的数据
47
            postData.put("data", encryptData);
48
        } else {
49
            postData.put("action", "ServerBean.addServer");
50
            postData.put("data", pushServerObj.toString());
51
        }
52
        String data = HttpTool.toQueryStringWithEncode(postData);
53
        try {
54
            String result = HttpTool.httpRequest(url, data, "POST");
55
            if(result.endsWith("\r")){
56
                result = result.substring(0, result.lastIndexOf("\r")); // 待测试,之前尾部没有“\r”???????????
57
            }
58
            IData resultData = new DataMap(result);
59
            if ("success".equals(resultData.getString("flag"))) {
60
                log.debug("注册push-server列表成功.");
61
            } else {
62
                log.debug("注册push-server列表失败.");
63
            }
64
        }
65
        catch (Exception e) {
66
            // TODO Auto-generated catch block
67
            e.printStackTrace();
68
        }
69
    }
70
    
71
}

+ 4 - 4
push-server/src/com/ai/server/action/MessageAction.java

@ -1,7 +1,7 @@
1 1
package com.ai.server.action;
2 2

3 3
import com.ai.ipu.basic.string.StringUtil;
4
import com.ai.ipu.basic.util.IpuUtility;
4
import com.ai.ipu.basic.util.IpuBaseException;
5 5
import com.ai.mobile.push.msg.TextMessage;
6 6
import com.ai.server.core.action.AppAction;
7 7
import com.ai.server.push.DefaultMessagePusher;
@ -23,7 +23,7 @@ public class MessageAction extends AppAction {
23 23
        TextMessage message = new TextMessage();
24 24
        IData data = new DataMap();
25 25
        try {
26
            message.setContent(param.getString("CONTENT"));
26
            message.setContent(param.getString("content"));
27 27
            message.setReceiver(param.getString("RECEIVER"));
28 28
            message.setSender(param.getString("SENDER", "system"));
29 29
            // 向客户端 发送消息
@ -44,12 +44,12 @@ public class MessageAction extends AppAction {
44 44
    public IData sendTextMessageToAccountSet(IData param) {
45 45
        String accountSetStr = param.getString("accountSet");
46 46
        TextMessage message = new TextMessage();
47
        message.setContent(param.getString("CONTENT"));
47
        message.setContent(param.getString("content"));
48 48
        message.setSender(param.getString("SENDER", "system"));
49 49
        if (StringUtil.isJSONArray(accountSetStr)) {// 多个account推送
50 50
            IDataset accountSet = new DatasetList(accountSetStr);
51 51
            if(accountSet == null || accountSet.size()==0){
52
                IpuUtility.error("is not expect json format");
52
                throw new IpuBaseException("is not expect json format");
53 53
            }
54 54
            for (int i=0;i<accountSet.size();i++) {
55 55
                message.setReceiver(accountSet.get(i).toString());

+ 23 - 0
push-server/src/com/ai/server/action/PushServerManagerAction.java

@ -0,0 +1,23 @@
1
package com.ai.server.action;
2

3
import com.ai.server.PushServer;
4
import com.ai.server.core.action.AppAction;
5
import com.ailk.common.data.IData;
6

7
public class PushServerManagerAction extends AppAction {
8
    
9
    public IData startMain(IData param) {
10
        String[] args = new String[8];
11
        // args应该读取配置文件
12
        args[0] = "1";// server_id
13
        args[1] = "192.168.253.1";// host
14
        args[2] = "服务器1";// name
15
        args[3] = "7070";// port
16
        args[4] = "1";// weight
17
        args[5] = "8080";// http_port
18
        args[6] = "push-server";// server_name
19
        args[7] = "mobiledata";// servlet_data_request_name
20
        PushServer.main(args);
21
        return param;
22
    }
23
}

+ 203 - 0
push-server/src/com/ai/server/push/cache/BizDataCacheManager.java

@ -0,0 +1,203 @@
1
package com.ai.server.push.cache;
2

3
import java.util.HashSet;
4
import java.util.Set;
5

6
import com.ai.ipu.basic.log.ILogger;
7
import com.ai.ipu.basic.log.IpuLoggerFactory;
8
import com.ai.ipu.basic.util.IpuBaseException;
9
import com.ai.ipu.server.cache.CacheFactory;
10
import com.ai.ipu.server.cache.intf.ICache;
11
import com.ai.server.util.PushConstant;
12
import com.ailk.common.data.IData;
13
import com.ailk.common.data.IDataset;
14
import com.ailk.common.data.impl.DatasetList;
15

16
/**
17
 * 业务数据缓存管理类
18
 */
19
public class BizDataCacheManager {
20

21
    transient protected static final ILogger log = IpuLoggerFactory.createLogger(BizDataCacheManager.class);
22

23
    private static final String BIZ_DATA_CACHE = PushConstant.BIZ_DATA_CACHE;
24

25
    public static final String PUSH_SERVER_LIST = PushConstant.PUSH_SERVER_LIST; // value:IDataSet
26

27
    public static final String PUSH_SERVER_ACCOUNTS_PREFIX = PushConstant.PUSH_SERVER_ACCOUNTS_PREFIX; // value:Set<String>
28

29
    public static final String AVAILABLE_ACCOUNTS = PushConstant.AVAILABLE_ACCOUNTS; // 用于P端用户有效性二次验证的集合,value:Set<String>
30

31
    public static final String PUSH_SERVER_ACCOUNTS_SIZE_PREFIX = PushConstant.PUSH_SERVER_ACCOUNTS_SIZE_PREFIX; // push-server链接account的数量,value:int
32

33
    public static ICache getBizDataCache() throws Exception {
34
        return CacheFactory.getCache(BIZ_DATA_CACHE);
35
    }
36

37
    /**
38
     * 获取push_server_list缓存
39
     */
40
    public static IDataset getPushServerListCache() throws Exception {
41

42
        if (null == getBizDataCache().get(PUSH_SERVER_LIST)) {
43

44
            synchronized (BizDataCacheManager.class) {
45
                if (null != getBizDataCache().get(PUSH_SERVER_LIST)) {// 避免时间差
46
                    return (IDataset) getBizDataCache().get(PUSH_SERVER_LIST);
47
                }
48
                initPushServerListCache();
49
            }
50
        }
51
        return (IDataset) getBizDataCache().get(PUSH_SERVER_LIST);
52
    }
53

54
    public static boolean containsPushServer(String serverId) throws Exception {
55
        if (null == serverId) {
56
            throw new IpuBaseException("serverId is null.");
57
        }
58
        IDataset list = getPushServerListCache();
59
        if (list.isEmpty()) {
60
            return false;
61
        }
62
        IData pushServer;
63
        for (int i = 0; i < list.size(); i++) {
64
            pushServer = list.getData(i);
65
            if (serverId.equals(pushServer.getString("serverId"))) {
66
                return true;
67
            }
68
        }
69
        return false;
70
    }
71

72
    /**
73
     * 读取数据库,初始化数据
74
     */
75
    // private static void initPushServerListCache() throws Exception {
76
    // ServerDao dao = new ServerDao(Constant.connName);
77
    // IData param = new DataMap();
78
    // param.put("STATE", Constant.Server.STATE_AVAILABLE);
79
    // IDataset list = dao.getServerList(param);
80
    // if (list == null || list.isEmpty()) {
81
    // IpuLogger.error(log, "tab_server表未找到数据.");
82
    // IpuUtility.error("tab_server表未找到数据.");
83
    // }
84
    // getBizDataCache().put(PUSH_SERVER_LIST, list);
85
    //
86
    // IpuLogger.debug(log, "初始化" + PUSH_SERVER_LIST + "成功.");
87
    // }
88

89
    /**
90
     * 初始化P的列表,应该是主动扫描P的列表
91
     */
92
    private static void initPushServerListCache() throws Exception {
93
        // 待处理。。。
94
        log.debug("待处理,初始化扫描可用的P的列表");
95
        IDataset list = new DatasetList();
96
        getBizDataCache().put(PUSH_SERVER_LIST, list);
97
    }
98

99
    /**
100
     * 主动更改缓存,用于数据库tab_server表变动
101
     */
102
    public static void putPushServerListCache(IDataset list) throws Exception {
103
        getBizDataCache().put(PUSH_SERVER_LIST, list);
104

105
        log.debug("更改" + PUSH_SERVER_LIST + "成功.");
106
    }
107

108
    /**
109
     * 获取指定push_server端的accounts的Set集合
110
     */
111
    @SuppressWarnings("unchecked")
112
    public static Set<String> getPushServerAccountsCache(String serverId) throws Exception {
113
        if (null == getBizDataCache().get(PUSH_SERVER_ACCOUNTS_PREFIX + serverId)) {
114
            return new HashSet<String>();
115
        }
116
        return (Set<String>) getBizDataCache().get(PUSH_SERVER_ACCOUNTS_PREFIX + serverId);
117
    }
118

119
    /**
120
     * 存放accountSet值
121
     */
122
    public static void putPushServerAccountsCache(Set<String> accountSet, String serverId) throws Exception {
123
        getBizDataCache().put(PUSH_SERVER_ACCOUNTS_PREFIX + serverId, accountSet);
124
    }
125

126
    /**
127
     * 初始化或者更改accountSet值
128
     */
129
    public static void addAccountToPushServerAccountsId(String account, String serverId) throws Exception {
130
        Set<String> accountSet = getPushServerAccountsCache(serverId);
131
        log.debug("M add route, put before:key=" + (PUSH_SERVER_ACCOUNTS_PREFIX + serverId) + ",value=" + accountSet.toString());
132
        accountSet.add(account);
133
        putPushServerAccountsCache(accountSet, serverId);
134
        log.debug("M add route, put after:key=" + (PUSH_SERVER_ACCOUNTS_PREFIX + serverId) + ",value=" + accountSet.toString());
135

136
    }
137

138
    /**
139
     * 删除指定serverId的一个account值
140
     */
141
    public static void removeAccountToPushServerAccountsId(String account, String serverId) throws Exception {
142
        Set<String> accountSet = getPushServerAccountsCache(serverId);
143
        if (null == accountSet || !accountSet.contains(account)) {
144
            log.debug("has not this account [" + account + "] on this " + serverId + "server");
145
            return;
146
        }
147
        accountSet.remove(account);
148
        putPushServerAccountsCache(accountSet, serverId);
149
    }
150

151
    public static void addAvailableAccount(String account) throws Exception {
152
        if (getAvailableAccountSet().contains(account)) {
153
            // account已经存在了
154
            log.debug("account[" + account + "] already exists.");
155
        }
156
        Set<String> accountSet = getAvailableAccountSet();
157
        accountSet.add(account);
158
        putAvailableAccountSet(accountSet);
159
    }
160

161
    @SuppressWarnings("unchecked")
162
    public static Set<String> getAvailableAccountSet() throws Exception {
163
        if (null == getBizDataCache().get(AVAILABLE_ACCOUNTS)) {
164
            return new HashSet<String>();
165
        }
166
        return (Set<String>) getBizDataCache().get(AVAILABLE_ACCOUNTS);
167
    }
168

169
    public static void putAvailableAccountSet(Set<String> accountSet) throws Exception {
170
        getBizDataCache().put(AVAILABLE_ACCOUNTS, accountSet);
171
    }
172

173
    public static boolean containsAvailableAccount(String account) throws Exception {
174
        return getAvailableAccountSet().contains(account);
175
    }
176

177
    public static void increasePushServerAccountsSize(String serverId) throws Exception {
178
        int size = getPushServerAccountsSize(serverId);
179
        putPushServerAccountsSize(serverId, size + 1);
180
        log.debug("Number of server connections plus one");
181
    }
182

183
    public static void decreasePushServerAccountsSize(String serverId) throws Exception {
184
        int size = getPushServerAccountsSize(serverId);
185
        if (size < 1) {
186
            throw new IpuBaseException("The number of current connected account is less than one.");
187
        }
188
        putPushServerAccountsSize(serverId, size - 1);
189
        log.debug("Number of server connections minus one");
190
    }
191

192
    private static void putPushServerAccountsSize(String serverId, int accountsSize) throws Exception {
193
        getBizDataCache().put(PUSH_SERVER_ACCOUNTS_SIZE_PREFIX + serverId, accountsSize);
194
    }
195

196
    private static int getPushServerAccountsSize(String serverId) throws Exception {
197
        if (null == getBizDataCache().get(PUSH_SERVER_ACCOUNTS_SIZE_PREFIX + serverId)) {
198
            return 0;
199
        }
200
        return (Integer) getBizDataCache().get(PUSH_SERVER_ACCOUNTS_SIZE_PREFIX + serverId);
201
    }
202

203
}

+ 48 - 0
push-server/src/com/ai/server/push/cache/PushRouteCacheManager.java

@ -0,0 +1,48 @@
1
package com.ai.server.push.cache;
2

3
import com.ai.ipu.basic.log.ILogger;
4
import com.ai.ipu.basic.log.IpuLoggerFactory;
5
import com.ai.ipu.basic.util.IpuBaseException;
6
import com.ai.ipu.server.cache.CacheFactory;
7
import com.ai.ipu.server.cache.intf.ICache;
8
import com.ai.server.push.route.Route;
9
import com.ai.server.util.PushConstant;
10

11
/**
12
 * 管理服务端路由关系缓存管理类
13
 */
14
public class PushRouteCacheManager {
15

16
    transient protected static final ILogger log = IpuLoggerFactory.createLogger(PushRouteCacheManager.class);
17

18
    private static final String PUSH_ROUTE_CACHE = PushConstant.PUSH_ROUTE_CACHE;
19

20
    public static ICache getPushRouteCache() throws Exception {
21
        return CacheFactory.getCache(PUSH_ROUTE_CACHE);
22
    }
23

24
    public static Route getRoute(String account) throws Exception {
25
        if (null == getPushRouteCache().get(account)) {
26
            return null;
27
        }
28
        return new Route(getPushRouteCache().get(account).toString());
29
    }
30

31
    public static void putRoute(String account, Route route) throws Exception {
32
        if (null == account || "".equals(account) || null == route) {
33
            throw new IpuBaseException("account or route is null.");
34
        }
35
        getPushRouteCache().put(account, route.toString());
36
        log.debug("set key=[" + account + "] route success.");
37
    }
38

39
    public static void removeRoute(String account) throws Exception {
40
        if (null == getRoute(account)) {
41
            log.debug("this route account [" + account + "] is null.");
42
            return;
43
        }
44
        getPushRouteCache().remove(account);
45
        log.debug("remove key=[" + account + "] route success.");
46
    }
47

48
}

+ 112 - 104
push-server/src/com/ai/server/push/handle/RegisterWithRouteHandler.java

@ -1,14 +1,12 @@
1 1
package com.ai.server.push.handle;
2 2

3 3
import java.net.InetAddress;
4
import java.util.HashMap;
5 4
import java.util.Map;
6 5
import java.util.UUID;
7 6

8 7
import org.apache.log4j.Logger;
9 8

10
import com.ai.ipu.basic.net.http.HttpTool;
11
import com.ai.ipu.basic.util.IpuLogger;
9
import com.ai.ipu.basic.util.IpuBaseException;
12 10
import com.ai.mobile.push.handle.IRequestHandler;
13 11
import com.ai.mobile.push.msg.AbstractMessage;
14 12
import com.ai.mobile.push.msg.RegisterMessage;
@ -17,82 +15,86 @@ import com.ai.mobile.push.session.DefaultSessionManager;
17 15
import com.ai.mobile.push.session.IMSession;
18 16
import com.ai.mobile.push.session.ISessionManager;
19 17
import com.ai.mobile.push.util.IMConstant;
18
import com.ai.server.push.cache.PushRouteCacheManager;
19
import com.ai.server.push.route.IRouteManager;
20 20
import com.ai.server.push.route.Route;
21
import com.ai.server.push.route.impl.RouteManagerImpl;
21 22
import com.ai.server.usermanager.DefaultUserManager;
22 23
import com.ai.server.usermanager.IUserManager;
23 24
import com.ai.server.util.BeanHolder;
24 25
import com.ai.server.util.Constant;
25
import com.ailk.common.data.IData;
26
import com.ailk.common.data.impl.DataMap;
27 26

28
public class RegisterWithRouteHandler implements IRequestHandler{
29
	transient protected final Logger logger = Logger.getLogger(RegisterWithRouteHandler.class);
30
	@Override
31
	public ReplyMessage process(IMSession session, AbstractMessage msg) {
32
	    System.out.println("服务端接收到注册消息,处理中。。。。。。");
33
		// TODO Auto-generated method stub
34
		ISessionManager sessionManager= BeanHolder.getBean(DefaultSessionManager.class);
35
		RegisterMessage message = (RegisterMessage)msg;
36
		ReplyMessage reply = new ReplyMessage();
37
		String account = message.getAccount();
38
		Map<String, Object> map = message.getMap();
39
		IUserManager userManager = new DefaultUserManager();
40
		userManager.verify(map.get("account").toString(), map);//用户连接权限验证
41
		try {
42
			reply.setAccount(account);
43
			session.setAccount(account);
44
			session.setDeviceId(message.getDeviceId());
45
			session.setGid(UUID.randomUUID().toString());
46
			session.setHost(InetAddress.getLocalHost().getHostAddress());
47
			session.setDeviceType(message.getDeviceType());
48
			session.setDeviceModel(message.getDeviceModel());
49
			
50
			/*客户端连接断开,服务端无法获知情况,因此重连需要关闭旧的连接*/
51
			IMSession oldSession = sessionManager.getSession(account);
52
			if (oldSession != null) {
53
				// 如果是账号已经在另一台终端登录。则让另一个终端下线
54
				if ((oldSession.getDeviceId() != null
55
						&& !oldSession.getDeviceId().equals(session.getDeviceId()) 
56
						|| !oldSession.equals(session))) {
27
public class RegisterWithRouteHandler implements IRequestHandler {
28
    transient protected final Logger logger = Logger.getLogger(RegisterWithRouteHandler.class);
57 29

58
					//oldSession.removeAttribute(IMConstant.SESSION_KEY);
59
					ReplyMessage oldReply = new ReplyMessage();
60
					oldReply.setCode(Constant.MessageType.TYPE_999);// 强行下线消息类型
61
					oldReply.setAccount(account);
30
    @Override
31
    public ReplyMessage process(IMSession session, AbstractMessage msg) {
32
        System.out.println("服务端接收到注册消息,处理中。。。。。。");
33
        // TODO Auto-generated method stub
34
        ISessionManager sessionManager = BeanHolder.getBean(DefaultSessionManager.class);
35
        RegisterMessage message = (RegisterMessage) msg;
36
        ReplyMessage reply = new ReplyMessage();
37
        String account = message.getAccount();
38
        Map<String, Object> map = message.getMap();
39
        try {
40
            IUserManager userManager = new DefaultUserManager();
41
            boolean checkUserAvalible = userManager.verify(map.get("account").toString());// 用户连接权限验证
42
            if (!checkUserAvalible) {
43
                throw new IpuBaseException("不是有效用户,禁止连接推送服务端。");
44
            }
45
            reply.setAccount(account);
46
            session.setAccount(account);
47
            session.setDeviceId(message.getDeviceId());
48
            session.setGid(UUID.randomUUID().toString());
49
            session.setHost(InetAddress.getLocalHost().getHostAddress());
50
            session.setDeviceType(message.getDeviceType());
51
            session.setDeviceModel(message.getDeviceModel());
52

53
            /* 客户端连接断开,服务端无法获知情况,因此重连需要关闭旧的连接 */
54
            IMSession oldSession = sessionManager.getSession(account);
55
            if (oldSession != null) {
56
                // 如果是账号已经在另一台终端登录。则让另一个终端下线
57
                if ((oldSession.getDeviceId() != null && !oldSession.getDeviceId().equals(session.getDeviceId()) || !oldSession.equals(session))) {
58

59
                    // oldSession.removeAttribute(IMConstant.SESSION_KEY);
60
                    ReplyMessage oldReply = new ReplyMessage();
61
                    oldReply.setCode(Constant.MessageType.TYPE_999);// 强行下线消息类型
62
                    oldReply.setAccount(account);
63

64
                    if (!oldSession.isLocalhost()) {
65
                        /*
66
                         * 判断当前session是否连接于本台服务器,如不是发往目标服务器处理
67
                         * MessageDispatcher.execute(msg, oldSession.getHost());
68
                         */
69
                    } else {
70
                        oldSession.write(oldReply);
71
                        oldSession.close(true);
72
                        sessionManager.removeSession(account);
73
                    }
74
                    oldSession = null;
75
                }
76
            }
77

78
            if (oldSession == null) {
79
                // 第一次设置心跳时间为登录时间
80
                session.setBindTime(System.currentTimeMillis());
81
                session.setHeartbeat(System.currentTimeMillis());
82
                sessionManager.addSession(account, session);
83
                // 发送M,M记录路由关系,并有业务处理
84
                session.setAttribute("port", map.get("port"));
85
                this.addRoute(session, message, false);
86
            }
87

88
            reply.setCode(IMConstant.CODE_200);
89
        }
90
        catch (Exception e) {
91
            reply.setCode(IMConstant.CODE_500);
92
            e.printStackTrace();
93
        }
94
        logger.debug("[register account]:" + account + "|" + reply.getCode());
95
        return reply;
96
    }
62 97

63
					if (!oldSession.isLocalhost()) {
64
						/*
65
						 * 判断当前session是否连接于本台服务器,如不是发往目标服务器处理
66
						 * MessageDispatcher.execute(msg, oldSession.getHost());
67
						 */
68
					} else {
69
						oldSession.write(oldReply);
70
						oldSession.close(true);
71
						sessionManager.removeSession(account);
72
					}
73
					oldSession = null;
74
				}
75
			}
76
			
77
			if (oldSession == null) {
78
				// 第一次设置心跳时间为登录时间
79
				session.setBindTime(System.currentTimeMillis());
80
				session.setHeartbeat(System.currentTimeMillis());
81
				sessionManager.addSession(account, session);
82
				// 发送M,M记录路由关系,并有业务处理
83
				session.setAttribute("port", map.get("port"));
84
				this.addRoute(session, message, false);
85
			}
86
			
87
			reply.setCode(IMConstant.CODE_200);
88
		} catch (Exception e) {
89
			reply.setCode(IMConstant.CODE_500);
90
			e.printStackTrace();
91
		}
92
		logger.debug("[register account]:" + account + "|" + reply.getCode());
93
		return reply;
94
	}
95
	
96 98
    private void addRoute(IMSession session, RegisterMessage message, boolean isEncrypt) throws Exception {
97 99
        Route route = new Route();
98 100
        route.setAccount(session.getAccount());
@ -111,41 +113,47 @@ public class RegisterWithRouteHandler implements IRequestHandler{
111 113
        route.setState("1");
112 114
        route.setWeight("1");
113 115
        route.setServerId(message.getMap().get("serverId").toString());
116

117
        IRouteManager routeManager = new RouteManagerImpl();
118
        routeManager.addRoute(route.getAccount(), route);
114 119
        
115
        // 1.memcache保存对象,因为不能序列化,故不能发送到M端保存,也可以节省网络开销
116
        //RouteCacheUtil.addRouteCache(session.getAccount(), session);
120
        System.out.println(PushRouteCacheManager.getRoute(route.getAccount()).toString());
117 121
        
118
        // 2.M端业务处理(暂时没有业务处理)
119
        IData dataParam = new DataMap();
120
        dataParam.put("key1", "value1");
121
        dataParam.put("route", route.toString());
122
        Map<String, String> postData = new HashMap<String, String>();
123
        if (isEncrypt) {
124
            /* 参数加密处理 */
125
            postData.put("action", "RouteBean.addRoute");
126
            // postData.put("key", MobileSecurity.getDesKey());
127
            String encryptData = "";// 加密后的数据
128
            postData.put("data", encryptData);
129
        } else {
130
            postData.put("action", "RouteBean.addRoute");
131
            postData.put("data", dataParam.toString());
132
        }
133
        String data = HttpTool.toQueryStringWithEncode(postData);
134

135
        String result = HttpTool.httpRequest("http://localhost:8080/push-manager-server/wlwdata", data, "POST");
136
        if (isEncrypt) {
137
            /*解密*/
138
            //result = MobileSecurity.responseDecrypt(result);
139
        }
140
        if(result.endsWith("\r")){
141
            result = result.substring(0, result.lastIndexOf("\r")); // 待测试,之前尾部没有“\r”???????????
142
        }
143
        IData resultData = new DataMap(result);
144
        if ("success".equals(resultData.getString("flag"))) {
145
            IpuLogger.debug(logger, "添加route路由关系成功.");
146
        } else {
147
            IpuLogger.debug(logger, "添加route路由关系失败.");
148
        }
122
        
123
//        // 1.memcache保存对象,因为不能序列化,故不能发送到M端保存,也可以节省网络开销
124
//        // RouteCacheUtil.addRouteCache(session.getAccount(), session);
125
//
126
//        // 2.M端业务处理(暂时没有业务处理)
127
//        IData dataParam = new DataMap();
128
//        dataParam.put("key1", "value1");
129
//        dataParam.put("route", route.toString());
130
//        Map<String, String> postData = new HashMap<String, String>();
131
//        if (isEncrypt) {
132
//            /* 参数加密处理 */
133
//            postData.put("action", "RouteBean.addRoute");
134
//            // postData.put("key", MobileSecurity.getDesKey());
135
//            String encryptData = "";// 加密后的数据
136
//            postData.put("data", encryptData);
137
//        } else {
138
//            postData.put("action", "RouteBean.addRoute");
139
//            postData.put("data", dataParam.toString());
140
//        }
141
//        String data = HttpTool.toQueryStringWithEncode(postData);
142
//
143
//        String result = HttpTool.httpRequest("http://localhost:8080/push-manager-server/wlwdata", data, "POST");
144
//        if (isEncrypt) {
145
//            /* 解密 */
146
//            // result = MobileSecurity.responseDecrypt(result);
147
//        }
148
//        if (result.endsWith("\r")) {
149
//            result = result.substring(0, result.lastIndexOf("\r")); // 待测试,之前尾部没有“\r”???????????
150
//        }
151
//        IData resultData = new DataMap(result);
152
//        if ("success".equals(resultData.getString("flag"))) {
153
//            IpuLogger.debug(logger, "添加route路由关系成功.");
154
//        } else {
155
//            IpuLogger.debug(logger, "添加route路由关系失败.");
156
//        }
149 157
    }
150 158

151 159
}

+ 41 - 39
push-server/src/com/ai/server/push/handle/UnregisterWithRouteHandler.java

@ -1,12 +1,7 @@
1 1
package com.ai.server.push.handle;
2 2

3
import java.util.HashMap;
4
import java.util.Map;
5

6
import org.apache.log4j.Logger;
7

8
import com.ai.ipu.basic.net.http.HttpTool;
9
import com.ai.ipu.basic.util.IpuLogger;
3
import com.ai.ipu.basic.log.ILogger;
4
import com.ai.ipu.basic.log.IpuLoggerFactory;
10 5
import com.ai.mobile.push.handle.IRequestHandler;
11 6
import com.ai.mobile.push.msg.AbstractMessage;
12 7
import com.ai.mobile.push.msg.RegisterMessage;
@ -14,13 +9,14 @@ import com.ai.mobile.push.msg.ReplyMessage;
14 9
import com.ai.mobile.push.session.DefaultSessionManager;
15 10
import com.ai.mobile.push.session.IMSession;
16 11
import com.ai.mobile.push.session.ISessionManager;
12
import com.ai.server.push.route.IRouteManager;
17 13
import com.ai.server.push.route.Route;
14
import com.ai.server.push.route.impl.RouteManagerImpl;
18 15
import com.ai.server.util.BeanHolder;
19
import com.ailk.common.data.IData;
20
import com.ailk.common.data.impl.DataMap;
21 16

22 17
public class UnregisterWithRouteHandler implements IRequestHandler {
23
    transient protected final Logger logger = Logger.getLogger(UnregisterWithRouteHandler.class);
18
    transient protected static final ILogger log = IpuLoggerFactory.createLogger(UnregisterWithRouteHandler.class);
19

24 20
    @Override
25 21
    public ReplyMessage process(IMSession session, AbstractMessage message) {
26 22
        // TODO Auto-generated method stub
@ -58,36 +54,42 @@ public class UnregisterWithRouteHandler implements IRequestHandler {
58 54
        route.setServerName(registerMessage.getMap().get("serverName").toString());
59 55
        route.setServletDataRequestName(registerMessage.getMap().get("servletDataRequestName").toString());
60 56

61
        IData dataParam = new DataMap();
62
        dataParam.put("key1", "value1");
63
        dataParam.put("route", route.toString());
64
        Map<String, String> postData = new HashMap<String, String>();
65
        if (isEncrypt) {
66
            /* 参数加密处理 */
67
            postData.put("action", "RouteBean.removeRoute");
68
            // postData.put("key", MobileSecurity.getDesKey());
69
            String encryptData = "";// 加密后的数据
70
            postData.put("data", encryptData);
71
        } else {
72
            postData.put("action", "RouteBean.removeRoute");
73
            postData.put("data", dataParam.toString());
74
        }
75
        String data = HttpTool.toQueryStringWithEncode(postData);
57
        IRouteManager routeManager = new RouteManagerImpl();
58
        routeManager.removeRoute(route);
76 59

77
        String result = HttpTool.httpRequest("http://localhost:8080/push-manager-server/wlwdata", data, "POST");
78
        if (isEncrypt) {
79
            /* 解密 */
80
            // result = MobileSecurity.responseDecrypt(result);
81
        }
82
        if (result.endsWith("\r")) {
83
            result = result.substring(0, result.lastIndexOf("\r")); // 待测试,之前尾部没有“\r”???????????
84
        }
85
        IData resultData = new DataMap(result);
86
        if ("success".equals(resultData.getString("flag"))) {
87
            IpuLogger.debug(logger, "删除route路由关系成功.");
88
        } else {
89
            IpuLogger.debug(logger, "删除route路由关系成功.");
90
        }
60
        // IData dataParam = new DataMap();
61
        // dataParam.put("key1", "value1");
62
        // dataParam.put("route", route.toString());
63
        // Map<String, String> postData = new HashMap<String, String>();
64
        // if (isEncrypt) {
65
        // /* 参数加密处理 */
66
        // postData.put("action", "RouteBean.removeRoute");
67
        // // postData.put("key", MobileSecurity.getDesKey());
68
        // String encryptData = "";// 加密后的数据
69
        // postData.put("data", encryptData);
70
        // } else {
71
        // postData.put("action", "RouteBean.removeRoute");
72
        // postData.put("data", dataParam.toString());
73
        // }
74
        // String data = HttpTool.toQueryStringWithEncode(postData);
75
        //
76
        // String result =
77
        // HttpTool.httpRequest("http://localhost:8080/push-manager-server/wlwdata",
78
        // data, "POST");
79
        // if (isEncrypt) {
80
        // /* 解密 */
81
        // // result = MobileSecurity.responseDecrypt(result);
82
        // }
83
        // if (result.endsWith("\r")) {
84
        // result = result.substring(0, result.lastIndexOf("\r")); //
85
        // 待测试,之前尾部没有“\r”???????????
86
        // }
87
        // IData resultData = new DataMap(result);
88
        // if ("success".equals(resultData.getString("flag"))) {
89
        // log.debug("删除route路由关系成功.");
90
        // } else {
91
        // log.debug("删除route路由关系成功.");
92
        // }
91 93
    }
92 94

93 95
}

+ 36 - 0
push-server/src/com/ai/server/push/route/IRouteManager.java

@ -0,0 +1,36 @@
1
package com.ai.server.push.route;
2

3
import com.ai.ipu.server.cache.intf.ICache;
4

5
public interface IRouteManager {
6
    /**
7
     * 添加新的路由关系
8
     */
9
    public void addRoute(String account, Route route) throws Exception;
10

11
    /**
12
     * 用账号来获取route
13
     */
14
    Route getRoute(String account) throws Exception;
15

16
    /**
17
     * 获取所有route
18
     */
19
    public ICache getRoutes() throws Exception;
20

21
    /**
22
     * 删除route
23
     */
24
    public void removeRoute(Route route) throws Exception;
25

26
    /**
27
     * 删除route
28
     */
29
    public void removeRoute(String account) throws Exception;
30

31
    /**
32
     * 判断route是否存在
33
     */
34
    public boolean containsRoute(Route route) throws Exception;
35

36
}

+ 2 - 2
push-server/src/com/ai/server/push/route/Route.java

@ -2,7 +2,7 @@ package com.ai.server.push.route;
2 2

3 3
import java.io.Serializable;
4 4

5
import com.ai.ipu.basic.util.IpuLogger;
5
import com.ai.ipu.basic.util.IpuBaseException;
6 6
import com.ailk.common.data.impl.DataMap;
7 7

8 8
/**
@ -210,7 +210,7 @@ public class Route extends DataMap implements Serializable {
210 210
                }
211 211
            }
212 212
        } else {
213
            IpuLogger.debug("无法解析,不是自定义解析格式。");
213
            throw new IpuBaseException("无法解析,不是自定义解析格式。");
214 214
        }
215 215
    }
216 216


+ 55 - 0
push-server/src/com/ai/server/push/route/impl/DefaultRouteManager.java

@ -0,0 +1,55 @@
1
package com.ai.server.push.route.impl;
2

3
import com.ai.ipu.basic.log.ILogger;
4
import com.ai.ipu.basic.log.IpuLoggerFactory;
5
import com.ai.ipu.server.cache.intf.ICache;
6
import com.ai.server.push.cache.BizDataCacheManager;
7
import com.ai.server.push.cache.PushRouteCacheManager;
8
import com.ai.server.push.route.IRouteManager;
9
import com.ai.server.push.route.Route;
10

11
public class DefaultRouteManager implements IRouteManager {
12

13
    transient protected static final ILogger log = IpuLoggerFactory.createLogger(DefaultRouteManager.class);
14

15
    @Override
16
    public void addRoute(String account, Route route) throws Exception {
17
        PushRouteCacheManager.putRoute(account, route);
18
        BizDataCacheManager.addAccountToPushServerAccountsId(account, route.getServerId());
19
    }
20

21
    @Override
22
    public Route getRoute(String account) throws Exception {
23
        return PushRouteCacheManager.getRoute(account);
24
    }
25

26
    @Override
27
    public ICache getRoutes() throws Exception {
28
        return PushRouteCacheManager.getPushRouteCache();
29
    }
30

31
    @Override
32
    public void removeRoute(Route route) throws Exception {
33
        removeRoute(route.getAccount());
34
    }
35

36
    @Override
37
    public void removeRoute(String account) throws Exception {
38
        Route route = PushRouteCacheManager.getRoute(account);
39
        if (null == route) {
40
            log.debug("Not found this designated account of the Route.");
41
            return;
42
        }
43
        BizDataCacheManager.decreasePushServerAccountsSize(route.getServerId());
44
        PushRouteCacheManager.removeRoute(account);
45
    }
46

47
    @Override
48
    public boolean containsRoute(Route route) throws Exception {
49
        if (null != PushRouteCacheManager.getPushRouteCache().get(route.getAccount())) {
50
            return true;
51
        }
52
        return false;
53
    }
54

55
}

+ 58 - 0
push-server/src/com/ai/server/push/route/impl/RouteManagerImpl.java

@ -0,0 +1,58 @@
1
package com.ai.server.push.route.impl;
2

3
import com.ai.ipu.basic.log.ILogger;
4
import com.ai.ipu.basic.log.IpuLoggerFactory;
5
import com.ai.ipu.server.cache.intf.ICache;
6
import com.ai.server.push.cache.BizDataCacheManager;
7
import com.ai.server.push.cache.PushRouteCacheManager;
8
import com.ai.server.push.route.IRouteManager;
9
import com.ai.server.push.route.Route;
10

11
/**
12
 * 路由关系管理实现类。 注:不保存push-server对象的account列表,只保存account的数量。
13
 */
14
public class RouteManagerImpl implements IRouteManager {
15

16
    transient protected static final ILogger log = IpuLoggerFactory.createLogger(RouteManagerImpl.class);
17

18
    @Override
19
    public void addRoute(String account, Route route) throws Exception {
20
        PushRouteCacheManager.putRoute(account, route);
21
        BizDataCacheManager.increasePushServerAccountsSize(route.getServerId());
22
    }
23

24
    @Override
25
    public Route getRoute(String account) throws Exception {
26
        return PushRouteCacheManager.getRoute(account);
27
    }
28

29
    @Override
30
    public ICache getRoutes() throws Exception {
31
        return PushRouteCacheManager.getPushRouteCache();
32
    }
33

34
    @Override
35
    public void removeRoute(Route route) throws Exception {
36
        removeRoute(route.getAccount());
37
    }
38

39
    @Override
40
    public void removeRoute(String account) throws Exception {
41
        Route route = PushRouteCacheManager.getRoute(account);
42
        if (null == route) {
43
            log.debug("Not found this designated account of the Route.");
44
            return;
45
        }
46
        BizDataCacheManager.decreasePushServerAccountsSize(route.getServerId());
47
        PushRouteCacheManager.removeRoute(account);
48
    }
49

50
    @Override
51
    public boolean containsRoute(Route route) throws Exception {
52
        if (null != PushRouteCacheManager.getPushRouteCache().get(route.getAccount())) {
53
            return true;
54
        }
55
        return false;
56
    }
57

58
}

+ 0 - 16
push-server/src/com/ai/server/usermanager/AbstractUserManager.java

@ -1,16 +0,0 @@
1
package com.ai.server.usermanager;
2

3
import java.util.Map;
4

5
import com.ai.ipu.basic.util.IpuUtility;
6

7
public abstract class AbstractUserManager implements IUserManager {
8

9
    @Override
10
    public void verify(String account, Map<String, Object> map) {
11
        if (account == null || "".equals(account)) {
12
            IpuUtility.error("account为空");
13
        }
14
        customVerify(account, map);
15
    }
16
}

+ 4 - 14
push-server/src/com/ai/server/usermanager/DefaultUserManager.java

@ -1,22 +1,12 @@
1 1
package com.ai.server.usermanager;
2 2

3
import java.util.Map;
3
import com.ai.server.push.cache.BizDataCacheManager;
4 4

5
import com.ai.ipu.basic.util.IpuLogger;
6
import com.ai.ipu.basic.util.IpuUtility;
7

8
public class DefaultUserManager extends AbstractUserManager{
5
public class DefaultUserManager implements IUserManager{
9 6

10 7
    @Override
11
    public void customVerify(String account, Map<String, Object> map) {
12
        // 用户名和密码的校验
13
        String user = (String) map.get("userName");
14
        String passwd = (String) map.get("passwd");
15
        if(user!=null&&passwd!=null){
16
            IpuLogger.debug("用户名密码校验未通过.");
17
            IpuUtility.error("User and password validation failed");
18
        }
19
        IpuLogger.debug("用户连接权限校验通过.");
8
    public boolean verify(String account) throws Exception {
9
        return BizDataCacheManager.containsAvailableAccount(account);
20 10
    }
21 11

22 12
}

+ 1 - 14
push-server/src/com/ai/server/usermanager/IUserManager.java

@ -1,24 +1,11 @@
1 1
package com.ai.server.usermanager;
2 2

3
import java.util.Map;
4 3

5 4
public interface IUserManager {
6 5

7 6
    /**
8 7
     * 验证account有效性
9
     * 
10
     * @param account
11
     * @param map
12
     * @throws Exception
13 8
     */
14
    public void verify(String account, Map<String, Object> map);
9
    public boolean verify(String account) throws Exception;
15 10

16
    /**
17
     * 自定义校验map
18
     * 
19
     * @param account
20
     * @param map
21
     * @throws Exception
22
     */
23
    public void customVerify(String account, Map<String, Object> map);
24 11
}

+ 42 - 0
push-server/src/com/ai/server/util/PushConstant.java

@ -0,0 +1,42 @@
1
package com.ai.server.util;
2

3
public class PushConstant {
4

5
    /**
6
     * 业务数据缓存key,memcache.xml的cluster name
7
     */
8
    public static final String BIZ_DATA_CACHE = "biz_data_cache";
9
    
10
    /**
11
     * 业务数据缓存之一,服务端列表缓存,即tab_server表数据
12
     */
13
    public static final String PUSH_SERVER_LIST = "PUSH_SERVER_LIST"; // value:IDataSet
14

15
    /**
16
     * 业务数据缓存之一的前缀,+serverId即key,单个push-server的链接accounts列表
17
     */
18
    public static final String PUSH_SERVER_ACCOUNTS_PREFIX = "PUSH_SERVER_ACCOUNTS_"; // value:Set<String>
19
    
20
    /**
21
     * 业务数据缓存之一的前缀,+serverId即key,单个push-server链接account的数量
22
     */
23
    public static final String PUSH_SERVER_ACCOUNTS_SIZE_PREFIX = "PUSH_SERVER_ACCOUNTS_SIZE_"; // value:int
24
    
25
    /**
26
     * 业务数据缓存之一,是account的Set集合
27
     */
28
    public static final String AVAILABLE_ACCOUNTS = "AVAILABLE_ACCOUNTS"; // value:Set<String>
29

30
    /**
31
     * 路由缓存key,memcache.xml的cluster name
32
     */
33
    public static final String PUSH_ROUTE_CACHE = "push_route_cache"; // value:Route
34

35
    public class Server {
36
        
37
        public static final String STATE_AVAILABLE = "1";// 可用
38

39
        public static final String STATE_UNAVAILABLE = "0";// 不可用
40
    }
41

42
}