Build proxy or not

@throws \Initially\Rpc\Exception\InitiallyRpcException
496438
public function buildProxyOrNot()
    {
        if (!Util::existsDirWritable(INITIALLY_RPC_ROOT_PATH)) {
            throw new InitiallyRpcException("rpc framework root dir not to be write");
        }

        if ($this->compareConfigFile()) {
            $services = $this->config->getServices();
            foreach ($services as $service) {
                $this->builder->create($service->getInterface());
            }
        }
    }
150717
protected function _ensureSocketCreated() {
        // Already ready!
        if (is_resource($this->socket_)) {
            return TRUE;
        }

        $sockaddr = $this->scheme_ . '://' . $this->host_;
        $port = $this->port_;

        // Ignore the Thrift specified timeout ($this->timeout_) and use the
        // socket-specific timeout set in this file.
        $timeout = self::DEFAULT_CONNECT_TIMEOUT_SECS;

        for ($retry = 0; $retry < self::MAX_SOCKET_OPEN_RETRIES; $retry++) {
            try {
                // Suppress connection error logs
                $fd = @pfsockopen($sockaddr, $port, $errno, $errstr, $timeout);
                if ($errno == 0 && is_resource($fd)) {
                    // Connection okay - break out of the retry loop
                    stream_set_blocking($fd, 0);
                    stream_set_timeout($fd, 0, self::DEFAULT_STREAM_TIMEOUT_MICROS);
                    $this->socket_ = $fd;
                    break;
                }
            } catch (Exception $e) {
                // Ignore the exception and retry
            }
        }

        return is_resource($this->socket_);
    }
859662
public function start()
    {
        if (false === ($this->socket = @socket_create(AF_INET, SOCK_STREAM, getprotobyname($this->config['protocol'])))) {
            throw new Exception(sprintf('socket_create(AF_INET, SOCK_STREAM, <%s>) failed: [%d] %s',
                $this->config['protocol'], $code = socket_last_error(), socket_strerror($code)));
        }

        if (false === @socket_bind($this->socket, $this->config['ip'], $this->config['port'])) {
            throw new Exception(sprintf('socket_bind($socket, "%s", %d) failed: [%d] %s',
                $this->config['ip'], $this->config['port'], $code = socket_last_error(), socket_strerror($code)));
        }

        if (false === @socket_getsockname($this->socket, $this->config['ip'], $this->config['port'])) {
            throw new Exception(sprintf('socket_getsockname($socket, "%s", %d) failed: [%d] %s',
                $this->config['ip'], $this->config['port'], $code = socket_last_error(), socket_strerror($code)));
        }

        if (false === @socket_listen($this->socket)) {
            throw new Exception(sprintf('socket_listen($socket) failed: [%d] %s', $code = socket_last_error(), socket_strerror($code)));
        }

        $this->started = true;

        $this->log('Listening for connections on <pop>'.$this.'</pop>', Logger::INFO);
    }
11503
protected function makeSocket(): void
    {
        if ($this->useSSL) {
            if (!file_exists($this->cert)) {
                throw new \Exception('Cert file not found');
            }

            $context = stream_context_create([
                'ssl' => [
                    'local_cert'        => $this->cert,
                    'passphrase'        => $this->passPhrase,
                    'verify_peer'       => false,
                    'verify_peer_name'  => false,
                    'allow_self_signed' => true,
                    'verify_depth'      => 0
                ]
            ]);

            $protocol = 'ssl';
        } else {
            $context = stream_context_create();
            $protocol = 'tcp';
        }

        $this->socket = stream_socket_server("$protocol://{$this->host}:{$this->port}", $errorNumber, $errorString, STREAM_SERVER_BIND | STREAM_SERVER_LISTEN, $context);

        if ($this->useConnector) {
            if (file_exists(static::$connector)) {
                unlink(static::$connector);
            }

            $this->unixConnector = stream_socket_server('unix://' . static::$connector, $errorNumber, $errorString, STREAM_SERVER_BIND | STREAM_SERVER_LISTEN);
            chmod(static::$connector, 0777);
        }

        if (!$this->socket) {
            throw new SocketException($errorString, $errorNumber);
        }
    }
