Skip to content

Commit

Permalink
refactor gateway proxy factories (#132)
Browse files Browse the repository at this point in the history
* refactor gateway proxy factories

* remove lazy built gateway proxies

* drop GatewayBuilder interface

---------

Co-authored-by: jlabedo <jean@needelp.com>
  • Loading branch information
jlabedo and jlabedo authored Jun 1, 2023
1 parent ea1482c commit a29c7de
Show file tree
Hide file tree
Showing 18 changed files with 84 additions and 612 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
use Ecotone\Messaging\Gateway\MessagingEntrypointWithHeadersPropagation;
use Ecotone\Messaging\Handler\Chain\ChainForwardPublisher;
use Ecotone\Messaging\Handler\Enricher\EnrichGateway;
use Ecotone\Messaging\Handler\Gateway\GatewayBuilder;
use Ecotone\Messaging\Handler\Gateway\GatewayProxyBuilder;
use Ecotone\Messaging\Handler\Gateway\ParameterToMessageConverter\GatewayHeaderBuilder;
use Ecotone\Messaging\Handler\Gateway\ParameterToMessageConverter\GatewayHeadersBuilder;
Expand Down Expand Up @@ -78,7 +77,7 @@ public function prepare(Configuration $messagingConfiguration, array $extensionO
$messagingConfiguration->registerMessageHandler($extensionObject);
} elseif ($extensionObject instanceof MessageChannelBuilder) {
$messagingConfiguration->registerMessageChannel($extensionObject);
} elseif ($extensionObject instanceof GatewayBuilder) {
} elseif ($extensionObject instanceof GatewayProxyBuilder) {
$messagingConfiguration->registerGatewayBuilder($extensionObject);
} elseif ($extensionObject instanceof ChannelAdapterConsumerBuilder) {
$messagingConfiguration->registerConsumer($extensionObject);
Expand Down Expand Up @@ -221,7 +220,7 @@ public function canHandle($extensionObject): bool
||
$extensionObject instanceof MessageChannelBuilder
||
$extensionObject instanceof GatewayBuilder
$extensionObject instanceof GatewayProxyBuilder
||
$extensionObject instanceof ChannelAdapterConsumerBuilder
||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use Ecotone\Messaging\Config\ConfigurationException;
use Ecotone\Messaging\Config\ModulePackageList;
use Ecotone\Messaging\Config\ModuleReferenceSearchService;
use Ecotone\Messaging\Handler\Gateway\GatewayBuilder;
use Ecotone\Messaging\Handler\Gateway\GatewayParameterConverterBuilder;
use Ecotone\Messaging\Handler\Gateway\GatewayProxyBuilder;
use Ecotone\Messaging\Handler\Gateway\ParameterToMessageConverter\GatewayHeaderBuilder;
Expand All @@ -32,14 +31,14 @@ class GatewayModule extends NoExternalConfigurationModule implements AnnotationM
public const MODULE_NAME = 'gatewayModule';

/**
* @var GatewayBuilder[]
* @var GatewayProxyBuilder[]
*/
private array $gatewayBuilders = [];

/**
* AnnotationGatewayConfiguration constructor.
*
* @param GatewayBuilder[] $gatewayBuilders
* @param GatewayProxyBuilder[] $gatewayBuilders
*/
private function __construct(array $gatewayBuilders)
{
Expand Down
5 changes: 2 additions & 3 deletions packages/Ecotone/src/Messaging/Config/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use Ecotone\Messaging\Endpoint\ChannelAdapterConsumerBuilder;
use Ecotone\Messaging\Endpoint\MessageHandlerConsumerBuilder;
use Ecotone\Messaging\Endpoint\PollingMetadata;
use Ecotone\Messaging\Handler\Gateway\GatewayBuilder;
use Ecotone\Messaging\Handler\Gateway\GatewayProxyBuilder;
use Ecotone\Messaging\Handler\InterfaceToCall;
use Ecotone\Messaging\Handler\MessageHandlerBuilder;
Expand Down Expand Up @@ -110,10 +109,10 @@ public function registerConsumer(ChannelAdapterConsumerBuilder $consumerBuilder)
public function registerConsumerFactory(MessageHandlerConsumerBuilder $consumerFactory): Configuration;

/**
* @param GatewayBuilder $gatewayBuilder
* @param GatewayProxyBuilder $gatewayBuilder
* @return Configuration
*/
public function registerGatewayBuilder(GatewayBuilder $gatewayBuilder): Configuration;
public function registerGatewayBuilder(GatewayProxyBuilder $gatewayBuilder): Configuration;

/**
* @return string[]
Expand Down
47 changes: 18 additions & 29 deletions packages/Ecotone/src/Messaging/Config/MessagingSystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
use Ecotone\Messaging\Endpoint\PollingMetadata;
use Ecotone\Messaging\Gateway\MessagingEntrypoint;
use Ecotone\Messaging\Handler\ChannelResolver;
use Ecotone\Messaging\Handler\Gateway\CombinedGatewayBuilder;
use Ecotone\Messaging\Handler\Gateway\GatewayProxyAdapter;
use Ecotone\Messaging\Handler\Gateway\GatewayProxyBuilder;
use Ecotone\Messaging\Handler\Gateway\ProxyFactory;
use Ecotone\Messaging\Handler\MessageHandlerBuilder;
use Ecotone\Messaging\Handler\ReferenceSearchService;
use Ecotone\Messaging\MessageChannel;
Expand Down Expand Up @@ -91,7 +92,6 @@ public function replaceWith(ConfiguredMessagingSystem $messagingSystem): void
* @param PollingMetadata[] $pollingMetadataConfigurations
* @param MessageHandlerBuilder[] $messageHandlerBuilders
* @param ChannelAdapterConsumerBuilder[] $channelAdapterConsumerBuilders
* @param bool $isLazyConfiguration
* @param ConsoleCommandConfiguration[] $consoleCommands
* @throws MessagingException
*/
Expand All @@ -104,12 +104,11 @@ public static function createFrom(
array $pollingMetadataConfigurations,
array $messageHandlerBuilders,
array $channelAdapterConsumerBuilders,
bool $isLazyConfiguration,
array $consoleCommands
): MessagingSystem {
$channelResolver = self::createChannelResolver($messageChannelInterceptors, $messageChannelBuilders, $referenceSearchService);

[$gateways, $nonProxyGateways] = self::configureGateways($gatewayBuilders, $referenceSearchService, $channelResolver, $isLazyConfiguration);
[$gateways, $nonProxyGateways] = self::configureGateways($gatewayBuilders, $referenceSearchService, $channelResolver);

$gatewayReferences = [];
foreach ($gateways as $gateway) {
Expand Down Expand Up @@ -184,42 +183,32 @@ private static function createChannelResolver(array $channelInterceptorBuilders,
* @param GatewayProxyBuilder[][] $preparedGateways
* @param ReferenceSearchService $referenceSearchService
* @param ChannelResolver $channelResolver
* @param bool $isLazyConfiguration
* @return GatewayReference[]
* @throws MessagingException
*/
private static function configureGateways(array $preparedGateways, ReferenceSearchService $referenceSearchService, ChannelResolver $channelResolver, bool $isLazyConfiguration): array
private static function configureGateways(array $preparedGateways, ReferenceSearchService $referenceSearchService, ChannelResolver $channelResolver): array
{
$gateways = [];
$nonProxyCombinedGateways = [];
/** @var ProxyFactory $proxyFactory */
$proxyFactory = $referenceSearchService->get(ProxyFactory::REFERENCE_NAME);

foreach ($preparedGateways as $referenceName => $preparedGatewaysForReference) {
$referenceName = $preparedGatewaysForReference[0]->getReferenceName();
$nonProxyCombinedGatewaysMethods = [];
foreach ($preparedGatewaysForReference as $proxyBuilder) {
$nonProxyCombinedGatewaysMethods[$proxyBuilder->getRelatedMethodName()] =
$proxyBuilder->buildWithoutProxyObject($referenceSearchService, $channelResolver);
}

if (count($preparedGatewaysForReference) === 1) {
$gatewayProxyBuilder = $preparedGatewaysForReference[0]
->withLazyBuild($isLazyConfiguration);
$nonProxyCombinedGateways[$referenceName] = NonProxyCombinedGateway::createWith($referenceName, [$gatewayProxyBuilder->getRelatedMethodName() => $gatewayProxyBuilder->buildWithoutProxyObject($referenceSearchService, $channelResolver)]);
$gateways[$referenceName] = GatewayReference::createWith(
$nonProxyCombinedGateways[$referenceName] = NonProxyCombinedGateway::createWith($referenceName, $nonProxyCombinedGatewaysMethods);
$interfaceName = $preparedGatewaysForReference[0]->getInterfaceName();
$proxyAdapter = new GatewayProxyAdapter($nonProxyCombinedGatewaysMethods);
$gateways[$referenceName] =
GatewayReference::createWith(
$referenceName,
$gatewayProxyBuilder->build($referenceSearchService, $channelResolver)
$proxyFactory->createProxyClassWithAdapter($interfaceName, $proxyAdapter)
);
} else {
$nonProxyCombinedGatewaysMethods = [];
foreach ($preparedGatewaysForReference as $proxyBuilder) {
$nonProxyCombinedGatewaysMethods[$proxyBuilder->getRelatedMethodName()] =
$proxyBuilder
->withLazyBuild($isLazyConfiguration)
->buildWithoutProxyObject($referenceSearchService, $channelResolver);
}

$nonProxyCombinedGateways[$referenceName] = NonProxyCombinedGateway::createWith($referenceName, $nonProxyCombinedGatewaysMethods);
$gateways[$referenceName] =
GatewayReference::createWith(
$referenceName,
CombinedGatewayBuilder::create($preparedGatewaysForReference[0]->getInterfaceName(), $nonProxyCombinedGatewaysMethods)
->build($referenceSearchService, $channelResolver)
);
}
}
return [$gateways, $nonProxyCombinedGateways];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
use Ecotone\Messaging\Endpoint\PollingMetadata;
use Ecotone\Messaging\Handler\Bridge\Bridge;
use Ecotone\Messaging\Handler\Chain\ChainMessageHandlerBuilder;
use Ecotone\Messaging\Handler\Gateway\GatewayBuilder;
use Ecotone\Messaging\Handler\Gateway\GatewayProxyBuilder;
use Ecotone\Messaging\Handler\Gateway\ProxyFactory;
use Ecotone\Messaging\Handler\InMemoryReferenceSearchService;
Expand Down Expand Up @@ -1100,11 +1099,11 @@ public function registerConsumer(ChannelAdapterConsumerBuilder $consumerBuilder)
}

/**
* @param GatewayBuilder $gatewayBuilder
* @param GatewayProxyBuilder $gatewayBuilder
*
* @return Configuration
*/
public function registerGatewayBuilder(GatewayBuilder $gatewayBuilder): Configuration
public function registerGatewayBuilder(GatewayProxyBuilder $gatewayBuilder): Configuration
{
foreach ($this->gatewayBuilders as $registeredGatewayBuilder) {
if (
Expand Down Expand Up @@ -1226,7 +1225,7 @@ public function buildMessagingSystemFromConfiguration(ReferenceSearchService $re
}
}

/** @var GatewayBuilder[][] $preparedGateways */
/** @var GatewayProxyBuilder[][] $preparedGateways */
$preparedGateways = [];
foreach ($this->gatewayBuilders as $gatewayBuilder) {
$preparedGateways[$gatewayBuilder->getReferenceName()][] = $gatewayBuilder->withMessageConverters($this->messageConverterReferenceNames);
Expand All @@ -1241,7 +1240,6 @@ public function buildMessagingSystemFromConfiguration(ReferenceSearchService $re
$this->pollingMetadata,
$this->messageHandlerBuilders,
$this->channelAdapters,
$this->isLazyConfiguration,
$this->consoleCommands
);
}
Expand Down

This file was deleted.

2 changes: 1 addition & 1 deletion packages/Ecotone/src/Messaging/Handler/Gateway/Gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ private function buildHandler(?MediaType $replyContentType): MessageHandler

return $chainHandler
->build(
InMemoryChannelResolver::createWithChannelResolver($this->channelResolver, []),
$this->channelResolver,
$this->referenceSearchService
);
}
Expand Down
73 changes: 0 additions & 73 deletions packages/Ecotone/src/Messaging/Handler/Gateway/GatewayBuilder.php

This file was deleted.

Loading

0 comments on commit a29c7de

Please sign in to comment.