use of com.aerospike.client.policy.ClientPolicy in project YCSB by brianfrankcooper.
the class AerospikeClient method init.
@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);
}
}
use of com.aerospike.client.policy.ClientPolicy in project gora by apache.
the class AerospikeStore method initialize.
/**
* {@inheritDoc}
* In initializing the aerospike datastore, read the mapping file, sets the basic
* aerospike specific parameters and creates the client with the user defined policies
*
* @param keyClass key class
* @param persistentClass persistent class
* @param properties properties
*/
@Override
public void initialize(Class<K> keyClass, Class<T> persistentClass, Properties properties) throws GoraException {
super.initialize(keyClass, persistentClass, properties);
try {
AerospikeMappingBuilder aerospikeMappingBuilder = new AerospikeMappingBuilder();
aerospikeMappingBuilder.readMappingFile(getConf().get(PARSE_MAPPING_FILE_KEY, DEFAULT_MAPPING_FILE), keyClass, persistentClass);
aerospikeParameters = new AerospikeParameters(aerospikeMappingBuilder.getAerospikeMapping(), properties, getConf());
ClientPolicy policy = new ClientPolicy();
policy.writePolicyDefault = aerospikeParameters.getAerospikeMapping().getWritePolicy();
policy.readPolicyDefault = aerospikeParameters.getAerospikeMapping().getReadPolicy();
// 'SendKey' property is enabled by default as the key is needed in query execution
policy.readPolicyDefault.sendKey = true;
policy.writePolicyDefault.sendKey = true;
// Set the credentials for servers with restricted access
if (aerospikeParameters.getUsername() != null) {
policy.user = aerospikeParameters.getUsername();
}
if (aerospikeParameters.getPassword() != null) {
policy.password = aerospikeParameters.getPassword();
}
aerospikeClient = new AerospikeClient(policy, aerospikeParameters.getHost(), aerospikeParameters.getPort());
aerospikeParameters.setServerSpecificParameters(aerospikeClient);
aerospikeParameters.validateServerBinConfiguration(persistentClass.getFields());
LOG.info("Aerospike Gora datastore initialized successfully.");
} catch (Exception e) {
throw new GoraException(e);
}
}
use of com.aerospike.client.policy.ClientPolicy in project aerospike-client-java by aerospike.
the class AsyncExample method runExamples.
/**
* Connect and run one or more asynchronous client examples.
*/
public static void runExamples(Console console, Parameters params, List<String> examples) throws Exception {
EventPolicy eventPolicy = new EventPolicy();
eventPolicy.maxCommandsInProcess = params.maxCommandsInProcess;
eventPolicy.maxCommandsInQueue = params.maxCommandsInQueue;
EventLoops eventLoops;
switch(params.eventLoopType) {
default:
case DIRECT_NIO:
{
eventLoops = new NioEventLoops(eventPolicy, 1);
break;
}
case NETTY_NIO:
{
EventLoopGroup group = new NioEventLoopGroup(1);
eventLoops = new NettyEventLoops(eventPolicy, group, params.eventLoopType);
break;
}
case NETTY_EPOLL:
{
EventLoopGroup group = new EpollEventLoopGroup(1);
eventLoops = new NettyEventLoops(eventPolicy, group, params.eventLoopType);
break;
}
case NETTY_KQUEUE:
{
EventLoopGroup group = new KQueueEventLoopGroup(1);
eventLoops = new NettyEventLoops(eventPolicy, group, params.eventLoopType);
break;
}
case NETTY_IOURING:
{
EventLoopGroup group = new IOUringEventLoopGroup(1);
eventLoops = new NettyEventLoops(eventPolicy, group, params.eventLoopType);
break;
}
}
try {
ClientPolicy policy = new ClientPolicy();
policy.eventLoops = eventLoops;
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 {
EventLoop eventLoop = eventLoops.get(0);
params.setServerSpecific(client);
for (String exampleName : examples) {
runExample(exampleName, client, eventLoop, params, console);
}
} finally {
client.close();
}
} finally {
eventLoops.close();
}
}
use of com.aerospike.client.policy.ClientPolicy in project aerospike-client-java by aerospike.
the class AerospikeServlet method initConnection.
private boolean initConnection(HttpServletRequest request, HttpServletResponse response) throws IOException {
String hostString = request.getParameter("host");
String portString = request.getParameter("port");
if (client != null && client.isConnected() && hostString != null && portString != null && host.equals(hostString) && Integer.toString(port).equals(portString))
return true;
host = hostString;
if (host == null || host.length() == 0) {
try {
host = getServletConfig().getInitParameter("clusterAddr").trim();
} catch (Exception e) {
host = "127.0.0.1";
}
}
if (portString == null || portString.length() == 0) {
try {
portString = getServletConfig().getInitParameter("clusterPort");
} catch (Exception e) {
portString = "3000";
}
}
try {
port = Integer.parseInt(portString);
} catch (Exception e) {
displayLoginError(response, host, portString, null);
return false;
}
try {
ClientPolicy policy = new ClientPolicy();
client = new AerospikeClient(policy, host, port);
if (client.isConnected())
return true;
displayLoginError(response, host, portString, null);
return false;
} catch (Exception ex) {
displayLoginError(response, host, portString, ex.getMessage());
return false;
}
}
use of com.aerospike.client.policy.ClientPolicy in project aerospike-client-java by aerospike.
the class SuiteSync method init.
@BeforeClass
public static void init() {
System.out.println("Begin AerospikeClient");
Args args = Args.Instance;
ClientPolicy policy = new ClientPolicy();
policy.user = args.user;
policy.password = args.password;
policy.authMode = args.authMode;
policy.tlsPolicy = args.tlsPolicy;
Host[] hosts = Host.parseHosts(args.host, args.port);
client = new AerospikeClient(policy, hosts);
try {
args.setServerSpecific(client);
} catch (RuntimeException re) {
client.close();
throw re;
}
}
Aggregations