net.spy.memcached.ops.Operation Java Examples

The following examples show how to use net.spy.memcached.ops.Operation. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EVCacheNodeImpl.java    From EVCache with Apache License 2.0 6 votes vote down vote up
public EVCacheNodeImpl(SocketAddress sa, SocketChannel c, int bufSize, BlockingQueue<Operation> rq, BlockingQueue<Operation> wq, BlockingQueue<Operation> iq,
            long opQueueMaxBlockTimeMillis, boolean waitForAuth, long dt, long at, ConnectionFactory fa, EVCacheClient client, long stTime) {
        super(sa, c, bufSize, rq, wq, iq, Long.valueOf(opQueueMaxBlockTimeMillis), waitForAuth, dt, at, fa);

        this.client = client;
        final String appName = client.getAppName();
        this.readQ = rq;
        this.inputQueue = iq;
        this.hostName = ((InetSocketAddress) getSocketAddress()).getHostName();
//        final List<Tag> tagsCounter = new ArrayList<Tag>(5);
//        tagsCounter.add(new BasicTag(EVCacheMetricsFactory.CACHE, client.getAppName()));
//        tagsCounter.add(new BasicTag(EVCacheMetricsFactory.SERVERGROUP, client.getServerGroupName()));
//        tagsCounter.add(new BasicTag(EVCacheMetricsFactory.ZONE, client.getZone()));
        //tagsCounter.add(new BasicTag(EVCacheMetricsFactory.HOST, hostName)); //TODO : enable this and see what is the impact
        this.operationsCounter = client.getOperationCounter();

        setConnectTime(stTime);
        setupMonitoring(appName);
    }
 
Example #2
Source File: EVCacheMemcachedClient.java    From EVCache with Apache License 2.0 6 votes vote down vote up
public <T> OperationFuture<Boolean> touch(final String key, final int exp, EVCacheLatch evcacheLatch) {
    final CountDownLatch latch = new CountDownLatch(1);
    final EVCacheOperationFuture<Boolean> rv = new EVCacheOperationFuture<Boolean>(key, latch, new AtomicReference<Boolean>(null), operationTimeout, executorService, client);
    final Operation op = opFact.touch(key, exp, new OperationCallback() {
        @Override
        public void receivedStatus(OperationStatus status) {
            rv.set(status.isSuccess(), status);
        }

        @Override
        public void complete() {
            latch.countDown();
            final String host = ((rv.getStatus().getStatusCode().equals(StatusCode.TIMEDOUT) && rv.getOperation() != null) ? getHostName(rv.getOperation().getHandlingNode().getSocketAddress()) : null);
            getTimer(EVCacheMetricsFactory.TOUCH_OPERATION, EVCacheMetricsFactory.WRITE, rv.getStatus(), null, host, getWriteMetricMaxValue()).record((System.currentTimeMillis() - rv.getStartTime()), TimeUnit.MILLISECONDS);
            rv.signalComplete();
        }
    });
    rv.setOperation(op);
    if (evcacheLatch != null && evcacheLatch instanceof EVCacheLatchImpl && !client.isInWriteOnly()) ((EVCacheLatchImpl) evcacheLatch).addFuture(rv);
    mconn.enqueueOperation(key, op);
    return rv;
}
 
Example #3
Source File: TCPMemcachedNodeImpl.java    From kylin with Apache License 2.0 6 votes vote down vote up
private Operation getNextWritableOp() {
    Operation o = getCurrentWriteOp();
    while (o != null && o.getState() == OperationState.WRITE_QUEUED) {
        synchronized (o) {
            if (o.isCancelled()) {
                getLogger().debug("Not writing cancelled op.");
                Operation cancelledOp = removeCurrentWriteOp();
                assert o == cancelledOp;
            } else if (o.isTimedOut(defaultOpTimeout)) {
                getLogger().debug("Not writing timed out op.");
                Operation timedOutOp = removeCurrentWriteOp();
                assert o == timedOutOp;
            } else {
                o.writing();
                if (!(o instanceof TapAckOperationImpl)) {
                    readQ.add(o);
                }
                return o;
            }
            o = getCurrentWriteOp();
        }
    }
    return o;
}
 
