|
| 1 | +package io.numaproj.numaflow.examples.servingstore.memory; |
| 2 | + |
| 3 | +import io.numaproj.numaflow.servingstore.GetDatum; |
| 4 | +import io.numaproj.numaflow.servingstore.Payload; |
| 5 | +import io.numaproj.numaflow.servingstore.PutDatum; |
| 6 | +import io.numaproj.numaflow.servingstore.Server; |
| 7 | +import io.numaproj.numaflow.servingstore.ServingStorer; |
| 8 | +import io.numaproj.numaflow.servingstore.StoredResult; |
| 9 | +import lombok.extern.slf4j.Slf4j; |
| 10 | + |
| 11 | +import java.util.Collections; |
| 12 | +import java.util.HashMap; |
| 13 | +import java.util.List; |
| 14 | +import java.util.Map; |
| 15 | + |
| 16 | +@Slf4j |
| 17 | +public class ServingInMemoryStore extends ServingStorer { |
| 18 | + private final Map<String, List<Payload>> store = new HashMap<>(); |
| 19 | + |
| 20 | + public void put(PutDatum putDatum) { |
| 21 | + log.info("Putting data into the store with ID: {}", putDatum.ID()); |
| 22 | + store.put(putDatum.ID(), putDatum.Payloads()); |
| 23 | + } |
| 24 | + |
| 25 | + public StoredResult get(GetDatum getDatum) { |
| 26 | + log.info("Getting data from the store with ID: {}", getDatum.ID()); |
| 27 | + List<Payload> payloads = store.getOrDefault(getDatum.ID(), Collections.emptyList()); |
| 28 | + return new StoredResult(getDatum.ID(), payloads); |
| 29 | + } |
| 30 | + |
| 31 | + public static void main(String[] args) throws Exception { |
| 32 | + Server server = new Server(new ServingInMemoryStore()); |
| 33 | + |
| 34 | + // Start the server |
| 35 | + server.start(); |
| 36 | + |
| 37 | + // Wait for the server to shutdown |
| 38 | + server.awaitTermination(); |
| 39 | + } |
| 40 | +} |
0 commit comments