Search in sources :

Example 16 with ConcurrentMap

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;
    }
}
Also used : ServiceBase(j.service.server.ServiceBase) ConcurrentMap(j.util.ConcurrentMap) List(java.util.List) ConcurrentList(j.util.ConcurrentList) Client(j.service.Client) HttpClient(org.apache.http.client.HttpClient) RemoteException(java.rmi.RemoteException)

Aggregations

ConcurrentMap (j.util.ConcurrentMap)16 ConcurrentList (j.util.ConcurrentList)8 List (java.util.List)7 HttpClient (org.apache.http.client.HttpClient)7 Client (j.service.Client)5 JUtilString (j.util.JUtilString)5 RemoteException (java.rmi.RemoteException)4 JHttpContext (j.http.JHttpContext)3 ServiceBase (j.service.server.ServiceBase)3 JUtilList (j.util.JUtilList)3 Map (java.util.Map)3 HashMap (java.util.HashMap)2 CachedMap (j.cache.CachedMap)1 JObject (j.common.JObject)1 JUtilSorter (j.util.JUtilSorter)1 Iterator (java.util.Iterator)1 Properties (java.util.Properties)1 Context (javax.naming.Context)1 InitialContext (javax.naming.InitialContext)1