本文整理汇总了Java中com.aerospike.client.Host类的典型用法代码示例。如果您正苦于以下问题:Java Host类的具体用法?Java Host怎么用?Java Host使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Host类属于com.aerospike.client包,在下文中一共展示了Host类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: init
import com.aerospike.client.Host; //导入依赖的package包/类
/**
* initialize and validate configuration options
*
* @param context
* @param issues
*/
public void init(Target.Context context, List<Target.ConfigIssue> issues) {
List<Host> hosts = getAerospikeHosts(issues, connectionString, Groups.AEROSPIKE.getLabel(), "aerospikeBeanConfig.connectionString", context);
ClientPolicy cp = new ClientPolicy();
try {
client = new AerospikeClient(cp, hosts.toArray(new Host[hosts.size()]));
int retries = 0;
while (!client.isConnected() && retries <= maxRetries) {
if (retries > maxRetries) {
issues.add(context.createConfigIssue(Groups.AEROSPIKE.getLabel(), "aerospikeBeanConfig.connectionString", AerospikeErrors.AEROSPIKE_03, connectionString));
return;
}
retries++;
try {
Thread.sleep(100);
} catch (InterruptedException ignored) {
}
}
} catch (AerospikeException ex) {
issues.add(context.createConfigIssue(Groups.AEROSPIKE.getLabel(), "aerospikeBeanConfig.connectionString", AerospikeErrors.AEROSPIKE_03, connectionString));
}
}
示例2: refresh
import com.aerospike.client.Host; //导入依赖的package包/类
/**
* Request current status from server node.
*
* @param friends other nodes in the cluster, populated by this method
* @throws Exception if status request fails
*/
public final void refresh(List<Host> friends) throws Exception {
Connection conn = getConnection(1000);
try {
HashMap<String,String> infoMap = Info.request(conn, "node", "partition-generation", "services");
verifyNodeName(infoMap);
restoreHealth();
responded = true;
addFriends(infoMap, friends);
updatePartitions(conn, infoMap);
putConnection(conn);
}
catch (Exception e) {
conn.close();
decreaseHealth();
throw e;
}
}
示例3: addSeeds
import com.aerospike.client.Host; //导入依赖的package包/类
public final void addSeeds(Host[] hosts) {
// Use copy on write semantics.
Host[] seedArray = new Host[seeds.length + hosts.length];
int count = 0;
// Add existing seeds.
for (Host seed : seeds) {
seedArray[count++] = seed;
}
// Add new seeds
for (Host host : hosts) {
if (Log.debugEnabled()) {
Log.debug("Add seed " + host);
}
seedArray[count++] = host;
}
// Replace nodes with copy.
seeds = seedArray;
}
示例4: removeNodes
import com.aerospike.client.Host; //导入依赖的package包/类
private final void removeNodes(List<Node> nodesToRemove) {
// There is no need to delete nodes from partitionWriteMap because the nodes
// have already been set to inactive. Further connection requests will result
// in an exception and a different node will be tried.
// Cleanup node resources.
for (Node node : nodesToRemove) {
// Remove node's aliases from cluster alias set.
// Aliases are only used in tend thread, so synchronization is not necessary.
for (Host alias : node.getAliases()) {
// Log.debug("Remove alias " + alias);
aliases.remove(alias);
}
node.close();
}
// Remove all nodes at once to avoid copying entire array multiple times.
removeNodesCopy(nodesToRemove);
}
示例5: AsyncCluster
import com.aerospike.client.Host; //导入依赖的package包/类
public AsyncCluster(AsyncClientPolicy policy, Host[] hosts) throws AerospikeException {
super(policy, hosts);
maxCommands = policy.asyncMaxCommands;
switch (policy.asyncMaxCommandAction) {
case ACCEPT:
bufferQueue = new AcceptBufferQueue();
break;
case REJECT:
bufferQueue = new RejectBufferQueue(maxCommands);
break;
case BLOCK:
default:
bufferQueue = new BlockBufferQueue(maxCommands);
break;
}
selectorManagers = new SelectorManagers(policy);
initTendThread();
}
示例6: getAliases
import com.aerospike.client.Host; //导入依赖的package包/类
private List<Host> getAliases(Host host) {
InetAddress[] addresses;
try {
addresses = InetAddress.getAllByName(host.name);
}
catch (UnknownHostException uhe) {
throw new AerospikeException.Connection("Invalid host: " + host);
}
if (addresses.length == 0) {
throw new AerospikeException.Connection("Failed to find addresses for " + host);
}
// Add capacity for current address aliases plus IPV6 address and hostname.
List<Host> aliases = new ArrayList<Host>(addresses.length + 2);
for (InetAddress address : addresses) {
aliases.add(new Host(address.getHostAddress(), host.tlsName, host.port));
}
return aliases;
}
示例7: getSfy
import com.aerospike.client.Host; //导入依赖的package包/类
/**
* This method brings Spikefy service up to speed
* ... can be called multiple times
* ... but will execute only once (and once it should be enough)
*/
public Spikeify getSfy() {
if (SpikeifyService.getClient() == null) {
log.info("Starting Aerospike initialization...");
Map<String, Integer> hosts;
log.info("--== LOCALHOST ==--");
hosts = new HashMap<>();
hosts.put(DEFAULT_HOST, DEFAULT_PORT);
String namespace = DEFAULT_NAMESPACE;
log.info("Aerospike default namespace: " + namespace);
List<Host> hostsData = hosts.entrySet().stream().map(stringIntegerEntry -> new Host(stringIntegerEntry.getKey(), stringIntegerEntry.getValue())).collect(Collectors.toList());
SpikeifyService.globalConfig(namespace, hostsData.toArray(new Host[hostsData.size()]));
log.info("Aerospike configured.");
log.info("Creating indexes...");
SpikeifyService.register(FileSegment.class);
/*SpikeifyService.getClient().createIndex(new Policy(), namespace, File.class.getSimpleName(), "fileName", "fileName", IndexType.STRING);
SpikeifyService.getClient().createIndex(new Policy(), namespace, FileLock.class.getSimpleName(), "lockName", "lockName", IndexType.STRING);
*/
log.info("End of creating indexes.");
}
return SpikeifyService.sfy();
}
示例8: validateConnectionString
import com.aerospike.client.Host; //导入依赖的package包/类
public List<Host> validateConnectionString(
List<Stage.ConfigIssue> issues,
String connectionString,
String configGroupName,
String configName,
Stage.Context context
) {
List<Host> clusterNodesList = new ArrayList<>();
if (connectionString == null || connectionString.isEmpty()) {
issues.add(context.createConfigIssue(configGroupName, configName,
AerospikeErrors.AEROSPIKE_01, configName));
} else {
String[] nodes = connectionString.split(",");
for (String node : nodes) {
try {
HostAndPort hostAndPort = HostAndPort.fromString(node);
if(!hostAndPort.hasPort() || hostAndPort.getPort() < 0) {
issues.add(context.createConfigIssue(configGroupName, configName, AerospikeErrors.AEROSPIKE_02, connectionString));
} else {
clusterNodesList.add(new Host(hostAndPort.getHostText(), hostAndPort.getPort()));
}
} catch (IllegalArgumentException e) {
issues.add(context.createConfigIssue(configGroupName, configName, AerospikeErrors.AEROSPIKE_02, connectionString));
}
}
}
return clusterNodesList;
}
示例9: getAerospikeHosts
import com.aerospike.client.Host; //导入依赖的package包/类
public static List<Host> getAerospikeHosts(
List<Target.ConfigIssue> issues,
List<String> connectionString,
String configGroupName,
String configName,
Target.Context context
) {
List<Host> clusterNodesList = new ArrayList<>();
if (connectionString == null || connectionString.isEmpty()) {
issues.add(context.createConfigIssue(configGroupName, configName,
AerospikeErrors.AEROSPIKE_01, configName));
} else {
for (String node : connectionString) {
try {
HostAndPort hostAndPort = HostAndPort.fromString(node);
if (!hostAndPort.hasPort() || hostAndPort.getPort() < 0) {
issues.add(context.createConfigIssue(configGroupName, configName, AerospikeErrors.AEROSPIKE_02, connectionString));
} else {
clusterNodesList.add(new Host(hostAndPort.getHostText(), hostAndPort.getPort()));
}
} catch (IllegalArgumentException e) {
issues.add(context.createConfigIssue(configGroupName, configName, AerospikeErrors.AEROSPIKE_02, connectionString));
}
}
}
return clusterNodesList;
}
示例10: getAerospikeHosts
import com.aerospike.client.Host; //导入依赖的package包/类
public Host[] getAerospikeHosts() {
String[] hostsCluster = readTextProperty(AEROSPIKE_HOSTS).split(",");
Host[] hosts = new Host[hostsCluster.length];
for (int i = 0; i < hostsCluster.length; i++) {
String[] nodeConfig = hostsCluster[i].split(":");
hosts[i] = new Host(nodeConfig[0], Integer.parseInt(nodeConfig[1]));
}
return hosts;
}
示例11: setAliases
import com.aerospike.client.Host; //导入依赖的package包/类
private void setAliases(Host host) throws AerospikeException {
try {
InetAddress[] addresses = InetAddress.getAllByName(host.name);
int count = 0;
aliases = new Host[addresses.length];
for (InetAddress address : addresses) {
aliases[count++] = new Host(address.getHostAddress(), host.port);
}
}
catch (UnknownHostException uhe) {
throw new AerospikeException.Connection("Invalid host: " + host);
}
}
示例12: addFriends
import com.aerospike.client.Host; //导入依赖的package包/类
private final void addFriends(HashMap <String,String> infoMap, List<Host> friends) throws AerospikeException {
// Parse the service addresses and add the friends to the list.
String friendString = infoMap.get("services");
if (friendString == null || friendString.length() == 0) {
return;
}
String friendNames[] = friendString.split(";");
for (String friend : friendNames) {
String friendInfo[] = friend.split(":");
String host = friendInfo[0];
int port = Integer.parseInt(friendInfo[1]);
Host alias = new Host(host, port);
Node node = cluster.findAlias(alias);
if (node != null) {
node.referenceCount++;
}
else {
if (! findAlias(friends, alias)) {
friends.add(alias);
}
}
}
}
示例13: findAlias
import com.aerospike.client.Host; //导入依赖的package包/类
private final static boolean findAlias(List<Host> friends, Host alias) {
for (Host host : friends) {
if (host.equals(alias)) {
return true;
}
}
return false;
}
示例14: addAlias
import com.aerospike.client.Host; //导入依赖的package包/类
/**
* Add node alias to list.
*/
public final void addAlias(Host aliasToAdd) {
// Aliases are only referenced in the cluster tend thread,
// so synchronization is not necessary.
Host[] tmpAliases = new Host[aliases.length + 1];
int count = 0;
for (Host host : aliases) {
tmpAliases[count++] = host;
}
tmpAliases[count] = aliasToAdd;
aliases = tmpAliases;
}
示例15: Cluster
import com.aerospike.client.Host; //导入依赖的package包/类
public Cluster(ClientPolicy policy, Host[] hosts) throws AerospikeException {
this.seeds = hosts;
connectionQueueSize = policy.maxThreads + 1; // Add one connection for tend thread.
connectionTimeout = policy.timeout;
maxSocketIdle = policy.maxSocketIdle;
if (policy.threadPool == null) {
// Create cached thread pool with daemon threads.
// Daemon threads automatically terminate when the program terminates.
threadPool = Executors.newCachedThreadPool(new ThreadFactory() {
public final Thread newThread(Runnable runnable) {
Thread thread = new Thread(runnable);
thread.setDaemon(true);
return thread;
}
});
}
else {
threadPool = policy.threadPool;
}
sharedThreadPool = policy.sharedThreadPool;
aliases = new HashMap<Host,Node>();
nodes = new Node[0];
partitionWriteMap = new HashMap<String,AtomicReferenceArray<Node>>();
nodeIndex = new AtomicInteger();
}