net.openhft.chronicle.bytes.BytesIn Java Examples

The following examples show how to use net.openhft.chronicle.bytes.BytesIn. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OrderBookDirectImpl.java    From exchange-core with Apache License 2.0 6 votes vote down vote up
public OrderBookDirectImpl(final BytesIn bytes,
                           final ObjectsPool objectsPool,
                           final OrderBookEventsHelper eventsHelper,
                           final LoggingConfiguration loggingCfg) {

    this.symbolSpec = new CoreSymbolSpecification(bytes);
    this.objectsPool = objectsPool;
    this.askPriceBuckets = new LongAdaptiveRadixTreeMap<>(objectsPool);
    this.bidPriceBuckets = new LongAdaptiveRadixTreeMap<>(objectsPool);
    this.eventsHelper = eventsHelper;
    this.orderIdIndex = new LongAdaptiveRadixTreeMap<>(objectsPool);
    this.logDebug = loggingCfg.getLoggingLevels().contains(LoggingConfiguration.LoggingLevel.LOGGING_MATCHING_DEBUG);

    final int size = bytes.readInt();
    for (int i = 0; i < size; i++) {
        DirectOrder order = new DirectOrder(bytes);
        insertOrder(order, null);
        orderIdIndex.put(order.orderId, order);
    }
}
 
Example #2
Source File: ReportsQueriesConfiguration.java    From exchange-core with Apache License 2.0 6 votes vote down vote up
private static void addQueryClass(final Map<Integer, Constructor<? extends ReportQuery<?>>> reportConstructors,
                                  final int reportTypeCode,
                                  final Class<? extends ReportQuery<?>> reportQueryClass) {

    final Constructor<? extends ReportQuery<?>> existing = reportConstructors.get(reportTypeCode);

    if (existing != null) {
        throw new IllegalArgumentException("Configuration error: report type code " + reportTypeCode + " is already occupied by " + existing.getDeclaringClass().getName());
    }

    try {
        reportConstructors.put(reportTypeCode, reportQueryClass.getConstructor(BytesIn.class));
    } catch (final NoSuchMethodException ex) {
        throw new IllegalArgumentException("Configuration error: report class " + reportQueryClass.getName() + "deserialization constructor accepting BytesIn");
    }

}
 
Example #3
Source File: ExecutionReport.java    From Chronicle-Queue-Demo with Apache License 2.0 6 votes vote down vote up
@Override
public void readMarshallable(BytesIn in) {
    super.readMarshallable(in);
    if (PREGENERATED_MARSHALLABLE) {
        int version = (int) in.readStopBit();
        if (version == MASHALLABLE_VERSION) {
            symbol = in.readLong();
            transactTime = in.readLong();
            orderQty = in.readDouble();
            price = in.readDouble();
            orderID = in.readLong();
            lastPx = in.readDouble();
            leavesQty = in.readDouble();
            cumQty = in.readDouble();
            avgPx = in.readDouble();
            side = (BuySell) in.readObject(BuySell.class);
            ordType = (OrderType) in.readObject(OrderType.class);
            clOrdID = (String) in.readObject(String.class);
            text = (String) in.readObject(String.class);
        } else {
            throw new IllegalStateException("Unknown version " + version);
        }
    }
}
 
Example #4
Source File: NewOrderSingle.java    From Chronicle-Queue-Demo with Apache License 2.0 6 votes vote down vote up
@Override
public void readMarshallable(BytesIn in) {
    super.readMarshallable(in);
    if (PREGENERATED_MARSHALLABLE) {
        int version = (int) in.readStopBit();
        if (version == MASHALLABLE_VERSION) {
            symbol = in.readLong();
            transactTime = in.readLong();
            orderQty = in.readDouble();
            price = in.readDouble();
            side = (BuySell) in.readObject(BuySell.class);
            ordType = (OrderType) in.readObject(OrderType.class);
            clOrdID = (String) in.readObject(String.class);
        }
    }
}
 
