/// <summary>
        /// Loads the priority order of currencies, used to determine the base currency of the market convention pair
        /// for pairs that aren't explicitly configured.
        /// </summary>
        /// <returns> a map of currency to order </returns>
        internal static ImmutableMap <Currency, int> loadOrdering()
        {
            try
            {
                IniFile     ini     = ResourceConfig.combinedIniFile(ResourceConfig.orderedResources(CURRENCY_DATA_INI));
                PropertySet section = ini.section("marketConventionPriority");
                string      list    = section.value("ordering");
                // The currency ordering is defined as a comma-separated list
//JAVA TO C# CONVERTER TODO TASK: Most Java stream collectors are not converted by Java to C# Converter:
                IList <Currency> currencies = java.util.list.Split(",", true).Select(string.Trim).Select(Currency.of).collect(toImmutableList());

                ImmutableMap.Builder <Currency, int> orderBuilder = ImmutableMap.builder();

                for (int i = 0; i < currencies.Count; i++)
                {
                    orderBuilder.put(currencies[i], i + 1);
                }
                return(orderBuilder.build());
            }
            catch (Exception ex)
            {
                // logging used because this is loaded in a static variable
                log.severe(Throwables.getStackTraceAsString(ex));
                // return an empty instance to avoid ExceptionInInitializerError
                return(ImmutableMap.of());
            }
        }
 //-------------------------------------------------------------------------
 /// <summary>
 /// Loads the available currencies.
 /// </summary>
 /// <param name="loadHistoric">  whether to load the historic or active currencies </param>
 /// <returns> the map of known currencies </returns>
 internal static ImmutableMap <string, Currency> loadCurrencies(bool loadHistoric)
 {
     try
     {
         IniFile ini = ResourceConfig.combinedIniFile(ResourceConfig.orderedResources(CURRENCY_INI));
         return(parseCurrencies(ini, loadHistoric));
     }
     catch (Exception ex)
     {
         // logging used because this is loaded in a static variable
         log.severe(Throwables.getStackTraceAsString(ex));
         // return an empty instance to avoid ExceptionInInitializerError
         return(ImmutableMap.of());
     }
 }
 //-------------------------------------------------------------------------
 /// <summary>
 /// Loads the available currency pairs.
 /// </summary>
 /// <returns> the map of known currency pairs, where the value is the number of digits in the rate </returns>
 internal static ImmutableMap <CurrencyPair, int> loadPairs()
 {
     try
     {
         IniFile ini = ResourceConfig.combinedIniFile(ResourceConfig.orderedResources(PAIR_INI));
         return(parsePairs(ini));
     }
     catch (Exception ex)
     {
         // logging used because this is loaded in a static variable
         log.severe(Throwables.getStackTraceAsString(ex));
         // return an empty instance to avoid ExceptionInInitializerError
         return(ImmutableMap.of());
     }
 }
        /// <summary>
        /// Obtains a failure from a reason, exception and message.
        /// <para>
        /// The message is produced using a template that contains zero to many "{}" placeholders.
        /// Each placeholder is replaced by the next available argument.
        /// If there are too few arguments, then the message will be left with placeholders.
        /// If there are too many arguments, then the excess arguments are appended to the
        /// end of the message. No attempt is made to format the arguments.
        /// See <seealso cref="Messages#formatWithAttributes(String, Object...)"/> for more details.
        ///
        /// </para>
        /// </summary>
        /// <param name="reason">  the reason </param>
        /// <param name="cause">  the cause </param>
        /// <param name="message">  a message explaining the failure, not empty, uses "{}" for inserting {@code messageArgs} </param>
        /// <param name="messageArgs">  the arguments for the message </param>
        /// <returns> the failure </returns>
        public static FailureItem of(FailureReason reason, Exception cause, string message, params object[] messageArgs)
        {
            ArgChecker.notNull(reason, "reason");
            ArgChecker.notNull(cause, "cause");
            Pair <string, IDictionary <string, string> > msg = Messages.formatWithAttributes(message, messageArgs);
            string      stackTrace   = Throwables.getStackTraceAsString(cause).replace(Environment.NewLine, "\n");
            FailureItem @base        = new FailureItem(reason, msg.First, msg.Second, stackTrace, cause.GetType());
            string      causeMessage = cause.Message;

            if ([email protected](EXCEPTION_MESSAGE_ATTRIBUTE) && !Strings.isNullOrEmpty(causeMessage))
            {
                return(@base.withAttribute(EXCEPTION_MESSAGE_ATTRIBUTE, causeMessage));
            }
            return(@base);
        }
