/** * <summary>Calculate Java hash code for Guid object.</summary> * * <param name="val">Guid object to calculate Java hash code for.</param> * <returns>Java hash code for passed Guid object.</returns> */ private static int HashCodeForGuid(Guid val) { var bytes = U.ToBytes((Guid)val); int hash = 0; Dbg.Assert(bytes.Length == 16, "Expect UUID bytes representation has 16 bytes"); for (int i = 0; i < 16; i += 4) { hash ^= U.BytesToInt32(bytes, i); } return(hash); }
/** * <summary> * Stops all currently open clients.</summary> * * <param name="wait">If <c>true</c> then each client will wait to finish all ongoing requests before</param> * closing (however, no new requests will be accepted). If <c>false</c>, clients will be * closed immediately and all ongoing requests will be failed. */ public static void StopAll(bool wait) { ICollection <GridClientImpl> clients; lock (openClients) { clients = new List <GridClientImpl>(openClients.Values); openClients.Clear(); } var closes = new List <IGridClientFuture>(); foreach (GridClientImpl client in clients) { var c = client; // Use local variable in closure instead of iterator. closes.Add(U.Async(() => StopSilent(c, wait))); } foreach (var fut in closes) { fut.WaitDone(); } }
/** * <summary> * Stops client silently.</summary> * * <param name="client">Client to stop.</param> * <param name="waitCompletion">If <c>true</c> will wait for all pending requests to be proceeded.</param> */ private static void StopSilent(GridClientImpl client, bool waitCompletion) { U.DoSilent <Exception>(() => client.stop(waitCompletion), e => Dbg.WriteLine("Client stop process failed (exception ignored) [client=" + client + ", e=" + e.Message + "]")); }
/** * <summary> * Silent connection close.</summary> * * <param name="conn">Connection to close.</param> * <param name="waitCompletion">If <c>true</c> will wait for all pending requests to be proceeded.</param> */ private static void closeSilent(C conn, bool waitCompletion) { U.DoSilent <Exception>(() => conn.Close(waitCompletion), e => Dbg.WriteLine("Failed to close connection [conn=" + conn + ", e=" + e.Message + "]")); }