Example #5
Source File: StateHashReportResult.java    From exchange-core with Apache License 2.0 5 votes vote down vote up
public static StateHashReportResult merge(final Stream<BytesIn> pieces) {

        return pieces.map(StateHashReportResult::new)
                .reduce(EMPTY, (r1, r2) -> {
                    SortedMap<SubmoduleKey, Integer> hashcodes = new TreeMap<>(r1.hashCodes);
                    hashcodes.putAll(r2.hashCodes);
                    return new StateHashReportResult(hashcodes);
                });
    }
 
Example #6
Source File: ReportsQueriesConfiguration.java    From exchange-core with Apache License 2.0 5 votes vote down vote up
private static void addBinaryCommandClass(Map<Integer, Constructor<? extends BinaryDataCommand>> binaryCommandConstructors,
                                          BinaryCommandType type,
                                          Class<? extends BinaryDataCommand> binaryCommandClass) {
    try {
        binaryCommandConstructors.put(type.getCode(), binaryCommandClass.getConstructor(BytesIn.class));
    } catch (final NoSuchMethodException ex) {
        throw new IllegalArgumentException(ex);
    }
}
 
Example #7
Source File: SymbolPositionRecord.java    From exchange-core with Apache License 2.0 5 votes vote down vote up
public SymbolPositionRecord(long uid, BytesIn bytes) {
    this.uid = uid;

    this.symbol = bytes.readInt();
    this.currency = bytes.readInt();

    this.direction = PositionDirection.of(bytes.readByte());
    this.openVolume = bytes.readLong();
    this.openPriceSum = bytes.readLong();
    this.profit = bytes.readLong();

    this.pendingSellSize = bytes.readLong();
    this.pendingBuySize = bytes.readLong();
}
 
Example #8
Source File: OrderBookDirectImpl.java    From exchange-core with Apache License 2.0 5 votes vote down vote up
public DirectOrder(BytesIn bytes) {


            this.orderId = bytes.readLong(); // orderId
            this.price = bytes.readLong();  // price
            this.size = bytes.readLong(); // size
            this.filled = bytes.readLong(); // filled
            this.reserveBidPrice = bytes.readLong(); // price2
            this.action = OrderAction.of(bytes.readByte());
            this.uid = bytes.readLong(); // uid
            this.timestamp = bytes.readLong(); // timestamp
            // this.userCookie = bytes.readInt();  // userCookie

            // TODO
        }
 
Example #9
Source File: CancelOrderRequest.java    From Chronicle-Queue-Demo with Apache License 2.0 5 votes vote down vote up
@Override
public void readMarshallable(BytesIn in) {
    super.readMarshallable(in);
    if (PREGENERATED_MARSHALLABLE) {
        int version = (int) in.readStopBit();
        if (version == MASHALLABLE_VERSION) {
            clOrdID = (String) in.readObject(String.class);
            symbol = in.readLong();
        } else {
            throw new IllegalStateException("Unknown version " + version);
        }
    }
}
 
Example #10
Source File: SingleUserReportResult.java    From exchange-core with Apache License 2.0 5 votes vote down vote up
private Position(BytesIn bytes) {

            this.quoteCurrency = bytes.readInt();

            this.direction = PositionDirection.of(bytes.readByte());
            this.openVolume = bytes.readLong();
            this.openPriceSum = bytes.readLong();
            this.profit = bytes.readLong();

            this.pendingSellSize = bytes.readLong();
            this.pendingBuySize = bytes.readLong();
        }
 
Example #11
Source File: SingleUserReportResult.java    From exchange-core with Apache License 2.0 5 votes vote down vote up
public static SingleUserReportResult merge(final Stream<BytesIn> pieces) {
        return pieces
                .map(SingleUserReportResult::new)
                .reduce(
                        IDENTITY,
                        (a, b) -> new SingleUserReportResult(
                                a.uid,
//                                SerializationUtils.preferNotNull(a.userProfile, b.userProfile),
                                SerializationUtils.preferNotNull(a.userStatus, b.userStatus),
                                SerializationUtils.preferNotNull(a.accounts, b.accounts),
                                SerializationUtils.preferNotNull(a.positions, b.positions),
                                SerializationUtils.mergeOverride(a.orders, b.orders),
                                a.queryExecutionStatus != QueryExecutionStatus.OK ? a.queryExecutionStatus : b.queryExecutionStatus));
    }
 