Пример #5
0
 private void FenceOldActive(byte[] data)
 {
     lock (this)
     {
         HAServiceTarget target = DataToTarget(data);
         try
         {
             DoFence(target);
         }
         catch (Exception t)
         {
             RecordActiveAttempt(new ZKFailoverController.ActiveAttemptRecord(false, "Unable to fence old active: "
                                                                              + StringUtils.StringifyException(t)));
             Throwables.Propagate(t);
         }
     }
 }
Пример #6
0
 /// <summary>
 /// Propagates {@code throwable} as-is if possible, or by wrapping in a {@code RuntimeException} if not.
 /// <ul>
 ///   <li>If {@code throwable} is an {@code InvocationTargetException} the cause is extracted and processed recursively.</li>
 ///   <li>If {@code throwable} is an {@code Error} or {@code RuntimeException} it is propagated as-is.</li>
 ///   <li>If {@code throwable} is an {@code IOException} it is wrapped in {@code UncheckedIOException} and thrown.</li>
 ///   <li>If {@code throwable} is an {@code ReflectiveOperationException} it is wrapped in
 ///     {@code UncheckedReflectiveOperationException} and thrown.</li>
 ///   <li>Otherwise {@code throwable} is wrapped in a {@code RuntimeException} and thrown.</li>
 /// </ul>
 /// This method always throws an exception. The return type is a convenience to satisfy the type system
 /// when the enclosing method returns a value. For example:
 /// <pre>
 ///   T foo() {
 ///     try {
 ///       return methodWithCheckedException();
 ///     } catch (Exception e) {
 ///       throw Unchecked.propagate(e);
 ///     }
 ///   }
 /// </pre>
 /// </summary>
 /// <param name="throwable"> the {@code Throwable} to propagate </param>
 /// <returns> nothing; this method always throws an exception </returns>
 public static Exception propagate(Exception throwable)
 {
     if (throwable is InvocationTargetException)
     {
         throw propagate(((InvocationTargetException)throwable).InnerException);
     }
     else if (throwable is IOException)
     {
         throw new UncheckedIOException((IOException)throwable);
     }
     else if (throwable is ReflectiveOperationException)
     {
         throw new UncheckedReflectiveOperationException((ReflectiveOperationException)throwable);
     }
     else
     {
         Throwables.throwIfUnchecked(throwable);
         throw new Exception(throwable);
     }
 }