929421
public function build()
    {
        $this->objectConfigurations = $this->objectManager->getObjectConfigurations();

        foreach ($this->objectConfigurations as $objectName => $objectConfiguration) {
            $className = $objectConfiguration->getClassName();
            if ($className === '' || $this->compiler->hasCacheEntryForClass($className) === true) {
                continue;
            }

            if ($objectName !== $className || $this->reflectionService->isClassAbstract($className)) {
                continue;
            }
            $proxyClass = $this->compiler->getProxyClass($className);
            if ($proxyClass === false) {
                continue;
            }
            $this->logger->debug('Building DI proxy for "' . $className . '".');

            $constructorPreCode = '';
            $constructorPostCode = '';

            $constructorPreCode .= $this->buildSetInstanceCode($objectConfiguration);
            $constructorPreCode .= $this->buildConstructorInjectionCode($objectConfiguration);

            $setRelatedEntitiesCode = '';
            if (!$this->reflectionService->hasMethod($className, '__sleep')) {
                $proxyClass->addTraits(['\\' . ObjectSerializationTrait::class]);
                $sleepMethod = $proxyClass->getMethod('__sleep');
                $sleepMethod->addPostParentCallCode($this->buildSerializeRelatedEntitiesCode($objectConfiguration));

                $setRelatedEntitiesCode = "\n        " . '$this->Flow_setRelatedEntities();' . "\n";
            }

            $wakeupMethod = $proxyClass->getMethod('__wakeup');
            $wakeupMethod->addPreParentCallCode($this->buildSetInstanceCode($objectConfiguration));
            $wakeupMethod->addPreParentCallCode($setRelatedEntitiesCode);
            $wakeupMethod->addPostParentCallCode($this->buildLifecycleInitializationCode($objectConfiguration, ObjectManagerInterface::INITIALIZATIONCAUSE_RECREATED));
            $wakeupMethod->addPostParentCallCode($this->buildLifecycleShutdownCode($objectConfiguration, ObjectManagerInterface::INITIALIZATIONCAUSE_RECREATED));

            $injectPropertiesCode = $this->buildPropertyInjectionCode($objectConfiguration);
            if ($injectPropertiesCode !== '') {
                $proxyClass->addTraits(['\\' . PropertyInjectionTrait::class]);
                $proxyClass->getMethod('Flow_Proxy_injectProperties')->addPreParentCallCode($injectPropertiesCode);
                $proxyClass->getMethod('Flow_Proxy_injectProperties')->overrideMethodVisibility('private');
                $wakeupMethod->addPreParentCallCode("        \$this->Flow_Proxy_injectProperties();\n");

                $constructorPostCode .= '        if (\'' . $className . '\' === get_class($this)) {' . "\n";
                $constructorPostCode .= '            $this->Flow_Proxy_injectProperties();' . "\n";
                $constructorPostCode .= '        }' . "\n";
            }

            $constructorPostCode .= $this->buildLifecycleInitializationCode($objectConfiguration, ObjectManagerInterface::INITIALIZATIONCAUSE_CREATED);
            $constructorPostCode .= $this->buildLifecycleShutdownCode($objectConfiguration, ObjectManagerInterface::INITIALIZATIONCAUSE_CREATED);

            $constructor = $proxyClass->getConstructor();
            $constructor->addPreParentCallCode($constructorPreCode);
            $constructor->addPostParentCallCode($constructorPostCode);

            if ($this->objectManager->getContext()->isProduction()) {
                $this->compileStaticMethods($className, $proxyClass);
            }
        }
    }
