You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by GitBox <gi...@apache.org> on 2021/04/05 13:37:48 UTC

[GitHub] [ignite-3] sashapolo opened a new pull request #84: IGNITE-14382 Rework network module API structure

sashapolo opened a new pull request #84:
URL: https://github.com/apache/ignite-3/pull/84


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite-3] asfgit closed pull request #84: IGNITE-14382 Rework network module API structure

Posted by GitBox <gi...@apache.org>.
asfgit closed pull request #84:
URL: https://github.com/apache/ignite-3/pull/84


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite-3] sashapolo commented on a change in pull request #84: IGNITE-14382 Rework network module API structure

Posted by GitBox <gi...@apache.org>.
sashapolo commented on a change in pull request #84:
URL: https://github.com/apache/ignite-3/pull/84#discussion_r611493688



##########
File path: modules/network/src/main/java/org/apache/ignite/network/scalecube/ScaleCubeMemberResolver.java
##########
@@ -19,46 +19,39 @@
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 import io.scalecube.cluster.Member;
-import org.apache.ignite.network.NetworkMember;
+import org.apache.ignite.network.ClusterNode;
 
 import static java.util.Objects.requireNonNull;
 
 /**
  * Resolver for scalecube specific member.
  */
-public class ScaleCubeMemberResolver {
+final class ScaleCubeMemberResolver {
     /** Map of public network member by its unique name. */
-    private final Map<String, NetworkMember> directMemberMap = new ConcurrentHashMap<>();
+    private final Map<String, ClusterNode> directMemberMap = new ConcurrentHashMap<>();

Review comment:
       fixed




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite-3] ascherbakoff commented on a change in pull request #84: IGNITE-14382 Rework network module API structure

Posted by GitBox <gi...@apache.org>.
ascherbakoff commented on a change in pull request #84:
URL: https://github.com/apache/ignite-3/pull/84#discussion_r611445566



##########
File path: modules/network/src/main/java/org/apache/ignite/network/AbstractMessagingService.java
##########
@@ -15,36 +15,28 @@
  * limitations under the License.
  */
 
-package org.apache.ignite.network.scalecube;
+package org.apache.ignite.network;
 
-import org.apache.ignite.network.message.NetworkMessage;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.concurrent.CopyOnWriteArrayList;
 
 /**
- * Test response.
+ * Base class for {@link MessagingService} implementations.
  */
-public class TestResponse implements NetworkMessage {
-    /** Public type for tests. */
-    public static final short TYPE = 2;
+public abstract class AbstractMessagingService implements MessagingService {
+    /** */
+    private final Collection<NetworkMessageHandler> messageHandlers = new CopyOnWriteArrayList<>();
 
-    /**
-     * Some response test value.
-     */
-    private final int responseNumber;
-
-    /** Constructor. */
-    public TestResponse(int responseNumber) {
-        this.responseNumber = responseNumber;
+    /** {@inheritDoc} */
+    @Override public void addMessageHandler(NetworkMessageHandler handler) {

Review comment:
       Some components (like a cache) can start/stop dynamically and should have possibility to deregister related listeners on stop.
   I'm ok to implement this as a separate ticket.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite-3] ascherbakoff commented on a change in pull request #84: IGNITE-14382 Rework network module API structure

Posted by GitBox <gi...@apache.org>.
ascherbakoff commented on a change in pull request #84:
URL: https://github.com/apache/ignite-3/pull/84#discussion_r611386864



##########
File path: modules/network/src/main/java/org/apache/ignite/network/ClusterLocalConfiguration.java
##########
@@ -0,0 +1,84 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.network;
+
+import java.util.List;
+import org.apache.ignite.network.message.MessageSerializationRegistry;
+
+/**
+ * Network configuration of a node.
+ *
+ * TODO: migrate to common configuration class when it's available, see
+ *  https://issues.apache.org/jira/browse/IGNITE-14496
+ */
+public class ClusterLocalConfiguration {
+    /** Network alias of a node. */
+    private final String name;
+
+    /** Port. */

Review comment:
       ```suggestion
       /** The port. */
   ```

##########
File path: modules/network/src/main/java/org/apache/ignite/network/AbstractMessagingService.java
##########
@@ -15,36 +15,28 @@
  * limitations under the License.
  */
 
-package org.apache.ignite.network.scalecube;
+package org.apache.ignite.network;
 
-import org.apache.ignite.network.message.NetworkMessage;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.concurrent.CopyOnWriteArrayList;
 
 /**
- * Test response.
+ * Base class for {@link MessagingService} implementations.
  */
-public class TestResponse implements NetworkMessage {
-    /** Public type for tests. */
-    public static final short TYPE = 2;
+public abstract class AbstractMessagingService implements MessagingService {
+    /** */
+    private final Collection<NetworkMessageHandler> messageHandlers = new CopyOnWriteArrayList<>();
 
-    /**
-     * Some response test value.
-     */
-    private final int responseNumber;
-
-    /** Constructor. */
-    public TestResponse(int responseNumber) {
-        this.responseNumber = responseNumber;
+    /** {@inheritDoc} */
+    @Override public void addMessageHandler(NetworkMessageHandler handler) {

Review comment:
       We need a way to unregister message handlers for dynamically started components.

##########
File path: modules/network/src/main/java/org/apache/ignite/network/ClusterService.java
##########
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.network;
+
+/**
+ * Class that represents the network-related resources of a node and provides entry points for working with the
+ * network members of a cluster.
+ */
+public interface ClusterService {
+    /**
+     * Returns the {@link TopologyService} for working with the cluster topology.
+     */
+    TopologyService getTopologyService();
+
+    /**
+     * Returns the {@link TopologyService} for sending messages to the cluster members.
+     */
+    MessagingService getMessagingService();

Review comment:
       ```suggestion
       MessagingService messagingService();
   ```

##########
File path: modules/network/src/main/java/org/apache/ignite/network/scalecube/ScaleCubeMemberResolver.java
##########
@@ -19,46 +19,39 @@
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 import io.scalecube.cluster.Member;
-import org.apache.ignite.network.NetworkMember;
+import org.apache.ignite.network.ClusterNode;
 
 import static java.util.Objects.requireNonNull;
 
 /**
  * Resolver for scalecube specific member.
  */
-public class ScaleCubeMemberResolver {
+final class ScaleCubeMemberResolver {
     /** Map of public network member by its unique name. */
-    private final Map<String, NetworkMember> directMemberMap = new ConcurrentHashMap<>();
+    private final Map<String, ClusterNode> directMemberMap = new ConcurrentHashMap<>();

Review comment:
       Looks like these maps are never cleared. Maybe they should on node leaving ?

##########
File path: modules/network/src/main/java/org/apache/ignite/network/AbstractTopologyService.java
##########
@@ -15,34 +15,28 @@
  * limitations under the License.
  */
 
-package org.apache.ignite.network.scalecube;
+package org.apache.ignite.network;
 
-import org.apache.ignite.network.message.NetworkMessage;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.concurrent.CopyOnWriteArrayList;
 
 /**
- * Test request which requires {@link TestResponse} as a response.
+ * Base class for {@link TopologyService} implementations.
  */
-public class TestRequest implements NetworkMessage {
-    /** Public type for tests. */
-    public static final short TYPE = 1;
+public abstract class AbstractTopologyService implements TopologyService {
+    /** */
+    private final Collection<TopologyEventHandler> eventHandlers = new CopyOnWriteArrayList<>();
 
-    /** Some test value. */
-    private final int number;
-
-    /** Constructor. */
-    public TestRequest(int number) {
-        this.number = number;
+    /** {@inheritDoc} */
+    @Override public void addEventHandler(TopologyEventHandler handler) {
+        eventHandlers.add(handler);

Review comment:
       We need a way to unregister event handlers for dynamically started components.

##########
File path: modules/network/src/main/java/org/apache/ignite/network/ClusterService.java
##########
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.network;
+
+/**
+ * Class that represents the network-related resources of a node and provides entry points for working with the
+ * network members of a cluster.
+ */
+public interface ClusterService {
+    /**
+     * Returns the {@link TopologyService} for working with the cluster topology.
+     */
+    TopologyService getTopologyService();
+
+    /**
+     * Returns the {@link TopologyService} for sending messages to the cluster members.
+     */
+    MessagingService getMessagingService();
+
+    /**
+     * Returns the context associated with the current node.
+     */
+    ClusterLocalConfiguration getLocalConfiguration();

Review comment:
       ```suggestion
       ClusterLocalConfiguration localConfiguration();
   ```

##########
File path: modules/network/src/main/java/org/apache/ignite/network/ClusterService.java
##########
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.network;
+
+/**
+ * Class that represents the network-related resources of a node and provides entry points for working with the
+ * network members of a cluster.
+ */
+public interface ClusterService {
+    /**
+     * Returns the {@link TopologyService} for working with the cluster topology.
+     */
+    TopologyService getTopologyService();

Review comment:
       ```suggestion
       TopologyService topologyService();
   ```




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite-3] sashapolo commented on a change in pull request #84: IGNITE-14382 Rework network module API structure

Posted by GitBox <gi...@apache.org>.
sashapolo commented on a change in pull request #84:
URL: https://github.com/apache/ignite-3/pull/84#discussion_r611418083



##########
File path: modules/network/src/main/java/org/apache/ignite/network/scalecube/ScaleCubeMemberResolver.java
##########
@@ -19,46 +19,39 @@
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 import io.scalecube.cluster.Member;
-import org.apache.ignite.network.NetworkMember;
+import org.apache.ignite.network.ClusterNode;
 
 import static java.util.Objects.requireNonNull;
 
 /**
  * Resolver for scalecube specific member.
  */
-public class ScaleCubeMemberResolver {
+final class ScaleCubeMemberResolver {
     /** Map of public network member by its unique name. */
-    private final Map<String, NetworkMember> directMemberMap = new ConcurrentHashMap<>();
+    private final Map<String, ClusterNode> directMemberMap = new ConcurrentHashMap<>();

Review comment:
       I didn't change this code, it was already present. But let's introduce a solution for this




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite-3] sashapolo commented on a change in pull request #84: IGNITE-14382 Rework network module API structure

Posted by GitBox <gi...@apache.org>.
sashapolo commented on a change in pull request #84:
URL: https://github.com/apache/ignite-3/pull/84#discussion_r611418519



##########
File path: modules/network/src/main/java/org/apache/ignite/network/AbstractMessagingService.java
##########
@@ -15,36 +15,28 @@
  * limitations under the License.
  */
 
-package org.apache.ignite.network.scalecube;
+package org.apache.ignite.network;
 
-import org.apache.ignite.network.message.NetworkMessage;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.concurrent.CopyOnWriteArrayList;
 
 /**
- * Test response.
+ * Base class for {@link MessagingService} implementations.
  */
-public class TestResponse implements NetworkMessage {
-    /** Public type for tests. */
-    public static final short TYPE = 2;
+public abstract class AbstractMessagingService implements MessagingService {
+    /** */
+    private final Collection<NetworkMessageHandler> messageHandlers = new CopyOnWriteArrayList<>();
 
-    /**
-     * Some response test value.
-     */
-    private final int responseNumber;
-
-    /** Constructor. */
-    public TestResponse(int responseNumber) {
-        this.responseNumber = responseNumber;
+    /** {@inheritDoc} */
+    @Override public void addMessageHandler(NetworkMessageHandler handler) {

Review comment:
       Can you elaborate on the use cases please, because I may be out of context for this suggestion?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite-3] AMashenkov commented on a change in pull request #84: IGNITE-14382 Rework network module API structure

Posted by GitBox <gi...@apache.org>.
AMashenkov commented on a change in pull request #84:
URL: https://github.com/apache/ignite-3/pull/84#discussion_r607773125



##########
File path: modules/network/src/main/java/org/apache/ignite/network/scalecube/ScaleCubeMessagingService.java
##########
@@ -0,0 +1,154 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.network.scalecube;
+
+import java.time.Duration;
+import java.util.Map;
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ConcurrentHashMap;
+import io.scalecube.cluster.Cluster;
+import io.scalecube.cluster.transport.api.Message;
+import io.scalecube.net.Address;
+import org.apache.ignite.network.AbstractMessagingService;
+import org.apache.ignite.network.MessagingService;
+import org.apache.ignite.network.NetworkMember;
+import org.apache.ignite.network.NetworkMessageHandler;
+import org.apache.ignite.network.message.NetworkMessage;
+
+import static org.apache.ignite.network.scalecube.ScaleCubeMessageCodec.HEADER_MESSAGE_TYPE;
+
+/**
+ * Implementation of {@link MessagingService} based on ScaleCube.
+ */
+final class ScaleCubeMessagingService extends AbstractMessagingService {
+    /**
+     * Inner representation ScaleCube cluster.
+     */
+    private Cluster cluster;
+
+    /**
+     * Resolver for ScaleCube-specific member.
+     */
+    private final ScaleCubeMemberResolver memberResolver;
+
+    /**
+     * Utility map for recognizing member for its address (ScaleCube doesn't provide such information in input
+     * message).
+     */
+    private final Map<Address, NetworkMember> addressMemberMap = new ConcurrentHashMap<>();
+
+    /**
+     *
+     */
+    ScaleCubeMessagingService(ScaleCubeMemberResolver memberResolver) {
+        this.memberResolver = memberResolver;
+    }
+
+    /**
+     * Sets the ScaleCube's {@link Cluster}. Needed for cyclic dependency injection.
+     */
+    void setCluster(Cluster cluster) {
+        this.cluster = cluster;
+    }
+
+    /**
+     * Delegates the received message to the registered message handlers.
+     */
+    void fireEvent(Message message) {
+        NetworkMessage msg = message.data();
+        NetworkMember sender = memberForAddress(message.sender());
+        String correlationId = message.correlationId();
+        for (NetworkMessageHandler handler : getMessageHandlers())
+            handler.onReceived(msg, sender, correlationId);
+    }
+
+    /**
+     * {@inheritDoc}
+     */

Review comment:
       ```suggestion
       /** {@inheritDoc} */
   ```

##########
File path: modules/network/src/main/java/org/apache/ignite/network/scalecube/ScaleCubeMessagingService.java
##########
@@ -0,0 +1,154 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.network.scalecube;
+
+import java.time.Duration;
+import java.util.Map;
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ConcurrentHashMap;
+import io.scalecube.cluster.Cluster;
+import io.scalecube.cluster.transport.api.Message;
+import io.scalecube.net.Address;
+import org.apache.ignite.network.AbstractMessagingService;
+import org.apache.ignite.network.MessagingService;
+import org.apache.ignite.network.NetworkMember;
+import org.apache.ignite.network.NetworkMessageHandler;
+import org.apache.ignite.network.message.NetworkMessage;
+
+import static org.apache.ignite.network.scalecube.ScaleCubeMessageCodec.HEADER_MESSAGE_TYPE;
+
+/**
+ * Implementation of {@link MessagingService} based on ScaleCube.
+ */
+final class ScaleCubeMessagingService extends AbstractMessagingService {
+    /**
+     * Inner representation ScaleCube cluster.
+     */
+    private Cluster cluster;
+
+    /**
+     * Resolver for ScaleCube-specific member.
+     */
+    private final ScaleCubeMemberResolver memberResolver;
+
+    /**
+     * Utility map for recognizing member for its address (ScaleCube doesn't provide such information in input
+     * message).
+     */
+    private final Map<Address, NetworkMember> addressMemberMap = new ConcurrentHashMap<>();
+
+    /**
+     *
+     */
+    ScaleCubeMessagingService(ScaleCubeMemberResolver memberResolver) {
+        this.memberResolver = memberResolver;
+    }
+
+    /**
+     * Sets the ScaleCube's {@link Cluster}. Needed for cyclic dependency injection.
+     */
+    void setCluster(Cluster cluster) {
+        this.cluster = cluster;
+    }
+
+    /**
+     * Delegates the received message to the registered message handlers.
+     */
+    void fireEvent(Message message) {
+        NetworkMessage msg = message.data();
+        NetworkMember sender = memberForAddress(message.sender());
+        String correlationId = message.correlationId();
+        for (NetworkMessageHandler handler : getMessageHandlers())
+            handler.onReceived(msg, sender, correlationId);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override public void weakSend(NetworkMember recipient, NetworkMessage msg) {
+        cluster
+            .send(memberResolver.resolveMember(recipient), fromNetworkMessage(msg).build())
+            .subscribe();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override public CompletableFuture<Void> send(NetworkMember recipient, NetworkMessage msg) {
+        return cluster
+            .send(memberResolver.resolveMember(recipient), fromNetworkMessage(msg).build())
+            .toFuture();
+    }
+
+    /**
+     * {@inheritDoc}
+     */

Review comment:
       ```suggestion
       /** {@inheritDoc} */
   ```

##########
File path: modules/network/src/main/java/org/apache/ignite/network/scalecube/ScaleCubeMessagingService.java
##########
@@ -0,0 +1,154 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.network.scalecube;
+
+import java.time.Duration;
+import java.util.Map;
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ConcurrentHashMap;
+import io.scalecube.cluster.Cluster;
+import io.scalecube.cluster.transport.api.Message;
+import io.scalecube.net.Address;
+import org.apache.ignite.network.AbstractMessagingService;
+import org.apache.ignite.network.MessagingService;
+import org.apache.ignite.network.NetworkMember;
+import org.apache.ignite.network.NetworkMessageHandler;
+import org.apache.ignite.network.message.NetworkMessage;
+
+import static org.apache.ignite.network.scalecube.ScaleCubeMessageCodec.HEADER_MESSAGE_TYPE;
+
+/**
+ * Implementation of {@link MessagingService} based on ScaleCube.
+ */
+final class ScaleCubeMessagingService extends AbstractMessagingService {
+    /**
+     * Inner representation ScaleCube cluster.
+     */
+    private Cluster cluster;
+
+    /**
+     * Resolver for ScaleCube-specific member.
+     */
+    private final ScaleCubeMemberResolver memberResolver;
+
+    /**
+     * Utility map for recognizing member for its address (ScaleCube doesn't provide such information in input
+     * message).
+     */
+    private final Map<Address, NetworkMember> addressMemberMap = new ConcurrentHashMap<>();
+
+    /**
+     *
+     */
+    ScaleCubeMessagingService(ScaleCubeMemberResolver memberResolver) {
+        this.memberResolver = memberResolver;
+    }
+
+    /**
+     * Sets the ScaleCube's {@link Cluster}. Needed for cyclic dependency injection.
+     */
+    void setCluster(Cluster cluster) {
+        this.cluster = cluster;
+    }
+
+    /**
+     * Delegates the received message to the registered message handlers.
+     */
+    void fireEvent(Message message) {
+        NetworkMessage msg = message.data();
+        NetworkMember sender = memberForAddress(message.sender());
+        String correlationId = message.correlationId();
+        for (NetworkMessageHandler handler : getMessageHandlers())
+            handler.onReceived(msg, sender, correlationId);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override public void weakSend(NetworkMember recipient, NetworkMessage msg) {
+        cluster
+            .send(memberResolver.resolveMember(recipient), fromNetworkMessage(msg).build())
+            .subscribe();
+    }
+
+    /**
+     * {@inheritDoc}
+     */

Review comment:
       ```suggestion
       /** {@inheritDoc} */
   ```

##########
File path: modules/network/src/main/java/org/apache/ignite/network/scalecube/ScaleCubeMessagingService.java
##########
@@ -0,0 +1,154 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.network.scalecube;
+
+import java.time.Duration;
+import java.util.Map;
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ConcurrentHashMap;
+import io.scalecube.cluster.Cluster;
+import io.scalecube.cluster.transport.api.Message;
+import io.scalecube.net.Address;
+import org.apache.ignite.network.AbstractMessagingService;
+import org.apache.ignite.network.MessagingService;
+import org.apache.ignite.network.NetworkMember;
+import org.apache.ignite.network.NetworkMessageHandler;
+import org.apache.ignite.network.message.NetworkMessage;
+
+import static org.apache.ignite.network.scalecube.ScaleCubeMessageCodec.HEADER_MESSAGE_TYPE;
+
+/**
+ * Implementation of {@link MessagingService} based on ScaleCube.
+ */
+final class ScaleCubeMessagingService extends AbstractMessagingService {
+    /**
+     * Inner representation ScaleCube cluster.
+     */
+    private Cluster cluster;
+
+    /**
+     * Resolver for ScaleCube-specific member.
+     */
+    private final ScaleCubeMemberResolver memberResolver;
+
+    /**
+     * Utility map for recognizing member for its address (ScaleCube doesn't provide such information in input
+     * message).
+     */
+    private final Map<Address, NetworkMember> addressMemberMap = new ConcurrentHashMap<>();
+
+    /**
+     *
+     */
+    ScaleCubeMessagingService(ScaleCubeMemberResolver memberResolver) {
+        this.memberResolver = memberResolver;
+    }
+
+    /**
+     * Sets the ScaleCube's {@link Cluster}. Needed for cyclic dependency injection.
+     */
+    void setCluster(Cluster cluster) {
+        this.cluster = cluster;
+    }
+
+    /**
+     * Delegates the received message to the registered message handlers.
+     */
+    void fireEvent(Message message) {
+        NetworkMessage msg = message.data();
+        NetworkMember sender = memberForAddress(message.sender());
+        String correlationId = message.correlationId();
+        for (NetworkMessageHandler handler : getMessageHandlers())
+            handler.onReceived(msg, sender, correlationId);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override public void weakSend(NetworkMember recipient, NetworkMessage msg) {
+        cluster
+            .send(memberResolver.resolveMember(recipient), fromNetworkMessage(msg).build())
+            .subscribe();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override public CompletableFuture<Void> send(NetworkMember recipient, NetworkMessage msg) {
+        return cluster
+            .send(memberResolver.resolveMember(recipient), fromNetworkMessage(msg).build())
+            .toFuture();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override public CompletableFuture<Void> send(NetworkMember recipient, NetworkMessage msg, String correlationId) {
+        var message = fromNetworkMessage(msg)
+            .correlationId(correlationId)
+            .build();
+        return cluster
+            .send(memberResolver.resolveMember(recipient), message)
+            .toFuture();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override public CompletableFuture<NetworkMessage> invoke(NetworkMember member, NetworkMessage msg, long timeout) {

Review comment:
       ```suggestion
       /** {@inheritDoc} */
   ```




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite-3] sergey-chugunov-1985 commented on a change in pull request #84: IGNITE-14382 Rework network module API structure

Posted by GitBox <gi...@apache.org>.
sergey-chugunov-1985 commented on a change in pull request #84:
URL: https://github.com/apache/ignite-3/pull/84#discussion_r607583972



##########
File path: modules/network/src/main/java/org/apache/ignite/network/Network.java
##########
@@ -17,50 +17,15 @@
 
 package org.apache.ignite.network;
 
-import java.util.Arrays;
-import java.util.Collections;
-import org.apache.ignite.network.message.MessageMapperProvider;
-
 /**
- * Entry point for network module.
+ * Entry point for the network module.
  */
-public class Network {
-    /** Message mapper providers, messageMapperProviders[message type] -> message mapper provider for message with message type. */
-    private final MessageMapperProvider<?>[] messageMapperProviders = new MessageMapperProvider<?>[Short.MAX_VALUE << 1];
-
-    /** Message handlers. */
-    private final MessageHandlerHolder messageHandlerHolder = new MessageHandlerHolder();
-
-    /** Cluster factory. */
-    private final NetworkClusterFactory clusterFactory;
-
-    /**
-     * Constructor.
-     * @param factory Cluster factory.
-     */
-    public Network(NetworkClusterFactory factory) {
-        clusterFactory = factory;
-    }
+public interface Network {

Review comment:
       What about renaming it to `Networking`? It is not ideal either but sounds a bit better to me than plain `Network`.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite-3] sashapolo commented on a change in pull request #84: IGNITE-14382 Rework network module API structure

Posted by GitBox <gi...@apache.org>.
sashapolo commented on a change in pull request #84:
URL: https://github.com/apache/ignite-3/pull/84#discussion_r607994578



##########
File path: modules/network/src/main/java/org/apache/ignite/network/Network.java
##########
@@ -17,50 +17,15 @@
 
 package org.apache.ignite.network;
 
-import java.util.Arrays;
-import java.util.Collections;
-import org.apache.ignite.network.message.MessageMapperProvider;
-
 /**
- * Entry point for network module.
+ * Entry point for the network module.
  */
-public class Network {
-    /** Message mapper providers, messageMapperProviders[message type] -> message mapper provider for message with message type. */
-    private final MessageMapperProvider<?>[] messageMapperProviders = new MessageMapperProvider<?>[Short.MAX_VALUE << 1];
-
-    /** Message handlers. */
-    private final MessageHandlerHolder messageHandlerHolder = new MessageHandlerHolder();
-
-    /** Cluster factory. */
-    private final NetworkClusterFactory clusterFactory;
-
-    /**
-     * Constructor.
-     * @param factory Cluster factory.
-     */
-    public Network(NetworkClusterFactory factory) {
-        clusterFactory = factory;
-    }
+public interface Network {

Review comment:
       We've had a discussion and decided to change it to `ClusterService`




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite-3] sashapolo commented on a change in pull request #84: IGNITE-14382 Rework network module API structure

Posted by GitBox <gi...@apache.org>.
sashapolo commented on a change in pull request #84:
URL: https://github.com/apache/ignite-3/pull/84#discussion_r611506175



##########
File path: modules/network/src/main/java/org/apache/ignite/network/AbstractMessagingService.java
##########
@@ -15,36 +15,28 @@
  * limitations under the License.
  */
 
-package org.apache.ignite.network.scalecube;
+package org.apache.ignite.network;
 
-import org.apache.ignite.network.message.NetworkMessage;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.concurrent.CopyOnWriteArrayList;
 
 /**
- * Test response.
+ * Base class for {@link MessagingService} implementations.
  */
-public class TestResponse implements NetworkMessage {
-    /** Public type for tests. */
-    public static final short TYPE = 2;
+public abstract class AbstractMessagingService implements MessagingService {
+    /** */
+    private final Collection<NetworkMessageHandler> messageHandlers = new CopyOnWriteArrayList<>();
 
-    /**
-     * Some response test value.
-     */
-    private final int responseNumber;
-
-    /** Constructor. */
-    public TestResponse(int responseNumber) {
-        this.responseNumber = responseNumber;
+    /** {@inheritDoc} */
+    @Override public void addMessageHandler(NetworkMessageHandler handler) {

Review comment:
       https://issues.apache.org/jira/browse/IGNITE-14519




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org