Example #12
Source File: SingleUserReportResult.java    From exchange-core with Apache License 2.0 5 votes vote down vote up
private SingleUserReportResult(final BytesIn bytesIn) {
        this.uid = bytesIn.readLong();
//        this.userProfile = bytesIn.readBoolean() ? new UserProfile(bytesIn) : null;
        this.userStatus = bytesIn.readBoolean() ? UserStatus.of(bytesIn.readByte()) : null;
        this.accounts = bytesIn.readBoolean() ? SerializationUtils.readIntLongHashMap(bytesIn) : null;
        this.positions = bytesIn.readBoolean() ? SerializationUtils.readIntHashMap(bytesIn, Position::new) : null;
        this.orders = bytesIn.readBoolean() ? SerializationUtils.readIntHashMap(bytesIn, b -> SerializationUtils.readList(b, Order::new)) : null;
        this.queryExecutionStatus = QueryExecutionStatus.of(bytesIn.readInt());
    }
 
Example #13
Source File: AbstractEvent.java    From Chronicle-Queue-Demo with Apache License 2.0 5 votes vote down vote up
@Override
public void readMarshallable(BytesIn in) {
    if (PREGENERATED_MARSHALLABLE) {
        int version = (int) in.readStopBit();
        if (version == MASHALLABLE_VERSION) {
            sender = in.readLong();
            target = in.readLong();
            sendingTime = in.readLong();
        } else {
            throw new IllegalStateException("Unknown version " + version);
        }
    } else {
        super.readMarshallable(in);
    }
}
 
Example #14
Source File: OrderBookNaiveImpl.java    From exchange-core with Apache License 2.0 5 votes vote down vote up
public OrderBookNaiveImpl(final BytesIn bytes, final LoggingConfiguration loggingCfg) {
    this.symbolSpec = new CoreSymbolSpecification(bytes);
    this.askBuckets = SerializationUtils.readLongMap(bytes, TreeMap::new, OrdersBucketNaive::new);
    this.bidBuckets = SerializationUtils.readLongMap(bytes, () -> new TreeMap<>(Collections.reverseOrder()), OrdersBucketNaive::new);

    this.eventsHelper = OrderBookEventsHelper.NON_POOLED_EVENTS_HELPER;
    // reconstruct ordersId-> Order cache
    // TODO check resulting performance
    askBuckets.values().forEach(bucket -> bucket.forEachOrder(order -> idMap.put(order.orderId, order)));
    bidBuckets.values().forEach(bucket -> bucket.forEachOrder(order -> idMap.put(order.orderId, order)));

    this.logDebug = loggingCfg.getLoggingLevels().contains(LoggingConfiguration.LoggingLevel.LOGGING_MATCHING_DEBUG);
    //validateInternalState();
}
 
Example #15
Source File: OrderCancelReject.java    From Chronicle-Queue-Demo with Apache License 2.0 5 votes vote down vote up
@Override
public void readMarshallable(BytesIn in) {
    super.readMarshallable(in);
    if (PREGENERATED_MARSHALLABLE) {
        int version = (int) in.readStopBit();
        if (version == MASHALLABLE_VERSION) {
            clOrdID = (String) in.readObject(String.class);
            symbol = in.readLong();
            reason = (String) in.readObject(String.class);
        } else {
            throw new IllegalStateException("Unknown version " + version);
        }
    }
}
 
Example #16
Source File: TotalCurrencyBalanceReportResult.java    From exchange-core with Apache License 2.0 5 votes vote down vote up
private TotalCurrencyBalanceReportResult(final BytesIn bytesIn) {
    this.accountBalances = SerializationUtils.readNullable(bytesIn, SerializationUtils::readIntLongHashMap);
    this.fees = SerializationUtils.readNullable(bytesIn, SerializationUtils::readIntLongHashMap);
    this.adjustments = SerializationUtils.readNullable(bytesIn, SerializationUtils::readIntLongHashMap);
    this.suspends = SerializationUtils.readNullable(bytesIn, SerializationUtils::readIntLongHashMap);
    this.ordersBalances = SerializationUtils.readNullable(bytesIn, SerializationUtils::readIntLongHashMap);
    this.openInterestLong = SerializationUtils.readNullable(bytesIn, SerializationUtils::readIntLongHashMap);
    this.openInterestShort = SerializationUtils.readNullable(bytesIn, SerializationUtils::readIntLongHashMap);
}
 