Пример #7
0
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();
        throwable = (Throwables)target;

        if (GUILayout.Button("Save Nade equip location."))
        {
            Transform weaponT   = throwable.transform;
            Vector3   weaponPos = weaponT.localPosition;
            Vector3   weaponRot = weaponT.localEulerAngles;
            throwable.throwablesettings.equipPosition = weaponPos;
            throwable.throwablesettings.equipRotation = weaponRot;
        }

        if (GUILayout.Button("Save Nade unequip location."))
        {
            Transform weaponT   = throwable.transform;
            Vector3   weaponPos = weaponT.localPosition;
            Vector3   weaponRot = weaponT.localEulerAngles;
            throwable.throwablesettings.unequipPosition = weaponPos;
            throwable.throwablesettings.unequipRotation = weaponRot;
        }

        EditorGUILayout.LabelField("Debug Positioning");

        if (GUILayout.Button("Move Nade to equip location"))
        {
            Transform weaponT = throwable.transform;
            weaponT.localPosition = throwable.throwablesettings.equipPosition;
            Quaternion eulerAngles = Quaternion.Euler(throwable.throwablesettings.equipRotation);
            weaponT.localRotation = eulerAngles;
        }

        if (GUILayout.Button("Move Made to unequip location"))
        {
            Transform weaponT = throwable.transform;
            weaponT.localPosition = throwable.throwablesettings.unequipPosition;
            Quaternion eulerAngles = Quaternion.Euler(throwable.throwablesettings.unequipRotation);
            weaponT.localRotation = eulerAngles;
        }
    }
	  //-------------------------------------------------------------------------
	  /// <summary>
	  /// Obtains a combined extended enum instance.
	  /// <para>
	  /// Calling this method loads configuration files to determine which extended enums to combine.
	  /// The configuration file has the same simple name as the specified type and is a
	  /// <seealso cref="IniFile INI file"/> with the suffix '.ini'.
	  /// 
	  /// </para>
	  /// </summary>
	  /// @param <R>  the type of the enum </param>
	  /// <param name="type">  the type to load </param>
	  /// <returns> the extended enum </returns>
	  public static CombinedExtendedEnum<R> of<R>(Type<R> type) where R : Named
	  {
		try
		{
		  // load all matching files
		  string name = type.Name + ".ini";
		  IniFile config = ResourceConfig.combinedIniFile(name);
		  // parse files
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: com.google.common.collect.ImmutableList<ExtendedEnum<? extends R>> children = parseChildren(config, type);
		  ImmutableList<ExtendedEnum<R>> children = parseChildren(config, type);
		  log.fine(() => "Loaded combined extended enum: " + name + ", providers: " + children);
		  return new CombinedExtendedEnum<R>(type, children);

		}
		catch (Exception ex)
		{
		  // logging used because this is loaded in a static variable
		  log.severe("Failed to load CombinedExtendedEnum for " + type + ": " + Throwables.getStackTraceAsString(ex));
		  // return an empty instance to avoid ExceptionInInitializerError
		  return new CombinedExtendedEnum<R>(type, ImmutableList.of());
		}
	  }
            //-------------------------------------------------------------------------
            internal Loader()
            {
                ImmutableMap <string, FloatingRateName>   names             = ImmutableMap.of();
                ImmutableMap <Currency, FloatingRateName> iborDefaults      = ImmutableMap.of();
                ImmutableMap <Currency, FloatingRateName> overnightDefaults = ImmutableMap.of();

                try
                {
                    IniFile ini = ResourceConfig.combinedIniFile(FLOATING_RATE_NAME_INI);
                    names             = parseIndices(ini);
                    iborDefaults      = parseIborDefaults(ini, names);
                    overnightDefaults = parseOvernightDefaults(ini, names);
                }
                catch (Exception ex)
                {
                    // logging used because this is loaded in a static variable
                    log.severe(Throwables.getStackTraceAsString(ex));
                    // return an empty instance to avoid ExceptionInInitializerError
                }
                this.names             = names;
                this.iborDefaults      = iborDefaults;
                this.overnightDefaults = overnightDefaults;
            }
