Search in sources :

Example 1 with BindingConfig

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;
}
Also used : MessageConsumer(io.aklivity.zilla.runtime.engine.binding.function.MessageConsumer) BindingConfig(io.aklivity.zilla.runtime.engine.config.BindingConfig) BeginFW(io.aklivity.zilla.runtime.binding.fan.internal.types.stream.BeginFW)

Example 2 with BindingConfig

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;
}
Also used : MessageConsumer(io.aklivity.zilla.runtime.engine.binding.function.MessageConsumer) BindingConfig(io.aklivity.zilla.runtime.engine.config.BindingConfig) BeginFW(io.aklivity.zilla.runtime.binding.echo.internal.types.stream.BeginFW)

Example 3 with BindingConfig

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);
}
Also used : JsonValue(jakarta.json.JsonValue) Collections.emptyList(java.util.Collections.emptyList) JsonArrayBuilder(jakarta.json.JsonArrayBuilder) BindingConfig(io.aklivity.zilla.runtime.engine.config.BindingConfig) Json(jakarta.json.Json) JsonbAdapter(jakarta.json.bind.adapter.JsonbAdapter) JsonObjectBuilder(jakarta.json.JsonObjectBuilder) OptionsConfigAdapterSpi(io.aklivity.zilla.runtime.engine.config.OptionsConfigAdapterSpi) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) OptionsConfig(io.aklivity.zilla.runtime.engine.config.OptionsConfig) RouteConfig(io.aklivity.zilla.runtime.engine.config.RouteConfig) JsonObject(jakarta.json.JsonObject) KindConfig(io.aklivity.zilla.runtime.engine.config.KindConfig) LinkedList(java.util.LinkedList) MutableInteger(org.agrona.collections.MutableInteger) NamespacedRef(io.aklivity.zilla.runtime.engine.config.NamespacedRef) OptionsConfig(io.aklivity.zilla.runtime.engine.config.OptionsConfig) MutableInteger(org.agrona.collections.MutableInteger) JsonValue(jakarta.json.JsonValue) JsonObject(jakarta.json.JsonObject) RouteConfig(io.aklivity.zilla.runtime.engine.config.RouteConfig) NamespacedRef(io.aklivity.zilla.runtime.engine.config.NamespacedRef) LinkedList(java.util.LinkedList) BindingConfig(io.aklivity.zilla.runtime.engine.config.BindingConfig) KindConfig(io.aklivity.zilla.runtime.engine.config.KindConfig)

Example 4 with BindingConfig

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();
}
Also used : BindingConfig(io.aklivity.zilla.runtime.engine.config.BindingConfig) JsonArrayBuilder(jakarta.json.JsonArrayBuilder) JsonObjectBuilder(jakarta.json.JsonObjectBuilder)

Example 5 with BindingConfig

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\"}}"));
}
Also used : BindingConfig(io.aklivity.zilla.runtime.engine.config.BindingConfig) NamespacedRef(io.aklivity.zilla.runtime.engine.config.NamespacedRef) Test(org.junit.Test)

Aggregations

BindingConfig (io.aklivity.zilla.runtime.engine.config.BindingConfig)11 Test (org.junit.Test)6 RouteConfig (io.aklivity.zilla.runtime.engine.config.RouteConfig)4 MessageConsumer (io.aklivity.zilla.runtime.engine.binding.function.MessageConsumer)2 NamespaceConfig (io.aklivity.zilla.runtime.engine.config.NamespaceConfig)2 NamespacedRef (io.aklivity.zilla.runtime.engine.config.NamespacedRef)2 JsonArrayBuilder (jakarta.json.JsonArrayBuilder)2 JsonObject (jakarta.json.JsonObject)2 JsonObjectBuilder (jakarta.json.JsonObjectBuilder)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 BeginFW (io.aklivity.zilla.runtime.binding.echo.internal.types.stream.BeginFW)1 BeginFW (io.aklivity.zilla.runtime.binding.fan.internal.types.stream.BeginFW)1 Engine (io.aklivity.zilla.runtime.engine.Engine)1 EngineConfiguration (io.aklivity.zilla.runtime.engine.EngineConfiguration)1 KindConfig (io.aklivity.zilla.runtime.engine.config.KindConfig)1 OptionsConfig (io.aklivity.zilla.runtime.engine.config.OptionsConfig)1 OptionsConfigAdapterSpi (io.aklivity.zilla.runtime.engine.config.OptionsConfigAdapterSpi)1 VaultConfig (io.aklivity.zilla.runtime.engine.config.VaultConfig)1 EngineExtContext (io.aklivity.zilla.runtime.engine.ext.EngineExtContext)1