Example #4
Source File: TCPMemcachedNodeImpl.java    From kylin with Apache License 2.0 5 votes vote down vote up
public final void copyInputQueue() {
    Collection<Operation> tmp = new ArrayList<Operation>();

    // don't drain more than we have space to place
    inputQueue.drainTo(tmp, writeQ.remainingCapacity());
    writeQ.addAll(tmp);
}
 
Example #5
Source File: TCPMemcachedNodeImpl.java    From kylin with Apache License 2.0 5 votes vote down vote up
public final void setupForAuth() {
    if (shouldAuth) {
        authLatch = new CountDownLatch(1);
        if (inputQueue.size() > 0) {
            reconnectBlocked = new ArrayList<Operation>(inputQueue.size() + 1);
            inputQueue.drainTo(reconnectBlocked);
        }
        assert (inputQueue.size() == 0);
        setupResend();
    } else {
        authLatch = new CountDownLatch(0);
    }
}
 
Example #6
Source File: EVCacheAsciiNodeImpl.java    From EVCache with Apache License 2.0 5 votes vote down vote up
public EVCacheAsciiNodeImpl(SocketAddress sa, SocketChannel c, int bufSize, BlockingQueue<Operation> rq, BlockingQueue<Operation> wq, BlockingQueue<Operation> iq,
        long opQueueMaxBlockTimeMillis, boolean waitForAuth, long dt, long at, ConnectionFactory fa, EVCacheClient client, long stTime) {
  // ASCII never does auth
  super(sa, c, bufSize, rq, wq, iq, opQueueMaxBlockTimeMillis, false, dt, at, fa);
  this.client = client;
  final String appName = client.getAppName();
  this.readQ = rq;
  this.inputQueue = iq;
  this.hostName = ((InetSocketAddress) getSocketAddress()).getHostName();
  this.operationsCounter = client.getOperationCounter();
  setConnectTime(stTime);
  setupMonitoring(appName);
}
 
Example #7
Source File: TCPMemcachedNodeImpl.java    From kylin with Apache License 2.0 5 votes vote down vote up
public final void addOp(Operation op) {
    try {
        if (!authLatch.await(authWaitTime, TimeUnit.MILLISECONDS)) {
            FailureMode mode = connectionFactory.getFailureMode();
            if (mode == FailureMode.Redistribute || mode == FailureMode.Retry) {
                getLogger().debug("Redistributing Operation " + op + " because auth " + "latch taken longer than "
                        + authWaitTime + " milliseconds to " + "complete on node " + getSocketAddress());
                connection.retryOperation(op);
            } else {
                op.cancel();
                getLogger().warn("Operation canceled because authentication "
                        + "or reconnection and authentication has " + "taken more than " + authWaitTime
                        + " milliseconds to " + "complete on node " + this);
                getLogger().debug("Canceled operation %s", op.toString());
            }
            return;
        }
        if (!inputQueue.offer(op, opQueueMaxBlockTime, TimeUnit.MILLISECONDS)) {
            throw new IllegalStateException(
                    "Timed out waiting to add " + op + "(max wait=" + opQueueMaxBlockTime + "ms)");
        }
    } catch (InterruptedException e) {
        // Restore the interrupted status
        Thread.currentThread().interrupt();
        throw new IllegalStateException("Interrupted while waiting to add " + op);
    }
}
 
Example #8
Source File: TCPMemcachedNodeImpl.java    From kylin with Apache License 2.0 5 votes vote down vote up
public final Operation removeCurrentWriteOp() {
    Operation rv = optimizedOp;
    if (rv == null) {
        rv = writeQ.remove();
    } else {
        optimizedOp = null;
    }
    return rv;
}
 
