Connect the shared object using the passed connection.

@param conn
Attach SO to given connection
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");
        }
    }
895467
protected void register(IConnection conn) {
        if (log.isDebugEnabled()) {
            if (conn == null) {
                log.debug("Register null connection, client id: {}", id);
            } else {
                log.debug("Register connection ({}:{}) client id: {}", conn.getRemoteAddress(), conn.getRemotePort(), id);
            }
        }
        if (conn != null) {
            IScope scope = conn.getScope();
            if (scope != null) {
                log.debug("Registering for scope: {}", scope);
                connections.add(conn);
            } else {
                log.warn("Clients scope is null. Id: {}", id);
            }
        } else {
            log.warn("Clients connection is null. Id: {}", id);
        }
    }
963269
public final void closeUnmanagedConnection(final Connection conn) throws SQLException {
      activeUnmanagedConnections.dec();
      if(!conn.isClosed()) {
         conn.close();
      }
   }
533661
def _set_new_connection(self, conn):
        
        with self._lock:
            old = self._connection
            self._connection = conn

        if old:
            log.debug("[control connection] Closing old connection %r, replacing with %r", old, conn)
            old.close()
1260157
protected void setSharedConnection(Object affinity, MCWrapper mcWrapper) {

        final boolean isTracingEnabled = TraceComponent.isAnyTracingEnabled();

        if (isTracingEnabled && tc.isEntryEnabled()) {
            Tr.entry(this, tc, "setSharedConnection");
        }
        /*
         * Set the shared pool affinity on the mcWrapper for comparing in the
         * getSharedConnection method
         */
        mcWrapper.setSharedPoolCoordinator(affinity);
        mcWrapper.setSharedPool(this);
        synchronized (sharedLockObject) {

            /*
             * Add the mcWrapper to the mcWrapper array list
             */
            mcWrapperList[mcWrapperListSize] = mcWrapper;
            mcWrapper.setPoolState(2);
            ++mcWrapperListSize;
            if (mcWrapperListSize >= objectArraySize) {
                /*
                 * We need to increase our size
                 */
                objectArraySize = objectArraySize * 2;
                mcWrapperListTemp = new MCWrapper[objectArraySize];
                System.arraycopy(mcWrapperList, 0, mcWrapperListTemp, 0, mcWrapperList.length);
                mcWrapperList = mcWrapperListTemp;
            }
        } // end synchronized (sharedLockObject)

        if (isTracingEnabled && tc.isEntryEnabled()) {
            Tr.exit(this, tc, "setSharedConnection");
        }

    }
839877
public void setConnections(java.util.Collection<String> connections) {
        if (connections == null) {
            this.connections = null;
            return;
        }

        this.connections = new java.util.ArrayList<String>(connections);
    }
833361
protected void setConnection(Text line) throws ParseException {
        connection = new ConnectionField();
        connection.strain(line);
        Collections.sort(this.candidates);
    }
359181
void registerConnection(ConnectionManager cm, ConnectionListener cl, Object c)
   {
      if (cmToCl == null)
         cmToCl = new HashMap<ConnectionManager, List<ConnectionListener>>();

      List<ConnectionListener> l = cmToCl.get(cm);

      if (l == null)
         l = new ArrayList<ConnectionListener>(1);

      l.add(cl);
      cmToCl.put(cm, l);

      if (clToC == null)
         clToC = new HashMap<ConnectionListener, List<Object>>();

      List<Object> connections = clToC.get(cl);

      if (connections == null)
         connections = new ArrayList<Object>(1);

      connections.add(c);
      clToC.put(cl, connections);
   }
1373723
public static void closeConnection(Connection conn){
		if (conn != null) {
			try {
				conn.close();
			} catch (Exception e) {
				log.warn("Exception when closing database connection.", e);
			}
		}
	}
381910
public void associateConnection(Object connection) throws ResourceException
   {
      if (connection == null)
         throw new ResourceException("Null connection handle");

      if (!(connection instanceof HelloWorldConnectionImpl))
         throw new ResourceException("Wrong connection handle");

      HelloWorldConnectionImpl handle = (HelloWorldConnectionImpl)connection;
      handle.setManagedConnection(this);
      connections.add(handle);
   }
1022592
protected void connect() throws RpcException {
        if (_state.equals(State.CONNECTED)) {
            return;
        }

        final ChannelFuture oldChannelFuture = _channelFuture;

        if (LOG.isDebugEnabled()) {
            String logPrefix = _usePrivilegedPort ? "usePrivilegedPort " : "";
            LOG.debug("{}connecting to {}", logPrefix, getRemoteAddress());
        }
        _state = State.CONNECTING;

        if (_usePrivilegedPort) {
            _channel = bindToPrivilegedPort();
            _channelFuture = _channel.connect(getRemoteAddress());
        } else {
            _channelFuture = _clientBootstrap.connect();
            _channel = _channelFuture.getChannel();
        }

        NioSocketChannelConfig cfg = (NioSocketChannelConfig) _channel.getConfig();
        cfg.setWriteBufferHighWaterMark(MAX_SENDING_QUEUE_SIZE);

        _channelFuture.addListener(new ChannelFutureListener() {
            /* (non-Javadoc)
             * @see org.jboss.netty.channel.ChannelFutureListener#operationComplete(org.jboss.netty.channel.ChannelFuture)
             */
            public void operationComplete(ChannelFuture future) {
                if (_channelFuture.isSuccess()) {
                    _state = State.CONNECTED;
                    oldChannelFuture.setSuccess();
                } else {
                    _state = State.DISCONNECTED;
                    oldChannelFuture.cancel();
                }

            }
        });

    }
1227740
public void open(Connection conn, String fileName, final int serverId, boolean nonBlocking) throws IOException {
        open(conn, fileName, BIN_LOG_HEADER_SIZE, serverId, nonBlocking);
    }
