![JAR search and dependency download from the Maven repository](/logo.png)
com.unbound.client.kmip.KMIPServer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of unbound-java-provider Show documentation
Show all versions of unbound-java-provider Show documentation
This is a collection of JAVA libraries that implement Unbound cryptographic classes for JAVA provider, PKCS11 wrapper, cryptoki, and advapi
package com.unbound.client.kmip;
import com.unbound.common.Log;
import java.net.URL;
import java.security.ProviderException;
import java.time.Clock;
import java.util.*;
class KMIPServer
{
private static final int CHECK_DISCONNECTED_TIMEOUT = 3000; // milliseconds
private static final Clock clock = Clock.systemUTC();
private static KMIPServer[] servers = null;
private static Random randomPicker = new Random();
private final URL url;
private final String name;
private long checkDisconnectedClock = 0;
//HashMap> connections = new HashMap<>();
public URL getUrl() { return url; }
private KMIPServer(String name)
{
Log log = Log.func("KMIPServer").log("Name", name).end(); try
{
this.name = name;
if (name.startsWith("https://"))
{
name = name.substring(8);
}
URL host = new URL("https://" + name);
int port = host.getPort();
if (port<=0) port = 443;
url = new URL("https", host.getHost(), port, "/kmip", null);
}
catch (Exception e) { log.failed(e); throw new ProviderException(e); } finally { log.leave(); }
}
static synchronized void initialize(String servers)
{
Log log = Log.func("KMIPServer.initialize").log("servers", servers).end(); try
{
initialize(servers.split(",")); // ep1,ep2,ep3
}
catch (Exception e) { log.failed(e); throw new ProviderException(e); } finally { log.leave(); }
}
static synchronized void initialize(String[] serverNames)
{
if (serverNames.length==0) throw new IllegalArgumentException("Server list is empty");
KMIPServer[] temp = new KMIPServer[serverNames.length];
int index = 0;
for (String name: serverNames)
{
temp[index++] = new KMIPServer(name.trim());
}
servers = temp;
}
/*private synchronized Connection getConnection(Partition partition)
{
Queue queue = connections.get(partition.name);
if (queue==null) return null;
return queue.poll();
}
private synchronized void releaseConnection(Connection connection)
{
String partitionName = connection.partition.name;
Queue queue = connections.get(partitionName);
if (queue==null)
{
queue = new ArrayDeque<>();
connections.put(partitionName, queue);
}
queue.add(connection);
}*/
static synchronized KMIPServer[] getList()
{
long now = clock.millis();
int count = 0;
for (KMIPServer server : servers)
{
if (now < server.checkDisconnectedClock + CHECK_DISCONNECTED_TIMEOUT) continue;
count++;
}
if (count==0)
{
KMIPServer server = servers[randomPicker.nextInt(servers.length)];
KMIPServer[] list = new KMIPServer[1];
list[0] = server;
return list;
}
KMIPServer[] list = new KMIPServer[count];
count = 0;
for (KMIPServer server : servers)
{
if (now < server.checkDisconnectedClock + CHECK_DISCONNECTED_TIMEOUT) continue;
list[count++] = server;
}
for (int i=0; i
© 2015 - 2025 Weber Informatics LLC | Privacy Policy