Adds a keepalive connection.

@param conn the connection to register as keepalive

@return true if the connection changes to the keepalive state
771674
@Override
  public PollResult startPoll(PollController conn)
  {
    if (! _lifecycle.isActive()) {
      log.warning(this + " select disabled");
        
      return PollResult.CLOSED;
    }
    else if (_selectMax <= _connectionCount.get()) {
      log.warning(this + " keepalive overflow "
                  + _connectionCount + " max=" + _selectMax);
      System.out.println("OVERFLOW:");
      
      return PollResult.CLOSED;
    }
    
    if (! conn.toKeepaliveStart()) {
      return PollResult.CLOSED;
    }

    // XXX: check for full
    _executor.execute(new PollTask(conn));
    
    return PollResult.START;
  }
1299879
protected boolean clearSpecial(DatabaseConnection connection, Logger logger) {
		NestedConnection currentSaved = specialConnection.get();
		boolean cleared = false;
		if (connection == null) {
			// ignored
		} else if (currentSaved == null) {
			logger.error("no connection has been saved when clear() called");
		} else if (currentSaved.connection == connection) {
			if (currentSaved.decrementAndGet() == 0) {
				// we only clear the connection if nested counter is 0
				specialConnection.set(null);
			}
			cleared = true;
		} else {
			logger.error("connection saved {} is not the one being cleared {}", currentSaved.connection, connection);
		}
		// release should then be called after clear
		return cleared;
	}
19567
def set_keepalive(sock, after_idle_sec=1, interval_sec=3, max_fails=5):
    
    if hasattr(socket, "SO_KEEPALIVE"):
        sock.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)
    if hasattr(socket, "TCP_KEEPIDLE"):
        sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPIDLE, after_idle_sec)
    if hasattr(socket, "TCP_KEEPINTVL"):
        sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPINTVL, interval_sec)
    if hasattr(socket, "TCP_KEEPCNT"):
        sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPCNT, max_fails)
1129089
public static boolean startTransaction(Connection conn) throws SQLException {
        if (conn == null) {
            return false;
        }
        String dsName = openConnDsName.get().get(conn);
        OpenConnStats connStats = dsName != null ? openConnStats.get().get(dsName) : null;
        if (connStats != null && !connStats.inTransaction) {
            conn.setAutoCommit(false);
            connStats.inTransaction = true;
            return true;
        }
        return false;
    }
562857
public static Connection newInstance(Connection conn) {
        return (Connection) java.lang.reflect.Proxy.newProxyInstance(Connection.class.getClassLoader(), new Class[]{Connection.class},
                new ConnectionProxy(conn));
        /*
        return (Connection) java.lang.reflect.Proxy.newProxyInstance(conn.getClass().getClassLoader(), conn.getClass().getInterfaces(),
                new ConnectionProxy(conn));
                */
    }
900723
public void setKeepAliveConfiguration(KeepAliveConfiguration keepAliveConfiguration)
    {
        if(keepAliveConfiguration != null)
            client.setConnectionPool(new ConnectionPool(keepAliveConfiguration.getMaxIdleConnections(),
                    keepAliveConfiguration.getKeepAliveDurationMs()));
    }
104366
public void addConnection(WebSocketConnection conn) {
        conns.add(conn);
        for (IWebSocketDataListener listener : listeners) {
            listener.onWSConnect(conn);
        }
    }
728152
@Override
  public NettyChannelBuilder keepAliveTime(long keepAliveTime, TimeUnit timeUnit) {
    checkArgument(keepAliveTime > 0L, "keepalive time must be positive");
    keepAliveTimeNanos = timeUnit.toNanos(keepAliveTime);
    keepAliveTimeNanos = KeepAliveManager.clampKeepAliveTimeInNanos(keepAliveTimeNanos);
    if (keepAliveTimeNanos >= AS_LARGE_AS_INFINITE) {
      // Bump keepalive time to infinite. This disables keepalive.
      keepAliveTimeNanos = KEEPALIVE_TIME_NANOS_DISABLED;
    }
    return this;
  }