Example #17
Source File: CHMUseCasesTest.java    From Chronicle-Map with Apache License 2.0 5 votes vote down vote up
@Override
public void readMarshallable(@NotNull BytesIn in) throws IllegalStateException {
    long magic = in.readLong();
    if (magic != MAGIC)
        throw new AssertionError("Start " + Long.toHexString(magic));
    text = in.readUTFΔ();
    number = in.readInt();
    long magic2 = in.readLong();
    if (magic2 != MAGIC2)
        throw new AssertionError("End " + Long.toHexString(magic2));
}
 
Example #18
Source File: MovingAverageCompact.java    From Chronicle-Map with Apache License 2.0 5 votes vote down vote up
@Override
public void readMarshallable(BytesIn in) throws IllegalStateException {
    movingAverage = in.readDouble();
    high = in.readDouble();
    low = in.readDouble();
    stdDev = in.readDouble();
}
 
Example #19
Source File: Order.java    From exchange-core with Apache License 2.0 5 votes vote down vote up
public Order(BytesIn bytes) {


        this.orderId = bytes.readLong(); // orderId
        this.price = bytes.readLong();  // price
        this.size = bytes.readLong(); // size
        this.filled = bytes.readLong(); // filled
        this.reserveBidPrice = bytes.readLong(); // price2
        this.action = OrderAction.of(bytes.readByte());
        this.uid = bytes.readLong(); // uid
        this.timestamp = bytes.readLong(); // timestamp
//        this.userCookie = bytes.readInt();  // userCookie

    }
 
Example #20
Source File: MovingAverageArray.java    From Chronicle-Map with Apache License 2.0 5 votes vote down vote up
@Override
public void readMarshallable(BytesIn bytes) throws IORuntimeException {
    int len = Maths.toUInt31(bytes.readStopBit());
    values.clear();
    for (int i = 0; i < len; i++) {
        if (buffer.size() <= values.size()) {
            buffer.add(ObjectUtils.newInstance(MovingAverageCompact.class));
        }
        MovingAverageCompact next = buffer.get(i);
        next.readMarshallable(bytes);
        values.add(next);
    }
}
 
Example #21
Source File: TotalCurrencyBalanceReportResult.java    From exchange-core with Apache License 2.0 5 votes vote down vote up
public static TotalCurrencyBalanceReportResult merge(final Stream<BytesIn> pieces) {
    return pieces
            .map(TotalCurrencyBalanceReportResult::new)
            .reduce(
                    TotalCurrencyBalanceReportResult.createEmpty(),
                    (a, b) -> new TotalCurrencyBalanceReportResult(
                            SerializationUtils.mergeSum(a.accountBalances, b.accountBalances),
                            SerializationUtils.mergeSum(a.fees, b.fees),
                            SerializationUtils.mergeSum(a.adjustments, b.adjustments),
                            SerializationUtils.mergeSum(a.suspends, b.suspends),
                            SerializationUtils.mergeSum(a.ordersBalances, b.ordersBalances),
                            SerializationUtils.mergeSum(a.openInterestLong, b.openInterestLong),
                            SerializationUtils.mergeSum(a.openInterestShort, b.openInterestShort)));
}
 
Example #22
Source File: RollingCycleTest.java    From Chronicle-Queue with Apache License 2.0 5 votes vote down vote up
@Override
public void readMarshallable(@NotNull BytesIn bytes) throws IORuntimeException {
    _name = bytes.readUtf8();
    _value1 = bytes.readLong();
    _value2 = bytes.readLong();
    _value3 = bytes.readLong();
}
 
