Quiesce connections

@pre quiesceIfPossible has been called.

@throws ResourceException
@concurrency concurrent
18081
private void quiesce() throws ResourceException {

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) {
            Tr.entry(this, tc, "quiesce", gConfigProps.cfName);
        }

        // Remove parked connection if it exists
        if ((gConfigProps.isSmartHandleSupport() == false)) {
            freePool[0].removeParkedConnection();
        }

        if (parkedMCWrapper != null) {
            parkedMCWrapper.clearMCWrapper();
        }

        pmQuiesced = true;

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) {
            Tr.exit(this, tc, "quiesce", gConfigProps.cfName);
        }

    }
29457
protected void nowReconnectedSync(IOException originalExcep) throws IOException {

        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
            Tr.debug(tc, "Reconnected sync for " + this);
        }
        if (!resetWriteBuffers()) {
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                Tr.debug(tc, "Resetting buffers (sync) failed");
            }
            throw originalExcep;
        }
        // now that we've reconnected, we should reset the "broken" flag. First
        // we set it to the default and then recheck the request msg
        setPersistent(true);
        updatePersistence(getRequestImpl());

        // Note: during a sync path, we don't actually enable reconnects once
        // we start reading and parsing the response (only async path)
        // in case we read any partial data, we need to clean out the response
        // resetRead();

        if (isReadAheadEnabled()) {
            // after a reconnect, there is no more read-ahead active
            this.bReadAheadEnabled = false;
        }
        try {
            getTSC().getWriteInterface().write(TCPWriteRequestContext.WRITE_ALL_DATA, getWriteTimeout());
        } catch (IOException ioe) {
            // no FFDC required
            // just set the "broken" connection flag
            setPersistent(false);
            throw ioe;
        }
    }
1355703
private void createMultipleListeners(final SibRaMessagingEngineConnection connection) throws ResourceException
    {
        final String methodName = "createMultipleListeners";
        if (TraceComponent.isAnyTracingEnabled() && TRACE.isEntryEnabled())
        {
            SibTr.entry(this, TRACE, methodName, connection);
        }

        try
        {
            final SICoreConnection coreConnection = connection.getConnection();

            /*
             * Create destination listener
             */

            final DestinationListener destinationListener = new SibRaDestinationListener(
                            connection, _messageEndpointFactory);

            /*
             * Determine destination type
             */

            final DestinationType destinationType = _endpointConfiguration
                            .getDestinationType();

            /*
             * Register destination listener
             */

            final SIDestinationAddress[] destinations = coreConnection
                            .addDestinationListener(_endpointConfiguration.getDestinationName(),
                                                    destinationListener,
                                                    destinationType,
                                                    DestinationAvailability.RECEIVE);

            if (TraceComponent.isAnyTracingEnabled() && TRACE.isDebugEnabled())
            {
                SibTr.debug(P2PTRACE, "Found " + destinations.length + " destinations that make the wildcard");
            }

            /*
             * Create a listener for each destination ...
             */

            for (int j = 0; j < destinations.length; j++)
            {
                try
                {
                    if (TraceComponent.isAnyTracingEnabled() && TRACE.isDebugEnabled())
                    {
                        SibTr.debug(P2PTRACE, "Creating a consumer for destination " + destinations[j]);
                    }
                    connection.createListener(destinations[j], _messageEndpointFactory);
                } catch (final ResourceException exception)
                {
                    FFDCFilter.processException(exception, CLASS_NAME + "."
                                                           + methodName, "1:877:1.45", this);
                    SibTr.error(TRACE, "CREATE_LISTENER_FAILED_CWSIV0803",
                                new Object[] { exception,
                                              destinations[j].getDestinationName(),
                                              connection.getConnection().getMeName(),
                                              connection.getBusName() });
                }
            }
        } catch (final SIException exception)
        {
            FFDCFilter.processException(exception, CLASS_NAME + "."
                                                   + methodName, "1:889:1.45", this);
            SibTr.error(TRACE, "ADD_DESTINATION_LISTENER_FAILED_CWSIV0804",
                        new Object[] { exception, connection.getConnection().getMeName(),
                                      connection.getBusName() });
            _connections.remove(connection.getConnection().getMeUuid());
            connection.close();
        }

        if (connection.getNumberListeners() == 0)
        {
            SibTr.warning(TRACE, "NO_LISTENERS_CREATED_CWSIV0809", new Object[] { _endpointConfiguration.getDestinationName(),
                                                                                 connection.getConnection().getMeName(),
                                                                                 connection.getBusName() });
        }

        if (TraceComponent.isAnyTracingEnabled() && TRACE.isEntryEnabled())
        {
            SibTr.exit(this, TRACE, methodName);
        }
    }
