use of io.atomix.primitive.proxy.PrimitiveProxy in project atomix by atomix.
the class IdGeneratorSessionIdService method start.
@Override
@SuppressWarnings("unchecked")
public CompletableFuture<SessionIdService> start() {
PrimitiveProxy proxy = partitions.getPartition(PRIMITIVE_NAME).getPrimitiveClient().newProxy(PRIMITIVE_NAME, AtomicIdGeneratorType.instance(), RaftProtocol.builder().withMinTimeout(Duration.ofMillis(250)).withMaxTimeout(Duration.ofSeconds(5)).withReadConsistency(ReadConsistency.LINEARIZABLE).withCommunicationStrategy(CommunicationStrategy.LEADER).withRecoveryStrategy(Recovery.RECOVER).withMaxRetries(5).build());
return proxy.connect().thenApply(v -> {
idGenerator = new DelegatingAtomicIdGenerator(new AtomicCounterProxy(proxy));
started.set(true);
return this;
});
}
use of io.atomix.primitive.proxy.PrimitiveProxy in project atomix by atomix.
the class RaftPerformanceTest method runIteration.
/**
* Runs a single performance test iteration, returning the iteration run time.
*/
@SuppressWarnings("unchecked")
private long runIteration() throws Exception {
reset();
createServers(3);
CompletableFuture<Void>[] futures = new CompletableFuture[NUM_CLIENTS];
RaftClient[] clients = new RaftClient[NUM_CLIENTS];
PrimitiveProxy[] proxies = new PrimitiveProxy[NUM_CLIENTS];
for (int i = 0; i < NUM_CLIENTS; i++) {
CompletableFuture<Void> future = new CompletableFuture<>();
clients[i] = createClient();
proxies[i] = createProxy(clients[i]).connect().join();
futures[i] = future;
}
long startTime = System.currentTimeMillis();
for (int i = 0; i < clients.length; i++) {
runProxy(proxies[i], futures[i]);
}
CompletableFuture.allOf(futures).join();
long endTime = System.currentTimeMillis();
long runTime = endTime - startTime;
System.out.println(String.format("readCount: %d/%d, writeCount: %d/%d, runTime: %dms", readCount.get(), TOTAL_OPERATIONS, writeCount.get(), TOTAL_OPERATIONS, runTime));
return runTime;
}
use of io.atomix.primitive.proxy.PrimitiveProxy in project atomix by atomix.
the class PrimaryBackupClient method newProxy.
@Override
@SuppressWarnings("unchecked")
public PrimitiveProxy newProxy(String primitiveName, PrimitiveType primitiveType, MultiPrimaryProtocol primitiveProtocol) {
Supplier<PrimitiveProxy> proxyBuilder = () -> new PrimaryBackupProxy(clientName, sessionIdService.nextSessionId().join(), primitiveType, new PrimitiveDescriptor(primitiveName, primitiveType.id(), primitiveProtocol.backups(), primitiveProtocol.replication()), clusterService, PrimaryBackupClient.this.protocol, primaryElection, threadContextFactory.createContext());
PrimitiveProxy proxy;
if (primitiveProtocol.recovery() == Recovery.RECOVER) {
proxy = new RecoveringPrimitiveProxy(clientName, primitiveName, primitiveType, proxyBuilder, threadContextFactory.createContext());
} else {
proxy = proxyBuilder.get();
}
// If max retries is set, wrap the client in a retrying proxy client.
if (primitiveProtocol.maxRetries() > 0) {
proxy = new RetryingPrimitiveProxy(proxy, threadContextFactory.createContext(), primitiveProtocol.maxRetries(), primitiveProtocol.retryDelay());
}
// Default the executor to use the configured thread pool executor and create a blocking aware proxy client.
Executor executor = primitiveProtocol.executor() != null ? primitiveProtocol.executor() : threadContextFactory.createContext();
return new BlockingAwarePrimitiveProxy(proxy, executor);
}
use of io.atomix.primitive.proxy.PrimitiveProxy in project atomix by atomix.
the class PrimaryBackupTest method testManyEvents.
/**
* Tests submitting a linearizable event that publishes to all sessions.
*/
private void testManyEvents(int nodes, int backups, Replication replication) throws Throwable {
createServers(nodes);
PrimaryBackupClient client = createClient();
PrimitiveProxy session = createProxy(client, backups, replication);
session.addEventListener(message -> {
threadAssertNotNull(message);
resume();
});
for (int i = 0; i < 10; i++) {
session.invoke(EVENT, SERIALIZER::encode, true).thenRun(this::resume);
await(5000, 2);
}
}
use of io.atomix.primitive.proxy.PrimitiveProxy in project atomix by atomix.
the class PrimaryBackupTest method testSubmitQuery.
/**
* Tests submitting a query with a configured consistency level.
*/
private void testSubmitQuery(int nodes, int backups, Replication replication) throws Throwable {
createServers(nodes);
PrimaryBackupClient client = createClient();
PrimitiveProxy session = createProxy(client, backups, replication);
session.invoke(READ).thenRun(this::resume);
await(5000);
}
Aggregations