Пример #10
0
        //-------------------------------------------------------------------------
        public virtual void failure()
        {
            System.ArgumentException ex   = new System.ArgumentException("failure");
            Result <string>          test = Result.failure(ex);

            assertEquals(test.Success, false);
            assertEquals(test.Failure, true);
            assertEquals(test.getValueOrElse("blue"), "blue");
            assertEquals(test.getValueOrElseApply(f => "blue"), "blue");
//JAVA TO C# CONVERTER TODO TASK: Method reference arbitrary object instance method syntax is not converted by Java to C# Converter:
            assertEquals(test.getValueOrElseApply(Failure::getMessage), "failure");
            assertThrowsIllegalArg(() => test.getValueOrElse(null));
            assertThrowsIllegalArg(() => test.getValueOrElseApply(null));
            assertEquals(test.Failure.Reason, ERROR);
            assertEquals(test.Failure.Message, "failure");
            assertEquals(test.Failure.Items.size(), 1);
            FailureItem item = test.Failure.Items.GetEnumerator().next();

            assertEquals(item.Reason, ERROR);
            assertEquals(item.Message, "failure");
            assertEquals(item.CauseType.get(), ex.GetType());
            assertEquals(item.StackTrace, Throwables.getStackTraceAsString(ex).replace(Environment.NewLine, "\n"));
        }
 //-------------------------------------------------------------------------
 /// <summary>
 /// Obtains an extended enum instance.
 /// <para>
 /// Calling this method loads configuration files to determine the extended enum values.
 /// The configuration file has the same simple name as the specified type and is a
 /// <seealso cref="IniFile INI file"/> with the suffix '.ini'.
 /// See class-level documentation for more information.
 ///
 /// </para>
 /// </summary>
 /// @param <R>  the type of the enum </param>
 /// <param name="type">  the type to load </param>
 /// <returns> the extended enum </returns>
 public static ExtendedEnum <R> of <R>(Type <R> type) where R : Named
 {
     try
     {
         // load all matching files
         string  name   = type.Name + ".ini";
         IniFile config = ResourceConfig.combinedIniFile(name);
         // parse files
         ImmutableList <NamedLookup <R> > lookups        = parseProviders(config, type);
         ImmutableMap <string, string>    alternateNames = parseAlternates(config);
         ImmutableMap <string, ImmutableMap <string, string> > externalNames = parseExternals(config);
         ImmutableList <Pair <Pattern, string> > lenientRegex = parseLenientPatterns(config);
         log.fine(() => "Loaded extended enum: " + name + ", providers: " + lookups);
         return(new ExtendedEnum <R>(type, lookups, alternateNames, externalNames, lenientRegex));
     }
     catch (Exception ex)
     {
         // logging used because this is loaded in a static variable
         log.severe("Failed to load ExtendedEnum for " + type + ": " + Throwables.getStackTraceAsString(ex));
         // return an empty instance to avoid ExceptionInInitializerError
         return(new ExtendedEnum <R>(type, ImmutableList.of(), ImmutableMap.of(), ImmutableMap.of(), ImmutableList.of()));
     }
 }
Пример #12
0
    public Throwables GetThrowable(string throwableName)
    {
        Throwables throwable = Array.Find(throwables, x => x.MyTitle == throwableName);

        return(throwable);
    }
Пример #13
0
        /// <exception cref="System.IO.IOException"/>
        private FSEditLogOp NextOpImpl(bool skipBrokenEdits)
        {
            FSEditLogOp op = null;

            switch (state)
            {
            case EditLogFileInputStream.State.Uninit:
            {
                try
                {
                    Init(true);
                }
                catch (Exception e)
                {
                    Log.Error("caught exception initializing " + this, e);
                    if (skipBrokenEdits)
                    {
                        return(null);
                    }
                    Throwables.PropagateIfPossible <IOException>(e);
                }
                Preconditions.CheckState(state != EditLogFileInputStream.State.Uninit);
                return(NextOpImpl(skipBrokenEdits));
            }

            case EditLogFileInputStream.State.Open:
            {
                op = reader.ReadOp(skipBrokenEdits);
                if ((op != null) && (op.HasTransactionId()))
                {
                    long txId = op.GetTransactionId();
                    if ((txId >= lastTxId) && (lastTxId != HdfsConstants.InvalidTxid))
                    {
                        //
                        // Sometimes, the NameNode crashes while it's writing to the
                        // edit log.  In that case, you can end up with an unfinalized edit log
                        // which has some garbage at the end.
                        // JournalManager#recoverUnfinalizedSegments will finalize these
                        // unfinished edit logs, giving them a defined final transaction
                        // ID.  Then they will be renamed, so that any subsequent
                        // readers will have this information.
                        //
                        // Since there may be garbage at the end of these "cleaned up"
                        // logs, we want to be sure to skip it here if we've read everything
                        // we were supposed to read out of the stream.
                        // So we force an EOF on all subsequent reads.
                        //
                        long skipAmt = log.Length() - tracker.GetPos();
                        if (skipAmt > 0)
                        {
                            if (Log.IsDebugEnabled())
                            {
                                Log.Debug("skipping " + skipAmt + " bytes at the end " + "of edit log  '" + GetName
                                              () + "': reached txid " + txId + " out of " + lastTxId);
                            }
                            tracker.ClearLimit();
                            IOUtils.SkipFully(tracker, skipAmt);
                        }
                    }
                }
                break;
            }

            case EditLogFileInputStream.State.Closed:
            {
                break;
            }
            }
            // return null
            return(op);
        }