Skip to content

Instantly share code, notes, and snippets.

machine("Circuit Breaker", machine -> {
machine.startWith("OPEN");
machine.at("OPEN", rule -> {
rule.when("connect", failOp, "OPEN", "CLOSED");
});
machine.at("CLOSED", rule -> {
rule.when("connect", s -> {
}, "CLOSED");
decisionSystem("FX Transaction", tradeSchema, s -> {
s.rule("High Transfer discount", condition -> {
condition
.gt("amount", 1000d)
.eq("source", "SGD")
.eq("target", "INR")
.action((rule, row) -> row.setDiscount(2.0d));
});
public interface RecordContainer<T> extends Closeable {
boolean append(T message);
void read(RecordConsumer<T> reader);
void read(long offSet, RecordConsumer<T> reader);
default void close() {}
int size();
String formatName();
}
(Avro) -> Size 43 Bytes
{"tradeId": 454442738626075203, "customerId": 1924973958993118808, "qty": 100, "tradeType": "Buy", "symbol": "GOOGL", "exchange": "NYSE"}
(Avro) -> Size 43 Bytes
{"tradeId": 1984810212692753661, "customerId": -7397692262047989958, "qty": 100, "tradeType": "Sell", "symbol": "AAPL", "exchange": "NYSE"}
(chronicle) -> Size 35 Bytes
CVCNX†©ãá¶NYSEBuyGOOGLd
(chronicle) -> Size 35 Bytes
ý|Z_v‹:?ùV™NYSESellAAPLd
Object[][] data = new Object[][]{
{new Random().nextLong(), new Random().nextLong(), "NYSE", "Buy", "GOOGL", 100},
{new Random().nextLong(), new Random().nextLong(), "NYSE", "Sell", "AAPL", 100},
};
process("Avro", Arrays.stream(data), AvroTradeRecordBuilder::newTrade, AvroTradeRecordBuilder::toBytes, AvroTradeRecordBuilder::fromBytes);
process("chronicle", Arrays.stream(data), ChronicleTradeRecordBuilder::newTrade, ChronicleTradeRecordBuilder::toBytes, ChronicleTradeRecordBuilder::fromBytes);
process("sbe", Arrays.stream(data), SBETradeRecordBuilder::newTrade, SBETradeRecordBuilder::toBytes, SBETradeRecordBuilder::fromBytes);
process("csv", Arrays.stream(data), CSVTradeRecordBuilder::newTrade, CSVTradeRecordBuilder::toBytes, CSVTradeRecordBuilder::fromBytes);
long tradeId , customerId;
int qty;
TradeType tradeType;
String symbol,exchange;
List functions = asList(
SerCode.f((Integer x) -> x * x),
SerCode.f((String x) -> x.toUpperCase()),
SerCode.p((String x) -> x.length() > 5)
);
byte[] code = saveFunction(functions);
ObjectInputStream fStream = codeStream(code);
List rFunctions = (List) fStream.readObject();
@FunctionalInterface
public interface SerFunction<T, R> extends Function<T, R>, Serializable {
}
@FunctionalInterface
public interface SerPredicate<T> extends Predicate<T>, Serializable {
}
....
@Test()
public void save_function_works() throws Exception {
// Addtional casting allow to mark as serilized
Function<String, String> upper = (Function<String, String> & Serializable) x -> x.toUpperCase();
try (ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream os = new ObjectOutputStream(bos)) {
os.writeObject(upper);
@Test
public void save_function() throws Exception {
Function<String, String> upper = x -> x.toUpperCase();
try (ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream os = new ObjectOutputStream(bos)) {
os.writeObject(upper);
}
}