use of j.util.ConcurrentMap in project JFramework by gugumall.
the class JRouterImpl method service.
/*
* (non-Javadoc)
* @see j.service.router.JRouter#service(java.lang.String, java.lang.String, java.lang.String, java.lang.String)
*/
public ServiceBase service(String clientUuid, String clusterCode, String md54Routing) throws RemoteException {
waitWhileMonitoring();
if (Constants.PRIVICY_PUBLIC.equalsIgnoreCase(routerConfig.getPrivacy())) {
// is public, nothing to do
} else if (Constants.PRIVICY_MD5.equalsIgnoreCase(routerConfig.getPrivacy())) {
Client client = routerConfig.getClient(clientUuid);
if (client == null) {
log.log("client " + clientUuid + " is not exists.", Logger.LEVEL_DEBUG);
throw new RemoteException(Constants.AUTH_FAILED);
}
String md5 = "";
md5 += clientUuid;
md5 += client.getKey();
md5 = JUtilMD5.MD5EncodeToHex(md5);
if (!md5.equalsIgnoreCase(md54Routing)) {
throw new RemoteException(Constants.AUTH_FAILED);
}
} else {
// 未实现的隐私策略
throw new RemoteException(Constants.AUTH_FAILED);
}
String codeOfUuid = null;
for (int i = 0; i < nodeInfoList.size(); i++) {
// 按uuid获得
String[] node = ((String) nodeInfoList.get(i)).split(",");
if (node[0].equals(clusterCode)) {
codeOfUuid = node[4];
break;
}
}
ConcurrentMap servantsOfCluster = (ConcurrentMap) servantsOfClusters.get(codeOfUuid == null ? clusterCode : codeOfUuid);
if (servantsOfCluster == null) {
throw new RemoteException("the service(rmi) " + clusterCode + " is not found.");
}
List nodes = servantsOfCluster.listValues();
if (nodes.size() == 0) {
throw new RemoteException("no valid node for the service(rmi) " + clusterCode + ".");
}
if (servantsOfCluster.containsKey(clusterCode)) {
// 按uuid获得
nodes.clear();
nodes = null;
return (ServiceBase) servantsOfCluster.get(clusterCode);
} else {
ServiceBase servant = (ServiceBase) nodes.get(JUtilRandom.nextInt(nodes.size()));
nodes.clear();
nodes = null;
return servant;
}
}
Aggregations