Example #23
Source File: CoreSymbolSpecification.java    From exchange-core with Apache License 2.0 5 votes vote down vote up
public CoreSymbolSpecification(BytesIn bytes) {
    this.symbolId = bytes.readInt();
    this.type = SymbolType.of(bytes.readByte());
    this.baseCurrency = bytes.readInt();
    this.quoteCurrency = bytes.readInt();
    this.baseScaleK = bytes.readLong();
    this.quoteScaleK = bytes.readLong();
    this.takerFee = bytes.readLong();
    this.makerFee = bytes.readLong();
    this.marginBuy = bytes.readLong();
    this.marginSell = bytes.readLong();
}
 
Example #24
Source File: DiskSerializationProcessor.java    From exchange-core with Apache License 2.0 5 votes vote down vote up
@Override
public <T> T loadData(long snapshotId,
                      SerializedModuleType type,
                      int instanceId,
                      Function<BytesIn, T> initFunc) {

    final Path path = resolveSnapshotPath(snapshotId, type, instanceId);

    log.debug("Loading state from {}", path);
    try (final InputStream is = Files.newInputStream(path, StandardOpenOption.READ);
         final InputStream bis = new BufferedInputStream(is);
         final LZ4FrameInputStream lz4is = new LZ4FrameInputStream(bis)) {

        // TODO improve reading algorithm
        final InputStreamToWire inputStreamToWire = new InputStreamToWire(WireType.RAW, lz4is);
        final Wire wire = inputStreamToWire.readOne();

        log.debug("start de-serializing...");

        AtomicReference<T> ref = new AtomicReference<>();
        wire.readBytes(bytes -> ref.set(initFunc.apply(bytes)));

        return ref.get();

    } catch (final IOException ex) {
        log.error("Can not read snapshot file: ", ex);
        throw new IllegalStateException(ex);
    }
}
 
Example #25
Source File: IOrderBook.java    From exchange-core with Apache License 2.0 5 votes vote down vote up
static IOrderBook create(BytesIn bytes, ObjectsPool objectsPool, OrderBookEventsHelper eventsHelper, LoggingConfiguration loggingCfg) {
    switch (OrderBookImplType.of(bytes.readByte())) {
        case NAIVE:
            return new OrderBookNaiveImpl(bytes, loggingCfg);
        case DIRECT:
            return new OrderBookDirectImpl(bytes, objectsPool, eventsHelper, loggingCfg);
        default:
            throw new IllegalArgumentException();
    }
}
 
Example #26
Source File: DtoBytesMarshallableTest.java    From Chronicle-Queue with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
public void readMarshallable(BytesIn bytes) {
    age = bytes.readInt();
    name.setLength(0);
    bytes.readUtf8(name);
}
 
Example #27
Source File: UserProfile.java    From exchange-core with Apache License 2.0 4 votes vote down vote up
public UserProfile(BytesIn bytesIn) {

        this.uid = bytesIn.readLong();

        // positions
        this.positions = SerializationUtils.readIntHashMap(bytesIn, b -> new SymbolPositionRecord(uid, b));

        // adjustmentsCounter
        this.adjustmentsCounter = bytesIn.readLong();

        // account balances
        this.accounts = SerializationUtils.readIntLongHashMap(bytesIn);

        // suspended
        this.userStatus = UserStatus.of(bytesIn.readByte());
    }
 
Example #28
Source File: PointListSerializationTest.java    From Chronicle-Map with Apache License 2.0 4 votes vote down vote up
@Override
public void readMarshallable(BytesIn in) {
    str_ = in.readUtf8();
}
 
Example #29
Source File: QueueMultiThreadedJLBHBenchmark.java    From Chronicle-Queue with Apache License 2.0 4 votes vote down vote up
@Override
public void readMarshallable(BytesIn bytes) throws IORuntimeException {
    ts = bytes.readLong();
    bytes.read(filler);
}
 
Example #30
Source File: DtoBytesMarshallableTest.java    From Chronicle-Queue with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
public void readMarshallable(BytesIn bytes) {
    age = bytes.readInt();
    name.setLength(0);
    bytes.readUtf8(name);
}