Ejemplo n.º 1
0
        /// <summary>
        /// Checks if server at the given location is alive
        /// </summary>
        /// <param name="serverUrl">Server URL</param>
        /// <returns>True if the server is alive; false otherwise.</returns>
        public bool TryConnection(string serverUrl, bool tryRemove)
        {
            //Console.WriteLine("Trying connection " + serverUrl + ": " + tryRemove);
            TSMan.CheckFreeze();

            TSMan.CheckDelay();


            if (serverUrl.Equals(TSMan.URL))
            {
                //Console.WriteLine("Return false #2");

                return(true);
            }

            // Get the reference for the tuple space server
            ITSpaceServer server = (ITSpaceServer)Activator.GetObject(typeof(ITSpaceServer), serverUrl);


            // Ping server
            if (server == null)
            {
                return(false);
            }

            PingDelegate del         = new PingDelegate(server.Ping);
            IAsyncResult asyncResult = del.BeginInvoke(TSMan.URL, null, null);

            asyncResult.AsyncWaitHandle.WaitOne(5000, false);

            if (asyncResult.IsCompleted)
            {
                try
                {
                    del.EndInvoke(asyncResult);
                    //Console.WriteLine("Return true");

                    return(true);
                }
                catch (Exception)
                {
                    if (tryRemove)
                    {
                        TryRemoveFromView(serverUrl);
                    }
                    //Console.WriteLine("Return false #2");

                    return(false);
                }
            }
            if (tryRemove)
            {
                TryRemoveFromView(serverUrl);
            }

            //Console.WriteLine("Return false #3");


            return(false);
        }
Ejemplo n.º 2
0
        private void DoPing(string remotingEndpointUrl)
        {
            var remotingEndpoint = GetRemoteEndpoint(remotingEndpointUrl);

            PingDelegate pingDelegate = remotingEndpoint.Ping;
            var          asyncResult  = pingDelegate.BeginInvoke(null, null);

            pingDelegate.EndInvoke(asyncResult);
        }
Ejemplo n.º 3
0
 private void pingCallback(IAsyncResult ar)
 {
     try
     {
         PingDelegate aPingDelegate = (PingDelegate)ar.AsyncState;
         aPingDelegate.EndInvoke(ar);
     }
     catch
     { }
 }