550106
public void cleanup() throws ResourceException {

        if (TraceComponent.isAnyTracingEnabled() && TRACE.isEntryEnabled()) {
            SibTr.entry(this, TRACE, "cleanup");
        }

        // Invalidate any currently associated connections
        for (Iterator iterator = _connections.iterator(); iterator.hasNext();) {

            final SibRaConnection connection = (SibRaConnection) iterator
                    .next();
            connection.invalidate();

        }

        // If we have a connection exception then we must have hit a problem with getting the
        // physical connection. We need to throw an exception here to force the destroy of this
        // managed connection else it goes in the free pool. I better solution would be to expose
        // an api that we can call on jca, this is work in progress.
        if (_connectionException != null)
        {
          //The string used here is searched for by jca so that it won't log the error
            ResourceException exception = new ResourceException("Skip logging for this failing connection");
            if (TRACE.isEventEnabled()) {
              SibTr.exception(this, TRACE, exception);
            }
            throw exception;
        }

        if (TraceComponent.isAnyTracingEnabled() && TRACE.isEntryEnabled()) {
            SibTr.exit(this, TRACE, "cleanup");
        }

    }
94640
@Override
    public SICoreConnection cloneConnection()
                    throws SIConnectionUnavailableException, SIConnectionDroppedException,
                    SIResourceException, SIConnectionLostException, SILimitExceededException,
                    SIErrorException
    {
        if (TraceComponent.isAnyTracingEnabled() && CoreSPIConnection.tc.isEntryEnabled())
            SibTr.entry(CoreSPIConnection.tc, "cloneConnection", this);

        SICoreConnection clone = null;

        // take a lock on  the MP _connections lock manager (required to maintain lock consistency)

        _messageProcessor.getConnectionLockManager().lock();

        try
        {
            // See if this connection has been closed
            checkNotClosed();

            //Create a new connection instance
            // The definition of a cloned connection is that it is connected to the
            // same ME. This is always true in the MP layer.
            clone = _messageProcessor.createConnection(_subject, false, _connectionProperties);
        } finally
        {
            _messageProcessor.getConnectionLockManager().unlock();
        }

        if (TraceComponent.isAnyTracingEnabled() && CoreSPIConnection.tc.isEntryEnabled())
            SibTr.exit(CoreSPIConnection.tc, "cloneConnection", clone);
        return clone;
    }
976480
void connectionCloses(final SynchronizeFXTomcatConnection connection) {
        LOG.info("Client connection closed.");
        synchronized (connections) {
            final ExecutorService executorService = connectionThreads.get(connection);
            if (executorService != null) {
                executorService.shutdown();
            }
            connectionThreads.remove(connection);
            connections.remove(connection);
        }
    }
326490
public void setVpcPeeringConnections(java.util.Collection<VpcPeeringConnection> vpcPeeringConnections) {
        if (vpcPeeringConnections == null) {
            this.vpcPeeringConnections = null;
            return;
        }

        this.vpcPeeringConnections = new java.util.ArrayList<VpcPeeringConnection>(vpcPeeringConnections);
    }
624545
static <K, V> void connectExpirables(ReferenceEntry<K, V> previous, ReferenceEntry<K, V> next) {
    previous.setNextExpirable(next);
    next.setPreviousExpirable(previous);
  }
1276092
public void setConnections(String uri, Set<ServerSentEventConnection> uriConnections) {
        Objects.requireNonNull(uri, Required.URI.toString());
        Objects.requireNonNull(uriConnections, Required.URI_CONNECTIONS.toString());

        this.cache.put(Default.SSE_CACHE_PREFIX.toString() + uri, uriConnections);
    }
956806
public void doReconnect() {
        if (channelRef.get() != null) {
            // if (channelRef.get().isWritable()) {
            // LOG.info("already exist a writable channel, give up reconnect, {}",
            // channelRef.get());
            // return;
            // }
            return;
        }

        if (isClosed()) {
            return;
        }

        if (isConnecting.getAndSet(true)) {
            LOG.info("Connect twice {}", name());
            return;
        }

        long sleepMs = getSleepTimeMs();
        LOG.info("Reconnect ... [{}], {}, sleep {}ms", retries.get(), name, sleepMs);
        ChannelFuture future = bootstrap.connect(remoteAddr);
        future.addListener(new ChannelFutureListener() {
            public void operationComplete(ChannelFuture future) throws Exception {
                isConnecting.set(false);
                Channel channel = future.getChannel();
                if (future.isSuccess()) {
                    // do something else
                    LOG.info("Connection established, channel = :{}", channel);
                    setChannel(channel);
                    // handleResponse();
                    BATCH_THRESHOLD_WARN = ConfigExtension.getNettyBufferThresholdSize(stormConf);

                    // Check if any pending message
                    /*synchronized (writeLock) {
                        if (channel != null && messageBuffer.size() > 0) {
                            MessageBatch messageBatch = messageBuffer.drain();
                            flushRequest(channel, messageBatch);
                        } else {
                            LOG.warn("Failed to flush pending message after reconnecting, channel={}, messageBuffer.size={}",
                                    channel, messageBuffer.size());
                        }
                    }*/
                } else {
                    if (!isClosed()) {
                        LOG.info("Failed to reconnect ... [{}], {}, channel = {}, cause = {}",
                                retries.get(), name, channel, future.getCause());
                        reconnect();
                    }
                }
            }
        });
        JStormUtils.sleepMs(sleepMs);
    }
