connects to pop server

@throws MessagingException
762373
public void start() throws MessagingException {
	Properties properties = new Properties();
	String type = getTypeAsString();
	properties.put("mail." + type + ".host", server);
	properties.put("mail." + type + ".port", new Double(port));
	properties.put("mail." + type + ".connectiontimeout", String.valueOf(timeout));
	properties.put("mail." + type + ".timeout", String.valueOf(timeout));
	// properties.put("mail.mime.charset", "UTF-8");
	if (secure) {
	    properties.put("mail." + type + ".ssl.enable", "true");
	    // properties.put("mail."+type+".starttls.enable", "true" );
	}

	if (TYPE_IMAP == getType()) {
	    properties.put("mail.imap.partialfetch", "false");
	}
	// if(TYPE_POP3==getType()){}
	_session = username != null ? Session.getInstance(properties, new _Authenticator(username, password)) : Session.getInstance(properties);
	_store = _session.getStore(type);
	if (!StringUtil.isEmpty(username)) _store.connect(server, username, password);
	else _store.connect();
    }
28381
protected function connect()
    {
        if (!empty($this->conn)) {
            return;
        }

        if (!extension_loaded('ftp')) {
            throw new ServerException(
                "Unable to initialize ftp storage server, extension 'ftp' not found"
            );
        }

        $conn = ftp_connect(
            $this->options['host'],
            $this->options['port'],
            $this->options['timeout']
        );

        if (empty($conn)) {
            throw new ServerException(
                "Unable to connect to remote FTP server '{$this->options['host']}'"
            );
        }

        if (!ftp_login($conn, $this->options['username'], $this->options['password'])) {
            throw new ServerException(
                "Unable to authorize on remote FTP server '{$this->options['host']}'"
            );
        }

        if (!ftp_pasv($conn, $this->options['passive'])) {
            throw new ServerException(
                "Unable to set passive mode at remote FTP server '{$this->options['host']}'"
            );
        }

        $this->conn = $conn;
    }
874445
public void connect() throws Exception {
        adminClients = new ArrayList<AdminClient>(urls.size());
        // bootstrap from two urls
        Map<String, Cluster> clusterMap = new HashMap<String, Cluster>(urls.size());
        Map<String, StoreDefinition> storeDefinitionMap = new HashMap<String, StoreDefinition>(urls.size());

        for(String url: urls) {
            /* connect to cluster through admin port */
            if(logger.isInfoEnabled()) {
                logger.info("Connecting to bootstrap server: " + url);
            }
            AdminClient adminClient = new AdminClient(url);
            adminClients.add(adminClient);
            /* get Cluster */
            Cluster cluster = adminClient.getAdminClientCluster();
            clusterMap.put(url, cluster);

            Integer nodeId = cluster.getNodeIds().iterator().next();
            /* get StoreDefinition */
            Versioned<List<StoreDefinition>> storeDefinitions = adminClient.metadataMgmtOps.getRemoteStoreDefList(nodeId);
            StoreDefinition storeDefinition = StoreDefinitionUtils.getStoreDefinitionWithName(storeDefinitions.getValue(),
                    storeName);
            storeDefinitionMap.put(url, storeDefinition);
        }

        /* confirm same number of partitions in all clusters. */
        int partitionCount = 0;
        for(Entry<String, Cluster> entry: clusterMap.entrySet()) {
            int currentPartitionCount = entry.getValue().getNumberOfPartitions();
            if(partitionCount == 0) {
                partitionCount = currentPartitionCount;
            }
            if(partitionCount != currentPartitionCount) {
                logger.error("Partition count of different clusters is not the same: "
                        + partitionCount + " vs " + currentPartitionCount);
                throw new VoldemortException("Will not connect because partition counts differ among clusters.");
            }
        }

        /* calculate nodes to scan */
        for(String url: urls) {
            StoreDefinition storeDefinition = storeDefinitionMap.get(url);
            Cluster cluster = clusterMap.get(url);
            Map<Integer, Integer> partitionToNodeMap = cluster.getPartitionIdToNodeIdMap();

            /* find list of nodeId hosting partition */
            List<Integer> partitionList = new RoutingStrategyFactory().updateRoutingStrategy(storeDefinition,
                    cluster)
                    .getReplicatingPartitionList(partitionId);
            for(int partition: partitionList) {
                Integer nodeId = partitionToNodeMap.get(partition);
                Node node = cluster.getNodeById(nodeId);
                clusterNodeList.add(new ClusterNode(urls.indexOf(url), node));
            }
        }

        /* print config info */
        if(logger.isInfoEnabled()) {
            StringBuilder configInfo = new StringBuilder();
            configInfo.append("TYPE,Store,PartitionId,Node,ZoneId,BootstrapUrl\n");
            for(ClusterNode clusterNode: clusterNodeList) {
                configInfo.append("CONFIG,");
                configInfo.append(storeName + ",");
                configInfo.append(partitionId + ",");
                configInfo.append(clusterNode.getNode().getId() + ",");
                configInfo.append(clusterNode.getNode().getZoneId() + ",");
                configInfo.append(urls.get(clusterNode.getPrefixId()) + "\n");
            }
            for(String line: configInfo.toString().split("\n")) {
                logger.info(line);
            }
        }

        /* calculate retention days and more */
        for(String url: urls) {
            StoreDefinition storeDefinition = storeDefinitionMap.get(url);
            /* retention */
            int storeRetentionDays = 0;
            if(storeDefinition.getRetentionDays() != null) {
                storeRetentionDays = storeDefinition.getRetentionDays().intValue();
            }
            if(retentionDays == null) {
                retentionDays = storeRetentionDays;
            }
            if(retentionDays != storeRetentionDays) {
                if(storeRetentionDays != 0 && (storeRetentionDays < retentionDays)) {
                    retentionDays = storeRetentionDays;
                }
                logger.warn("Retention-days is not consistent between clusters by urls. Will use the shorter.");
            }

            /* replication writes */
            replicationFactor += storeDefinition.getReplicationFactor();

            /* required writes */
            requiredWrites += storeDefinition.getRequiredWrites();
        }
        if(replicationFactor != clusterNodeList.size()) {
            logger.error("Replication factor is not consistent with number of nodes routed to.");
            throw new VoldemortException("Will not connect because replication factor does not accord with number of nodes routed to.");
        }
        retentionChecker = new RetentionChecker(retentionDays);
    }
