1313import modelengine .fitframework .annotation .Component ;
1414import modelengine .fitframework .broker .Endpoint ;
1515import modelengine .fitframework .broker .Target ;
16+ import modelengine .fitframework .conf .runtime .CommunicationProtocol ;
1617import modelengine .fitframework .conf .runtime .MatataConfig ;
1718import modelengine .fitframework .conf .runtime .WorkerConfig ;
1819import modelengine .fitframework .log .Logger ;
@@ -41,25 +42,41 @@ public class AddressRepository implements RegistryLocator {
4142 * @param servers 表示 FIT 的服务器的列表的 {@link List}{@code <}{@link FitServer}{@code >}。
4243 * @param worker 表示进程配置的 {@link WorkerConfig}。
4344 * @param matata 表示 matata 配置的 {@link MatataConfig}。
45+ * @param fitServer 表示 FIT 服务器的 {@link FitServer}。
4446 */
45- public AddressRepository (List <FitServer > servers , WorkerConfig worker , MatataConfig matata ) {
47+ public AddressRepository (List <FitServer > servers , WorkerConfig worker , MatataConfig matata , FitServer fitServer ) {
4648 List <FitServer > actualServers = ObjectUtils .getIfNull (servers , Collections ::emptyList );
4749 notNull (worker , "The worker config cannot be null." );
4850 notNull (matata , "The matata config cannot be null." );
51+ notNull (fitServer , "The fitserver cannot be null." );
52+ int port = matata .registry ().port ();
53+ int protocolCode = matata .registry ().protocolCode ();
54+ CommunicationProtocol protocol = matata .registry ().protocol ();
55+ if (0 == port ){
56+ Endpoint endpoint = fitServer .endpoints ().stream ().findFirst ().orElse (null );
57+ notNull (endpoint , "The fit server must have at least one endpoint." );
58+ port = endpoint .port ();
59+ protocolCode = endpoint .protocolCode ();
60+ protocol = CommunicationProtocol .from (endpoint .protocol ());
61+ }
62+ String host = matata .registry ().host ();
63+ if (StringUtils .isBlank (matata .registry ().host ())) {
64+ host = worker .host ();
65+ }
4966 boolean isRegistryLocalhost = isRegistryLocalhost (actualServers ,
5067 worker .host (),
5168 worker .domain (),
52- matata . registry (). host () ,
53- matata . registry (). port () ,
54- matata . registry (). protocolCode () );
69+ host ,
70+ port ,
71+ protocolCode );
5572 String registryWorkerId =
56- isRegistryLocalhost ? worker .id () : matata . registry (). host () + ":" + matata . registry (). port () ;
73+ isRegistryLocalhost ? worker .id () : host + ":" + port ;
5774 this .registryTarget = Target .custom ()
5875 .workerId (registryWorkerId )
59- .host (matata . registry (). host () )
76+ .host (host )
6077 .endpoints (Collections .singletonList (Endpoint .custom ()
61- .port (matata . registry (). port () )
62- .protocol (matata . registry (). protocol () .name (), matata . registry (). protocolCode () )
78+ .port (port )
79+ .protocol (protocol .name (), protocolCode )
6380 .build ()))
6481 .environment (matata .registry ().environment ())
6582 .extensions (matata .registry ().visualExtensions ())
@@ -68,7 +85,7 @@ public AddressRepository(List<FitServer> servers, WorkerConfig worker, MatataCon
6885 }
6986
7087 private static boolean isRegistryLocalhost (List <FitServer > servers , String localHost , String localDomain ,
71- String registryHost , int registryPort , int registryProtocol ) {
88+ String registryHost , int registryPort , int registryProtocol ) {
7289 if (!isRegistryHost (localHost , localDomain , registryHost )) {
7390 return false ;
7491 }
0 commit comments