Skip to content
This repository has been archived by the owner on May 10, 2022. It is now read-only.

feat: support create client with Proprities object #166

Merged
merged 2 commits into from
Aug 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import com.xiaomi.infra.pegasus.security.Credential;
import java.time.Duration;
import java.util.Properties;
import org.apache.commons.configuration2.Configuration;
import org.apache.commons.configuration2.ConfigurationConverter;

Expand Down Expand Up @@ -131,9 +132,17 @@ public static ClientOptions create() {
return builder().build();
}

public static ClientOptions create(Properties properties) throws PException {
Configuration config = ConfigurationConverter.getConfiguration(properties);
return create(config);
}

public static ClientOptions create(String configPath) throws PException {
Configuration config = ConfigurationConverter.getConfiguration(loadConfiguration(configPath));
return create(config);
}

private static ClientOptions create(Configuration config) throws PException {
String metaList = config.getString(PEGASUS_META_SERVERS_KEY);
if (metaList == null) {
throw new IllegalArgumentException("no property set: " + PEGASUS_META_SERVERS_KEY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.nio.ByteBuffer;
import java.util.Arrays;
import java.util.List;
import java.util.Properties;
import java.util.concurrent.ConcurrentHashMap;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.Validate;
Expand Down Expand Up @@ -67,6 +68,10 @@ private PegasusTable getTable(String tableName, InternalTableOptions internalTab
return table;
}

public PegasusClient(Properties properties) throws PException {
this(ClientOptions.create(properties));
}

// configPath could be:
// - zk path: zk://host1:port1,host2:port2,host3:port3/path/to/config
// - local file path: file:///path/to/config
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// can be found in the LICENSE file in the root directory of this source tree.
package com.xiaomi.infra.pegasus.client;

import java.util.Properties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -35,6 +36,17 @@ public static PegasusClientInterface createClient(String configPath) throws PExc
return new PegasusClient(configPath);
}

/**
* Create a client instance. After used, should call client.close() to release resource.
*
* @param properties properties
* @return PegasusClientInterface {@link PegasusClientInterface}
* @throws PException throws exception if any error occurs.
*/
public static PegasusClientInterface createClient(Properties properties) throws PException {
return new PegasusClient(properties);
}

/**
* Create a client instance instance with {@link ClientOptions}. After used, should call
* client.close() to release resource.
Expand Down Expand Up @@ -94,6 +106,18 @@ public static PegasusClientInterface getSingletonClient(String configPath) throw
}
}

/**
* Get the singleton client instance with properties. After used, should call
* PegasusClientFactory.closeSingletonClient() to release resource.
*
* @param properties properties
* @return PegasusClientInterface {@link PegasusClientInterface}
* @throws PException throws exception if any error occurs.
*/
public static PegasusClientInterface getSingletonClient(Properties properties) throws PException {
return getSingletonClient(ClientOptions.create(properties));
}

/**
* Get the singleton client instance instance with {@link ClientOptions}. After used, should call
* PegasusClientFactory.closeSingletonClient() to release resource.
Expand Down