205466
public function onConnect(Connection $conn)
    {
        // 加入新连接重新调整所有连接rdy状态
        $conn->setDelegate($this);
        $conn->writeCmd(Command::subscribe($this->topic, $this->channel));
        $this->maybeUpdateRDY($conn);
    }
879425
public function init($keepalive = false)
        {
            $this->handshake();
            $this->connect();

            if ($keepalive) {
                $this->keepAlive();
            } else {
                return $this;
            }
        }
232172
public NettyServerBuilder keepAliveTimeout(long keepAliveTimeout, TimeUnit timeUnit) {
    checkArgument(keepAliveTimeout > 0L, "keepalive timeout must be positive");
    keepAliveTimeoutInNanos = timeUnit.toNanos(keepAliveTimeout);
    keepAliveTimeoutInNanos =
        KeepAliveManager.clampKeepAliveTimeoutInNanos(keepAliveTimeoutInNanos);
    if (keepAliveTimeoutInNanos < MIN_KEEPALIVE_TIMEOUT_NANO) {
      // Bump keepalive timeout.
      keepAliveTimeoutInNanos = MIN_KEEPALIVE_TIMEOUT_NANO;
    }
    return this;
  }
1250508
public boolean addObserver(ConnectionObserver obs) {
    boolean rv = conn.addObserver(obs);
    if (rv) {
      for (MemcachedNode node : conn.getLocator().getAll()) {
        if (node.isActive()) {
          obs.connectionEstablished(node.getSocketAddress(), -1);
        }
      }
    }
    return rv;
  }
495019
public void connect(IConnection conn) {
        if (conn instanceof RTMPConnection) {
            if (!isConnected()) {
                source = conn;
                SharedObjectMessage msg = new SharedObjectMessage(name, 0, isPersistent());
                msg.addEvent(new SharedObjectEvent(Type.SERVER_CONNECT, null, null));
                Channel c = ((RTMPConnection) conn).getChannel(3);
                c.write(msg);
            } else {
                throw new UnsupportedOperationException("Already connected");
            }
        } else {
            throw new UnsupportedOperationException("Only RTMP connections are supported");
        }
    }
1062192
public function markConnBusy(ClientConnection $conn, $url)
    {
        if (!isset($this->servConnFree[$url])) {
            return;
        }
        $this->servConnFree[$url]->detach($conn);
    }
648774
@Override
	public void connectionEvent(Connection conn, Events type) {
		switch (type) {
		case CONNECTED:

			// The connection is permanently closed, either by manual action or
			// failed reconnects
			if (debug) {
				logger.info("NATS connection opened.");
			}
			break;

		case CLOSED:

			// The connection lost its connection, but may try to reconnect if
			// configured to
			logger.info("NATS connection closed.");
			if (started.get()) {
				reconnect();
			}
			break;

		case DISCONNECTED:

			// The connection was connected, lost its connection and
			// successfully reconnected
			if (debug) {
				logger.info("NATS pub-sub connection disconnected.");
			}
			break;

		case RECONNECTED:

			// The connection was reconnected and the server has been notified
			// of all subscriptions
			if (debug) {
				logger.info("NATS connection reconnected.");
			}
			break;

		case RESUBSCRIBED:

			// The connection was told about new servers from, from the current
			// server
			if (debug) {
				logger.info("NATS subscriptions re-established.");
			}
			break;

		case DISCOVERED_SERVERS:

			// Servers discovered
			if (debug) {
				logger.info("NATS servers discovered.");
			}
			break;

		default:
			break;
		}
	}
293390
public void put( Object key, URLConnection conn )
    {
        synchronized( this ) // ensure no ConcurrentModificationException can occur.
        {
            Entry entry = new Entry( conn );
            m_hardStore.put( key, entry );
            if( m_thread == null )
            {
                m_thread = new Thread( this, "ConnectionCache-cleaner" );
                m_thread.setDaemon( true );
                m_thread.start();
            }
        }
    }
743863
protected final void resetHeartSeq(JConnection conn)
	{
		if(conn.hasAttribute(IdleConnectionKey.HeartConfig))
		{//重置心跳序号
			HeartConfig hc=(HeartConfig) conn.getAttribute(IdleConnectionKey.HeartConfig);
			hc.setSeq(0);
		}
	}