1110332
protected function initialize() {
	$request   = bootstrap::get_library('request');
	$response  = bootstrap::get_library('response');
	$exception = bootstrap::get_library('exception');
	
	$this->url    = $request::get_url();
	$this->method = $request::get_method();
	
	if (empty($this->method)) {
		throw new $exception('unknown http method', $response::STATUS_METHOD_NOT_ALLOWED);
	}
}
1037398
private void startProxy() throws Exception {
    mProxyProcess = ProxyProcess.Factory.create();
    Runnable runProxy = () -> {
      try {
        mProxyProcess.start();
      } catch (InterruptedException e) {
        // this is expected
      } catch (Exception e) {
        // Log the exception as the RuntimeException will be caught and handled silently by JUnit
        LOG.error("Start proxy error", e);
        throw new RuntimeException(e + " \n Start Proxy Error \n" + e.getMessage(), e);
      }
    };

    mProxyThread = new Thread(runProxy);
    mProxyThread.setName("ProxyThread-" + System.identityHashCode(mProxyThread));
    mProxyThread.start();
    TestUtils.waitForReady(mProxyProcess);
  }
615677
protected function build()
    {
        // Check for config file
        $configFile = __dir__ . DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'googleconfig.php';
        if (!file_exists($configFile))
            throw new \ErrorException('Unable to find config file.');
        $this->configData = require $configFile;
        // Validate Key parameter
        if (!Arr::has($this->configData,'key'))
            throw new \ErrorException('Unable to find Key parameter in configuration file.');
        // Validate service config
        if (!Arr::has($this->configData, 'service.' . $this->service))
            throw new \ErrorException('Unable to find '.$this->service.' parameter in configuration file.');
        $this->setService();
        // set default endpoint
        $this->setEndpoint();
        // is service key set, use it, otherwise use default key
        if(is_null($this->getApiKey()))
            $this->apiKey = (!$this->getService('key')) ? $this->getConfig('key') : $this->getService('key');
        // set service url
        $this->requestUrl = UrlHandler::parse($this->getService('url'));
        // is ssl_verify_peer key set, use it, otherwise use default key
        $this->verifySSL = (bool)$this->getConfig('ssl_verify_peer');
    }
883006
public function main()
    {
        if (method_exists($this->proxy, "setLocation")) {
            try { // try to set location
                $this->proxy->setLocation($this->getLocation());
            } catch (Exception $ex) {
                $this->log("Error setting location in " . get_class($this->proxy) . Project::MSG_ERR);
                throw new BuildException($ex);
            }
        } else {
            throw new Exception("Error setting location in class " . get_class($this->proxy));
        }

        if (method_exists($this->proxy, "setProject")) {
            try { // try to set project
                $this->proxy->setProject($this->project);
            } catch (Exception $ex) {
                $this->log("Error setting project in " . get_class($this->proxy) . Project::MSG_ERR);
                throw new BuildException($ex);
            }
        } else {
            throw new Exception("Error setting project in class " . get_class($this->proxy));
        }

        try { //try to call main
            DispatchUtils::main($this->proxy);
        } catch (BuildException $be) {
            throw $be;
        } catch (Exception $ex) {
            $this->log("Error in " . get_class($this->proxy), Project::MSG_ERR);
            throw new BuildException("Error in " . get_class($this->proxy), $ex);
        }
    }
491376
public function compileProxies()
    {
        Files::emptyDirectoryRecursively(Files::concatenatePaths([$this->environment->getPathToTemporaryDirectory(), 'Doctrine/Proxies']));
        /** @var \Doctrine\ORM\Proxy\ProxyFactory $proxyFactory */
        $proxyFactory = $this->entityManager->getProxyFactory();
        $proxyFactory->generateProxyClasses($this->entityManager->getMetadataFactory()->getAllMetadata());
    }
1373355
def proxyInit(self):
        
        # Call init() with local XML RPC config and interface_id (the name of
        # the receiver) to receive events. XML RPC server has to be running.
        for interface_id, proxy in self.proxies.items():
            if proxy._skipinit:
                continue
            if proxy._callbackip and proxy._callbackport:
                callbackip = proxy._callbackip
                callbackport = proxy._callbackport
            else:
                callbackip = proxy._localip
                callbackport = self._localport
            LOG.debug("ServerThread.proxyInit: init('http://%s:%i', '%s')" %
                      (callbackip, callbackport, interface_id))
            try:
                proxy.init("http://%s:%i" %
                           (callbackip, callbackport), interface_id)
                LOG.info("Proxy initialized")
            except Exception as err:
                LOG.debug("proxyInit: Exception: %s" % str(err))
                LOG.warning("Failed to initialize proxy")
                self.failed_inits.append(interface_id)