Example #9
Source File: EVCacheMemcachedClient.java    From EVCache with Apache License 2.0 5 votes vote down vote up
public <T> EVCacheOperationFuture<CASValue<T>> asyncGetAndTouch(final String key, final int exp, final Transcoder<T> tc) {
    final CountDownLatch latch = new CountDownLatch(1);
    final EVCacheOperationFuture<CASValue<T>> rv = new EVCacheOperationFuture<CASValue<T>>(key, latch, new AtomicReference<CASValue<T>>(null), operationTimeout, executorService, client);
    Operation op = opFact.getAndTouch(key, exp, new GetAndTouchOperation.Callback() {
        private CASValue<T> val = null;

        public void receivedStatus(OperationStatus status) {
            if (log.isDebugEnabled()) log.debug("GetAndTouch Key : " + key + "; Status : " + status.getStatusCode().name()
                    + (log.isTraceEnabled() ?  " Node : " + getEVCacheNode(key) : "")
                    + "; Message : " + status.getMessage() + "; Elapsed Time - " + (System.currentTimeMillis() - rv.getStartTime()));
            rv.set(val, status);
        }

        public void complete() {
            latch.countDown();
            final String host = ((rv.getStatus().getStatusCode().equals(StatusCode.TIMEDOUT) && rv.getOperation() != null) ? getHostName(rv.getOperation().getHandlingNode().getSocketAddress()) : null);
            getTimer(EVCacheMetricsFactory.GET_AND_TOUCH_OPERATION, EVCacheMetricsFactory.READ, rv.getStatus(), (val != null ? EVCacheMetricsFactory.YES : EVCacheMetricsFactory.NO), host, getReadMetricMaxValue()).record((System.currentTimeMillis() - rv.getStartTime()), TimeUnit.MILLISECONDS);
            rv.signalComplete();
        }

        public void gotData(String k, int flags, long cas, byte[] data) {
            if (!key.equals(k)) log.warn("Wrong key returned. Key - " + key + "; Returned Key " + k);
            if (data != null) getDataSizeDistributionSummary(EVCacheMetricsFactory.GET_AND_TOUCH_OPERATION, EVCacheMetricsFactory.READ, EVCacheMetricsFactory.IPC_SIZE_INBOUND).record(data.length);
            val = new CASValue<T>(cas, tc.decode(new CachedData(flags, data, tc.getMaxSize())));
        }
    });
    rv.setOperation(op);
    mconn.enqueueOperation(key, op);
    return rv;
}
 
Example #10
Source File: TCPMemcachedNodeImpl.java    From kylin with Apache License 2.0 5 votes vote down vote up
private boolean preparePending() {
    // Copy the input queue into the write queue.
    copyInputQueue();

    // Now check the ops
    Operation nextOp = getCurrentWriteOp();
    while (nextOp != null && nextOp.isCancelled()) {
        getLogger().info("Removing cancelled operation: %s", nextOp);
        removeCurrentWriteOp();
        nextOp = getCurrentWriteOp();
    }
    return nextOp != null;
}
 
Example #11
Source File: TCPMemcachedNodeImpl.java    From kylin with Apache License 2.0 5 votes vote down vote up
public final void setupResend() {
    // First, reset the current write op, or cancel it if we should
    // be authenticating
    Operation op = getCurrentWriteOp();
    if (shouldAuth && op != null) {
        op.cancel();
    } else if (op != null) {
        ByteBuffer buf = op.getBuffer();
        if (buf != null) {
            buf.reset();
        } else {
            getLogger().info("No buffer for current write op, removing");
            removeCurrentWriteOp();
        }
    }
    // Now cancel all the pending read operations. Might be better to
    // to requeue them.
    while (hasReadOp()) {
        op = removeCurrentReadOp();
        if (op != getCurrentWriteOp()) {
            getLogger().warn("Discarding partially completed op: %s", op);
            op.cancel();
        }
    }

    while (shouldAuth && hasWriteOp()) {
        op = removeCurrentWriteOp();
        getLogger().warn("Discarding partially completed op: %s", op);
        op.cancel();
    }

    getWbuf().clear();
    getRbuf().clear();
    toWrite = 0;
}
 
