@Override public MutableFudgeMsg buildMessage(FudgeSerializationContext context, ZonedDateTime object) { final MutableFudgeMsg msg = context.newMessage(); msg.add(ODT_FIELD_NAME, object.toOffsetDateTime()); msg.add(ZONE_FIELD_NAME, object.getZone().getID()); return msg; }
@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; }
protected void encodeMarketDataAliases( final FudgeSerializer serializer, final MutableFudgeMsg msg, final Map<ValueSpecification, Collection<ValueSpecification>> marketDataEntries) { final MutableFudgeMsg msgRequirements = msg.addSubMessage(MARKET_DATA_REQUIREMENTS_FIELD, null); final MutableFudgeMsg msgAliases = msg.addSubMessage(MARKET_DATA_ALIASES_FIELD, null); for (final Map.Entry<ValueSpecification, Collection<ValueSpecification>> requirement : marketDataEntries.entrySet()) { final ValueSpecification marketData = requirement.getKey(); serializer.addToMessage(msgRequirements, null, null, marketData); if (requirement.getValue().size() == 1) { final ValueSpecification alias = requirement.getValue().iterator().next(); if (alias.equals(marketData)) { msgAliases.add(null, null, IndicatorType.INSTANCE); } else { serializer.addToMessage(msgAliases, null, null, alias); } } else { final MutableFudgeMsg aliases = msgAliases.addSubMessage(null, null); aliases.add(null, 0, "list"); for (ValueSpecification alias : requirement.getValue()) { if (alias.equals(marketData)) { msgAliases.add(null, null, IndicatorType.INSTANCE); } else { serializer.addToMessage(aliases, null, null, alias); } } } } }
@Override protected void buildMessage( final FudgeSerializer serializer, final MutableFudgeMsg message, final IndexON object) { message.add(CURRENCY_FIELD, object.getCurrency().getCode()); message.add(NAME_FIELD, object.getName()); message.add(DAY_COUNT_FIELD, object.getDayCount().getConventionName()); message.add(PUBLICATION_LAG_FIELD, object.getPublicationLag()); }
@Override protected void buildMessage( final FudgeSerializer serializer, final MutableFudgeMsg message, final MoneynessPiecewiseSABRSurfaceFitter object) { message.add(TIME_FIELD_NAME, null, object.useLogTime()); message.add(SPACE_FIELD_NAME, null, object.useIntegratedVariance()); message.add(LAMBDA_FIELD_NAME, null, object.getLambda()); }
/** * Adds an object to the specified message if non-null. * * @param msg the msg to populate, not null * @param fieldName the field name, may be null * @param value the value, null ignored */ protected static void addToMessage( final MutableFudgeMsg msg, final String fieldName, final Object value) { if (value != null) { if (value instanceof String) { msg.add(fieldName, null, FudgeWireType.STRING, value); } else if (value instanceof Enum<?>) { msg.add(fieldName, null, FudgeWireType.STRING, ((Enum<?>) value).name()); } else { msg.add(fieldName, null, value); } } }
private static void encodeTrades( final MutableFudgeMsg message, final FudgeSerializer serializer, final Collection<Trade> trades) { if (!trades.isEmpty()) { final MutableFudgeMsg msg = serializer.newMessage(); for (Trade trade : trades) { msg.add(null, null, TradeBuilder.buildMessageImpl(serializer, trade)); } message.add(FIELD_TRADES, msg); } }
@Override protected void buildMessage( final FudgeSerializer serializer, final MutableFudgeMsg message, final CurveBuildingBlock object) { final Map<String, Pair<Integer, Integer>> data = object.getData(); for (final Map.Entry<String, Pair<Integer, Integer>> entry : data.entrySet()) { message.add(CURVE_NAME_FIELD, entry.getKey()); message.add(START_INDEX_FIELD, entry.getValue().getFirst()); message.add(NUMBER_FIELD, entry.getValue().getSecond()); } }
@Override protected void buildMessage( final FudgeSerializer serializer, final MutableFudgeMsg message, final StringLabelledMatrix1D object) { final MutableFudgeMsg msg = serializer.newMessage(); final String[] keys = object.getKeys(); final double[] values = object.getValues(); for (int i = 0; i < object.size(); i++) { msg.add(KEY_ORDINAL, keys[i]); msg.add(VALUE_ORDINAL, values[i]); } message.add(MATRIX_FIELD_NAME, msg); }
/** * Adds an object to the specified message if non-null. This handles object hierarchies. * * @param <T> the declared type * @param serializer the serializer, not null * @param msg the msg to populate, not null * @param fieldName the field name, may be null * @param value the value, null ignored * @param declaredType the declared Java type of the field, not null */ protected static <T> void addToMessage( final FudgeSerializer serializer, final MutableFudgeMsg msg, final String fieldName, final T value, final Class<T> declaredType) { if (value != null) { MutableFudgeMsg subMsg = serializer.newMessage(); FudgeSerializer.addClassHeader(subMsg, value.getClass(), declaredType); FudgeMsg builtMsg = serializer.objectToFudgeMsg(value); for (FudgeField field : builtMsg) { subMsg.add(field); } msg.add(fieldName, null, subMsg); } }
public MutableFudgeMsg toFudgeMsg(final FudgeSerializer context) { final MutableFudgeMsg msg = context.newMessage(); for (Map.Entry<String, Entry> entry : _data.entrySet()) { msg.add(entry.getKey(), entry.getValue().toFudgeMsg(context)); } return msg; }
/** * Builds the message by serializing the specified object. * * <p>This method creates a new message and uses {@link #buildMessage(FudgeSerializer, * MutableFudgeMsg, Object)} to populate it. * * @param serializer the serializer, not null * @param object the object being serialized * @return the created object, not null */ @Override public final MutableFudgeMsg buildMessage(FudgeSerializer serializer, T object) { final MutableFudgeMsg message = serializer.newMessage(); message.add(null, 0, object.getClass().getName()); buildMessage(serializer, message, object); return message; }
@Override protected void buildMessage( final FudgeSerializer serializer, final MutableFudgeMsg message, final DoubleMatrix1D object) { message.add(DATA_FIELD_NAME, null, object.getData()); }
@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); } }
// ------------------------------------------------------------------------- public MutableFudgeMsg toFudgeMsg(final FudgeMsgFactory factory, final MutableFudgeMsg message) { ArgumentChecker.notNull(factory, "factory"); ArgumentChecker.notNull(message, "message"); for (IdentifierWithDates identifier : getIdentifiers()) { message.add(ID_FUDGE_FIELD_NAME, identifier.toFudgeMsg(factory)); } return message; }
public void toFudgeMsg( final org.fudgemsg.mapping.FudgeSerializationContext fudgeContext, final org.fudgemsg.MutableFudgeMsg msg) { super.toFudgeMsg(fudgeContext, msg); if (_chooseDate != null) { fudgeContext.addToMessage(msg, CHOOSE_DATE_KEY, null, _chooseDate); } msg.add(UNDERLYING_STRIKE_KEY, null, _underlyingStrike); if (_underlyingExpiry != null) { final org.fudgemsg.MutableFudgeMsg fudge1 = org.fudgemsg.mapping.FudgeSerializationContext.addClassHeader( fudgeContext.newMessage(), _underlyingExpiry.getClass(), com.opengamma.util.time.Expiry.class); _underlyingExpiry.toFudgeMsg(fudgeContext, fudge1); msg.add(UNDERLYING_EXPIRY_KEY, null, fudge1); } }
/*package*/ static MutableFudgeMsg multiplyField( MutableFudgeMsg msg, String field, double multiplier) { Double value = msg.getDouble(field); if (value != null) { double newValue = value * multiplier; msg.remove(field); msg.add(field, newValue); } return msg; }
@Override protected void buildMessage( final FudgeSerializer serializer, final MutableFudgeMsg message, final DoubleLabelledMatrix1D object) { final MutableFudgeMsg msg = serializer.newMessage(); final Double[] keys = object.getKeys(); final Object[] labels = object.getLabels(); final double[] values = object.getValues(); for (int i = 0; i < object.size(); i++) { msg.add(LABEL_TYPE_ORDINAL, labels[i].getClass().getName()); msg.add(KEY_ORDINAL, keys[i]); serializer.addToMessage(msg, null, LABEL_ORDINAL, labels[i]); msg.add(VALUE_ORDINAL, values[i]); } message.add(MATRIX_FIELD_NAME, msg); }
/** * Adds an object to the specified message if non-null. * * @param <T> the declared type * @param msg the msg to populate, not null * @param fieldName the field name, may be null * @param objectMsg the object converted to a message, null ignored * @param value the value, null ignored * @param declaredType the declared Java type of the field, not null */ protected static <T> void addToMessage( final MutableFudgeMsg msg, final String fieldName, final FudgeMsg objectMsg, final T value, final Class<T> declaredType) { if (objectMsg != null) { FudgeSerializer.addClassHeader((MutableFudgeMsg) objectMsg, value.getClass(), declaredType); msg.add(fieldName, null, objectMsg); } }
@Override public FudgeMsg next() { MutableFudgeMsg currentMsg = s_fudgeContext.newMessage(); int size = getMessageSize(); for (int i = 0; i < size; i++) { String currentRow = StringUtils.trimToNull(_currentRow[i]); if (currentRow != null) { currentMsg.add(_header[i], currentRow); } } return currentMsg; }
@Override protected void buildMessage( final FudgeSerializer serializer, final MutableFudgeMsg message, final IborIndex object) { message.add(SPOT_LAG_FIELD, object.getSpotLag()); message.add(DAY_COUNT_FIELD, object.getDayCount().getConventionName()); message.add( BUSINESS_DAY_CONVENTION_FIELD, object.getBusinessDayConvention().getConventionName()); message.add(EOM_FIELD, object.isEndOfMonth()); message.add(TENOR_FIELD, object.getTenor().toString()); message.add(NAME_FIELD, object.getName()); message.add(CURRENCY_FIELD, object.getCurrency().getCode()); }
public void testBasicSnapshotOperation() { final FireHose fireHose = new FireHose(); final FireHoseLiveDataServer liveDataServer = new FireHoseLiveDataServer(ExternalSchemes.SURF, fireHose); liveDataServer.start(); try { final MutableFudgeMsg msg = FudgeContext.GLOBAL_DEFAULT.newMessage(); msg.add("X", "Y"); fireHose.storeValue("Foo", msg); assertEquals(liveDataServer.doSnapshot("Foo").getString("X"), "Y"); } finally { liveDataServer.stop(); } }
@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()); } }
public void toFudgeMsg( final org.fudgemsg.mapping.FudgeSerializer serializer, final org.fudgemsg.MutableFudgeMsg msg) { if (_responses != null) { for (com.opengamma.livedata.msg.EntitlementResponse fudge1 : _responses) { final org.fudgemsg.MutableFudgeMsg fudge2 = org.fudgemsg.mapping.FudgeSerializer.addClassHeader( serializer.newMessage(), fudge1.getClass(), com.opengamma.livedata.msg.EntitlementResponse.class); fudge1.toFudgeMsg(serializer, fudge2); msg.add(RESPONSES_KEY, null, fudge2); } } }
@Override public MutableFudgeMsg buildMessage( FudgeSerializationContext context, FixedIncomeStripWithSecurity object) { MutableFudgeMsg message = context.newMessage(); context.addToMessage(message, "type", null, object.getInstrumentType()); context.addToMessage(message, "tenor", null, object.getTenor()); context.addToMessage(message, "resolvedTenor", null, object.getResolvedTenor()); ZonedDateTimeBuilder zonedDateTimeBuilder = new ZonedDateTimeBuilder(); MutableFudgeMsg subMessage = zonedDateTimeBuilder.buildMessage(context, object.getMaturity()); context.addToMessage(message, "maturity", null, subMessage); context.addToMessage(message, "identifier", null, object.getSecurityIdentifier()); context.addToMessageWithClassHeaders(message, "security", null, object.getSecurity()); if (object.getInstrumentType() == StripInstrumentType.FUTURE) { message.add("numFutures", object.getNumberOfFuturesAfterTenor()); } return message; }
public void testBasicSubscription() throws InterruptedException { final FireHose fireHose = new FireHose(); final FireHoseLiveDataServer liveDataServer = new FireHoseLiveDataServer(ExternalSchemes.SURF, fireHose); final BlockingQueue<LiveDataValueUpdateBean> updates = connect(liveDataServer, Integer.MAX_VALUE); liveDataServer.start(); try { final MutableFudgeMsg msg = FudgeContext.GLOBAL_DEFAULT.newMessage(); msg.add("X", "Y"); fireHose.storeValue("Foo", msg); assertNotNull(liveDataServer.subscribe("Foo")); final LiveDataValueUpdateBean update = updates.poll(Timeout.standardTimeoutMillis(), TimeUnit.MILLISECONDS); assertNotNull(update); assertEquals(update.getFields().getString("X"), "Y"); } finally { liveDataServer.stop(); } }
protected static MutableFudgeMsg buildMessageImpl( final FudgeSerializer serializer, final Position position) { final MutableFudgeMsg message = serializer.newMessage(); if (position.getUniqueId() != null) { serializer.addToMessage(message, FIELD_UNIQUE_ID, null, position.getUniqueId()); } if (position.getQuantity() != null) { message.add(FIELD_QUANTITY, null, position.getQuantity()); } if (position.getSecurityLink().getExternalId().size() > 0) { serializer.addToMessage( message, FIELD_SECURITYKEY, null, position.getSecurityLink().getExternalId()); } if (position.getSecurityLink().getObjectId() != null) { serializer.addToMessage( message, FIELD_SECURITYID, null, position.getSecurityLink().getObjectId()); } encodeTrades(message, serializer, position.getTrades()); return message; }
@Override public MutableFudgeMsg buildMessage( final FudgeSerializer serializer, final BloombergEquityFutureOptionVolatilitySurfaceInstrumentProvider object) { final MutableFudgeMsg message = serializer.newMessage(); FudgeSerializer.addClassHeader( message, BloombergEquityFutureOptionVolatilitySurfaceInstrumentProvider.class); message.add(PREFIX_FIELD_NAME, object.getFutureOptionPrefix()); message.add(POSTFIX_FIELD_NAME, object.getPostfix()); message.add(DATA_FIELD_NAME, object.getDataFieldName()); message.add(CALL_FIELD_NAME, object.useCallAboveStrike()); message.add(EXCHANGE_ID_FIELD_NAME, object.getExchangeIdName()); message.add(TICKER_SCHEME_NAME, object.getSchemeName()); return message; }
public void toFudgeMsg( final org.fudgemsg.mapping.FudgeSerializationContext fudgeContext, final org.fudgemsg.MutableFudgeMsg msg) { super.toFudgeMsg(fudgeContext, msg); if (_result != null) { fudgeContext.addToMessageWithClassHeaders( msg, RESULT_KEY, null, _result, com.opengamma.engine.view.calcnode.CalculationJobResult.class); } if (_ready != null) { final org.fudgemsg.MutableFudgeMsg fudge1 = org.fudgemsg.mapping.FudgeSerializationContext.addClassHeader( fudgeContext.newMessage(), _ready.getClass(), com.opengamma.engine.view.calcnode.msg.Ready.class); _ready.toFudgeMsg(fudgeContext, fudge1); msg.add(READY_KEY, null, fudge1); } }
@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()); }