Package net.rubyeye.xmemcached.exception

Examples of net.rubyeye.xmemcached.exception.MemcachedException


  private String sanitizeKey(String key) throws MemcachedException {
    try {
      return this.sanitizeKeys ? URLEncoder.encode(key, "UTF-8") : key;
    } catch (UnsupportedEncodingException e) {
      throw new MemcachedException(
          "Unsupport encoding utf-8 when sanitizeKey", e);
    }
  }
View Full Code Here


    if (address == null) {
      throw new IllegalArgumentException("null address");
    }
    Queue<Session> sessions = this.connector.getSessionByAddress(address);
    if (sessions == null || sessions.size() == 0) {
      throw new MemcachedException(
          "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()) {
View Full Code Here

  }

  public void destroy() {
    Command command = this.currentCommand.get();
    if (command != null) {
      command.setException(new MemcachedException(
          "Session has been closed"));
      command.getLatch().countDown();
    }
    while ((command = this.commandAlreadySent.poll()) != null) {
      command.setException(new MemcachedException(
          "Session has been closed"));
      if (command.getLatch() != null) {
        command.getLatch().countDown();
      }
    }
View Full Code Here

  public void send(final Command msg) throws MemcachedException {
    MemcachedSession session = (MemcachedSession) this
        .findSessionByKey(msg.getKey());
    if (session == null) {
      throw new MemcachedException(
          "There is no available connection at this moment");
    }
    // If session was closed,try to use standby memcached node
    if (session.isClosed()) {
      session = this.findStandbySession(session);
    }
    if (session.isClosed()) {
      throw new MemcachedException("Session("
          + SystemUtils.getRawAddress(session
              .getRemoteSocketAddress()) + ":"
          + session.getRemoteSocketAddress().getPort()
          + ") has been closed");
    }
    if (session.isAuthFailed()) {
      throw new MemcachedException("Auth failed to connection "
          + session.getRemoteSocketAddress());
    }
    session.write(msg);
  }
View Full Code Here

    int itemNumber = this.itemNumbersList.remove();
    Queue<Session> sessions = this.memcachedClient.getConnector()
        .getSessionByAddress(this.inetSocketAddress);
    if (sessions == null || sessions.size() == 0) {
      throw new MemcachedException(
          "The memcached server is not connected,address="
              + this.inetSocketAddress);
    }
    Session session = sessions.peek();
    CountDownLatch latch = new CountDownLatch(1);
    if (this.memcachedClient.getProtocol() == Protocol.Text) {
      TextCacheDumpCommand textCacheDumpCommand = new TextCacheDumpCommand(
          latch, itemNumber);
      session.write(textCacheDumpCommand);
      if (!latch.await(this.opTimeout, TimeUnit.MILLISECONDS)) {
        throw new TimeoutException("stats cachedump timeout");
      }
      if (textCacheDumpCommand.getException() != null) {
        if (textCacheDumpCommand.getException() instanceof MemcachedException) {
          throw (MemcachedException) textCacheDumpCommand
              .getException();
        } else {
          throw new MemcachedServerException(textCacheDumpCommand
              .getException());
        }
      }
      this.currentKeyList = (LinkedList<String>) textCacheDumpCommand
          .getResult();
    } else {
      throw new MemcachedException(
          this.memcachedClient.getProtocol().name()
              + " protocol doesn't support iterating all keys in memcached");
    }
    return next();
  }
View Full Code Here

  }

  public void destroy() {
    Command command = this.currentCommand.get()
    if (command != null) {
      command.setException(new MemcachedException(
          "Session has been closed"));
      CountDownLatch latch = command.getLatch();
      if (latch != null) {
        latch.countDown();
      }
    }
    while ((command = this.commandAlreadySent.poll()) != null) {
      command.setException(new MemcachedException(
          "Session has been closed"));
      CountDownLatch latch = command.getLatch();
      if (latch != null) {
        latch.countDown();
      }
View Full Code Here

  public Session send(final Command msg) throws MemcachedException {
    MemcachedSession session = (MemcachedSession) this.findSessionByKey(msg
        .getKey());
    if (session == null) {
      throw new MemcachedException(
          "There is no available connection at this moment");
    }
    // If session was closed,try to use standby memcached node
    if (session.isClosed()) {
      session = this.findStandbySession(session);
    }
    if (session.isClosed()) {
      throw new MemcachedException("Session("
          + SystemUtils.getRawAddress(session
              .getRemoteSocketAddress()) + ":"
              + session.getRemoteSocketAddress().getPort()
              + ") has been closed");
    }
    if (session.isAuthFailed()) {
      throw new MemcachedException("Auth failed to connection "
          + session.getRemoteSocketAddress());
    }
    session.write(msg);
    return session;
  }
View Full Code Here

    int itemNumber = this.itemNumbersList.remove();
    Queue<Session> sessions = this.memcachedClient.getConnector()
        .getSessionByAddress(this.inetSocketAddress);
    if (sessions == null || sessions.size() == 0) {
      throw new MemcachedException(
          "The memcached server is not connected,address="
              + this.inetSocketAddress);
    }
    Session session = sessions.peek();
    CountDownLatch latch = new CountDownLatch(1);
    if (this.memcachedClient.getProtocol() == Protocol.Text) {
      TextCacheDumpCommand textCacheDumpCommand = new TextCacheDumpCommand(
          latch, itemNumber);
      session.write(textCacheDumpCommand);
      if (!latch.await(this.opTimeout, TimeUnit.MILLISECONDS)) {
        throw new TimeoutException("stats cachedump timeout");
      }
      if (textCacheDumpCommand.getException() != null) {
        if (textCacheDumpCommand.getException() instanceof MemcachedException) {
          throw (MemcachedException) textCacheDumpCommand
              .getException();
        } else {
          throw new MemcachedServerException(textCacheDumpCommand
              .getException());
        }
      }
      this.currentKeyList = (LinkedList<String>) textCacheDumpCommand
          .getResult();
    } else {
      throw new MemcachedException(
          this.memcachedClient.getProtocol().name()
              + " protocol doesn't support iterating all keys in memcached");
    }
    return next();
  }
View Full Code Here

TOP

Related Classes of net.rubyeye.xmemcached.exception.MemcachedException

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.