public bool Login(string userName, string jobClassPriority)
        {
            lock(lockObj)
            {
                this.userName = userName;
                this.jobClassPriority = jobClassPriority;
                try
                {
                    SyncNodeServerLoginRequestMessage msg = new SyncNodeServerLoginRequestMessage();

                    System.Net.IPAddress[] ipaddr = System.Net.Dns.GetHostAddresses(System.Net.Dns.GetHostName());
                    for (int i = 0; i < ipaddr.Length; ++i)
                    {
                        msg.nodeIP = ipaddr[i].ToString();
                        if (System.Net.IPAddress.Parse(ipaddr[i].ToString()).AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
                        {
                            break;
                        }
                    }
                    msg.nodePCName = System.Environment.MachineName;
                    msg.nodeName = this.userName;
                    msg.priorityKeyData = this.jobClassPriority;// "EQT=FICC>TEST";
                    msg.totalWorkerCount = this.totalWorkerCount;// Environment.ProcessorCount;
                    msg.benchmarkRunningTimeMS = this.benchmarkRunningTimeMS;
                    msg.lastProcBinaryVersion = DPSNodeSetting.Instance.LastProcBinaryVersion;
                    msg.lastNodeBinaryVersion = DPSNodeSetting.Instance.NodeVersion;
                    if (verbose)
                        Console.WriteLine(DateTime.Now.ToString("[HH:mm:ss.fff]")+"[N->S][Login] called.");
                    string ret = syncServerComm.Call(msg.GetJson());
                    if (verbose)
                        Console.WriteLine(DateTime.Now.ToString("[HH:mm:ss.fff]")+"[N->S][Login] finished.");
                    if (ret == null)
                        return false;
                    SyncNodeServerLoginResponseMessage retMsg = JsonConvert.DeserializeObject<SyncNodeServerLoginResponseMessage>(ret);

                    if (retMsg.returnCode == 0)
                    {
                        loggedin = true;
                        nodeKey = retMsg.nodeKey;
                        serverKey = retMsg.serverKey;
                        
                        
                        //login succeed. Open async queue between server and current node
                        asyncServerCommSender = AsyncMessageCommunicator.Instance.CreateCommunicator("DSDPS_ASYNC", "SERVER", "NODE", nodeKey, false, AsyncMessageProcessor);
                        asyncServerCommSender.Init();

                        //hb will be sent to server in 3 sec from hbmanager creation. 
                        hbManager = new NodeHeartbeatManager(nodeKey, OnServerUnreachable);

                        return true;
                    }
                    else
                        return false;
                }
                catch (Exception)
                {
                    return false;
                }
            }
        }
        public bool Login(){
            try
            {
                SyncClientServerLoginRequestMessage msg = new SyncClientServerLoginRequestMessage();

                System.Net.IPAddress[] ipaddr = System.Net.Dns.GetHostAddresses(System.Net.Dns.GetHostName());
                for (int i = 0; i < ipaddr.Length; ++i)
                {
                    msg.clientIP = ipaddr[i].ToString();
                    if (System.Net.IPAddress.Parse(ipaddr[i].ToString()).AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
                    {
                        break;
                    }
                }
                msg.clientPCName = System.Environment.MachineName;
                msg.clientName = "User";
                string ret = syncServerComm.Call(msg.GetJson());

                SyncClientServerLoginResponseMessage retMsg = JsonConvert.DeserializeObject<SyncClientServerLoginResponseMessage>(ret);

                if (retMsg.returnCode == 0)
                {
                    loggedIn = true;
                    clientKey = retMsg.clientKey;
                    asyncServerCommSender = AsyncMessageCommunicator.Instance.CreateCommunicator("DSDPS_ASYNC", "SERVER", "CLIENT", clientKey, false, ProcessAsyncServerMessage);
                    asyncServerCommSender.Init();
                    //hb will be sent to server in 3 sec from hbmanager creation. 
                    hbManager = new ClientHeartbeatManager(clientKey, OnServerUnreachable);
                    NotifyReady();
                    return true;
                }
                else
                    return false;
            }
            catch(Exception e)
            {
                return false;
            }
        }