Package net.rubyeye.xmemcached.command

Examples of net.rubyeye.xmemcached.command.Command


      throws TimeoutException, InterruptedException, MemcachedException {
    key = this.preProcessKey(key);
    final byte[] keyBytes = ByteUtils.getBytes(key);
    ByteUtils.checkKey(keyBytes);
    CountDownLatch latch = new CountDownLatch(1);
    final Command command = this.commandFactory.createGetAndTouchCommand(
        key, keyBytes, latch, newExp, false);
    this.latchWait(command, opTimeout, this.sendCommand(command));
    command.getIoBuffer().free();
    this.checkException(command);
    CachedData data = (CachedData) command.getResult();
    if (data == null) {
      return null;
    }
    return (T) this.transcoder.decode(data);
  }
View Full Code Here


    final Collection<Session> sessions = this.connector.getSessionSet();
    CountDownLatch latch = new CountDownLatch(sessions.size());
    List<Command> commands = new ArrayList<Command>(sessions.size());
    for (Session session : sessions) {
      if (session != null && !session.isClosed()) {
        Command command = this.commandFactory.createFlushAllCommand(
            latch, exptime, noreply);

        session.write(command);
      } else {
        latch.countDown();
View Full Code Here

      throw new MemcachedException("could not find session for "
          + SystemUtils.getRawAddress(address) + ":"
          + address.getPort() + ",maybe it have not been connected");
    }

    Command command = this.commandFactory.createVerbosityCommand(latch,
        level, noreply);
    final Session session = sessionQueue.peek();
    session.write(command);
    if (!noreply) {
      this.latchWait(command, this.opTimeout, session);
View Full Code Here

    if (sessionQueue == null || sessionQueue.peek() == null) {
      throw new MemcachedException("could not find session for "
          + SystemUtils.getRawAddress(address) + ":"
          + address.getPort() + ",maybe it have not been connected");
    }
    Command command = this.commandFactory.createFlushAllCommand(latch,
        exptime, noreply);
    final Session session = sessionQueue.peek();
    session.write(command);
    if (!noreply) {
      this.latchWait(command, timeout, session);
View Full Code Here

    if (sessionQueue == null || sessionQueue.peek() == null) {
      throw new MemcachedException("could not find session for "
          + SystemUtils.getRawAddress(address) + ":"
          + address.getPort() + ",maybe it have not been connected");
    }
    Command command = this.commandFactory.createStatsCommand(address,
        latch, null);
    final Session session = sessionQueue.peek();
    session.write(command);
    this.latchWait(command, timeout, session);
    return (Map<String, String>) command.getResult();
  }
View Full Code Here

      return collectResult;
    }
    final CountDownLatch latch = new CountDownLatch(sessionSet.size());
    List<Command> commands = new ArrayList<Command>(sessionSet.size());
    for (Session session : sessionSet) {
      Command command = this.commandFactory.createStatsCommand(
          session.getRemoteSocketAddress(), latch, itemName);

      session.write(command);
      commands.add(command);

    }
    if (!latch.await(timeout, TimeUnit.MILLISECONDS)) {
      for (Command command : commands) {
        command.cancel();
      }
      throw new TimeoutException("Timed out waiting for operation");
    }
    for (Command command : commands) {
      this.checkException(command);
      collectResult.put(((ServerAddressAware) command).getServer(),
          (Map<String, String>) command.getResult());
    }
    return collectResult;
  }
View Full Code Here

      return collectResult;
    }
    final CountDownLatch latch = new CountDownLatch(sessionSet.size());
    List<Command> commands = new ArrayList<Command>(sessionSet.size());
    for (Session session : sessionSet) {
      Command command = this.commandFactory.createVersionCommand(latch,
          session.getRemoteSocketAddress());
      session.write(command);
      commands.add(command);

    }

    if (!latch.await(timeout, TimeUnit.MILLISECONDS)) {
      for (Command command : commands) {
        command.cancel();
      }
      throw new TimeoutException("Timed out waiting for operation");
    }
    for (Command command : commands) {
      this.checkException(command);
      collectResult.put(((ServerAddressAware) command).getServer(),
          (String) command.getResult());
    }
    return collectResult;
  }
