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/07/20 09:20:00 UTC
[GitHub] [ignite-3] sashapolo opened a new pull request #229: IGNITE-14983 Enable registering message listeners for message groups
sashapolo opened a new pull request #229:
URL: https://github.com/apache/ignite-3/pull/229
https://issues.apache.org/jira/browse/IGNITE-14983
--
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.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [ignite-3] ibessonov commented on a change in pull request #229: IGNITE-14983 Enable registering message listeners for message groups
Posted by GitBox <gi...@apache.org>.
ibessonov commented on a change in pull request #229:
URL: https://github.com/apache/ignite-3/pull/229#discussion_r672996990
##########
File path: modules/network-api/src/main/java/org/apache/ignite/network/AbstractMessagingService.java
##########
@@ -17,26 +17,56 @@
package org.apache.ignite.network;
+import java.util.ArrayList;
import java.util.Collection;
-import java.util.Collections;
-import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicReferenceArray;
+import org.apache.ignite.network.annotations.MessageGroup;
/**
* Base class for {@link MessagingService} implementations.
*/
public abstract class AbstractMessagingService implements MessagingService {
- /** */
- private final Collection<NetworkMessageHandler> messageHandlers = new CopyOnWriteArrayList<>();
+ /** Mapping from group type (array index) to a list of registered message handlers. */
+ private final AtomicReferenceArray<List<NetworkMessageHandler>> handlersByGroupType =
+ new AtomicReferenceArray<>(Short.MAX_VALUE + 1);
/** {@inheritDoc} */
- @Override public void addMessageHandler(NetworkMessageHandler handler) {
- messageHandlers.add(handler);
+ @Override public void addMessageHandler(Class<?> messageGroup, NetworkMessageHandler handler) {
+ handlersByGroupType.getAndUpdate(getMessageGroupType(messageGroup), handlers -> {
+ if (handlers == null)
+ return List.of(handler);
+
+ var result = new ArrayList<NetworkMessageHandler>(handlers.size() + 1);
+
+ result.addAll(handlers);
+ result.add(handler);
+
+ return result;
+ });
+ }
+
+ /**
+ * Extracts the message group ID from a class annotated with {@link MessageGroup}.
+ */
+ private static short getMessageGroupType(Class<?> messageGroup) {
Review comment:
Parameter javadoc is missing
##########
File path: modules/network-api/src/main/java/org/apache/ignite/network/AbstractMessagingService.java
##########
@@ -17,26 +17,56 @@
package org.apache.ignite.network;
+import java.util.ArrayList;
import java.util.Collection;
-import java.util.Collections;
-import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicReferenceArray;
+import org.apache.ignite.network.annotations.MessageGroup;
/**
* Base class for {@link MessagingService} implementations.
*/
public abstract class AbstractMessagingService implements MessagingService {
- /** */
- private final Collection<NetworkMessageHandler> messageHandlers = new CopyOnWriteArrayList<>();
+ /** Mapping from group type (array index) to a list of registered message handlers. */
+ private final AtomicReferenceArray<List<NetworkMessageHandler>> handlersByGroupType =
+ new AtomicReferenceArray<>(Short.MAX_VALUE + 1);
/** {@inheritDoc} */
- @Override public void addMessageHandler(NetworkMessageHandler handler) {
- messageHandlers.add(handler);
+ @Override public void addMessageHandler(Class<?> messageGroup, NetworkMessageHandler handler) {
+ handlersByGroupType.getAndUpdate(getMessageGroupType(messageGroup), handlers -> {
+ if (handlers == null)
+ return List.of(handler);
+
+ var result = new ArrayList<NetworkMessageHandler>(handlers.size() + 1);
+
+ result.addAll(handlers);
+ result.add(handler);
+
+ return result;
+ });
+ }
+
+ /**
+ * Extracts the message group ID from a class annotated with {@link MessageGroup}.
+ */
+ private static short getMessageGroupType(Class<?> messageGroup) {
+ MessageGroup annotation = messageGroup.getAnnotation(MessageGroup.class);
+
+ assert annotation != null : "No MessageGroup annotation present";
Review comment:
Please add "messageGroup" class itself as assertion message
##########
File path: modules/metastorage/src/main/java/org/apache/ignite/internal/metastorage/MetaStorageManager.java
##########
@@ -174,7 +174,7 @@ public MetaStorageManager(
// );
// TODO: IGNITE-14414 Cluster initialization flow. Here we should complete metaStorageServiceFuture.
- clusterNetSvc.messagingService().addMessageHandler((message, senderAddr, correlationId) -> {});
+// clusterNetSvc.messagingService().addMessageHandler((message, senderAddr, correlationId) -> {});
Review comment:
What is this exactly? Can we simply remove this line?
##########
File path: modules/network-api/src/main/java/org/apache/ignite/network/AbstractMessagingService.java
##########
@@ -17,26 +17,56 @@
package org.apache.ignite.network;
+import java.util.ArrayList;
import java.util.Collection;
-import java.util.Collections;
-import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicReferenceArray;
+import org.apache.ignite.network.annotations.MessageGroup;
/**
* Base class for {@link MessagingService} implementations.
*/
public abstract class AbstractMessagingService implements MessagingService {
- /** */
- private final Collection<NetworkMessageHandler> messageHandlers = new CopyOnWriteArrayList<>();
+ /** Mapping from group type (array index) to a list of registered message handlers. */
+ private final AtomicReferenceArray<List<NetworkMessageHandler>> handlersByGroupType =
+ new AtomicReferenceArray<>(Short.MAX_VALUE + 1);
/** {@inheritDoc} */
- @Override public void addMessageHandler(NetworkMessageHandler handler) {
- messageHandlers.add(handler);
+ @Override public void addMessageHandler(Class<?> messageGroup, NetworkMessageHandler handler) {
+ handlersByGroupType.getAndUpdate(getMessageGroupType(messageGroup), handlers -> {
+ if (handlers == null)
+ return List.of(handler);
+
+ var result = new ArrayList<NetworkMessageHandler>(handlers.size() + 1);
+
+ result.addAll(handlers);
+ result.add(handler);
+
+ return result;
+ });
+ }
+
+ /**
+ * Extracts the message group ID from a class annotated with {@link MessageGroup}.
+ */
+ private static short getMessageGroupType(Class<?> messageGroup) {
+ MessageGroup annotation = messageGroup.getAnnotation(MessageGroup.class);
+
+ assert annotation != null : "No MessageGroup annotation present";
+
+ short groupType = annotation.groupType();
+
+ assert groupType >= 0 : "Group type must not be negative";
+
+ return groupType;
}
/**
* @return registered message handlers.
*/
- public Collection<NetworkMessageHandler> getMessageHandlers() {
- return Collections.unmodifiableCollection(messageHandlers);
+ protected Collection<NetworkMessageHandler> getMessageHandlers(short groupType) {
+ List<NetworkMessageHandler> result = handlersByGroupType.get(groupType);
Review comment:
I'd add assertion that "groupType >= 0" here as well just in case. Method should be final btw
--
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.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [ignite-3] ibessonov merged pull request #229: IGNITE-14983 Enable registering message listeners for message groups
Posted by GitBox <gi...@apache.org>.
ibessonov merged pull request #229:
URL: https://github.com/apache/ignite-3/pull/229
--
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.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [ignite-3] sashapolo commented on a change in pull request #229: IGNITE-14983 Enable registering message listeners for message groups
Posted by GitBox <gi...@apache.org>.
sashapolo commented on a change in pull request #229:
URL: https://github.com/apache/ignite-3/pull/229#discussion_r673002110
##########
File path: modules/metastorage/src/main/java/org/apache/ignite/internal/metastorage/MetaStorageManager.java
##########
@@ -174,7 +174,7 @@ public MetaStorageManager(
// );
// TODO: IGNITE-14414 Cluster initialization flow. Here we should complete metaStorageServiceFuture.
- clusterNetSvc.messagingService().addMessageHandler((message, senderAddr, correlationId) -> {});
+// clusterNetSvc.messagingService().addMessageHandler((message, senderAddr, correlationId) -> {});
Review comment:
I don't know =( But there's a TODO, so its author might need it...
##########
File path: modules/network-api/src/main/java/org/apache/ignite/network/AbstractMessagingService.java
##########
@@ -17,26 +17,56 @@
package org.apache.ignite.network;
+import java.util.ArrayList;
import java.util.Collection;
-import java.util.Collections;
-import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicReferenceArray;
+import org.apache.ignite.network.annotations.MessageGroup;
/**
* Base class for {@link MessagingService} implementations.
*/
public abstract class AbstractMessagingService implements MessagingService {
- /** */
- private final Collection<NetworkMessageHandler> messageHandlers = new CopyOnWriteArrayList<>();
+ /** Mapping from group type (array index) to a list of registered message handlers. */
+ private final AtomicReferenceArray<List<NetworkMessageHandler>> handlersByGroupType =
+ new AtomicReferenceArray<>(Short.MAX_VALUE + 1);
/** {@inheritDoc} */
- @Override public void addMessageHandler(NetworkMessageHandler handler) {
- messageHandlers.add(handler);
+ @Override public void addMessageHandler(Class<?> messageGroup, NetworkMessageHandler handler) {
+ handlersByGroupType.getAndUpdate(getMessageGroupType(messageGroup), handlers -> {
+ if (handlers == null)
+ return List.of(handler);
+
+ var result = new ArrayList<NetworkMessageHandler>(handlers.size() + 1);
+
+ result.addAll(handlers);
+ result.add(handler);
+
+ return result;
+ });
+ }
+
+ /**
+ * Extracts the message group ID from a class annotated with {@link MessageGroup}.
+ */
+ private static short getMessageGroupType(Class<?> messageGroup) {
Review comment:
AFAIK this is not mandatory for non-public methods
--
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.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [ignite-3] ibessonov commented on a change in pull request #229: IGNITE-14983 Enable registering message listeners for message groups
Posted by GitBox <gi...@apache.org>.
ibessonov commented on a change in pull request #229:
URL: https://github.com/apache/ignite-3/pull/229#discussion_r673004869
##########
File path: modules/network-api/src/main/java/org/apache/ignite/network/AbstractMessagingService.java
##########
@@ -17,26 +17,56 @@
package org.apache.ignite.network;
+import java.util.ArrayList;
import java.util.Collection;
-import java.util.Collections;
-import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicReferenceArray;
+import org.apache.ignite.network.annotations.MessageGroup;
/**
* Base class for {@link MessagingService} implementations.
*/
public abstract class AbstractMessagingService implements MessagingService {
- /** */
- private final Collection<NetworkMessageHandler> messageHandlers = new CopyOnWriteArrayList<>();
+ /** Mapping from group type (array index) to a list of registered message handlers. */
+ private final AtomicReferenceArray<List<NetworkMessageHandler>> handlersByGroupType =
+ new AtomicReferenceArray<>(Short.MAX_VALUE + 1);
/** {@inheritDoc} */
- @Override public void addMessageHandler(NetworkMessageHandler handler) {
- messageHandlers.add(handler);
+ @Override public void addMessageHandler(Class<?> messageGroup, NetworkMessageHandler handler) {
+ handlersByGroupType.getAndUpdate(getMessageGroupType(messageGroup), handlers -> {
+ if (handlers == null)
+ return List.of(handler);
+
+ var result = new ArrayList<NetworkMessageHandler>(handlers.size() + 1);
+
+ result.addAll(handlers);
+ result.add(handler);
+
+ return result;
+ });
+ }
+
+ /**
+ * Extracts the message group ID from a class annotated with {@link MessageGroup}.
+ */
+ private static short getMessageGroupType(Class<?> messageGroup) {
Review comment:
You're right
--
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.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [ignite-3] ibessonov merged pull request #229: IGNITE-14983 Enable registering message listeners for message groups
Posted by GitBox <gi...@apache.org>.
ibessonov merged pull request #229:
URL: https://github.com/apache/ignite-3/pull/229
--
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.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [ignite-3] sashapolo commented on a change in pull request #229: IGNITE-14983 Enable registering message listeners for message groups
Posted by GitBox <gi...@apache.org>.
sashapolo commented on a change in pull request #229:
URL: https://github.com/apache/ignite-3/pull/229#discussion_r673002110
##########
File path: modules/metastorage/src/main/java/org/apache/ignite/internal/metastorage/MetaStorageManager.java
##########
@@ -174,7 +174,7 @@ public MetaStorageManager(
// );
// TODO: IGNITE-14414 Cluster initialization flow. Here we should complete metaStorageServiceFuture.
- clusterNetSvc.messagingService().addMessageHandler((message, senderAddr, correlationId) -> {});
+// clusterNetSvc.messagingService().addMessageHandler((message, senderAddr, correlationId) -> {});
Review comment:
I don't know =( But there's a TODO, so its author might need it...
--
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.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [ignite-3] ibessonov commented on a change in pull request #229: IGNITE-14983 Enable registering message listeners for message groups
Posted by GitBox <gi...@apache.org>.
ibessonov commented on a change in pull request #229:
URL: https://github.com/apache/ignite-3/pull/229#discussion_r673005227
##########
File path: modules/metastorage/src/main/java/org/apache/ignite/internal/metastorage/MetaStorageManager.java
##########
@@ -174,7 +174,7 @@ public MetaStorageManager(
// );
// TODO: IGNITE-14414 Cluster initialization flow. Here we should complete metaStorageServiceFuture.
- clusterNetSvc.messagingService().addMessageHandler((message, senderAddr, correlationId) -> {});
+// clusterNetSvc.messagingService().addMessageHandler((message, senderAddr, correlationId) -> {});
Review comment:
Ok
--
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.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [ignite-3] ibessonov commented on a change in pull request #229: IGNITE-14983 Enable registering message listeners for message groups
Posted by GitBox <gi...@apache.org>.
ibessonov commented on a change in pull request #229:
URL: https://github.com/apache/ignite-3/pull/229#discussion_r672996990
##########
File path: modules/network-api/src/main/java/org/apache/ignite/network/AbstractMessagingService.java
##########
@@ -17,26 +17,56 @@
package org.apache.ignite.network;
+import java.util.ArrayList;
import java.util.Collection;
-import java.util.Collections;
-import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicReferenceArray;
+import org.apache.ignite.network.annotations.MessageGroup;
/**
* Base class for {@link MessagingService} implementations.
*/
public abstract class AbstractMessagingService implements MessagingService {
- /** */
- private final Collection<NetworkMessageHandler> messageHandlers = new CopyOnWriteArrayList<>();
+ /** Mapping from group type (array index) to a list of registered message handlers. */
+ private final AtomicReferenceArray<List<NetworkMessageHandler>> handlersByGroupType =
+ new AtomicReferenceArray<>(Short.MAX_VALUE + 1);
/** {@inheritDoc} */
- @Override public void addMessageHandler(NetworkMessageHandler handler) {
- messageHandlers.add(handler);
+ @Override public void addMessageHandler(Class<?> messageGroup, NetworkMessageHandler handler) {
+ handlersByGroupType.getAndUpdate(getMessageGroupType(messageGroup), handlers -> {
+ if (handlers == null)
+ return List.of(handler);
+
+ var result = new ArrayList<NetworkMessageHandler>(handlers.size() + 1);
+
+ result.addAll(handlers);
+ result.add(handler);
+
+ return result;
+ });
+ }
+
+ /**
+ * Extracts the message group ID from a class annotated with {@link MessageGroup}.
+ */
+ private static short getMessageGroupType(Class<?> messageGroup) {
Review comment:
Parameter javadoc is missing
##########
File path: modules/network-api/src/main/java/org/apache/ignite/network/AbstractMessagingService.java
##########
@@ -17,26 +17,56 @@
package org.apache.ignite.network;
+import java.util.ArrayList;
import java.util.Collection;
-import java.util.Collections;
-import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicReferenceArray;
+import org.apache.ignite.network.annotations.MessageGroup;
/**
* Base class for {@link MessagingService} implementations.
*/
public abstract class AbstractMessagingService implements MessagingService {
- /** */
- private final Collection<NetworkMessageHandler> messageHandlers = new CopyOnWriteArrayList<>();
+ /** Mapping from group type (array index) to a list of registered message handlers. */
+ private final AtomicReferenceArray<List<NetworkMessageHandler>> handlersByGroupType =
+ new AtomicReferenceArray<>(Short.MAX_VALUE + 1);
/** {@inheritDoc} */
- @Override public void addMessageHandler(NetworkMessageHandler handler) {
- messageHandlers.add(handler);
+ @Override public void addMessageHandler(Class<?> messageGroup, NetworkMessageHandler handler) {
+ handlersByGroupType.getAndUpdate(getMessageGroupType(messageGroup), handlers -> {
+ if (handlers == null)
+ return List.of(handler);
+
+ var result = new ArrayList<NetworkMessageHandler>(handlers.size() + 1);
+
+ result.addAll(handlers);
+ result.add(handler);
+
+ return result;
+ });
+ }
+
+ /**
+ * Extracts the message group ID from a class annotated with {@link MessageGroup}.
+ */
+ private static short getMessageGroupType(Class<?> messageGroup) {
+ MessageGroup annotation = messageGroup.getAnnotation(MessageGroup.class);
+
+ assert annotation != null : "No MessageGroup annotation present";
Review comment:
Please add "messageGroup" class itself as assertion message
##########
File path: modules/metastorage/src/main/java/org/apache/ignite/internal/metastorage/MetaStorageManager.java
##########
@@ -174,7 +174,7 @@ public MetaStorageManager(
// );
// TODO: IGNITE-14414 Cluster initialization flow. Here we should complete metaStorageServiceFuture.
- clusterNetSvc.messagingService().addMessageHandler((message, senderAddr, correlationId) -> {});
+// clusterNetSvc.messagingService().addMessageHandler((message, senderAddr, correlationId) -> {});
Review comment:
What is this exactly? Can we simply remove this line?
##########
File path: modules/network-api/src/main/java/org/apache/ignite/network/AbstractMessagingService.java
##########
@@ -17,26 +17,56 @@
package org.apache.ignite.network;
+import java.util.ArrayList;
import java.util.Collection;
-import java.util.Collections;
-import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicReferenceArray;
+import org.apache.ignite.network.annotations.MessageGroup;
/**
* Base class for {@link MessagingService} implementations.
*/
public abstract class AbstractMessagingService implements MessagingService {
- /** */
- private final Collection<NetworkMessageHandler> messageHandlers = new CopyOnWriteArrayList<>();
+ /** Mapping from group type (array index) to a list of registered message handlers. */
+ private final AtomicReferenceArray<List<NetworkMessageHandler>> handlersByGroupType =
+ new AtomicReferenceArray<>(Short.MAX_VALUE + 1);
/** {@inheritDoc} */
- @Override public void addMessageHandler(NetworkMessageHandler handler) {
- messageHandlers.add(handler);
+ @Override public void addMessageHandler(Class<?> messageGroup, NetworkMessageHandler handler) {
+ handlersByGroupType.getAndUpdate(getMessageGroupType(messageGroup), handlers -> {
+ if (handlers == null)
+ return List.of(handler);
+
+ var result = new ArrayList<NetworkMessageHandler>(handlers.size() + 1);
+
+ result.addAll(handlers);
+ result.add(handler);
+
+ return result;
+ });
+ }
+
+ /**
+ * Extracts the message group ID from a class annotated with {@link MessageGroup}.
+ */
+ private static short getMessageGroupType(Class<?> messageGroup) {
+ MessageGroup annotation = messageGroup.getAnnotation(MessageGroup.class);
+
+ assert annotation != null : "No MessageGroup annotation present";
+
+ short groupType = annotation.groupType();
+
+ assert groupType >= 0 : "Group type must not be negative";
+
+ return groupType;
}
/**
* @return registered message handlers.
*/
- public Collection<NetworkMessageHandler> getMessageHandlers() {
- return Collections.unmodifiableCollection(messageHandlers);
+ protected Collection<NetworkMessageHandler> getMessageHandlers(short groupType) {
+ List<NetworkMessageHandler> result = handlersByGroupType.get(groupType);
Review comment:
I'd add assertion that "groupType >= 0" here as well just in case. Method should be final btw
##########
File path: modules/network-api/src/main/java/org/apache/ignite/network/AbstractMessagingService.java
##########
@@ -17,26 +17,56 @@
package org.apache.ignite.network;
+import java.util.ArrayList;
import java.util.Collection;
-import java.util.Collections;
-import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicReferenceArray;
+import org.apache.ignite.network.annotations.MessageGroup;
/**
* Base class for {@link MessagingService} implementations.
*/
public abstract class AbstractMessagingService implements MessagingService {
- /** */
- private final Collection<NetworkMessageHandler> messageHandlers = new CopyOnWriteArrayList<>();
+ /** Mapping from group type (array index) to a list of registered message handlers. */
+ private final AtomicReferenceArray<List<NetworkMessageHandler>> handlersByGroupType =
+ new AtomicReferenceArray<>(Short.MAX_VALUE + 1);
/** {@inheritDoc} */
- @Override public void addMessageHandler(NetworkMessageHandler handler) {
- messageHandlers.add(handler);
+ @Override public void addMessageHandler(Class<?> messageGroup, NetworkMessageHandler handler) {
+ handlersByGroupType.getAndUpdate(getMessageGroupType(messageGroup), handlers -> {
+ if (handlers == null)
+ return List.of(handler);
+
+ var result = new ArrayList<NetworkMessageHandler>(handlers.size() + 1);
+
+ result.addAll(handlers);
+ result.add(handler);
+
+ return result;
+ });
+ }
+
+ /**
+ * Extracts the message group ID from a class annotated with {@link MessageGroup}.
+ */
+ private static short getMessageGroupType(Class<?> messageGroup) {
Review comment:
You're right
##########
File path: modules/metastorage/src/main/java/org/apache/ignite/internal/metastorage/MetaStorageManager.java
##########
@@ -174,7 +174,7 @@ public MetaStorageManager(
// );
// TODO: IGNITE-14414 Cluster initialization flow. Here we should complete metaStorageServiceFuture.
- clusterNetSvc.messagingService().addMessageHandler((message, senderAddr, correlationId) -> {});
+// clusterNetSvc.messagingService().addMessageHandler((message, senderAddr, correlationId) -> {});
Review comment:
Ok
--
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.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [ignite-3] sashapolo commented on a change in pull request #229: IGNITE-14983 Enable registering message listeners for message groups
Posted by GitBox <gi...@apache.org>.
sashapolo commented on a change in pull request #229:
URL: https://github.com/apache/ignite-3/pull/229#discussion_r673002311
##########
File path: modules/network-api/src/main/java/org/apache/ignite/network/AbstractMessagingService.java
##########
@@ -17,26 +17,56 @@
package org.apache.ignite.network;
+import java.util.ArrayList;
import java.util.Collection;
-import java.util.Collections;
-import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicReferenceArray;
+import org.apache.ignite.network.annotations.MessageGroup;
/**
* Base class for {@link MessagingService} implementations.
*/
public abstract class AbstractMessagingService implements MessagingService {
- /** */
- private final Collection<NetworkMessageHandler> messageHandlers = new CopyOnWriteArrayList<>();
+ /** Mapping from group type (array index) to a list of registered message handlers. */
+ private final AtomicReferenceArray<List<NetworkMessageHandler>> handlersByGroupType =
+ new AtomicReferenceArray<>(Short.MAX_VALUE + 1);
/** {@inheritDoc} */
- @Override public void addMessageHandler(NetworkMessageHandler handler) {
- messageHandlers.add(handler);
+ @Override public void addMessageHandler(Class<?> messageGroup, NetworkMessageHandler handler) {
+ handlersByGroupType.getAndUpdate(getMessageGroupType(messageGroup), handlers -> {
+ if (handlers == null)
+ return List.of(handler);
+
+ var result = new ArrayList<NetworkMessageHandler>(handlers.size() + 1);
+
+ result.addAll(handlers);
+ result.add(handler);
+
+ return result;
+ });
+ }
+
+ /**
+ * Extracts the message group ID from a class annotated with {@link MessageGroup}.
+ */
+ private static short getMessageGroupType(Class<?> messageGroup) {
Review comment:
AFAIK this is not mandatory for non-public methods
--
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.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org