Example #12
Source File: FutureGetInterceptor.java    From pinpoint with Apache License 2.0 5 votes vote down vote up
@Override
protected void doInAfterTrace(SpanEventRecorder recorder, Object target, Object[] args, Object result, Throwable throwable) {
    recorder.recordApi(methodDescriptor);
    recorder.recordDestinationId("MEMCACHED");
    recorder.recordServiceType(ArcusConstants.MEMCACHED_FUTURE_GET);

    if (!(target instanceof OperationAccessor)) {
        logger.info("operation not found");
        return;
    }

    // find the target node
    final Operation op = ((OperationAccessor) target)._$PINPOINT$_getOperation();
    if (op == null) {
        logger.info("operation is null");
        return;
    }

    recorder.recordException(op.getException());

    final MemcachedNode handlingNode = op.getHandlingNode();
    if (handlingNode != null) {
        final String endPoint = getEndPoint(handlingNode);
        if (endPoint != null) {
            recorder.recordEndPoint(endPoint);
        }
        recorder.recordException(op.getException());
    } else {
        logger.info("no handling node");
    }

    if (op instanceof ServiceCodeAccessor) {
        // determine the service type
        String serviceCode = ((ServiceCodeAccessor) op)._$PINPOINT$_getServiceCode();
        if (serviceCode != null) {
            recorder.recordDestinationId(serviceCode);
            recorder.recordServiceType(ArcusConstants.ARCUS_FUTURE_GET);
        }
    }
}
 
Example #13
Source File: TCPMemcachedNodeImpl.java    From kylin with Apache License 2.0 5 votes vote down vote up
public TCPMemcachedNodeImpl(SocketAddress sa, SocketChannel c, int bufSize, BlockingQueue<Operation> rq,
        BlockingQueue<Operation> wq, BlockingQueue<Operation> iq, long opQueueMaxBlockTime, boolean waitForAuth,
        long dt, long authWaitTime, ConnectionFactory fact) {
    super();
    assert sa != null : "No SocketAddress";
    assert c != null : "No SocketChannel";
    assert bufSize > 0 : "Invalid buffer size: " + bufSize;
    assert rq != null : "No operation read queue";
    assert wq != null : "No operation write queue";
    assert iq != null : "No input queue";
    socketAddress = sa;
    connectionFactory = fact;
    this.authWaitTime = authWaitTime;
    setChannel(c);
    // Since these buffers are allocated rarely (only on client creation
    // or reconfigure), and are passed to Channel.read() and Channel.write(),
    // use direct buffers to avoid
    //   http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6214569
    rbuf = ByteBuffer.allocateDirect(bufSize);
    wbuf = ByteBuffer.allocateDirect(bufSize);
    getWbuf().clear();
    readQ = rq;
    writeQ = wq;
    inputQueue = iq;
    this.opQueueMaxBlockTime = opQueueMaxBlockTime;
    shouldAuth = waitForAuth;
    defaultOpTimeout = dt;
    setupForAuth();
}
 
Example #14
Source File: EVCacheMemcachedClient.java    From EVCache with Apache License 2.0 5 votes vote down vote up
public EVCacheItemMetaData metaDebug(String key) {
    final CountDownLatch latch = new CountDownLatch(1);
    final EVCacheItemMetaData rv = new EVCacheItemMetaData();
    if(opFact instanceof EVCacheAsciiOperationFactory) {
    final Operation op = ((EVCacheAsciiOperationFactory)opFact).metaDebug(key, new MetaDebugOperation.Callback() {
        public void receivedStatus(OperationStatus status) {
            if (!status.isSuccess()) {
                if (log.isDebugEnabled()) log.debug("Unsuccessful stat fetch: %s", status);
              }
            if (log.isDebugEnabled()) log.debug("Getting Meta Debug: " + key + "; Status : " + status.getStatusCode().name() + (log.isTraceEnabled() ?  " Node : " + getEVCacheNode(key) : "") + "; Message : " + status.getMessage());
        }

        public void debugInfo(String k, String val) {
            if (log.isDebugEnabled()) log.debug("key " + k + "; val : " + val);
            if(k.equals("exp")) rv.setSecondsLeftToExpire(Long.parseLong(val) * -1);
            else if(k.equals("la")) rv.setSecondsSinceLastAccess(Long.parseLong(val));
            else if(k.equals("cas")) rv.setCas(Long.parseLong(val));
            else if(k.equals("fetch")) rv.setHasBeenFetchedAfterWrite(Boolean.parseBoolean(val));
            else if(k.equals("cls")) rv.setSlabClass(Integer.parseInt(val));
            else if(k.equals("size")) rv.setSizeInBytes(Integer.parseInt(val));
        }

        public void complete() {
            latch.countDown();
        }});
        mconn.enqueueOperation(key, op);
        try {
            if (!latch.await(operationTimeout, TimeUnit.MILLISECONDS)) {
                if (log.isDebugEnabled()) log.debug("meta debug operation timeout. Will return empty opbject.");
            }
        } catch (Exception e) {
            log.error("Exception on meta debug operation : Key : " + key, e);
        }
        if (log.isDebugEnabled()) log.debug("Meta Debug Data : " + rv);
    }
    return rv;
}
 
