Search in sources :

Example 1 with OperationStatus

use of net.spy.memcached.ops.OperationStatus in project oxAuth by GluuFederation.

the class MemcacheManual method main.

public static void main(String[] args) throws IOException {
    final MemcachedClient client = createClients();
    final ExecutorService executorService = Executors.newFixedThreadPool(1000, daemonThreadFactory());
    int count = 10000;
    final long start = System.currentTimeMillis();
    for (int i = 0; i < count; i++) {
        final int key = i;
        executorService.execute(new Runnable() {

            @Override
            public void run() {
                // MemcachedClient client = clients.get(random);
                Object toPut = testGrant();
                // Object toPut = UUID.randomUUID().toString();
                OperationFuture<Boolean> set = null;
                for (int j = 0; j < 3; j++) {
                    set = client.set(Integer.toString(key), 60, toPut);
                }
                // block
                OperationStatus status = set.getStatus();
                System.out.println(" key: " + key + ", time: " + (new Date().getTime() - start) + "ms, set: " + status);
                executorService.execute(new Runnable() {

                    @Override
                    public void run() {
                        int random = random();
                        if (random % 3 == 0) {
                            try {
                                Thread.sleep(10000);
                            } catch (InterruptedException e) {
                                e.printStackTrace();
                            }
                        }
                        Object get = client.get(Integer.toString(key));
                        System.out.println("GET key: " + key + " result: " + get);
                    }
                });
            }
        });
    }
    sleep(40);
    // System.out.println(client.get("myKey"));
    //
    // client.set("myKey", 30, testState());
    //
    // sleep(12);
    // System.out.println(client.get("myKey"));
    //
    // sleep(12);
    // System.out.println(client.get("myKey"));
    client.shutdown();
}
Also used : MemcachedClient(net.spy.memcached.MemcachedClient) OperationStatus(net.spy.memcached.ops.OperationStatus) ExecutorService(java.util.concurrent.ExecutorService) OperationFuture(net.spy.memcached.internal.OperationFuture) Date(java.util.Date)

Example 2 with OperationStatus

use of net.spy.memcached.ops.OperationStatus in project oxCore by GluuFederation.

the class MemcachedProvider method put.

// it is so weird but we use as workaround "region" field to pass "expiration" for put operation
@Override
public void put(String expirationInSeconds, String key, Object object) {
    try {
        int expiration = putExpiration(expirationInSeconds);
        OperationFuture<Boolean> set = client.set(key, expiration, object);
        // block
        OperationStatus status = set.getStatus();
        log.trace("set - key:" + key + ", expiration: " + expiration + ", status:" + status + ", get:" + get(key));
    } catch (Exception e) {
        log.error("Failed to put object in cache, key: " + key, e);
    }
}
Also used : OperationStatus(net.spy.memcached.ops.OperationStatus)

Aggregations

OperationStatus (net.spy.memcached.ops.OperationStatus)2 Date (java.util.Date)1 ExecutorService (java.util.concurrent.ExecutorService)1 MemcachedClient (net.spy.memcached.MemcachedClient)1 OperationFuture (net.spy.memcached.internal.OperationFuture)1