コード例 #1
0
 public MutableFudgeMsg toFudgeMsg(final FudgeSerializer context) {
   final MutableFudgeMsg msg = context.newMessage();
   for (Map.Entry<ExternalIdBundle, HistoricalTimeSeries> data : _timeSeries.entrySet()) {
     context.addToMessageWithClassHeaders(msg, null, 1, data.getKey(), ExternalIdBundle.class);
     context.addToMessageWithClassHeaders(
         msg, null, 2, data.getValue(), HistoricalTimeSeries.class);
   }
   return msg;
 }
コード例 #2
0
 @Override
 protected void buildMessage(
     final FudgeSerializer serializer,
     final MutableFudgeMsg message,
     final InflationProviderDiscount object) {
   serializer.addToMessageWithClassHeaders(
       message, YIELD_CURVES_FIELD, null, object.getMulticurveProvider());
   final Map<IndexPrice, PriceIndexCurve> priceIndexCurves = object.getPriceIndexCurves();
   for (final Map.Entry<IndexPrice, PriceIndexCurve> entry : priceIndexCurves.entrySet()) {
     serializer.addToMessageWithClassHeaders(message, PRICE_INDEX_FIELD, null, entry.getKey());
     serializer.addToMessageWithClassHeaders(
         message, PRICE_INDEX_CURVE_FIELD, null, entry.getValue());
   }
 }
コード例 #3
0
 @Override
 protected void buildMessage(
     final FudgeSerializer serializer,
     final MutableFudgeMsg message,
     final CurveBuildingBlockBundle object) {
   final Map<String, Pair<CurveBuildingBlock, DoubleMatrix2D>> data = object.getData();
   for (final Map.Entry<String, Pair<CurveBuildingBlock, DoubleMatrix2D>> entry :
       data.entrySet()) {
     message.add(CURVE_NAME_FIELD, entry.getKey());
     serializer.addToMessageWithClassHeaders(
         message, BLOCK_FIELD, null, entry.getValue().getFirst());
     serializer.addToMessageWithClassHeaders(
         message, MATRIX_FIELD, null, entry.getValue().getSecond().getData());
   }
 }
コード例 #4
0
 @Override
 public MutableFudgeMsg buildMessage(FudgeSerializer serializer, CalculationJobItem object) {
   MutableFudgeMsg msg = serializer.newMessage();
   ComputationTargetSpecification computationTargetSpecification =
       object.getComputationTargetSpecification();
   if (computationTargetSpecification != null) {
     MutableFudgeMsg specMsg = serializer.objectToFudgeMsg(computationTargetSpecification);
     for (FudgeField fudgeField : specMsg.getAllFields()) {
       msg.add(fudgeField);
     }
   }
   String functionUniqueIdentifier = object.getFunctionUniqueIdentifier();
   if (functionUniqueIdentifier != null) {
     msg.add(FUNCTION_UNIQUE_ID_FIELD_NAME, functionUniqueIdentifier);
   }
   FunctionParameters functionParameters = object.getFunctionParameters();
   if (functionParameters != null) {
     serializer.addToMessageWithClassHeaders(
         msg, FUNCTION_PARAMETERS_FIELD_NAME, null, functionParameters);
   }
   long[] inputs = object.getInputIdentifiers();
   msg.add(INPUT_FIELD_NAME, inputs);
   for (ValueRequirement desiredValue : object.getDesiredValues()) {
     serializer.addToMessage(msg, DESIRED_VALUE_FIELD_NAME, null, desiredValue);
   }
   return msg;
 }
コード例 #5
0
 @Override
 protected void buildMessage(
     final FudgeSerializer serializer,
     final MutableFudgeMsg message,
     final YieldCurveBundle object) {
   serializer.addToMessageWithClassHeaders(
       message, FX_MATRIX_FIELD_NAME, null, object.getFxRates());
   for (final String curve : object.getAllNames()) {
     serializer.addToMessageWithClassHeaders(
         message, CURVES_FIELD_NAME, null, object.getCurve(curve));
     serializer.addToMessageWithClassHeaders(message, CURVES_NAME_FIELD_NAME, null, curve);
   }
   for (Map.Entry<String, Currency> ccyEntry : object.getCurrencyMap().entrySet()) {
     serializer.addToMessage(message, CURRENCY_CURVE_FIELD_NAME, null, ccyEntry.getKey());
     serializer.addToMessageWithClassHeaders(
         message, CURRENCY_FIELD_NAME, null, ccyEntry.getValue());
   }
 }