655835
public static function init()
    {
        // Instantiate the application
        $app = Application::fromCwd();

        // Give proxies an instance of the application
        $app->initializeProxies();

        // Boot the app
        $app->boot();

        static::$appPath = \App::appPath();
        static::$vendorPath = \App::vendorPath();

        if (defined('COMPILING')) {
            static::$appPath = BUILD_PATH.'/app';
            static::$vendorPath = BUILD_PATH.'/vendor';
        }
    }
1247254
private function buildClient()
    {
        //====================================================================//
        // Compute target client url
        if ((false === strpos($this->host, 'http://')) && (false === strpos($this->host, 'https://'))) {
            $this->url = 'https://'.$this->host;
        } else {
            $this->url = $this->host;
        }
        //====================================================================//
        // Build Webservice Client
        Splash::com()->buildClient($this->url, $this->httpUser, $this->httpPassword);

        return true;
    }
451302
public function build()
    {
        $client         = $this->buildClient();
        $requestHandler = $this->getRequestHandler();
        // Pass through any configuration options set here which need to be made
        // available elsewhere in the ThisData instance.
        $configuration  = [
            self::CONF_EXPECT_JS_COOKIE => $this->expectJsCookie
        ];

        return new ThisData($client, $requestHandler, $configuration);
    }
1093227
@SuppressWarnings("deprecation")
	ProxyConfig buildProxyConfig() {
		validateProxy();
		return new ProxyConfig(getProxyHost(), getProxyPort(), getProxyUsername(), getProxyPassword(), getProxyBridgePort());
	}
593255
public function build(): UnbindRequest
	{
		$instance = new UnbindRequest();
		if ($this->port === null) {
			throw new BuilderException('Property [port] is required.');
		}
		$instance->port = $this->port;
		return $instance;
	}
810377
public function main()
    {
        if ($this->prefix != null && $this->regex != null) {
            throw new BuildException("Please specify either prefix or regex, but not both", $this->getLocation());
        }

        //copy the properties file
        $allProps = [];

        /* load properties from file if specified, otherwise use Phing's properties */
        if ($this->inFile == null) {
            // add phing properties
            $allProps = $this->getProject()->getProperties();
        } elseif ($this->inFile != null) {
            if ($this->inFile->exists() && $this->inFile->isDirectory()) {
                $message = "srcfile is a directory!";
                $this->failOnErrorAction(null, $message, Project::MSG_ERR);
                return;
            }

            if ($this->inFile->exists() && !$this->inFile->canRead()) {
                $message = "Can not read from the specified srcfile!";
                $this->failOnErrorAction(null, $message, Project::MSG_ERR);
                return;
            }

            try {
                $props = new Properties();
                $props->load(new PhingFile($this->inFile));
                $allProps = $props->getProperties();
            } catch (IOException $ioe) {
                $message = "Could not read file " . $this->inFile->getAbsolutePath();
                $this->failOnErrorAction($ioe, $message, Project::MSG_WARN);
                return;
            }
        }

        $os = null;
        try {
            if ($this->destfile == null) {
                $os = Phing::getOutputStream();
                $this->saveProperties($allProps, $os);
                $this->log($os, Project::MSG_INFO);
            } else {
                if ($this->destfile->exists() && $this->destfile->isDirectory()) {
                    $message = "destfile is a directory!";
                    $this->failOnErrorAction(null, $message, Project::MSG_ERR);
                    return;
                }

                if ($this->destfile->exists() && !$this->destfile->canWrite()) {
                    $message = "Can not write to the specified destfile!";
                    $this->failOnErrorAction(null, $message, Project::MSG_ERR);
                    return;
                }
                $os = new FileOutputStream($this->destfile);
                $this->saveProperties($allProps, $os);
            }
        } catch (IOException $ioe) {
            $this->failOnErrorAction($ioe);
        }
    }