358651
protected synchronized void setConnection (PresentsConnection conn)
    {
        long now = System.currentTimeMillis();
        if (_conn != null) {
            // if our connection is being cleared out, record the amount of time we were connected
            // to our total connected time
            if (conn == null) {
                _connectTime += ((now - _networkStamp) / 1000);
                _messagesDropped = 0;
            }

            // make damn sure we don't get any more messages from the old connection
            _conn.clearMessageHandler();
        }

        // keep a handle to the new connection
        _conn = conn;

        // if we're setting a connection rather than clearing one out...
        if (_conn != null) {
            // tell the connection to pass messages on to us
            _conn.setMessageHandler(this);

            // configure any active custom class loader
            if (_loader != null) {
                _conn.setClassLoader(_loader);
            }
        }

        // make a note that our network status changed
        _networkStamp = now;
    }
1176307
void connectDBConn(DBConn dbConn) throws DBNotAvailableException, RuntimeException {
        // If we're using failover hosts, see if it's time to try primary hosts again.
        if (m_bUseSecondaryHosts &&
            (System.currentTimeMillis() - m_lastPrimaryHostCheckTimeMillis) > getParamInt("primary_host_recheck_millis", 60000)) {
            m_bUseSecondaryHosts = false;
        }
        
        // Try all primary hosts first if possible.
        DBNotAvailableException lastException = null;
        if (!m_bUseSecondaryHosts) {
            String[] dbHosts = getParamString("dbhost").split(",");
            for (int attempt = 1; !dbConn.isOpen() && attempt <= dbHosts.length; attempt++) {
                try {
                    dbConn.connect(chooseHost(dbHosts));
                } catch (DBNotAvailableException ex) {
                    lastException = ex;
                } catch (RuntimeException ex) {
                    throw ex;   // bad keyspace; abort connection attempts
                }
            }
            m_lastPrimaryHostCheckTimeMillis = System.currentTimeMillis();
        }
        
        // Try secondary hosts if needed and if configured.
        if (!dbConn.isOpen() && !Utils.isEmpty(getParamString("secondary_dbhost"))) {
            if (!m_bUseSecondaryHosts) {
                m_logger.info("All connections to 'dbhost' failed; trying 'secondary_dbhost'");
            }
            String[] dbHosts = getParamString("secondary_dbhost").split(",");
            for (int attempt = 1; !dbConn.isOpen() && attempt <= dbHosts.length; attempt++) {
                try {
                    dbConn.connect(chooseHost(dbHosts));
                } catch (DBNotAvailableException e) {
                    lastException = e;
                } catch (RuntimeException ex) {
                    throw ex;   // bad keyspace; abort connection attempts
                }
            }
            if (dbConn.isOpen()) {
                m_bUseSecondaryHosts = true; // stick with secondary hosts for now.
            }
        }
        
        if (!dbConn.isOpen()) {
            m_logger.error("All Thrift connection attempts failed.", lastException);
            throw lastException;
        }
    }
830723
public synchronized void connectionEstablished (
        PresentsConnection conn, Name authname, AuthRequest req, AuthResponse rsp)
    {
        String type = authname.getClass().getSimpleName();

        // see if a session is already registered with this name
        PresentsSession session = getClient(authname);

        if (session != null) {
            //log.info("Resuming session", "type", type, "who", authname, "conn", conn);
            session.resumeSession(req, conn);

        } else {
            log.info("Session initiated", "type", type, "who", authname, "conn", conn);
            // figure out our session class
            Class<? extends PresentsSession> sessionClass = null;
            for (SessionFactory factory : _factories) {
                if ((sessionClass = factory.getSessionClass(req)) != null) {
                    break;
                }
            }
            // create a new session and stick'em in the table
            session = _injector.getInstance(sessionClass);
            session.startSession(authname, req, conn, rsp.authdata);

            // map their session instance
            synchronized (_usermap) {
                // we refetch the authname from the session for use in the map in case it decides
                // to do something crazy like rewrite it in startSession()
                _usermap.put(session.getAuthName(), session);
            }
        }

        // map this connection to this session
        _conmap.put(conn, session);
    }
509271
void releaseConnection(ConnectionPool pool, Cassandra.Client conn)
    {
        if (pool != null && conn != null)
        {
            pool.release(conn);
        }
    }
1199166
public void disconnect(IConnection conn) {
        log.debug("Disconnect: {}", conn);
        // call disconnect handlers in reverse order of connection. ie. roomDisconnect is called before appDisconnect.
        final IClient client = conn.getClient();
        if (client == null) {
            // early bail out
            removeEventListener(conn);
            connectionStats.decrement();
            if (hasParent()) {
                parent.disconnect(conn);
            }
            return;
        }
        // remove it if it exists
        if (clients.remove(client)) {
            IScopeHandler handler = getHandler();
            if (handler != null) {
                try {
                    handler.disconnect(conn, this);
                } catch (Exception e) {
                    log.error("Error while executing \"disconnect\" for connection {} on handler {}. {}", new Object[] { conn, handler, e });
                }
                try {
                    // there may be a timeout here ?
                    handler.leave(client, this);
                } catch (Exception e) {
                    log.error("Error while executing \"leave\" for client {} on handler {}. {}", new Object[] { conn, handler, e });
                }
            }
            // remove listener
            removeEventListener(conn);
            // decrement if there was a set of connections
            connectionStats.decrement();
            if (this.equals(conn.getScope())) {
                final IServer server = getServer();
                if (server instanceof Server) {
                    ((Server) server).notifyDisconnected(conn);
                }
            }
        }
        if (hasParent()) {
            parent.disconnect(conn);
        }
    }