petrov-mg commented on code in PR #13346:
URL: https://github.com/apache/ignite/pull/13346#discussion_r3564371246


##########
modules/zookeeper/src/main/java/org/apache/ignite/spi/discovery/zk/internal/ZookeeperDiscoveryImpl.java:
##########
@@ -1164,6 +1174,18 @@ private void 
marshalCredentialsOnJoin(ZookeeperClusterNode node) throws IgniteSp
         }
     }
 
+    /**
+     * Sends from-Ignite custom event, not Zookeeper-related. Is aware of 
distributed {@link OperationContext}.
+     *
+     * @see ZkCustomEventMessage
+     */
+    public void sendExternalCustomMessage(DiscoverySpiCustomMessage msg) {
+        // Holds the distributed operation context.
+        msg = new ZkCustomEventMessage(msg, 
opCtxDispatcher.collectDistributedAttributes());
+
+        sendCustomMessage(msg);
+    }

Review Comment:
   ```suggestion
        public void sendCustomEvent(DiscoverySpiCustomMessage msg) {
           OperationContextMessage opCtx = 
opCtxDispatcher.collectDistributedAttributes();
   
           if (opCtx != null && msg != null)
               sendCustomMessage(new ZkOperationContextAwareCustomMessage(msg, 
opCtx));
           else
               sendCustomMessage(msg);
       }
   ```



