Search in sources :

Example 21 with PrimitiveProxy

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;
    });
}
Also used : PrimitiveProxy(io.atomix.primitive.proxy.PrimitiveProxy) AtomicCounterProxy(io.atomix.core.counter.impl.AtomicCounterProxy)

Example 22 with PrimitiveProxy

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;
}
Also used : PrimitiveProxy(io.atomix.primitive.proxy.PrimitiveProxy) CompletableFuture(java.util.concurrent.CompletableFuture) Endpoint(io.atomix.messaging.Endpoint)

Example 23 with PrimitiveProxy

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);
}
Also used : BlockingAwarePrimitiveProxy(io.atomix.primitive.proxy.impl.BlockingAwarePrimitiveProxy) RetryingPrimitiveProxy(io.atomix.primitive.proxy.impl.RetryingPrimitiveProxy) RecoveringPrimitiveProxy(io.atomix.primitive.proxy.impl.RecoveringPrimitiveProxy) PrimitiveProxy(io.atomix.primitive.proxy.PrimitiveProxy) PrimaryBackupProxy(io.atomix.protocols.backup.proxy.PrimaryBackupProxy) Executor(java.util.concurrent.Executor) BlockingAwarePrimitiveProxy(io.atomix.primitive.proxy.impl.BlockingAwarePrimitiveProxy) PrimitiveDescriptor(io.atomix.protocols.backup.protocol.PrimitiveDescriptor) RecoveringPrimitiveProxy(io.atomix.primitive.proxy.impl.RecoveringPrimitiveProxy) RetryingPrimitiveProxy(io.atomix.primitive.proxy.impl.RetryingPrimitiveProxy)

Example 24 with PrimitiveProxy

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);
    }
}
Also used : PrimitiveProxy(io.atomix.primitive.proxy.PrimitiveProxy)

Example 25 with PrimitiveProxy

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);
}
Also used : PrimitiveProxy(io.atomix.primitive.proxy.PrimitiveProxy)

Aggregations

PrimitiveProxy (io.atomix.primitive.proxy.PrimitiveProxy)35 AtomicLong (java.util.concurrent.atomic.AtomicLong)5 Test (org.junit.Test)4 Endpoint (io.atomix.messaging.Endpoint)2 BlockingAwarePrimitiveProxy (io.atomix.primitive.proxy.impl.BlockingAwarePrimitiveProxy)2 RecoveringPrimitiveProxy (io.atomix.primitive.proxy.impl.RecoveringPrimitiveProxy)2 RetryingPrimitiveProxy (io.atomix.primitive.proxy.impl.RetryingPrimitiveProxy)2 Executor (java.util.concurrent.Executor)2 AtomicCounterProxy (io.atomix.core.counter.impl.AtomicCounterProxy)1 PrimitiveDescriptor (io.atomix.protocols.backup.protocol.PrimitiveDescriptor)1 PrimaryBackupProxy (io.atomix.protocols.backup.proxy.PrimaryBackupProxy)1 DefaultRaftProxy (io.atomix.protocols.raft.proxy.impl.DefaultRaftProxy)1 Scheduler (io.atomix.utils.concurrent.Scheduler)1 SingleThreadContext (io.atomix.utils.concurrent.SingleThreadContext)1 ThreadContext (io.atomix.utils.concurrent.ThreadContext)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ExecutionException (java.util.concurrent.ExecutionException)1