1319518
public function connect()
    {
        if ($this->connection->isOpened()) {
            throw new LogicException('It is not possible to re-open the connection to the EPP server.');
        }

        $this->connection->open();
        $xml = $this->connection->read();
        $this->logger->info('Greeting on connection to the EPP server.', ['body' => $xml]);

        $greeting = new Greeting($xml);
        if (!$greeting->isSuccess()) {
            throw new ConnectionException('Invalid greeting on connection to the EPP server.');
        }

        return $greeting;
    }
816657
public void connect() throws Exception {
        if (connection != null && !connection.isConnected()) {
            connection.connect();
            transaction = connection.getModbusTransport().createTransaction();
            setTransaction(transaction);
        }
    }
418308
void postInvokePopCallbackContexts(EJSDeployedSupport s) {
        // Pop the callback bean if Activator.preInvokeActivateBean was called
        // successfully (excluding homes).                                 d694142
        if (s.ivPopCallbackBeanORequired) {
            s.ivThreadData.popCallbackBeanO();

            // If necessary, return the bean to the pool.  It will be null for
            // BeanNotReentrantException, which will prevent an in-use bean from
            // being returned to the pool.                                RTC107108
            BeanO beanO = s.beanO;
            if (beanO != null) {
                BeanMetaData bmd = beanO.home.beanMetaData;
                if (bmd.type == InternalConstants.TYPE_STATELESS_SESSION ||
                    bmd.type == InternalConstants.TYPE_MESSAGE_DRIVEN) {
                    try {
                        beanO.returnToPool();
                    } catch (RemoteException ex) {
                        FFDCFilter.processException(ex, CLASS_NAME + ".postInvoke", "359", this);
                    }
                }
            }
        }

        s.ivThreadData.ivComponentMetaDataContext.endContext(); // d646139.1
    }
805422
public function pollMessage()
    {
        if (!$this->isConnected()) {
            throw new ConnectionException('Connection Closed!');
        }

        $r = [$this->socket];
        $w = [];
        $e = [];
        $s = socket_select($r, $w, $e, Constants::TIMEOUT_SEC, Constants::TIMEOUT_USEC);

        if ($s) {

            // Something to read
            if ($stanza = $this->readStanza()) {
                $this->processInboundData($stanza);

                return true;
            }
        }
        if (time() - $this->timeout > 60) {
            if ($this->pingCounter >= 3)
            {
              $this->sendOfflineStatus();
              $this->disconnect();
              $this->iqCounter = 1;
              $this->connect();
              $this->loginWithPassword($this->password);
              $this->pingCounter = 1;
            }
            else {
              $this->sendPing();
              $this->pingCounter++;
            }
        }

        return false;
    }
149463
function connect()
    {
        if ( $this->mailbox !== null && $this->username !== null && $this->password !== null ) {
            if ( $this->stream = imap_open($this->mailbox, $this->username, $this->password) ) {
                return true;
            } else {
                throw new Exception(sprintf("Invalid IMAP stream (mailbox: %s, username: %s)", $this->mailbox, $this->username));
            }
        } else {
            throw new Exception(sprintf("Missing IMAP settings: mailbox, username, and/or password"));
        }
    }