コード例 #6
0
 @Override
 protected void buildMessage(
     final FudgeSerializer serializer, final MutableFudgeMsg message, final FXMatrix object) {
   final Map<Currency, Integer> currencies = object.getCurrencies();
   for (final Map.Entry<Currency, Integer> entry : currencies.entrySet()) {
     message.add(CURRENCY_FIELD, entry.getKey().getCode());
     message.add(ORDER_FIELD, entry.getValue());
   }
   final double[][] rates = object.getRates();
   for (final double[] array : rates) {
     message.add(ENTRIES_FIELD, array.length);
     final MutableFudgeMsg msg = serializer.newMessage();
     serializer.addToMessageWithClassHeaders(msg, ROW_FIELD, null, array);
     message.add(FX_RATES_FIELD, msg);
   }
 }
コード例 #7
0
 @Override
 protected void buildMessage(
     final FudgeSerializer serializer,
     final MutableFudgeMsg message,
     final MulticurveProviderDiscount object) {
   final Map<Currency, YieldAndDiscountCurve> discountingCurves = object.getDiscountingCurves();
   for (final Map.Entry<Currency, YieldAndDiscountCurve> entry : discountingCurves.entrySet()) {
     message.add(CURRENCY_FIELD, entry.getKey().getCode());
     serializer.addToMessageWithClassHeaders(
         message, DISCOUNTING_CURVE_FIELD, null, entry.getValue());
   }
   final Map<IborIndex, YieldAndDiscountCurve> forwardIborCurves = object.getForwardIborCurves();
   for (final Map.Entry<IborIndex, YieldAndDiscountCurve> entry : forwardIborCurves.entrySet()) {
     serializer.addToMessageWithClassHeaders(message, INDEX_IBOR_FIELD, null, entry.getKey());
     serializer.addToMessageWithClassHeaders(message, INDEX_IBOR_CURVE, null, entry.getValue());
   }
   final Map<IndexON, YieldAndDiscountCurve> forwardONCurves = object.getForwardONCurves();
   for (final Map.Entry<IndexON, YieldAndDiscountCurve> entry : forwardONCurves.entrySet()) {
     serializer.addToMessageWithClassHeaders(message, INDEX_ON_FIELD, null, entry.getKey());
     serializer.addToMessageWithClassHeaders(
         message, OVERNIGHT_CURVE_FIELD, null, entry.getValue());
   }
   serializer.addToMessageWithClassHeaders(message, FX_MATRIX_FIELD, null, object.getFxRates());
 }
コード例 #8
0
  @Override
  public MutableFudgeMsg buildMessage(FudgeSerializer serializer, final T auto) {
    MutableFudgeMsg outerMsg = serializer.newMessage();
    outerMsg.add(
        null,
        FudgeSerializer.TYPES_HEADER_ORDINAL,
        FudgeWireType.STRING,
        AutoFudgable.class.getName());
    final K inner = auto.object();
    assertValid(inner.getClass());
    try {
      MutableFudgeMsg msg = outerMsg.addSubMessage("inner", null);
      // save the internal class name
      msg.add(
          null,
          FudgeSerializer.TYPES_HEADER_ORDINAL,
          FudgeWireType.STRING,
          inner.getClass().getName());

      // save the ctor parameters
      List<Object> parameters =
          AccessController.doPrivileged(
              new PrivilegedAction<List<Object>>() {
                @Override
                public List<Object> run() {
                  try {
                    final Constructor<?>[] ctors = inner.getClass().getDeclaredConstructors();
                    // We require that inner classes got only one ctor (anonymous inner classes will
                    // do)
                    // in order to avoid disambiguity
                    if (ctors.length == 1) {
                      final Constructor<?> ctor = ctors[0];
                      // types of parameters of ctor
                      final Class<?>[] parameterTypes = ctor.getParameterTypes();
                      // all declared parameters of the inner class
                      final Field[] fs = inner.getClass().getDeclaredFields();
                      // extracting copiler synthetized fields of inner class
                      // first are the not sinthetized fields (regular ones) we need to skip
                      // then there are compiler synthetized fields with corresponds to ctor
                      // parameters
                      // the last field is the reference to enclosing object so we need to skipp it
                      // as well
                      final Field[] paramFields =
                          Arrays.copyOfRange(fs, fs.length - parameterTypes.length, fs.length - 1);
                      final List<Object> parameters = newArrayList();
                      for (Field paramField : paramFields) {
                        paramField.setAccessible(true);
                        parameters.add(paramField.get(inner));
                      }
                      return parameters;
                    }
                  } catch (IllegalAccessException e) {
                    // Ignore
                  }
                  return null;
                }
              });

      for (Object parameter : parameters) {
        // save the ctor parameter
        serializer.addToMessageWithClassHeaders(msg, null, 1, parameter);
      }
      return outerMsg;

    } catch (RuntimeException ex) {
      throw new FudgeRuntimeException("Unable to serialize: " + inner.getClass().getName(), ex);
    }
  }