##########
modules/zookeeper/src/main/java/org/apache/ignite/spi/discovery/zk/internal/ZkCustomEventMessage.java:
##########
@@ -0,0 +1,86 @@
+/*
+ * 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.spi.discovery.zk.internal;
+
+import org.apache.ignite.internal.OperationContextMessage;
+import org.apache.ignite.internal.Order;
+import org.apache.ignite.internal.thread.context.OperationContext;
+import org.apache.ignite.internal.thread.context.OperationContextDispatcher;
+import org.apache.ignite.plugin.extensions.communication.MessageFactory;
+import org.apache.ignite.spi.discovery.DiscoverySpiCustomMessage;
+import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
+import 
org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryAbstractMessage;
+import org.apache.ignite.spi.discovery.zk.ZookeeperDiscoverySpi;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * <p>A holder for effective attributes of distributed {@link 
OperationContext}. Analogue of
+ * {@link TcpDiscoveryAbstractMessage#opCtxMsg} while we do not use a common 
base class for all the Zookeeper messages.</p>
+ *
+ * <p>NOTE: The difference is also the limitation on message type. In {@link 
TcpDiscoverySpi} we transfer distributed
+ * {@link OperationContext} with all the messages. In {@link 
ZookeeperDiscoverySpi} with from-Ignite
+ * {@link DiscoverySpiCustomMessage} only.</p>
+ *
+ * @see OperationContextDispatcher
+ * @see ZookeeperDiscoverySpi#sendCustomEvent(DiscoverySpiCustomMessage)
+ */
+public class ZkCustomEventMessage implements DiscoverySpiCustomMessage {
+    /** */
+    @Order(0)
+    DiscoverySpiCustomMessage delegate;
+
+    /** */
+    @Order(1)
+    @Nullable OperationContextMessage opCtxMsg;
+
+    /** Default constructor for {@link MessageFactory}. */
+    public ZkCustomEventMessage() {
+        // No-op.
+    }
+
+    /**
+     * @param delegate Original message.
+     * @param opCtxMsg Distributed operation context message.
+     */
+    public ZkCustomEventMessage(DiscoverySpiCustomMessage delegate, @Nullable 
OperationContextMessage opCtxMsg) {
+        this.delegate = delegate;
+        this.opCtxMsg = opCtxMsg;
+    }
+
+    /** {@inheritDoc} */
+    @Override public @Nullable DiscoverySpiCustomMessage ackMessage() {
+        DiscoverySpiCustomMessage res = delegate.ackMessage();
+
+        assert !(res instanceof ZkCustomEventMessage);
+
+        if (opCtxMsg == null || res == null)
+            return res;
+
+        return new ZkCustomEventMessage(res, opCtxMsg);

Review Comment:
   ```suggestion
           DiscoverySpiCustomMessage ack = delegate.ackMessage();
   
           return ack == null ? null : new 
ZkOperationContextAwareCustomMessage(ack, opCtxMsg);
   ```



##########
modules/zookeeper/src/main/java/org/apache/ignite/spi/discovery/zk/internal/ZkCustomEventMessage.java:
##########
@@ -0,0 +1,86 @@
+/*
+ * 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.spi.discovery.zk.internal;
+
+import org.apache.ignite.internal.OperationContextMessage;
+import org.apache.ignite.internal.Order;
+import org.apache.ignite.internal.thread.context.OperationContext;
+import org.apache.ignite.internal.thread.context.OperationContextDispatcher;
+import org.apache.ignite.plugin.extensions.communication.MessageFactory;
+import org.apache.ignite.spi.discovery.DiscoverySpiCustomMessage;
+import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
+import 
org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryAbstractMessage;
+import org.apache.ignite.spi.discovery.zk.ZookeeperDiscoverySpi;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * <p>A holder for effective attributes of distributed {@link 
OperationContext}. Analogue of
+ * {@link TcpDiscoveryAbstractMessage#opCtxMsg} while we do not use a common 
base class for all the Zookeeper messages.</p>
+ *
+ * <p>NOTE: The difference is also the limitation on message type. In {@link 
TcpDiscoverySpi} we transfer distributed
+ * {@link OperationContext} with all the messages. In {@link 
ZookeeperDiscoverySpi} with from-Ignite
+ * {@link DiscoverySpiCustomMessage} only.</p>
+ *
+ * @see OperationContextDispatcher
+ * @see ZookeeperDiscoverySpi#sendCustomEvent(DiscoverySpiCustomMessage)
+ */
+public class ZkCustomEventMessage implements DiscoverySpiCustomMessage {
+    /** */
+    @Order(0)
+    DiscoverySpiCustomMessage delegate;
+
+    /** */
+    @Order(1)
+    @Nullable OperationContextMessage opCtxMsg;
+
+    /** Default constructor for {@link MessageFactory}. */
+    public ZkCustomEventMessage() {
+        // No-op.
+    }
+
+    /**
+     * @param delegate Original message.
+     * @param opCtxMsg Distributed operation context message.
+     */
+    public ZkCustomEventMessage(DiscoverySpiCustomMessage delegate, @Nullable 
OperationContextMessage opCtxMsg) {
+        this.delegate = delegate;
+        this.opCtxMsg = opCtxMsg;

Review Comment:
   ```suggestion
           assert delegate != null;
           assert opCtxMsg != null;
           assert !(delegate instanceof ZkOperationContextAwareCustomMessage);
   
           this.delegate = delegate;
           this.opCtxMsg = opCtxMsg;
   ```



##########
modules/zookeeper/src/main/java/org/apache/ignite/spi/discovery/zk/internal/ZkDiscoveryCustomEventData.java:
##########
@@ -37,10 +37,12 @@ class ZkDiscoveryCustomEventData extends 
ZkDiscoveryEventData {
     /** */
     final String evtPath;
 
-    /** Message (can be marshalled as part of ZkDiscoveryCustomEventData or 
stored in separate znode. */
+    /** Message (can be marshalled as part of ZkDiscoveryCustomEventData or 
stored in separate node. */
     byte[] msgBytes;
 
-    /** Unmarshalled message. */
+    /**
+     * Unmarshalled custom message holder. Can be wrapped with {@link 
ZkCustomEventMessage}.
+     */

Review Comment:
   Replace this with one-line javadoc.



##########
modules/zookeeper/src/main/java/org/apache/ignite/spi/discovery/zk/internal/ZookeeperDiscoveryImpl.java:
##########


Review Comment:
   ```suggestion
       void sendCustomMessage(DiscoverySpiCustomMessage msg) {
   ```



##########
modules/zookeeper/src/main/java/org/apache/ignite/spi/discovery/zk/ZookeeperDiscoverySpi.java:
##########
@@ -407,7 +407,7 @@ public DiscoverySpiNodeAuthenticator getAuthenticator() {
 
     /** {@inheritDoc} */
     @Override public void sendCustomEvent(DiscoverySpiCustomMessage msg) {
-        impl.sendCustomMessage(msg);
+        impl.sendExternalCustomMessage(msg);

Review Comment:
   ```suggestion
           impl.sendCustomEvent(msg);
   ```



##########
modules/zookeeper/src/main/java/org/apache/ignite/spi/discovery/zk/internal/ZkCustomEventMessage.java:
##########
@@ -0,0 +1,86 @@
+/*
+ * 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.spi.discovery.zk.internal;
+
+import org.apache.ignite.internal.OperationContextMessage;
+import org.apache.ignite.internal.Order;
+import org.apache.ignite.internal.thread.context.OperationContext;
+import org.apache.ignite.internal.thread.context.OperationContextDispatcher;
+import org.apache.ignite.plugin.extensions.communication.MessageFactory;
+import org.apache.ignite.spi.discovery.DiscoverySpiCustomMessage;
+import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
+import 
org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryAbstractMessage;
+import org.apache.ignite.spi.discovery.zk.ZookeeperDiscoverySpi;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * <p>A holder for effective attributes of distributed {@link 
OperationContext}. Analogue of
+ * {@link TcpDiscoveryAbstractMessage#opCtxMsg} while we do not use a common 
base class for all the Zookeeper messages.</p>
+ *
+ * <p>NOTE: The difference is also the limitation on message type. In {@link 
TcpDiscoverySpi} we transfer distributed
+ * {@link OperationContext} with all the messages. In {@link 
ZookeeperDiscoverySpi} with from-Ignite
+ * {@link DiscoverySpiCustomMessage} only.</p>
+ *
+ * @see OperationContextDispatcher
+ * @see ZookeeperDiscoverySpi#sendCustomEvent(DiscoverySpiCustomMessage)
+ */
+public class ZkCustomEventMessage implements DiscoverySpiCustomMessage {

Review Comment:
   ```suggestion
   public class ZkOperationContextAwareCustomMessage implements 
DiscoverySpiCustomMessage {
   ```



##########
modules/zookeeper/src/main/java/org/apache/ignite/spi/discovery/zk/internal/ZkMessageFactory.java:
##########
@@ -29,5 +29,6 @@ public class ZkMessageFactory implements 
MessageFactoryProvider {
         factory.register(402, ZkForceNodeFailMessage::new, new 
ZkForceNodeFailMessageSerializer());
         factory.register(403, ZkNoServersMessage::new, new 
ZkNoServersMessageSerializer());
         factory.register(404, ZkDiscoDataBagWrapper::new, new 
ZkDiscoDataBagWrapperSerializer());
+        factory.register(405, ZkCustomEventMessage::new, new 
ZkCustomEventMessageSerializer());

Review Comment:
   ```suggestion
           factory.register(405, ZkOperationContextAwareCustomMessage::new, new 
ZkOperationContextAwareCustomMessageSerializer());
   ```



##########
modules/zookeeper/src/main/java/org/apache/ignite/spi/discovery/zk/internal/ZkDiscoveryCustomEventData.java:
##########
@@ -37,10 +37,12 @@ class ZkDiscoveryCustomEventData extends 
ZkDiscoveryEventData {
     /** */
     final String evtPath;
 
-    /** Message (can be marshalled as part of ZkDiscoveryCustomEventData or 
stored in separate znode. */
+    /** Message (can be marshalled as part of ZkDiscoveryCustomEventData or 
stored in separate node. */

Review Comment:
   Remove this change.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to