1358985
private function connect() {
        $connection = fsockopen('tcp://'.$this->options['host'],
                                         $this->options['port'],
                                         $errorCode,
                                         $errorMsg,
                                         $this->options['timeout']);
        // TODO: connect() might hang without producing an error if the connection fails
        if (!$connection) throw new RuntimeException('Could not open socket: '.$errorMsg.' (error '.$errorCode.')');

        $data = stream_get_meta_data($connection);
        if ($data['timed_out']) throw new InfrastructureException('Timeout on socket connection');

        socket_set_timeout($connection, $this->options['timeout']);
        $this->connection = $connection;

        // init connection
        $this->readResponse();                          // read greeting
        $this->writeData('EHLO '.$this->hostName);      // extended "Hello" first
        $response = $this->readResponse();

        $this->parseResponse($response);
        if ($this->responseStatus != 250) {
            $this->writeData('HELO '.$this->hostName);  // regular "Hello" if the extended one fails
            $response = $this->readResponse();

            $this->parseResponse($response);
            if ($this->responseStatus != 250)
                throw new RuntimeException('HELO command not accepted: '.$this->responseStatus.' '.$this->response);
        }
    }
99878
public function connect()
    {
        $nodes = $this->nodeUrls;

        while (count($nodes)) {
            // pick random server
            $idx = rand(0, count($nodes) - 1);

            try {
                $stream = new DefaultStream($nodes[$idx], $this->log);
                $stream->connect();

                return $stream;
            } catch (ConnectException $e) {
                $this->log->warning($e->getMessage());
            }

            // remove the selected server from the list
            array_splice($nodes, $idx, 1);
        }

        throw new ConnectException('unable to connect to any of ['.implode(',', $this->nodeUrls).']');
    }
600342
public function connect()
    {
        $connection = $this->_connection;
        $connection->setLogin($this->_config['user']);
        $connection->setPassword($this->_config['password']);
        $connection->setHost($this->_config['host']);
        $connection->setPort($this->_config['port']);
        $connection->setVhost($this->_config['vhost']);
        $connection->setReadTimeout($this->_config['readTimeout']);

        # You shall not use persistent connections
        #
        # AMQPChannelException' with message 'Could not create channel. Connection has no open channel slots remaining
        #
        # The PECL extension is foobar, http://stackoverflow.com/questions/23864647/how-to-avoid-max-channels-per-tcp-connection-with-amqp-php-persistent-connectio
        #

        $connection->connect();
    }
362146
public void connect() throws IOException, DeploymentException {
        WebSocketContainer container = ContainerProvider.getWebSocketContainer();
        container.connectToServer(this, wssUri);
        log.debug("client connected to the server: {}", wssUri);
    }
540503
public function connect()
    {
        if ($this->ssl) {
            $this->connection = ftp_ssl_connect($this->getHost(), $this->getPort(), $this->getTimeout());
        } else {
            $this->connection = ftp_connect($this->getHost(), $this->getPort(), $this->getTimeout());
        }

        if ( ! $this->connection) {
            throw new RuntimeException('Could not connect to host: ' . $this->getHost() . ', port:' . $this->getPort());
        }

        $this->login();
        $this->setUtf8Mode();
        $this->setConnectionPassiveMode();
        $this->setConnectionRoot();
        $this->isPureFtpd = $this->isPureFtpdServer();
    }
648118
private function connect()
    {
        if (!$this->_sock) {
            if ($this->_persistentSocket) {
                $this->_sock = pfsockopen($this->_host, $this->_port, $errno, $errstr, $this->_connectTimeout/1000);
            } else {
                $this->_sock = fsockopen($this->_host, $this->_port, $errno, $errstr, $this->_connectTimeout/1000);
            }

            if (!$this->_sock) {
                throw new \Exception('Unable to connect to FastCGI application: ' . $errstr);
            }

            if (!$this->set_ms_timeout($this->_readWriteTimeout)) {
                throw new \Exception('Unable to set timeout on socket');
            }
        }
    }
1292747
public function connect() {
        $count = 0;
        do {
            $count += 1;
            $this->Resource = pg_connect($this->getConnectionString());
            if ($this->Resource !== false) {
                return true;
            }
        } while ($count < $this->getConnectTries());

        throw new TriesOverConnectException();
    }
1025822
@Override
	public final void closeTcpConnection() throws CommunicationException {
		IOException tmpException = null;
		try {
			closeTcpConnectionImpl();
		} catch (IOException e) {
			tmpException = e;
		} finally {
			try {

				if (mSocket != null) {
					mSocket.close();
				}

			} catch (IOException e) {
				tmpException = e;
			} finally {
				mSocket = null;
			}
		}

		if (tmpException != null) {
			throw new CommunicationException(tmpException);
		}
	}
660069
@Override
    public void onConnected() {
        HMSAgentLog.d("connect success");
        timeoutHandler.removeMessages(APICLIENT_TIMEOUT_HANDLE_MSG);
        onConnectEnd(ConnectionResult.SUCCESS);
    }