Package com.google.code.yanf4j.core

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


    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


    }
    // 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

  public final Session getSessionByKey(final String key) {
    if (this.ketamaSessions == null || this.ketamaSessions.size() == 0) {
      return null;
    }
    long hash = hashAlgorithm.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

  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

  }

  public Session getSessionByKey(String key) {
    // copy on write
    List<Session> copySessionList = new ArrayList<Session>(this.sessions);
    Session result = this.getSessionByElection(key, copySessionList);
    while (!this.failureMode && (result == null || result.isClosed())
        && copySessionList.size() > 0) {
      copySessionList.remove(result);
      result = this.getSessionByElection(key, copySessionList);
    }
    return result;
View Full Code Here

    return result;
  }

  private Session getSessionByElection(String key,
      List<Session> copySessionList) {
    Session result = null;
    long highScore = 0;
    for (Session session : copySessionList) {
      long hash = 0;
      if (session instanceof MemcachedTCPSession) {
        MemcachedSession tcpSession = (MemcachedSession) session;
View Full Code Here

  /**
   * Cancel selection key
   */
  public void closeSelectionKey(SelectionKey key) {
    if (key.attachment() instanceof Session) {
      Session session = (Session) key.attachment();
      if (session != null) {
        session.close();
      }
    }
  }
View Full Code Here

    super(configuration, handler, codecFactory);
  }

  @Override
  protected final void dispatchReadEvent(SelectionKey key) {
    Session session = (Session) key.attachment();
    if (session != null) {
      ((NioSession) session).onEvent(EventType.READABLE, key.selector());
    } else {
      log
          .warn("Could not find session for readable event,maybe it is closed");
View Full Code Here

    }
  }

  @Override
  protected final void dispatchWriteEvent(SelectionKey key) {
    Session session = (Session) key.attachment();
    if (session != null) {
      ((NioSession) session).onEvent(EventType.WRITEABLE, key.selector());
    } else {
      log
          .warn("Could not find session for writable event,maybe it is closed");
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.