use of io.aklivity.zilla.runtime.engine.config.BindingConfig in project zilla by aklivity.
the class FanServerFactory method newStream.
@Override
public MessageConsumer newStream(int msgTypeId, DirectBuffer buffer, int index, int length, MessageConsumer replyTo) {
final BeginFW begin = beginRO.wrap(buffer, index, index + length);
final long routeId = begin.routeId();
final BindingConfig binding = bindings.get(routeId);
MessageConsumer newStream = null;
if (binding != null) {
final long initialId = begin.streamId();
final long replyId = supplyReplyId.applyAsLong(initialId);
final FanServerGroup group = supplyFanServerGroup(binding.exit.id);
newStream = new FanServer(group, routeId, initialId, replyId, replyTo)::onMemberMessage;
}
return newStream;
}
use of io.aklivity.zilla.runtime.engine.config.BindingConfig in project zilla by aklivity.
the class EchoServerFactory method newStream.
@Override
public MessageConsumer newStream(int msgTypeId, DirectBuffer buffer, int index, int length, MessageConsumer sender) {
final BeginFW begin = beginRO.wrap(buffer, index, index + length);
final long routeId = begin.routeId();
final long authorization = begin.authorization();
final BindingConfig binding = router.resolve(routeId, authorization);
MessageConsumer newStream = null;
if (binding != null) {
final long initialId = begin.streamId();
newStream = new EchoServer(sender, routeId, initialId)::onMessage;
}
return newStream;
}
use of io.aklivity.zilla.runtime.engine.config.BindingConfig in project zilla by aklivity.
the class BindingConfigsAdapter method adaptFromJson.
@Override
public BindingConfig[] adaptFromJson(JsonObject object) {
List<BindingConfig> bindings = new LinkedList<>();
for (String entry : object.keySet()) {
JsonObject item = object.getJsonObject(entry);
String type = item.getString(TYPE_NAME);
route.adaptType(type);
options.adaptType(type);
NamespacedRef vault = item.containsKey(VAULT_NAME) ? NamespacedRef.of(item.getString(VAULT_NAME)) : null;
KindConfig kind = this.kind.adaptFromJson(item.getJsonString(KIND_NAME));
OptionsConfig opts = item.containsKey(OPTIONS_NAME) ? options.adaptFromJson(item.getJsonObject(OPTIONS_NAME)) : null;
MutableInteger order = new MutableInteger();
List<RouteConfig> routes = item.containsKey(ROUTES_NAME) ? item.getJsonArray(ROUTES_NAME).stream().map(JsonValue::asJsonObject).peek(o -> route.adaptFromJsonIndex(order.value++)).map(route::adaptFromJson).collect(toList()) : ROUTES_DEFAULT;
RouteConfig exit = item.containsKey(EXIT_NAME) ? new RouteConfig(routes.size(), item.getString(EXIT_NAME)) : null;
bindings.add(new BindingConfig(vault, entry, type, kind, opts, routes, exit));
}
return bindings.toArray(BindingConfig[]::new);
}
use of io.aklivity.zilla.runtime.engine.config.BindingConfig in project zilla by aklivity.
the class BindingConfigsAdapter method adaptToJson.
@Override
public JsonObject adaptToJson(BindingConfig[] bindings) {
JsonObjectBuilder object = Json.createObjectBuilder();
for (BindingConfig binding : bindings) {
route.adaptType(binding.type);
options.adaptType(binding.type);
JsonObjectBuilder item = Json.createObjectBuilder();
if (binding.vault != null) {
// TODO: qualified name format
item.add(VAULT_NAME, binding.vault.name);
}
item.add(TYPE_NAME, binding.type);
item.add(KIND_NAME, kind.adaptToJson(binding.kind));
if (binding.options != null) {
item.add(OPTIONS_NAME, options.adaptToJson(binding.options));
}
if (!ROUTES_DEFAULT.equals(binding.routes)) {
JsonArrayBuilder routes = Json.createArrayBuilder();
binding.routes.forEach(r -> routes.add(route.adaptToJson(r)));
item.add(ROUTES_NAME, routes);
}
if (binding.exit != null) {
item.add(EXIT_NAME, binding.exit.exit);
}
object.add(binding.entry, item);
}
return object.build();
}
use of io.aklivity.zilla.runtime.engine.config.BindingConfig in project zilla by aklivity.
the class BindingConfigsAdapterTest method shouldWriteBindingWithVault.
@Test
public void shouldWriteBindingWithVault() {
NamespacedRef vault = new NamespacedRef("default", "test");
BindingConfig[] bindings = { new BindingConfig(vault, "test", "test", SERVER, null, emptyList(), null) };
String text = jsonb.toJson(bindings);
assertThat(text, not(nullValue()));
assertThat(text, equalTo("{\"test\":{\"vault\":\"test\",\"type\":\"test\",\"kind\":\"server\"}}"));
}
Aggregations