View Full Code Here

      long initValue, final CommandType cmdType, boolean noreply,
      long operationTimeout, int exp) throws InterruptedException,
      TimeoutException, MemcachedException {
    final byte[] keyBytes = ByteUtils.getBytes(key);
    ByteUtils.checkKey(keyBytes);
    final Command command = this.commandFactory.createIncrDecrCommand(key,
        keyBytes, delta, initValue, exp, cmdType, noreply);
    final Session session = this.sendCommand(command);
    if (!command.isNoreply()) {
      this.latchWait(command, operationTimeout, session);
      command.getIoBuffer().free();
      this.checkException(command);
      if (command.getResult() == null) {
        throw new MemcachedException(
            "Operation fail,may be caused by networking or timeout");
      }
      final Object result = command.getResult();
      if (result instanceof String) {
        if (((String) result).equals("NOT_FOUND")) {
          if (this.add0(key, exp, String.valueOf(initValue),
              this.transcoder, this.opTimeout)) {
            return initValue;
          } else {
            return this.sendIncrOrDecrCommand(key, delta,
                initValue, cmdType, noreply, operationTimeout,
                exp);
          }
        } else {
          throw new MemcachedException(
              "Unknown result type for incr/decr:"
                  + result.getClass() + ",result=" + result);
        }
      } else {
        return (Long) command.getResult();
      }
    } else {
      return -1;
    }
  }
View Full Code Here

          "The special memcached server has not been connected,"
              + address);
    }
    Session session = sessions.peek();
    CountDownLatch latch = new CountDownLatch(1);
    Command command = this.commandFactory.createStatsCommand(
        session.getRemoteSocketAddress(), latch, "items");
    session.write(command);
    if (!latch.await(5000, TimeUnit.MILLISECONDS)) {
      throw new TimeoutException("Operation timeout");
    }
    if (command.getException() != null) {
      if (command.getException() instanceof MemcachedException) {
        throw (MemcachedException) command.getException();
      } else {
        throw new MemcachedException("stats items failed",
            command.getException());
      }
    }
    Map<String, String> result = (Map<String, String>) command.getResult();
    LinkedList<Integer> itemNumberList = new LinkedList<Integer>();
    for (Map.Entry<String, String> entry : result.entrySet()) {
      final String key = entry.getKey();
      final String[] keys = key.split(":");
      if (keys.length == 3 && keys[2].equals("number")
View Full Code Here

  public void testOperationDecodeTimeOut() throws Exception {
    memcachedClient.set("name", 0, "dennis");
    assertEquals("dennis", memcachedClient.get("name"));
    CountDownLatch latch = new CountDownLatch(1);
    Command errorCommand = null;
    if (memcachedClient.getProtocol() == Protocol.Text) {
      errorCommand = new MockDecodeTimeoutTextGetOneCommand("name",
          "name".getBytes(), CommandType.GET_ONE, latch, 1000);
    } else {
      errorCommand = new MockDecodeTimeoutBinaryGetOneCommand("name",
          "name".getBytes(), CommandType.GET_ONE, latch, OpCode.GET,
          false, 1000);
    }
    memcachedClient.getConnector().send(errorCommand);
    // wait 100 milliseconds,the operation will be timeout
    latch.await(100, TimeUnit.MILLISECONDS);
    assertNull(errorCommand.getResult());
    Thread.sleep(1000);
    // It works.
    assertNotNull(errorCommand.getResult());
    assertEquals("dennis", memcachedClient.get("name"));
  }
View Full Code Here

TOP

Related Classes of net.rubyeye.xmemcached.command.Command

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.