929975
public final void addConnections (final int max) throws Exception {

        if (connections.size() < maxConnections) {
            for (int i = 1; i < max; i++) {
                addNewConnection();
            }
        }
    }
877772
@Override
    public boolean addSync() throws ResourceException {

        if (tc.isEntryEnabled()) {
            Tr.entry(this, tc, "addSync");
        }

        UOWCoordinator uowCoord = mcWrapper.getUOWCoordinator();

        if (uowCoord == null) {
            IllegalStateException e = new IllegalStateException("addSync: illegal state exception. uowCoord is null");
            Tr.error(tc, "ILLEGAL_STATE_EXCEPTION_J2CA0079", "addSync", e);
            if (tc.isEntryEnabled())
                Tr.exit(this, tc, "addSync", e);
            throw e;
        }

        try {
            // added a second synchronization
            //
            // RRS Transactions don't follow the XA model, and therefore don't receive callbacks for
            // end, prepare, and commit/rollback.  Defect  added State Management for RRS
            // controlled transactions, and because the state on the adapter is, for XA transactions,
            // reset during the commit callback, we need to reset the adapter state as close as
            // possible after the commit time.  Therefore, we need to register as a priority sync
            // for the purpose of resetting the adapter state.  We need to also register as a normal
            // sync, however, because we have additional afterCompletion code that returns the
            // managed connection to the free pool.  This code must be executed AFTER DB2 gets its
            // afterCompletion callback.  DB2 is also registered as a priority sync, and since we
            // can't guarantee the order of the afterCompletion callbacks if two syncs are registered
            // as priority, we need to register as a regular sync to execute this part of the code.
            EmbeddableWebSphereTransactionManager tranMgr = mcWrapper.pm.connectorSvc.transactionManager;
            tranMgr.registerSynchronization(uowCoord, this); 
            final ManagedConnection mc = mcWrapper.getManagedConnection();

            // Registering a synchronization object with priority SYNC_TIER_RRS (3) allows the
            // synchronization to be called last.
            if (mc instanceof WSManagedConnection)
            {
                tranMgr.registerSynchronization( 
                uowCoord,
                                                new Synchronization()
                                                {
                                                    @Override
                                                    public void beforeCompletion() 
                                                    {
                                                    } 

                                                    @Override
                                                    public void afterCompletion(int status) 
                                                    {
                                                        ((WSManagedConnection) mc).afterCompletionRRS();
                                                    }
                                                },
                                                RegisteredSyncs.SYNC_TIER_RRS
               );
            }
        } catch (Exception e) {
            com.ibm.ws.ffdc.FFDCFilter.processException(
                                                        e,
                                                        "com.ibm.ejs.j2c.RRSGlobalTransactionWrapper.addSync",
                                                        "238",
                                                        this);
            Tr.error(tc, "REGISTER_WITH_SYNCHRONIZATION_EXCP_J2CA0026", "addSync", e, "ResourceException");
            ResourceException re = new ResourceException("addSync: caught Exception");
            re.initCause(e); 
            if (tc.isEntryEnabled())
                Tr.exit(this, tc, "addSync", e);
            throw re;
        }
        if (tc.isEntryEnabled()) {
            Tr.exit(this, tc, "addSync", true);
        }
        return true;
    }
1254557
public function setConnectionResource($resource): void
    {
        if ($this->itemConverter instanceof ConnectionAware) {
            $this->itemConverter->setConnectionResource($resource);
        }
    }
572970
protected function shouldBeConnected()
    {
        // If we lost the connection, first let's try and reconnect
        if (!$this->isConnected()) {
            try {
                $this->switchNodeIfNeeded();
            } catch (ConnectionException $e) {
                throw new ConnectionException('Not connected. ' . $e->getMessage(), 0, $e);
            }
        }
    }
590623
protected void updateCreatedConnections(int increment) {

		try {
			this.statsLock.writeLock().lock();
			this.createdConnections += increment;
		} finally {
			this.statsLock.writeLock().unlock();
		}
	}
985536
@Override
    final public void dissociateConnections() throws ResourceException {

        if (TraceComponent.isAnyTracingEnabled() && TRACE.isEntryEnabled()) {
            SibTr.entry(TRACE, "dissociateConnections");
        }

        // Dissociate sessions

        for (final Iterator iterator = _sessions.iterator(); iterator.hasNext();) {
            final Object object = iterator.next();
            if (object instanceof JmsJcaSessionImpl) {
                ((JmsJcaSessionImpl) object).dissociate();
                iterator.remove();
            }
        }

        if (TraceComponent.isAnyTracingEnabled() && TRACE.isEntryEnabled()) {
            SibTr.exit(this, TRACE, "dissociateConnections");
        }

    }
41361
public void process( List<List<SquareNode>> clusters ) {

		valid.reset();
		for( int i = 0; i < clusters.size(); i++ ) {
			List<SquareNode> graph = clusters.get(i);

			if( graph.size() < minimumElements )
				continue;

			switch( checkNumberOfConnections(graph) ) {
				case 1:orderIntoLine(graph); break;
				case 2:orderIntoGrid(graph); break;
//				default: System.out.println("Failed number of connections. size = "+graph.size());
			}
		}
	}