manages connections as necessary (creating or destroying)
430317
@Override
    public int doEndTag() throws JspException {
        try {
            // If we didn't expose a Reader earlier...
            if (varReader == null) {
                // ... store it in 'var', if available ...
                if (var != null) {
                    pageContext.setAttribute(var, acquireString(), scope);
                }
                // ... or simply output it, if we have nowhere to expose it
                else {
                    pageContext.getOut().print(acquireString());
                }
            }
            return EVAL_PAGE;
        } catch (IOException ex) {
            throw new JspTagException(ex.toString(), ex);
        }
    }
503192
function remove(connection, connections) {
  for (var i = 0; i < connections.length; i++) {
    if (connections[i] === connection) {
      connections.splice(i, 1);
      return true;
    }
  }
}
910152
def _cleanupConnections(senderkey, signal):
    """"""
    try:
        receivers = connections[senderkey][signal]
    except:
        pass
    else:
        if not receivers:
            # No more connected receivers. Therefore, remove the signal.
            try:
                signals = connections[senderkey]
            except KeyError:
                pass
            else:
                del signals[signal]
                if not signals:
                    # No more signal connections. Therefore, remove the sender.
                    _removeSender(senderkey)
163796
function handleConnection(conn, conf, appParams)
{
    var requiredApp = null;
    var runningApp = null;
    var runningAppID = null;
    var buffer = "";

    // console.log("New connection from [" + conn.remoteAddress + "]");

    conn.on('data', function (message)
    {
        var pkg;
        var strMessage = buffer + message.toString();
        pkg = strMessage.split("\n");

        if (strMessage.substr(-1) !== "\n")
        {
            buffer = pkg.pop();
        }

        pkg.map(function (jsonPkg)
        {
            if (jsonPkg.length < 2)
            {
                return;
            }

            var o = JSON.parse(jsonPkg);
            switch (o["a"])
            {
                case "x":
                    // if the alias exists: executes it
                    if (conf["aliases"] && conf["aliases"][o["w"]])
                    {
                        var tmpLog = "Starting [" + o["w"] + "] ...";
                        try
                        {
                            requiredApp = r_equire(global.__base_path + conf["aliases"][o["w"]]);
                            tmpLog += "OK!";

                            runningApp = requiredApp({
                                "send": function (m)
                                {
                                    conn.write(m);
                                },
                                "close": function ()
                                {
                                    runningApp.app.destroyAll();
                                    conn.close();
                                }
                            }, appParams);
                        }
                        catch (e)
                        {
                            requiredApp = null;
                            runningApp = null;
                            tmpLog += "ERROR [" + e + "]!";
                        }

                        if (runningApp !== null)
                        {
                            // registers the app
                            runningAppID = registerRunningApp(runningApp);
                            // enables the broadcasting
                            injectBroadcasting(runningApp);
                        }

                        console.log(tmpLog);
                    }
                    else
                    {
                        console.log('Error: Alias [' + o["w"] + '] not found!');
                    }
                    break;
                default:
                    // packages handled by the app itself
                    runningApp && runningApp.parseRequests(o);
            }

        });

    });
    conn.on('close', function ()
    {
        runningApp && runningApp.onClose();

        if (runningAppID !== null)
        {
            unregisterRunningApp(runningAppID);
        }
    });
    conn.on('error', function ()
    {
        runningApp && runningApp.onError();

        console.log("Connection ERROR!!!");
    });
}
1279969
function (node) {

        var toberemoved = this.handler[node];
        this.handler[node] = [];

        // remove handler
        if (toberemoved && toberemoved.length > 0) {
            for (var i = 0, l = toberemoved.length; i < l; i++) {
                this._connection.deleteHandler(toberemoved[i])
            }
        }
    }
1028525
function (connectionName, cb) {
            var closeConnection = function (connectionName) {
                var connection = me.connections[connectionName];
                if (connection) {
                    if (connection.conn && typeof connection.conn.close === 'function') {
                        connection.conn.close(function (err) {
                            if (err) console.error(err);
                        });
                    }
                    else {
                        connection.close(function (err) {
                            if (err) console.error(err);
                        });
                    }
                }

                delete me.connections[connectionName];
            };

            if (connectionName) closeConnection(connectionName);
            else _.each(me.connections, closeConnection);

            return cb();
        }
1373549
def main(ctx, connection):
    """"""
    ctx.obj = Manager(connection=connection)
    ctx.obj.bind()
7935
private void discardIdleConnections() {
        List<Connection<CL>> connections = Lists.newArrayList();
        availableConnections.drainTo(connections);
        activeCount.addAndGet(-connections.size());

        for (Connection<CL> connection : connections) {
            try {
                closedConnections.incrementAndGet();
                connection.close(); // This is usually an async operation
            }
            catch (Throwable t) {
                // TODO
            }
        }
    }
121365
function destroy() {
  this.conn = null;
  this.cmd = null;
  this.args = null;
  this.db = null;
  this.info = null;
  this.conf = null;
  this.def = null;
}
887997
function (conn, cb) {

      // TODO: disconnect here
      if (typeof conn == 'function') {
        cb = conn;
        conn = null;
      }
      if (!conn) {
        connections = {};
        return cb();
      }
      if(!connections[conn]) return cb();
      delete connections[conn];
      cb();
    }
1221320
function () {
    if (!self.connections.length) {
      self.removeListener('remove', remove);
      self.closing = false;
      return callback();
    }
  }
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()
752692
async def _manage_connection(self):
        """"""

        try:
            while True:
                message = await self._con.recv()

                try:
                    unpacked = unpack(message)
                except Exception:  # pylint:disable=broad-except;This is a background worker
                    self._logger.exception("Corrupt message received")
                    continue

                if not VALID_SERVER_MESSAGE.matches(unpacked):
                    self._logger.warning("Dropping invalid message from server: %s", unpacked)
                    continue

                # Don't block until all callbacks have finished since once of
                # those callbacks may call self.send_command, which would deadlock
                # since it couldn't get the response until it had already finished.
                if not await self._manager.process_message(unpacked, wait=False):
                    self._logger.warning("No handler found for received message, message=%s", unpacked)
        except asyncio.CancelledError:
            self._logger.info("Closing connection to server due to stop()")
        finally:
            await self._manager.process_message(dict(type='event', name=self.DISCONNECT_EVENT, payload=None))
            await self._con.close()
316369
void connectionCloses(final Session connection) {
        synchronized (connections) {
            final ExecutorService executorService = connectionThreads.get(connection);
            if (executorService != null) {
                executorService.shutdownNow();
            }
            connectionThreads.remove(connection);
            connections.remove(connection);
        }
    }
689014
def _ensure_connection(self):
        """"""
        conn = self.connect()
        if conn.recycle and conn.recycle < time.time():
            logger.debug('Client session expired after %is. Recycling.', self._recycle)
            self.close()
            conn = self.connect()
        return conn
497595
def ensure_connected(self):
        """"""
        if not self.is_connected():
            if not self._auto_connect:
                raise DBALConnectionError.connection_closed()
            self.connect()
132526
def on_delete(self, forced):
        
        # Do not remove connection if it was not forced and there's running connection
        if not forced and self.handler is not None and not self.is_closed:
            self.promote()
        else:
            self.close()