Example #15
Source File: FutureSetOperationInterceptor.java    From pinpoint with Apache License 2.0 5 votes vote down vote up
@Override
public void before(Object target, Object[] args) {
    if (isDebug) {
        logger.beforeInterceptor(target, args);
    }

    if (target instanceof OperationAccessor) {
        ((OperationAccessor) target)._$PINPOINT$_setOperation((Operation) args[0]);
    }
}
 
Example #16
Source File: EVCacheConnection.java    From EVCache with Apache License 2.0 5 votes vote down vote up
@Override
public void addOperations(Map<MemcachedNode, Operation> ops) {
    super.addOperations(ops);
    for (MemcachedNode node : ops.keySet()) {
        ((EVCacheNode) node).incrOps();
    }
}
 
Example #17
Source File: EVCacheBulkGetFuture.java    From EVCache with Apache License 2.0 5 votes vote down vote up
public EVCacheBulkGetFuture(Map<String, Future<T>> m, Collection<Operation> getOps, CountDownLatch l, ExecutorService service, EVCacheClient client) {
    super(m, getOps, l, service);
    rvMap = m;
    ops = getOps;
    latch = l;
    this.start = System.currentTimeMillis();
    this.client = client;
}
 
Example #18
Source File: BaseAsciiConnectionFactory.java    From EVCache with Apache License 2.0 4 votes vote down vote up
public BlockingQueue<Operation> createOperationQueue() {
    return new ArrayBlockingQueue<Operation>(getOpQueueLen());
}
 
Example #19
Source File: EVCacheConnection.java    From EVCache with Apache License 2.0 4 votes vote down vote up
@Override
public void enqueueOperation(final String key, final Operation o) {
    checkState();
    addOperation(key, o);
  }
 
Example #20
Source File: EVCacheConnection.java    From EVCache with Apache License 2.0 4 votes vote down vote up
protected void addOperation(final MemcachedNode node, final Operation o) {
    super.addOperation(node, o);
    ((EVCacheNode) node).incrOps();
}
 
Example #21
Source File: BaseAsciiConnectionFactory.java    From EVCache with Apache License 2.0 4 votes vote down vote up
public BlockingQueue<Operation> createWriteOperationQueue() {
    return super.createWriteOperationQueue();
}
 
Example #22
Source File: BaseAsciiConnectionFactory.java    From EVCache with Apache License 2.0 4 votes vote down vote up
public BlockingQueue<Operation> createReadOperationQueue() {
    return super.createReadOperationQueue();
}
 
Example #23
Source File: MemcachedConnectionFactory.java    From kylin-on-parquet-v2 with Apache License 2.0 4 votes vote down vote up
@Override
public BlockingQueue<Operation> createReadOperationQueue() {
    return underlying.createReadOperationQueue();
}
 
