Accept connections from the remote server,
and start transfer threads that will read incoming data and store
in the sink.

@param connections the number of expected connections
503739
public synchronized void passiveConnect(DataSink sink,
                                            TransferContext context,
                                            int connections,
                                            ServerSocket serverSocket)
        throws ServerException {

        // things would get messed up if more than 1 file was transfered
        // simultaneously with the same transfer manager
        if (transferThreadCount != 0) {
            throw new ServerException(
                            ServerException.PREVIOUS_TRANSFER_ACTIVE);
        }

        for (int i = 0; i < connections; i++) {
            Task task =
                new GridFTPPassiveConnectTask(
                                serverSocket,
                                sink,
                                localControlChannel,
                                gSession,
                                dataChannelFactory,
                                (EBlockParallelTransferContext) context);

            runTask(task);
        }
    }
929975
public final void addConnections (final int max) throws Exception {

        if (connections.size() < maxConnections) {
            for (int i = 1; i < max; i++) {
                addNewConnection();
            }
        }
    }
67500
function broadcast(connections, packet) {
    var i = connections.length;
    while (i--) {
        connections[i].write(packet);
        flush(connections[i]);
    }
}
1868
@PostConstruct
    public void acquireConnections() throws JMSException {
        LOGGER.debug("Initializing: {}", this.getClass().getCanonicalName());

        connection = connectionFactory.createConnection();
        connection.start();
        jmsSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        producer = jmsSession.createProducer(createDestination());
        eventBus.register(this);
    }
869116
public void send(String uri, String data) {
        Objects.requireNonNull(uri, Required.URI.toString());

        final Set<ServerSentEventConnection> uriConnections = getConnections(uri);
        if (uriConnections != null) {
            uriConnections.stream()
                .filter(ServerSentEventConnection::isOpen)
                .forEach((ServerSentEventConnection connection) -> connection.send(data));
            
       }
    }
274997
public synchronized void startTransfer(DataSource source,
                                           TransferContext context,
                                           int connections,
                                           boolean reusable)
        throws ServerException {

        // things would get messed up if more than 1 file was transfered
        // simultaneously with the same transfer manager
        if (transferThreadCount != 0) {
            throw new ServerException(
                            ServerException.PREVIOUS_TRANSFER_ACTIVE);
        }

        for (int i = 0; i < connections; i++) {
            logger.debug(
                         "checking out a socket; total cached sockets = "
                         + socketPool.count()
                         + "; free = "
                         + socketPool.countFree()
                         + "; busy = "
                         + socketPool.countBusy());

            SocketBox sbox = socketPool.checkOut();
            if (sbox == null) {
                logger.debug("No free sockets available, aborting.");
                return;
            }
            ((ManagedSocketBox) sbox).setReusable(reusable);

            Task task =
                new ActiveStartTransferTask(source,
                                            localControlChannel,
                                            sbox,
                                            gSession,
                                            dataChannelFactory,
                                            context);

            runTask(task);
        }
    }
862984
public RiakNode setMinConnections(int minConnections)
    {
        stateCheck(State.CREATED, State.RUNNING, State.HEALTH_CHECKING);
        if (minConnections <= getMaxConnections())
        {
            this.minConnections = minConnections;
        }
        else
        {
            throw new IllegalArgumentException("Min connections greater than max connections");
        }
        // TODO: Start / reap delta?
        return this;
    }
388074
public void register(K key, T connection) {
        connections.put(key, new Sync<>(key, connection));
    }
978576
public void connect(List<Tree> children) {
        this.children = children;
        for (Tree t : children)
            t.setParent(this);
    }
1345878
private static List<ConnectionNotation> getAllSelfCycleConnections(List<ConnectionNotation> connections) {
    List<ConnectionNotation> listSelfCycle = new ArrayList<ConnectionNotation>();
    for (ConnectionNotation connection : connections) {
      if ((connection.getTargetId().getId().equals(connection.getSourceId().getId()))) {
        listSelfCycle.add(connection);
      }
    }
    return listSelfCycle;
  }
