Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplifying Native Java client instantiation #93

Closed
hazelcast opened this issue Mar 23, 2012 · 0 comments

Comments

Projects
None yet
2 participants
@ghost
Copy link
Collaborator

commented Mar 23, 2012

It will be wery nice to have possibilities to instantiate native client from java.util.Properties and/or from classpath-located config file.

Our current client instantiation code:
private HazelcastInstance createClient() {
String hosts = configurationService.getString(HazelcastClientParameters.P_HOSTS, HazelcastClientParameters.DEFAULT_HOST);
String[] addresses = hosts.split(",|;");

    ClientConfig config = new ClientConfig();

    config.setGroupConfig(new GroupConfig(
            configurationService.getString(GROUP_NAME.getName(), GROUP_NAME.getDefaultValue()),
            configurationService.getString(GROUP_PASSWORD.getName(), GROUP_PASSWORD.getDefaultValue())
    ));

    config.setAddresses(Arrays.asList(addresses));

    config.setInitialConnectionAttemptLimit(
            configurationService.getInt(INIT_CONNECTION_ATTEMPTS_LIMIT.getName(), Integer.valueOf(INIT_CONNECTION_ATTEMPTS_LIMIT.getDefaultValue()))
    );

    config.setConnectionTimeout(
            configurationService.getInt(CONNECTION_TIMEOUT.getName(), Integer.valueOf(CONNECTION_TIMEOUT.getDefaultValue()))
    );
    config.setReconnectionAttemptLimit(
            configurationService.getInt(RECONNECTION_ATTEMPTS_LIMIT.getName(), Integer.valueOf(RECONNECTION_ATTEMPTS_LIMIT.getDefaultValue()))
    );
    config.setReConnectionTimeOut(
            configurationService.getInt(RECONNECTION_TIMEOUT.getName(), Integer.valueOf(RECONNECTION_TIMEOUT.getDefaultValue()))
    );

    config.setShuffle(
            configurationService.getBoolean(HazelcastClientParameters.P_SHUFFLE, Boolean.valueOf(HazelcastClientParameters.DEFAULT_SHUFFLE))
    );

    config.setUpdateAutomatic(false);
    return HazelcastClient.newHazelcastClient(config);
}

I think something like this will be much better:
    private HazelcastInstance createClient() {
      return HazelcastClient.newHazelcastClient("./conf/hazelcast-client.xml");
    }

or with Guice with Properties loaded from file and binded:

@Inject
private HazelcastInstance createClient(@nAmed("hazelcast-client-config) Properties properties) {
return HazelcastClient.newHazelcastClient(properties);
}

Our current self-made hazelcast-client.conf:

hazelcast.client.hosts=0.0.0.0:5701
hazelcast.client.group.name=dev
hazelcast.client.group.password=dev-pass
hazelcast.client.init.connection.attempts.limit=5
hazelcast.client.reconnection.attempts.limit=5
hazelcast.client.connection.timeout=300000
hazelcast.client.reconnection.timeout=5000
hazelcast.client.shuffle=false
system.hazelcast.logging.type=slf4j

It uses standard properties, except hazelcast.client.hosts.

Migrated from http://code.google.com/p/hazelcast/issues/detail?id=821

@mdogan mdogan closed this in 32ca918 May 14, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.