Create a new service event

@param string $name
@param CommandInterface $command
@return \ValuSo\Broker\ServiceEvent
434264
protected function createEvent($name, CommandInterface $command)
	{
	    $event = new ServiceEvent();
	    $event->setName($name);
	    $event->setCommand($command);
	    $event->setParams($command->getParams());

	    return $event;
	}
776095
public function runCommand(Command $command, InputInterface $input, OutputInterface $output) {
    return $this->doRunCommand($command, $input, $output);
  }
393256
public function create($name, $startPoint = null)
    {
        $this->clearAll();
        $this->addCommandName(self::BRANCH_COMMAND);
        $this->addCommandSubject($name);
        if (null !== $startPoint) {
            $this->addCommandSubject2($startPoint);
        }

        return $this->getCommand();
    }
1055162
final public function handle(CommandInterface $command)
    {
        $this->validateCommand($command);

        try {
            // @todo - Update this to return the succes event object, rather than using the getSuccessEvent() method
            $this->_handle($command);
        } catch (\Exception $exception) {

            // Log exception
            $commandClass = get_class($command);
            $this->logError(
                "Exception throw while handling {$commandClass} command... {$exception->getMessage()}\n",
                $exception
            );

            // Fire failure event
            $this->emit($this->getFailureEvent($exception));

            throw $exception;
        }

        $event = $this->getSuccessEvent($command);
        $this->emit($event);
    }
388617
public function push($name, $command, array $options = [])
    {
        $this->connection()->rpush('commands:'.$name, json_encode([
            'command' => $command,
            'options' => $options,
        ]));
    }
48145
protected function createService(string $name, array $service) : void
    {
        if (!isset($service["callback"])) {
            throw new Exception("The service '$name' is missing a callback.");
        }

        if (isset($service["shared"]) && $service["shared"]) {
            $this->setShared($name, $service["callback"]);
        } else {
            $this->set($name, $service["callback"]);
        }

        if (isset($service["active"]) && $service["active"]) {
            $this->get($name);
        }
    }
1078243
private function createMethod(string $name): MethodInterface
    {
        $class = 'Ekyna\\Component\\Dpd\\EPrint\\Method\\' . ucwords($name);
        if (class_exists($class)) {
            /** @var MethodInterface $instance */
            return new $class($this->getClient());
        }

        throw new RuntimeException("Method {$name} does not exist");
    }
547018
protected function createCommand($commandName, array $commandDca)
    {

        $command = $this->createCommandInstance($commandName, $commandDca);
        $command->setName($commandName);

        $parameters = $command->getParameters();

        if (isset($commandDca['href'])) {
            \parse_str($commandDca['href'], $queryParameters);
            foreach ($queryParameters as $name => $value) {
                $parameters[$name] = $value;
            }
            unset($commandDca['href']);
        }

        if (isset($commandDca['parameters'])) {
            foreach ($commandDca['parameters'] as $name => $value) {
                $parameters[$name] = $value;
            }
            unset($commandDca['parameters']);
        }

        if (isset($commandDca['label'])) {
            $lang = $commandDca['label'];

            if (\is_array($lang)) {
                $label       = \reset($lang);
                $description = \next($lang);

                $command->setDescription($description);
            } else {
                $label = $lang;
            }

            $command->setLabel($label);

            unset($commandDca['label']);
        }

        if (isset($commandDca['description'])) {
            $command->setDescription($commandDca['description']);

            unset($commandDca['description']);
        }

        // Callback is transformed into event in parseCallbacks().
        unset($commandDca['button_callback']);

        if (\count($commandDca)) {
            $extra = $command->getExtra();

            foreach ($commandDca as $name => $value) {
                $extra[$name] = $value;
            }
        }

        return $command;
    }
1093229
public function buildCommand(string $name, array $definition): CommandInterface
    {
        $command = new Command($name);
        $command->setExecutable($definition[static::CONFIG_COMMAND]);

        $this->setExcluded($command, $definition);
        $this->setGroups($command, $definition);
        $this->setEnv($command, $definition);
        $this->setIsStoreAware($command, $definition);
        $this->setStores($command, $definition);
        $this->addCommandConditions($command, $definition);
        $this->setPreCommand($command, $definition);
        $this->setPostCommand($command, $definition);
        $this->setBreakOnFailure($command, $definition);
        $this->setTimeout($command, $definition);

        return $command;
    }
770881
public function prepareCommand(CommandInterface $command)
    {
        $request = parent::prepareCommand($command);
        $request->setHeader('Authorization ','Bearer '. $this->prepareAccessToken());
        return $request;
    }
7434
private function createInstanceCallback($name, $spec)
    {
        if (is_string($spec) && class_exists($spec)) {
            $spec = new $spec;
        }
        if ($spec instanceof ServiceFactoryInterface) {
            return function () use ($spec) {
                return $spec->createService($this);
            };
        }
        if (is_callable($spec)) {
            return function () use ($spec) {
                return $spec($this);
            };
        }
        if (is_object($spec)) {
            return function () use ($spec) {
                return $spec;
            };
        }
        throw new Exception\InvalidServiceException($name, $spec);
    }
1186231
public function dispatchEvent($eventName, EventInterface $event = null)
    {
        $this->getEventDispatcher()->dispatch($eventName, $event);
        
        return $this;
    }
343339
private function createCommandHandler()
    {
        return function (CommandInterface $command) {
            return Promise\coroutine(function () use ($command) {
                // Prepare the HTTP options.
                $opts = $command['@http'] ?: [];
                unset($command['@http']);

                try {
                    // Prepare the request from the command and send it.
                    $request = $this->transformCommandToRequest($command);
                    $promise = $this->httpClient->sendAsync($request, $opts);

                    // Create a result from the response.
                    $response = (yield $promise);
                    yield $this->transformResponseToResult($response, $request, $command);
                } catch (\Exception $e) {
                    throw CommandException::fromPrevious($command, $e);
                }
            });
        };
    }
783601
protected function createEventFromCommand(Command $command, string $suffix): Event
    {
        /** @var NodeRef $nodeRef */
        $nodeRef = $command->get('node_ref') ?: NodeRef::fromNode($command->get('node'));
        $curie = $command::schema()->getCurie();
        $eventCurie = "{$curie->getVendor()}:{$curie->getPackage()}:event:{$nodeRef->getLabel()}-{$suffix}";

        /** @var Event $class */
        $class = MessageResolver::resolveCurie(SchemaCurie::fromString($eventCurie));
        return $class::create();
    }
497003
public function setup(CommandInterface $command, $identity)
    {
        if (!$identity) {
            throw new RuntimeException(
                'Unable to initialize Job: identity is not available');
        }
        
        $this->setContent([
            'context'      => $command->getContext(),
            'service'      => $command->getName(),
            'operation'    => $command->getOperation(),
            'params'       => $command->getParams()->getArrayCopy(),
            'identity'     => $identity
        ]);
    }
877806
public function request(CommandInterface $command)
    {
        if ($command instanceof UploadFile
            || $command instanceof UploadNewFileVersion) {
            return $command->execute($this->uploadClient);
        }

        return $command->execute($this->apiClient);
    }
834645
protected function createContainer($name)
    {
        $this->containers[$name] = new Container($this->getView(), $this->service, $name);
    }