package org.age.akka.config;

import com.google.common.eventbus.EventBus;
import com.hazelcast.config.Config;
import com.hazelcast.config.JoinConfig;
import com.hazelcast.config.ListenerConfig;
import com.hazelcast.config.MulticastConfig;
import com.hazelcast.config.NetworkConfig;
import com.hazelcast.config.TcpIpConfig;
import com.hazelcast.core.MembershipListener;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;

import java.util.List;

@Configuration
@ComponentScan("org.age.akka")
@PropertySource("classpath:cluster.properties")
public class SpringConfiguration {

    @Value("#{'${network.tcp.members:127.0.0.1}'.split(',')}")
    private List<String> tcpMembers;

    @Bean
    public Config hazelcastConfig(MembershipListener membershipListener) {
        Config config = new Config();
        NetworkConfig networkConfig = config.getNetworkConfig();

        JoinConfig join = networkConfig.getJoin();
        MulticastConfig multicastConfig = join.getMulticastConfig();
        multicastConfig.setEnabled(false);

        TcpIpConfig tcpIpConfig = join.getTcpIpConfig();
        tcpIpConfig.setEnabled(true);
        tcpMembers.forEach(tcpIpConfig::addMember);

        config.getProperties().put("hazelcast.logging.type", "slf4j");
        config.getProperties().put("hazelcast.shutdownhook.enabled", "false");

        config.addListenerConfig(new ListenerConfig(membershipListener));

        return config;
    }

    @Bean
    public static PropertySourcesPlaceholderConfigurer propertyConfigIn() {
        return new PropertySourcesPlaceholderConfigurer();
    }

    @Bean
    public EventBus eventBus() {
        return new EventBus();
    }

}

@@ -1117,24 +1117,25 @@
 nfig();%0A
+%0A
         
 NetworkC
@@ -1130,35 +1130,23 @@
     
-NetworkConfig networkConfig
+JoinConfig join
  = c
@@ -1173,154 +1173,53 @@
 ig()
-;%0A%0A        JoinConfig join = networkConfig.getJoin();%0A        MulticastConfig multicastConfig = join.getMulticastConfig();%0A        multicastConfig
+.getJoin();%0A        join.getMulticastConfig()
 .set

simplify hazelcast config