@Override public void init() throws DBException { insertPolicy.recordExistsAction = RecordExistsAction.CREATE_ONLY; updatePolicy.recordExistsAction = RecordExistsAction.REPLACE_ONLY; Properties props = getProperties(); namespace = props.getProperty("as.namespace", DEFAULT_NAMESPACE); String host = props.getProperty("as.host", DEFAULT_HOST); String user = props.getProperty("as.user"); String password = props.getProperty("as.password"); int port = Integer.parseInt(props.getProperty("as.port", DEFAULT_PORT)); int timeout = Integer.parseInt(props.getProperty("as.timeout", DEFAULT_TIMEOUT)); readPolicy.timeout = timeout; insertPolicy.timeout = timeout; updatePolicy.timeout = timeout; deletePolicy.timeout = timeout; ClientPolicy clientPolicy = new ClientPolicy(); if (user != null && password != null) { clientPolicy.user = user; clientPolicy.password = password; } try { client = new com.aerospike.client.AerospikeClient(clientPolicy, host, port); } catch (AerospikeException e) { throw new DBException(String.format("Error while creating Aerospike " + "client for %s:%d.", host, port), e); } }
public static AerospikeHandler getInstance(String host, int port, int connections) { INSTANCE.host = host; INSTANCE.port = port; INSTANCE.count = connections / 300; if (connections % 300 > 0) INSTANCE.count++; for (int i=0;i<INSTANCE.count;i++) { AerospikeClient x = new AerospikeClient(host,port); INSTANCE.clients.add(x); } INSTANCE.count = INSTANCE.clients.size(); return INSTANCE; }
/** * Create connection with database. */ @Override public void connect() { try { client = new AerospikeClient(node, port); logger.debug("Aerospike connection Success"); } catch (AerospikeException ex) { throw new RuntimeException("closing database resource", ex); } catch (Throwable t) { DTThrowable.rethrow(t); } }
/** * Create connection with database. */ @Override public void connect() { try { client = new AerospikeClient(node, port); logger.debug("Aerospike connection Success"); } catch (AerospikeException ex) { throw new RuntimeException("closing database resource", ex); } catch (Throwable t) { DTThrowable.rethrow(t); } }
@Bean(name = "aerospikeClient", destroyMethod = "close") public AerospikeClient aerospikeClient() { Collection<Host> hosts = getHosts(); return new AerospikeClient(getClientPolicy(), hosts.toArray(new Host[hosts.size()])); }
public static void main(String args[]) throws Exception { AerospikeClient client = new AerospikeClient(args[0], 3000); String skey = "accountingsystem"; Key key = new Key("test", "cache", skey); while(true) { Record record = null; record = client.get(null, key); String value = (String)record.bins.get("value"); System.out.println(value); Thread.sleep(1000); } } }
/** * Let's test this mess. * @param args * @throws Exception */ public static void main(String args[]) throws Exception { AerospikeClient client = new AerospikeClient("localhost",3000); Membership m = new Membership("c1x-cookies", "/home/ben/Downloads/c1x_cookies.csv", client); System.out.println(m.query("9786B01215534DEB9AAC2D5FEE23A497")); } }
AerospikeClient x = new AerospikeClient(host,port); clients.add(x);
boolean range = false; AerospikeClient client = new AerospikeClient("localhost",3000);
private static AerospikeClient getAerospikeClient(CommandLine cl) { ClientPolicy clientPolicy = new ClientPolicy(); initClientPolicy(cl, clientPolicy); AerospikeClient client = new AerospikeClient(clientPolicy, params.hosts); if (!client.isConnected()) { log.error("Client is not able to connect:" + params.hosts); return null; } try { // Check read-write role is given to user. if (!client.queryUser(null, clientPolicy.user).roles.contains(Role.ReadWrite)) { log.error("User role:" + client.queryUser(null, clientPolicy.user).roles.toString() + " Expected:" + Role.ReadWrite); return null; } } catch (AerospikeException e) { // Ignore if security is not enabled. } return client; }
@Override protected boolean isReady() { String containerId = waitStrategyTarget.getContainerId(); log.debug("Check Aerospike container {} status", containerId); InspectContainerResponse containerInfo = waitStrategyTarget.getContainerInfo(); if (containerInfo == null) { log.debug("Aerospike container[{}] doesn't contain info. Abnormal situation, should not happen.", containerId); return false; } int port = getMappedPort(containerInfo.getNetworkSettings(), properties.port); String host = DockerClientFactory.instance().dockerHostIpAddress(); //TODO: Remove dependency to client https://www.aerospike.com/docs/tools/asmonitor/common_tasks.html try (AerospikeClient client = new AerospikeClient(host, port)) { return client.isConnected(); } catch (AerospikeException.Connection e) { log.debug("Aerospike container: {} not yet started. {}", containerId, e.getMessage()); } return false; }
/** * Connect and run one or more client examples. */ public static void runExamples(Console console, Parameters params, List<String> examples) throws Exception { ClientPolicy policy = new ClientPolicy(); policy.user = params.user; policy.password = params.password; policy.authMode = params.authMode; policy.tlsPolicy = params.tlsPolicy; params.policy = policy.readPolicyDefault; params.writePolicy = policy.writePolicyDefault; Host[] hosts = Host.parseHosts(params.host, params.port); AerospikeClient client = new AerospikeClient(policy, hosts); try { params.setServerSpecific(client); for (String exampleName : examples) { runExample(exampleName, client, params, console); } } finally { client.close(); } }
public void insertEventsInTable(int numEvents) { AerospikeClient client = null; try { client = new AerospikeClient(NODE, PORT); Key key; Bin bin; for (int i = 0; i < numEvents; i++) { key = new Key(NAMESPACE,SET_NAME,String.valueOf(i)); bin = new Bin("ID",i); client.put(null, key, bin); } } catch (AerospikeException e) { throw e; } finally { if (null != client) { client.close(); } } }
static long getNumOfEventsInStore() { AerospikeClient client = null; try { long count = 0; client = new AerospikeClient(NODE, PORT); Statement stmnt = new Statement(); stmnt.setNamespace(NAMESPACE); stmnt.setSetName(SET_NAME); RecordSet rs = client.query(null, stmnt); while (rs.next()) { count++; } return count; } catch (AerospikeException e) { LOG.error("getNumOfEventsInStore failed: {}", e); throw e; } finally { if (null != client) { client.close(); } } }
aerospikeClient = new AerospikeClient(policy, aerospikeParameters.getHost(), aerospikeParameters.getPort()); aerospikeParameters.setServerSpecificParameters(aerospikeClient);
AerospikeClient client = new AerospikeClient(policy, hosts);
aerospikeClient = new AerospikeClient(policy, aerospikeParameters.getHost(), aerospikeParameters.getPort()); aerospikeParameters.setServerSpecificParameters(aerospikeClient);
static void cleanMetaTable() { AerospikeClient client = null; try { client = new AerospikeClient(NODE, PORT); Statement stmnt = new Statement(); stmnt.setNamespace(NAMESPACE); stmnt.setSetName(AerospikeTransactionalStore.DEFAULT_META_SET); RecordSet rs = client.query(null, stmnt); while (rs.next()) { client.delete(null, rs.getKey()); } } catch (AerospikeException e) { LOG.error("cleanMetaTable failed: {}", e); throw e; } finally { if (null != client) { client.close(); } } }
static void cleanTable() { AerospikeClient client = null; try { client = new AerospikeClient(NODE, PORT); Statement stmnt = new Statement(); stmnt.setNamespace(NAMESPACE); stmnt.setSetName(SET_NAME); RecordSet rs = client.query(null, stmnt); while (rs.next()) { client.delete(null, rs.getKey()); } } catch (AerospikeException e) { LOG.error("cleanTable failed: {}", e); throw e; } finally { if (null != client) { client.close(); } } }
static boolean checkEvents() { long count = 0; AerospikeClient client = null; try { client = new AerospikeClient(NODE, PORT); Statement stmnt = new Statement(); stmnt.setNamespace(NAMESPACE); stmnt.setSetName(SET_NAME); RecordSet rs = client.query(null, stmnt); while ( rs.next() ) { Record record = rs.getRecord(); Key key = rs.getKey(); if (!TestPOJO.check(key, record)) { return false; } count++; } } catch (AerospikeException e) { throw new RuntimeException("Error fetching records: ", e); } finally { if (null != client) { client.close(); } } return NUM_TUPLES == count; }