All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.reaktivity.nukleus.tls.internal.TlsElektron Maven / Gradle / Ivy

There is a newer version: 0.185
Show newest version
/**
 * Copyright 2016-2021 The Reaktivity Project
 *
 * The Reaktivity Project licenses this file to you under the Apache License,
 * version 2.0 (the "License"); you may not use this file except in compliance
 * with the License. You may obtain a copy of the License at:
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations
 * under the License.
 */
package org.reaktivity.nukleus.tls.internal;

import static org.reaktivity.reaktor.config.Role.CLIENT;
import static org.reaktivity.reaktor.config.Role.PROXY;
import static org.reaktivity.reaktor.config.Role.SERVER;

import java.util.EnumMap;
import java.util.Map;

import org.reaktivity.nukleus.tls.internal.stream.TlsClientFactory;
import org.reaktivity.nukleus.tls.internal.stream.TlsProxyFactory;
import org.reaktivity.nukleus.tls.internal.stream.TlsServerFactory;
import org.reaktivity.nukleus.tls.internal.stream.TlsStreamFactory;
import org.reaktivity.reaktor.config.Binding;
import org.reaktivity.reaktor.config.Role;
import org.reaktivity.reaktor.nukleus.Elektron;
import org.reaktivity.reaktor.nukleus.ElektronContext;
import org.reaktivity.reaktor.nukleus.stream.StreamFactory;

final class TlsElektron implements Elektron
{
    private final Map factories;

    TlsElektron(
        TlsConfiguration config,
        ElektronContext context)
    {
        TlsCounters counters = new TlsCounters(context::supplyCounter, context::supplyAccumulator);
        Map factories = new EnumMap<>(Role.class);
        factories.put(SERVER, new TlsServerFactory(config, context, counters));
        factories.put(PROXY, new TlsProxyFactory(config, context, counters));
        factories.put(CLIENT, new TlsClientFactory(config, context, counters));
        this.factories = factories;
    }

    @Override
    public StreamFactory attach(
        Binding binding)
    {
        TlsStreamFactory factory = factories.get(binding.kind);
        if (factory != null)
        {
            factory.attach(binding);
        }
        return factory;
    }

    @Override
    public void detach(
        Binding binding)
    {
        TlsStreamFactory factory = factories.get(binding.kind);
        if (factory != null)
        {
            factory.detach(binding.id);
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy