Java Code Examples for com.hazelcast.client.config.ClientConfig#setProperty()

The following examples show how to use com.hazelcast.client.config.ClientConfig#setProperty() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HazelcastAdapter.java    From dew with Apache License 2.0 5 votes vote down vote up
/**
 * Init.
 */
@PostConstruct
public void init() {
    ClientConfig clientConfig = new ClientConfig();
    clientConfig.setProperty("hazelcast.logging.type", "slf4j");
    if (hazelcastConfig.getUsername() != null) {
        clientConfig.getGroupConfig().setName(hazelcastConfig.getUsername()).setPassword(hazelcastConfig.getPassword());
    }
    clientConfig.getNetworkConfig().setConnectionTimeout(hazelcastConfig.getConnectionTimeout());
    clientConfig.getNetworkConfig().setConnectionAttemptLimit(hazelcastConfig.getConnectionAttemptLimit());
    clientConfig.getNetworkConfig().setConnectionAttemptPeriod(hazelcastConfig.getConnectionAttemptPeriod());
    hazelcastConfig.getAddresses().forEach(i -> clientConfig.getNetworkConfig().addAddress(i));
    hazelcastInstance = HazelcastClient.newHazelcastClient(clientConfig);
    active = true;
}
 
Example 2
Source File: DefaultHazelcastProvider.java    From dolphin-platform with Apache License 2.0 5 votes vote down vote up
public synchronized HazelcastInstance getHazelcastInstance(final 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().setConnectionAttemptLimit(configuration.getConnectionAttemptLimit());
        clientConfig.getNetworkConfig().setConnectionAttemptPeriod(configuration.getConnectionAttemptPeriod());
        clientConfig.getNetworkConfig().setConnectionTimeout(configuration.getConnectionTimeout());
        clientConfig.getNetworkConfig().addAddress(serverName + ":" + serverPort);
        clientConfig.getGroupConfig().setName(groupName);
        clientConfig.setProperty(LOGGER_PROPERTY_NAME, LOGGER_PROPERTY_SLF4J_TYPE);

        final SerializerConfig dolphinEventSerializerConfig = new SerializerConfig().
                setImplementation(new EventStreamSerializer()).setTypeClass(DolphinEvent.class);

        clientConfig.getSerializationConfig().getSerializerConfigs().add(dolphinEventSerializerConfig);


        hazelcastInstance = HazelcastClient.newHazelcastClient(clientConfig);
    }
    return hazelcastInstance;
}
 
Example 3
Source File: KeyUtilsTest.java    From hazelcast-simulator with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void beforeClass() {
    Config config = new Config();
    config.setProperty("hazelcast.partition.count", "" + PARTITION_COUNT);

    hz = newHazelcastInstance(config);
    HazelcastInstance remoteInstance = newHazelcastInstance(config);
    warmupPartitions(hz);
    warmupPartitions(remoteInstance);

    ClientConfig clientconfig = new ClientConfig();
    clientconfig.setProperty("hazelcast.partition.count", "" + PARTITION_COUNT);

    client = HazelcastClient.newHazelcastClient(clientconfig);
}
 
Example 4
Source File: HazelcastConfiguration.java    From devicehive-java-server with Apache License 2.0 5 votes vote down vote up
@Bean
public HazelcastInstance hazelcast() throws Exception {
    ClientConfig clientConfig = new ClientConfig();
    clientConfig.getGroupConfig()
            .setName(groupName)
            .setPassword(groupPassword);
    clientConfig.getNetworkConfig()
            .setAddresses(clusterMembers);
    clientConfig.getSerializationConfig()
            .addPortableFactory(1, new DevicePortableFactory());
    clientConfig.setProperty("hazelcast.client.event.thread.count", eventThreadCount);

    return HazelcastClient.newHazelcastClient(clientConfig);
}
 
Example 5
Source File: Cluster.java    From OSPREY3 with GNU General Public License v2.0 4 votes vote down vote up
public Client(Parallelism parallelism) {

			this.parallelism = parallelism;

			this.name = String.format("%s-client-%d", Cluster.this.name, nodeId);

			// make a member first, if needed
			if (clientIsMember) {
				member = new Member(parallelism);
			} else {
				member = null;
			}

			// configure the cluster
			ClientConfig cfg = new ClientConfig();
			cfg.setClusterName(id);
			cfg.setInstanceName(name);

			// disable Hazelcast's automatic phone home "feature", which is on by default
			cfg.setProperty("hazelcast.phone.home.enabled", "false");

			log("node looking for cluster named %s ...", id);

			inst = HazelcastClient.newHazelcastClient(cfg);

			log("node started on cluster %s", id);

			activeId = new Value<>(inst, TasksActiveIdName);
			scatter = inst.getQueue(TasksScatterName);
			gather = inst.getQueue(TasksGatherName);

			listener = new Thread(() -> {
				try {
					while (listenerActive.get()) {

						// get the next task result, if any
						TaskResult<?> taskResult = gather.poll(400, TimeUnit.MILLISECONDS);
						if (taskResult != null) {

							// find the task for this result
							TaskAndListener<?,?> tal = tasks.get(taskResult.taskId);
							if (tal == null) {
								log("WARNING: received result for unknown task: %d", taskResult.taskId);
								continue;
							}

							try {

								// handle the task result
								if (taskResult.t != null) {
									taskFailure(tal.task, tal.listener, taskResult.t);
								} else {
									taskSuccessCoerceTypes(tal.task, tal.listener, taskResult.result);
								}

							} finally {
								// clean up the handled task
								tasks.remove(taskResult.taskId);
							}
						}
					}
				} catch (InterruptedException ex) {
					// exit the thread
				} catch (Throwable t) {
					t.printStackTrace(System.err);
				}
			});
			listener.setName("ClusterClientListener");
			listener.setDaemon(true);
			listener.start();
		}