1362289
public void addConnection(RedisURI redisURI, StatefulRedisConnection<String, String> connection) {

        if (this.closed) { // fastpath
            connection.closeAsync();
            return;
        }

        synchronized (this.connections) {

            if (this.closed) {
                connection.closeAsync();
                return;
            }

            this.connections.put(redisURI, connection);
        }
    }
597188
public void store(DataSink sink) {
        try {

            localControlChannel.resetReplyCount();

            if (session.transferMode != GridFTPSession.MODE_EBLOCK) {
                //
                // no EBLOCK
                //
                EBlockParallelTransferContext context =
                    (EBlockParallelTransferContext) createTransferContext();
                context.setEodsTotal(0);

                if (session.serverMode == Session.SERVER_PASSIVE) {
                    transferThreadManager.passiveConnect(
                                                         sink,
                                                         context,
                                                         1,
                                                         serverSocket);

                } else {
                    //1 non reusable connection
                    transferThreadManager.startTransfer(
                                                        sink,
                                                        context,
                                                        1,
                                                        ManagedSocketBox.NON_REUSABLE);
                }

            } else if (
                       session.serverMode != GridFTPSession.SERVER_EPAS
                       && session.serverMode != GridFTPSession.SERVER_PASSIVE) {
                //
                // EBLOCK, local server not passive
                //
                exceptionToControlChannel(
                                          new DataChannelException(
                                                                   DataChannelException.BAD_SERVER_MODE),
                                          "refusing to store with active mode");
            } else {
                //
                // EBLOCK, local server passive
                //

                // data channels will
                // share this transfer context
                EBlockParallelTransferContext context =
                    (EBlockParallelTransferContext) createTransferContext();

                // we are the passive side, so we don't really get to decide
                // how many connections will be used
                int willReuseConnections = socketPool.countFree();
                int needNewConnections = 0;
                if (gSession.parallel > willReuseConnections) {
                    needNewConnections = gSession.parallel - willReuseConnections;
                }

                logger.debug("will reuse " + willReuseConnections +
                             " connections and start " + needNewConnections +
                             " new ones.");

                transferThreadManager.startTransfer(
                                                    sink,
                                                    context,
                                                    willReuseConnections,
                                                    ManagedSocketBox.REUSABLE);

                if (needNewConnections > 0) {
                    transferThreadManager.passiveConnect(
                                                         sink,
                                                         context,
                                                         needNewConnections,
                                                         serverSocket);
                }
            }
        } catch (Exception e) {
            exceptionToControlChannel(e, "ocurred during store()");
        }
    }
1310197
@Override
    public void processConnect(WebSocketChannel channel, WSURI location, String[] protocols) {
        LOG.entering(CLASS_NAME, "connect", channel);

        nextHandler.processConnect(channel, location, protocols);
    }
322032
public void setConnectionList(java.util.Collection<Connection> connectionList) {
        if (connectionList == null) {
            this.connectionList = null;
            return;
        }

        this.connectionList = new java.util.ArrayList<Connection>(connectionList);
    }
1306202
private static synchronized void closeRegisteredConnections() {
        for (Connection connection : activeConnections) {
            LOGGER.log(Level.INFO, "Forcing connection to {0}:{1} closed.",
                    new Object[]{connection.getHostname(), connection.getPort()});
            // force closed just in case
            connection.close();
        }
        activeConnections.clear();
    }
1103713
public static final void commit(final Connection connection) {
        if (connection == null) {
            return;
        }

        try {
            connection.commit();
        } catch (Exception e) {
            if (LOG.isWarnEnabled()) LOG.warn("Error committing Connection: " + connection, e);
        }
    }
66284
public void setSinks(java.util.Collection<CatalogEntry> sinks) {
        if (sinks == null) {
            this.sinks = null;
            return;
        }

        this.sinks = new java.util.ArrayList<CatalogEntry>(sinks);
    }