Package com.google.code.yanf4j.core

Examples of com.google.code.yanf4j.core.Session


    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)
View Full Code Here


    }
    // If it is in failure mode,remove closed session from list
    if (this.failureMode) {
      Iterator<Session> it = sessions.iterator();
      while (it.hasNext()) {
        Session tmp = it.next();
        if (tmp.isClosed()) {
          it.remove();
          break;
        }
      }
    }

    sessions.offer(session);
    // Remove old session and close it
    while (sessions.size() > this.connectionPoolSize) {
      Session oldSession = sessions.poll();
      ((MemcachedSession) oldSession).setAllowReconnect(false);
      oldSession.close();
    }
  }
View Full Code Here

    int size = sessionList.size();
    if (size == 0) {
      return null;
    }
    long start = this.getHash(size, key);
    Session session = sessionList.get((int) start);
    // If it is not failure mode,get next available session
    if (!this.failureMode && (session == null || session.isClosed())) {
      long next = this.getNext(size, start);
      while ((session == null || session.isClosed()) && next != start) {
        session = sessionList.get((int) next);
        next = this.getNext(size, next);
      }
    }
    return session;
View Full Code Here

  public final Session getSessionByKey(final String key) {
    if (this.ketamaSessions == null || this.ketamaSessions.size() == 0) {
      return null;
    }
    long hash = this.hashAlg.hash(key);
    Session rv = this.getSessionByHash(hash);
    int tries = 0;
    while (!this.failureMode && (rv == null || rv.isClosed())
        && tries++ < this.maxTries) {
      hash = this.nextHash(hash, key, tries);
      rv = this.getSessionByHash(hash);
    }
    return rv;
View Full Code Here

    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) {
View Full Code Here

    int size = sessionList.size();
    if (size == 0) {
      return null;
    }
    long start = this.getHash(size, key);
    Session session = sessionList.get((int) start);
    // If it is not failure mode,get next available session
    if (!this.failureMode && (session == null || session.isClosed())) {
      long next = this.getNext(size, start);
      while ((session == null || session.isClosed()) && next != start) {
        session = sessionList.get((int) next);
        next = this.getNext(size, next);
      }
    }
    return session;
View Full Code Here

    if (size == 0) {
      return null;
    }
    long start = this.getHash(size, key);
    List<Session> sessions = sessionList.get((int) start);
    Session session = getRandomSession(sessions);

    // If it is not failure mode,get next available session
    if (!this.failureMode && (session == null || session.isClosed())) {
      long next = this.getNext(size, start);
      while ((session == null || session.isClosed()) && next != start) {
        sessions = sessionList.get((int) next);
        next = this.getNext(size, next);
        session = getRandomSession(sessions);
      }
    }
View Full Code Here

      assertSame(sessions.get(mod), sessionLocator.getSessionByKey(key));
    }

    String key = "test";
    int oldIndex = key.hashCode() % sessions.size();
    Session oldSession = sessions.get(oldIndex);

    assertSame(oldSession, sessionLocator.getSessionByKey(key));
    // close old session
    oldSession.close();
    assertNotSame(oldSession, sessionLocator.getSessionByKey(key));
    // use next
    assertSame(sessions.get(oldIndex + 1), sessionLocator
        .getSessionByKey(key));
    sessions = new ArrayList<Session>();
View Full Code Here

    }
    sessionLocator.updateSessions(sessions);
    for (int i = 1; i <= 10; i++) {
      String key = String.valueOf(i);

      Session session = sessionLocator.getSessionByKey(key);
      assertSame(((KetamaMemcachedSessionLocator) sessionLocator)
          .getSessionByHash(key.hashCode()), session);
      assertSame(sessionLocator.getSessionByKey(key), session);
      assertSame(sessionLocator.getSessionByKey(key), session);
    }
View Full Code Here

      this.sessions = Collections.emptyList();
      return;
    }
    Collection<Session> copySessions = list;
    List<List<Session>> tmpList = new ArrayList<List<Session>>();
    Session target = null;
    List<Session> subList = null;
    for (Session session : copySessions) {
      if (target == null) {
        target = session;
        subList = new ArrayList<Session>();
        subList.add(target);
      } else {
        if (session.getRemoteSocketAddress().equals(
            target.getRemoteSocketAddress())) {
          subList.add(session);
        } else {         
          tmpList.add(subList);
          target = session;
          subList = new ArrayList<Session>();
          subList.add(target);
        }
      }
    }

    // The last one
    if (subList != null) {
      tmpList.add(subList);
    }

    List<List<Session>> newSessions = new ArrayList<List<Session>>(
        tmpList.size() * 2);
    for (List<Session> sessions : tmpList) {
      if (sessions != null && !sessions.isEmpty()) {
        Session session = sessions.get(0);
        if (session instanceof MemcachedTCPSession) {
          int weight = ((MemcachedSession) session).getWeight();
          for (int i = 0; i < weight; i++) {
            newSessions.add(sessions);
          }
View Full Code Here

TOP

Related Classes of com.google.code.yanf4j.core.Session

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.