Sets-up the connector for this MINA session.

@return {@code true} if the setup succeeds, else {@code false}.
197225
protected boolean setConnector() {
    if (this.host == null) {
      log.error("No host value set, cannot set up socket connector.");
      return false;
    }
    if (this.port < 0 || this.port > 65535) {
      log.error("Port value is invalid {}.", Integer.valueOf(this.port));
      return false;
    }
    if (this.executors == null) {
      this.executors = new ExecutorFilter(1);
    }

    this.connector = new NioSocketConnector();
    this.connector.getSessionConfig().setIdleTime(IdleStatus.WRITER_IDLE,
        ClientWorldModelInterface.TIMEOUT_PERIOD / 2);
//    this.connector.getSessionConfig().setIdleTime(IdleStatus.READER_IDLE,
//        (int) (ClientWorldModelInterface.TIMEOUT_PERIOD * 1.1f));
    if (!this.connector.getFilterChain().contains(
        WorldModelClientProtocolCodecFactory.CODEC_NAME)) {
      this.connector.getFilterChain().addLast(
          WorldModelClientProtocolCodecFactory.CODEC_NAME,
          new ProtocolCodecFilter(
              new WorldModelClientProtocolCodecFactory(true)));
    }
    this.connector.getFilterChain().addLast("ExecutorPool", this.executors);
    this.connector.setHandler(this.ioHandler);
    log.debug("Connector set up successful.");
    return true;
  }
787687
public boolean setCurrentConfiguration(CmsGitConfiguration configuration) {

        if ((null != configuration) && configuration.isValid()) {
            m_currentConfiguration = configuration;
            return true;
        }
        return false;
    }
1000941
private ServerConnector configureConnector() {
        ServerConnector connector = null;
        if (m_tls) {
            connector = createSSLConnector();
        } else {
            // Unsecured connector
            connector = new ServerConnector(m_jettyServer);
        }
        if (m_restaddr != null) {
            connector.setHost(m_restaddr);
        }
        connector.setPort(m_restport);
        connector.setIdleTimeout(SOCKET_TIMEOUT_MILLIS);
        connector.addBean(new ConnListener());  // invokes registered callbacks, if any
        return connector;
    }
602992
protected boolean _connect(long timeout) {
    log.debug("Attempting connection...");
    ConnectFuture connFuture = this.connector.connect(new InetSocketAddress(
        this.host, this.port));
    if (!connFuture.awaitUninterruptibly(timeout)) {
      log.warn("Unable to connect to world model after {}ms.",
          Long.valueOf(this.connectionTimeout));
      return false;
    }
    if (!connFuture.isConnected()) {
      log.debug("Failed to connect.");
      return false;
    }

    try {
      log.debug("Attempting connection to {}:{}.", this.host,
          Integer.valueOf(this.port));
      this.session = connFuture.getSession();
    } catch (RuntimeIoException ioe) {
      log.error(String.format(
          "Could not create session to World Model (C) %s:%d.", this.host,
          Integer.valueOf(this.port)), ioe);
      return false;
    }
    return true;
  }
195334
protected Session createSession(Connection connection) throws JMSException {
        if (connection instanceof QueueConnection) {
            return ((QueueConnection) connection).createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
        }
        return connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    }
793045
public function setup()
	{
		$this->addRule('component', function($data)
		{
			self::$connection->setQuery("SELECT element FROM `#__extensions` AS e WHERE e.type = 'component' ORDER BY e.name ASC");
			$extensions = self::$connection->loadColumn();
			if (!in_array($data['component'], $extensions))
			{
				return Lang::txt('Component does not exist.');
			}
			return false;
		});
	}
1314400
private void setupConnection(final Connection connection) throws ConnectionSetupException
   {
      try {
         if (networkTimeout == UNINITIALIZED) {
            networkTimeout = getAndSetNetworkTimeout(connection, validationTimeout);
         }
         else {
            setNetworkTimeout(connection, validationTimeout);
         }

         if (connection.isReadOnly() != isReadOnly) {
            connection.setReadOnly(isReadOnly);
         }

         if (connection.getAutoCommit() != isAutoCommit) {
            connection.setAutoCommit(isAutoCommit);
         }

         checkDriverSupport(connection);

         if (transactionIsolation != defaultTransactionIsolation) {
            connection.setTransactionIsolation(transactionIsolation);
         }

         if (catalog != null) {
            connection.setCatalog(catalog);
         }

         if (schema != null) {
            connection.setSchema(schema);
         }

         executeSql(connection, config.getConnectionInitSql(), true);

         setNetworkTimeout(connection, networkTimeout);
      }
      catch (SQLException e) {
         throw new ConnectionSetupException(e);
      }
   }
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);
    }
