Beispiel #1
0
        /**
         * <summary>
         * Starts a client with given configuration. Starting client will be assigned a randomly generated
         * Guid which can be obtained by <see ctype="GridClient#id()"/> method.</summary>
         *
         * <param name="cfg">Client configuration.</param>
         * <returns>Started client.</returns>
         * <exception cref="GridClientException">If client could not be created.</exception>
         */
        public static IGridClient Start(IGridClientConfiguration cfg)
        {
            Guid clientId = Guid.NewGuid();

            GridClientImpl client = new GridClientImpl(clientId, cfg);

            try {
                lock (openClients) {
                    openClients.Add(clientId, client);
                }
            }
            // If such clientId already exists in the collection.
            catch (ArgumentException e) {
                StopSilent(client, false);

                throw new InvalidOperationException("System generates duplicated guid for client: " + clientId, e);
            }

            return client;
        }
Beispiel #2
0
 /**
  * <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 + "]"));
 }