Example #24
Source File: EVCacheMemcachedClient.java    From EVCache with Apache License 2.0 4 votes vote down vote up
public <T> EVCacheOperationFuture<T> asyncGet(final String key, final Transcoder<T> tc, EVCacheGetOperationListener<T> listener) {
    final CountDownLatch latch = new CountDownLatch(1);
    final EVCacheOperationFuture<T> rv = new EVCacheOperationFuture<T>(key, latch, new AtomicReference<T>(null), readTimeout.get().intValue(), executorService, client);
    final Operation op = opFact.get(key, new GetOperation.Callback() {
        private Future<T> val = null;

        public void receivedStatus(OperationStatus status) {
            if (log.isDebugEnabled()) log.debug("Getting Key : " + key + "; Status : " + status.getStatusCode().name() + (log.isTraceEnabled() ?  " Node : " + getEVCacheNode(key) : "")
                    + "; Message : " + status.getMessage() + "; Elapsed Time - " + (System.currentTimeMillis() - rv.getStartTime()));
            try {
                if (val != null) {
                    if (log.isTraceEnabled() && client.getPool().getEVCacheClientPoolManager().shouldLog(appName)) log.trace("Key : " + key + "; val : " + val.get());
                    rv.set(val.get(), status);
                } else {
                    if (log.isTraceEnabled() && client.getPool().getEVCacheClientPoolManager().shouldLog(appName)) log.trace("Key : " + key + "; val is null");
                    rv.set(null, status);
                }
            } catch (Exception e) {
                log.error(e.getMessage(), e);
                rv.set(null, status);
            }
        }

        @SuppressWarnings("unchecked")
        public void gotData(String k, int flags, byte[] data) {

            if (!key.equals(k)) {
                log.error("Wrong key returned. Key - " + key + "; Returned Key " + k);
                return;
            }
            if (log.isDebugEnabled() && client.getPool().getEVCacheClientPoolManager().shouldLog(appName)) log.debug("Read data : key " + key + "; flags : " + flags + "; data : " + data);
            if (data != null)  {
                if (log.isDebugEnabled() && client.getPool().getEVCacheClientPoolManager().shouldLog(appName)) log.debug("Key : " + key + "; val size : " + data.length);
                getDataSizeDistributionSummary(EVCacheMetricsFactory.GET_OPERATION, EVCacheMetricsFactory.READ, EVCacheMetricsFactory.IPC_SIZE_INBOUND).record(data.length);
                if (tc == null) {
                    if (tcService == null) {
                        log.error("tcService is null, will not be able to decode");
                        throw new RuntimeException("TranscoderSevice is null. Not able to decode");
                    } else {
                        final Transcoder<T> t = (Transcoder<T>) getTranscoder();
                        val = tcService.decode(t, new CachedData(flags, data, t.getMaxSize()));
                    }
                } else {
                    if (tcService == null) {
                        log.error("tcService is null, will not be able to decode");
                        throw new RuntimeException("TranscoderSevice is null. Not able to decode");
                    } else {
                        val = tcService.decode(tc, new CachedData(flags, data, tc.getMaxSize()));
                    }
                }
            } else {
                if (log.isDebugEnabled() && client.getPool().getEVCacheClientPoolManager().shouldLog(appName)) log.debug("Key : " + key + "; val is null" );
            }
        }

        public void complete() {
            latch.countDown();
            final String host = ((rv.getStatus().getStatusCode().equals(StatusCode.TIMEDOUT) && rv.getOperation() != null) ? getHostName(rv.getOperation().getHandlingNode().getSocketAddress()) : null);
            getTimer(EVCacheMetricsFactory.GET_OPERATION, EVCacheMetricsFactory.READ, rv.getStatus(), (val != null ? EVCacheMetricsFactory.YES : EVCacheMetricsFactory.NO), host, getReadMetricMaxValue()).record((System.currentTimeMillis() - rv.getStartTime()), TimeUnit.MILLISECONDS);
            rv.signalComplete();
        }
    });
    rv.setOperation(op);
    if (listener != null) rv.addListener(listener);
    mconn.enqueueOperation(key, op);
    return rv;
}
 