1319430
public boolean startSession() {

        synchronized (sharedLock) {
            SessionData session = loadSession();
            if (isSessionActive(session)) {
                sharedLock.notifyAll();
                return false;
            } else {
                clearAll();
            }
            sharedLock.notifyAll();
        }

        return true;
    }
438890
public static boolean bindPort(Session session, String remoteHost, int remotePort, int localPort) throws JschRuntimeException {
		if (session != null && session.isConnected()) {
			try {
				session.setPortForwardingL(localPort, remoteHost, remotePort);
			} catch (JSchException e) {
				throw new JschRuntimeException(e, "From [{}] mapping to [{}] error！", remoteHost, localPort);
			}
			return true;
		}
		return false;
	}
741448
@Override
    public void start() {
        synchronized (this.lifecycleMonitor) {
            if (!isRunning()) {
                log.info("start: Starting ConnectorManager");
                try {
                    connector.start();
                } catch (ConfigError | RuntimeError ex) {
                    throw new ConfigurationException(ex.getMessage(), ex);
                } catch (Throwable ex) {
                    throw new IllegalStateException("Could not start the connector", ex);
                }

                running = true;
            }
        }
    }
92437
public static boolean saveSshSessionAndChannel(Session session, Channel channel, GlobalSessionObject<Map<String, SSHConnection>> sessionParam, String sessionId) {
        final SSHConnection sshConnection;
        if (channel != null) {
            sshConnection = new SSHConnection(session, channel);
        } else {
            sshConnection = new SSHConnection(session);
        }
        if (sessionParam != null) {
            Map<String, SSHConnection> tempMap = sessionParam.get();
            if (tempMap == null) {
                tempMap = new HashMap<>();
            }
            tempMap.put(sessionId, sshConnection);
            sessionParam.setResource(new SSHSessionResource(tempMap));
            return true;
        }
        return false;
    }
404735
public void connect() throws IOException {
        if (isConnected() && tree.session.transport.tconHostName == null) {
            /* Tree thinks it is connected but transport disconnected
             * under it, reset tree to reflect the truth.
             */
            tree.treeDisconnect(true);
        }

        if( isConnected() ) {
            return;
        }

        getUncPath0();
        getFirstAddress();
        for ( ;; ) {
            try {
                doConnect();
                return;
            } catch(SmbAuthException sae) {
                throw sae; // Prevents account lockout on servers with multiple IPs
            } catch(SmbException se) {
                if (getNextAddress() == null) 
                    throw se;
                if (log.level >= 3)
                    se.printStackTrace(log);
            }
        }
    }
74001
protected ActiveMqQueue<ID, DATA> setConnectionFactory(
            ActiveMQConnectionFactory connectionFactory, boolean setMyOwnConnectionFactory) {
        if (myOwnConnectionFactory && this.connectionFactory != null) {
            // destroy this.connectionFactory
        }
        this.connectionFactory = connectionFactory;
        myOwnConnectionFactory = setMyOwnConnectionFactory;
        return this;
    }
235578
public function establish() {

                // Check whether the socket is already connected
                if( isset($this->established) && $this->established ) {
                        return true;
                }
                
		// Try to open the socket connection to MPD with a 5 second timeout
		if( !$this->socket = @fsockopen( $this->host, $this->port, $errn, $errs, 5 ) ) {

			// Throw an MPDConnectionException along with the connection errors
			throw new MPDConnectionException( 'Connection failed: '.$errs, self::MPD_CONNECTION_FAILED );
		}

                // Clear connection messages
                while( !feof( $this->socket ) ) {

                        $response = trim( fgets( $this->socket ) );

                        // If the connection messages have cleared
                        if( strncmp( self::MPD_OK, $response, strlen( self::MPD_OK ) ) == 0 ) {

				// Successully connected
                                $this->established = true;

                                // Parse the MPD version from the response and replace the ending 0 with an x 
                                $this->version = preg_replace('/[0]$/','x', current( sscanf( $response, self::MPD_OK . " MPD %s\n" )));

				// Connected successfully
				return true;
                        }

                        // Check to see if there is a connection error message that was sent in the response
                        if( strncmp( self::MPD_ERROR, $response, strlen( self::MPD_ERROR ) ) == 0 ) {

				// Parse out the error message from the response
                                preg_match( '/^ACK \[(.*?)\@(.*?)\] \{(.*?)\} (.*?)$/', $response, $matches );

				// Throw an exception and include the response errors
                                throw new MPDConnectionException( 'Connection failed: '.$matches[4], self::MPD_CONNECTION_FAILED );
                        }
                }
      
		// Throw a general connection failed exception 
		throw new MPDConnectionException( 'Connection failed', self::MPD_CONNECTION_FAILED );
        }
