<commit_before>/*
 * Copyright 2015-2017 Canoo Engineering AG.
 *
 * Licensed 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 com.canoo.dp.impl.server.event;

import com.canoo.platform.remoting.server.event.MessageEvent;
import com.google.gson.Gson;
import com.hazelcast.client.config.ClientConfig;
import com.hazelcast.config.SerializerConfig;
import com.hazelcast.core.HazelcastInstance;
import org.apiguardian.api.API;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static org.apiguardian.api.API.Status.INTERNAL;

@API(since = "0.x", status = INTERNAL)
public class DefaultHazelcastProvider implements HazelcastProvider {

    private static final Logger LOG = LoggerFactory.getLogger(DefaultHazelcastProvider.class);

    private HazelcastInstance hazelcastInstance;

    public synchronized HazelcastInstance getHazelcastInstance(HazelcastConfig configuration) {
        if (hazelcastInstance == null) {
            final String serverName = configuration.getServerName();
            final String serverPort = configuration.getServerPort();
            final String groupName = configuration.getGroupName();

            LOG.debug("Hazelcast server name: {}", serverName);
            LOG.debug("Hazelcast server port: {}", serverPort);
            LOG.debug("Hazelcast group name: {}", groupName);

            final ClientConfig clientConfig = new ClientConfig();
            clientConfig.getNetworkConfig().addAddress(serverName + ":" + serverPort);
            clientConfig.getGroupConfig().setName(groupName);
            final SerializerConfig dolphinEventSerializerConfig = new SerializerConfig();
            dolphinEventSerializerConfig.setImplementation(new EventStreamSerializer(new Gson()));
            dolphinEventSerializerConfig.setClass(EventStreamSerializer.class);
            dolphinEventSerializerConfig.setTypeClass(MessageEvent.class);
            dolphinEventSerializerConfig.setTypeClassName(MessageEvent.class.getName());
            clientConfig.getSerializationConfig().getSerializerConfigs().add(dolphinEventSerializerConfig);
        }
        return hazelcastInstance;
    }
}<commit_msg>hazelcast creation<commit_after>/*
 * Copyright 2015-2017 Canoo Engineering AG.
 *
 * Licensed 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 com.canoo.dp.impl.server.event;

import com.canoo.platform.remoting.server.event.MessageEvent;
import com.google.gson.Gson;
import com.hazelcast.client.HazelcastClient;
import com.hazelcast.client.config.ClientConfig;
import com.hazelcast.config.SerializerConfig;
import com.hazelcast.core.HazelcastInstance;
import org.apiguardian.api.API;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static org.apiguardian.api.API.Status.INTERNAL;

@API(since = "0.x", status = INTERNAL)
public class DefaultHazelcastProvider implements HazelcastProvider {

    private static final Logger LOG = LoggerFactory.getLogger(DefaultHazelcastProvider.class);

    private HazelcastInstance hazelcastInstance;

    public synchronized HazelcastInstance getHazelcastInstance(HazelcastConfig configuration) {
        if (hazelcastInstance == null) {
            final String serverName = configuration.getServerName();
            final String serverPort = configuration.getServerPort();
            final String groupName = configuration.getGroupName();

            LOG.debug("Hazelcast server name: {}", serverName);
            LOG.debug("Hazelcast server port: {}", serverPort);
            LOG.debug("Hazelcast group name: {}", groupName);

            final ClientConfig clientConfig = new ClientConfig();
            clientConfig.getNetworkConfig().addAddress(serverName + ":" + serverPort);
            clientConfig.getGroupConfig().setName(groupName);
            final SerializerConfig dolphinEventSerializerConfig = new SerializerConfig();
            dolphinEventSerializerConfig.setImplementation(new EventStreamSerializer(new Gson()));
            dolphinEventSerializerConfig.setClass(EventStreamSerializer.class);
            dolphinEventSerializerConfig.setTypeClass(MessageEvent.class);
            dolphinEventSerializerConfig.setTypeClassName(MessageEvent.class.getName());
            clientConfig.getSerializationConfig().getSerializerConfigs().add(dolphinEventSerializerConfig);
            hazelcastInstance = HazelcastClient.newHazelcastClient(clientConfig);
        }
        return hazelcastInstance;
    }
}
{'fraction_non_alphanumeric': 0.08594037541405962, 'fraction_numerical': 0.005520794994479205, 'mean_word_length': 3.9908172635445363, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5837824', 'n_tokens_mistral': 1432, 'n_tokens_neox': 1395, 'n_words': 359}