Example #25
Source File: EVCacheMemcachedClient.java    From EVCache with Apache License 2.0 4 votes vote down vote up
public long mutate(final Mutator m, String key, long by, long def, int exp) {
    final String operationStr = m.name();
    final long start = System.currentTimeMillis();
    final AtomicLong rv = new AtomicLong();
    final CountDownLatch latch = new CountDownLatch(1);
    final List<OperationStatus> statusList = new ArrayList<OperationStatus>(1);
    final Operation op = opFact.mutate(m, key, by, def, exp, new OperationCallback() {
        @Override
        public void receivedStatus(OperationStatus s) {
            statusList.add(s);
            rv.set(new Long(s.isSuccess() ? s.getMessage() : "-1"));
        }

        @Override
        public void complete() {
            latch.countDown();
        }
    });
    mconn.enqueueOperation(key, op);
    long retVal = def;
    try {
        if(mutateOperationTimeout == null) {
            mutateOperationTimeout = EVCacheConfig.getInstance().getPropertyRepository().get(appName + ".mutate.timeout", Long.class).orElse(connectionFactory.getOperationTimeout());
        }


        if (!latch.await(mutateOperationTimeout.get(), TimeUnit.MILLISECONDS)) {
            if (log.isDebugEnabled()) log.debug("Mutation operation timeout. Will return -1");
            retVal = -1;
        } else {
            retVal = rv.get();
        }

    } catch (Exception e) {
        log.error("Exception on mutate operation : " + operationStr + " Key : " + key + "; by : " + by + "; default : " + def + "; exp : " + exp
                + "; val : " + retVal + "; Elapsed Time - " + (System.currentTimeMillis() - start), e);

    }
    final OperationStatus status = statusList.size() > 0 ? statusList.get(0) : null;
    final String host = ((status != null && status.getStatusCode().equals(StatusCode.TIMEDOUT) && op != null) ? getHostName(op.getHandlingNode().getSocketAddress()) : null);
    getTimer(operationStr, EVCacheMetricsFactory.WRITE, status, null, host, getWriteMetricMaxValue()).record((System.currentTimeMillis() - start), TimeUnit.MILLISECONDS);
    if (log.isDebugEnabled() && client.getPool().getEVCacheClientPoolManager().shouldLog(appName)) log.debug(operationStr + " Key : " + key + "; by : " + by + "; default : " + def + "; exp : " + exp
            + "; val : " + retVal + "; Elapsed Time - " + (System.currentTimeMillis() - start));
    return retVal;
}
 
Example #26
Source File: EVCacheMemcachedClient.java    From EVCache with Apache License 2.0 4 votes vote down vote up
public Map<SocketAddress, String> execCmd(final String cmd, String[] ips) {
    final Map<SocketAddress, String> rv = new HashMap<SocketAddress, String>();
    Collection<MemcachedNode> nodes = null;
    if(ips == null || ips.length == 0) {
        nodes = mconn.getLocator().getAll();
    } else {
        nodes = new ArrayList<MemcachedNode>(ips.length);
        for(String ip : ips) {
            for(MemcachedNode node : mconn.getLocator().getAll()) {
                if(((InetSocketAddress)node.getSocketAddress()).getAddress().getHostAddress().equals(ip)) {
                    nodes.add(node);
                }
            }
        }
    }
    if(nodes != null && !nodes.isEmpty()) {
        CountDownLatch blatch = broadcastOp(new BroadcastOpFactory() {
            @Override
            public Operation newOp(final MemcachedNode n, final CountDownLatch latch) {
                final SocketAddress sa = n.getSocketAddress();
                return ((EVCacheAsciiOperationFactory)opFact).execCmd(cmd, new ExecCmdOperation.Callback() {

                    @Override
                    public void receivedStatus(OperationStatus status) {
                        if (log.isDebugEnabled()) log.debug("cmd : " + cmd + "; MemcachedNode : " + n + "; Status : " + status);
                        rv.put(sa, status.getMessage());
                    }

                    @Override
                    public void complete() {
                        latch.countDown();
                    }
                });
            }
        }, nodes);
        try {
            blatch.await(operationTimeout, TimeUnit.MILLISECONDS);
        } catch (InterruptedException e) {
            throw new RuntimeException("Interrupted waiting for stats", e);
        }
    }
    return rv;
}
 
Example #27
Source File: EVCacheMemcachedNodeROImpl.java    From EVCache with Apache License 2.0 4 votes vote down vote up
public void addOp(Operation op) {
    throw new UnsupportedOperationException();
}
 
Example #28
Source File: EVCacheMemcachedNodeROImpl.java    From EVCache with Apache License 2.0 4 votes vote down vote up
public void insertOp(Operation op) {
    throw new UnsupportedOperationException();
}
 
Example #29
Source File: EVCacheMemcachedNodeROImpl.java    From EVCache with Apache License 2.0 4 votes vote down vote up
public Operation getCurrentReadOp() {
    throw new UnsupportedOperationException();
}
 
Example #30
Source File: EVCacheMemcachedNodeROImpl.java    From EVCache with Apache License 2.0 4 votes vote down vote up
public Operation getCurrentWriteOp() {
    throw new UnsupportedOperationException();
}