Search in sources :

Example 1 with ChannelInitializer

use of com.hazelcast.internal.networking.ChannelInitializer in project hazelcast by hazelcast.

the class ChannelInitializerFunction method init.

public void init() {
    AdvancedNetworkConfig advancedNetworkConfig = config.getAdvancedNetworkConfig();
    if (!advancedNetworkConfig.isEnabled() || advancedNetworkConfig.getEndpointConfigs().isEmpty()) {
        initializerMap = Collections.emptyMap();
        return;
    }
    Map<EndpointQualifier, ChannelInitializer> map = new HashMap<EndpointQualifier, ChannelInitializer>();
    for (EndpointConfig endpointConfig : advancedNetworkConfig.getEndpointConfigs().values()) {
        checkSslConfigAvailability(endpointConfig.getSSLConfig());
        switch(endpointConfig.getProtocolType()) {
            case MEMBER:
                map.put(EndpointQualifier.MEMBER, provideMemberChannelInitializer(endpointConfig));
                break;
            case CLIENT:
                map.put(EndpointQualifier.CLIENT, provideClientChannelInitializer(endpointConfig));
                break;
            case REST:
                map.put(EndpointQualifier.REST, provideTextChannelInitializer(endpointConfig, true));
                break;
            case MEMCACHE:
                map.put(EndpointQualifier.MEMCACHE, provideTextChannelInitializer(endpointConfig, false));
                break;
            case WAN:
                map.put(endpointConfig.getQualifier(), provideMemberChannelInitializer(endpointConfig));
                break;
            default:
                throw new IllegalStateException("Cannot build channel initializer for protocol type " + endpointConfig.getProtocolType());
        }
    }
    initializerMap = map;
}
Also used : AdvancedNetworkConfig(com.hazelcast.config.AdvancedNetworkConfig) HashMap(java.util.HashMap) EndpointQualifier(com.hazelcast.instance.EndpointQualifier) TextChannelInitializer(com.hazelcast.internal.nio.ascii.TextChannelInitializer) ChannelInitializer(com.hazelcast.internal.networking.ChannelInitializer) EndpointConfig(com.hazelcast.config.EndpointConfig)

Example 2 with ChannelInitializer

use of com.hazelcast.internal.networking.ChannelInitializer in project hazelcast by hazelcast.

the class TcpServerConnectionManager method newChannel.

Channel newChannel(SocketChannel socketChannel, boolean clientMode) throws IOException {
    Networking networking = server.getNetworking();
    ChannelInitializer channelInitializer = channelInitializerFn.apply(endpointQualifier);
    assert channelInitializer != null : "Found NULL channel initializer for endpoint-qualifier " + endpointQualifier;
    Channel channel = networking.register(channelInitializer, socketChannel, clientMode);
    // Advanced Network
    if (endpointConfig != null) {
        setChannelOptions(channel, endpointConfig);
    }
    acceptedChannels.add(channel);
    return channel;
}
Also used : Networking(com.hazelcast.internal.networking.Networking) SocketChannel(java.nio.channels.SocketChannel) Channel(com.hazelcast.internal.networking.Channel) ChannelInitializer(com.hazelcast.internal.networking.ChannelInitializer)

Aggregations

ChannelInitializer (com.hazelcast.internal.networking.ChannelInitializer)2 AdvancedNetworkConfig (com.hazelcast.config.AdvancedNetworkConfig)1 EndpointConfig (com.hazelcast.config.EndpointConfig)1 EndpointQualifier (com.hazelcast.instance.EndpointQualifier)1 Channel (com.hazelcast.internal.networking.Channel)1 Networking (com.hazelcast.internal.networking.Networking)1 TextChannelInitializer (com.hazelcast.internal.nio.ascii.TextChannelInitializer)1 SocketChannel (java.nio.channels.SocketChannel)1 HashMap (java.util.HashMap)1