848002
public boolean connect() throws RestApiConnectionException {
    if (this.autoEstablishAuthToken) {
      if (this.authTokenTimeout <= 0) {
        return false;
      } else if ((System.currentTimeMillis() - this.createdAt) > this.authTokenTimeout) {
        return false;
      }
    }

    HttpEntity httpEntity = null;
    try {
      httpEntity = getAuthentication();

      if (httpEntity != null) {
        JsonElement json = GSON.fromJson(EntityUtils.toString(httpEntity), JsonObject.class);
        if (json == null) {
          log.error("Http entity: " + httpEntity);
          log.error("entity class: " + httpEntity.getClass().getName());
          log.error("entity string size: " + EntityUtils.toString(httpEntity).length());
          log.error("content length: " + httpEntity.getContentLength());
          log.error("content: " + IOUtils.toString(httpEntity.getContent(), Charsets.UTF_8));
          throw new RestApiConnectionException(
              "JSON is NULL ! Failed on authentication with the following HTTP response received:\n"
                  + EntityUtils.toString(httpEntity));
        }

        JsonObject jsonRet = json.getAsJsonObject();
        log.info("jsonRet: " + jsonRet.toString());
        parseAuthenticationResponse(jsonRet);
      }
    } catch (IOException e) {
      throw new RestApiConnectionException("Failed to get rest api connection; error - " + e.getMessage(), e);
    } finally {
      if (httpEntity != null) {
        try {
          EntityUtils.consume(httpEntity);
        } catch (IOException e) {
          throw new RestApiConnectionException("Failed to consume httpEntity; error - " + e.getMessage(), e);
        }
      }
    }

    return true;
  }
850822
public boolean setupDirectDataSourceConnection() throws DBException
    {
        if (m_JDBCConnection != null)
            return true;
        try {
            if (m_datasourceFactory == null)
            {
                String strClassName = this.getProperty(SQLParams.DATASOURCE_FACTORY);
            	strClassName = ClassServiceUtility.getFullClassName(strClassName);
                try {
                	m_datasourceFactory = (DatasourceFactory)ClassServiceUtility.getClassService().makeObjectFromClassName(strClassName);
             	    //xClass<?> c = Class.forName(strClassName);
             	    //xm_datasourceFactory = (DatasourceFactory)c.newInstance();
                } catch (Exception e) {
            		Utility.getLogger().warning("Error on create class: " + strClassName);
            		e.printStackTrace();
                }
            }
            if (m_datasourceFactory == null)
                return false;   // No factory
            ConnectionPoolDataSource poolDataSource = m_datasourceFactory.getPooledDataSource(this);
            if (poolDataSource != null)
            	if (poolDataSource.getPooledConnection() != null)
            		m_JDBCConnection = poolDataSource.getPooledConnection().getConnection();
            if (m_JDBCConnection == null)
            {   // Otherwise, just try plain datasource connection
                DataSource dataSource = m_datasourceFactory.getFakePooledDataSource(this);
                if (dataSource != null)
                    m_JDBCConnection = dataSource.getConnection();
            }
            if (m_JDBCConnection == null)
            {   // Otherwise, just try plain datasource connection
                DataSource dataSource = m_datasourceFactory.getDataSource(this);
                if (dataSource != null)
                    m_JDBCConnection = dataSource.getConnection();
                else
                    return false;   // Failure
            }
        } catch (SQLException e) {
            return false;   // Failure
        }
        return true;    // Success!
    }