# IGNITE-831 Add RingEndAwareCustomMessage class.

Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/f382ebca
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/f382ebca
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/f382ebca

Branch: refs/heads/ignite-709_2
Commit: f382ebca278177752e00d31911b851c09d9ba482
Parents: 94fed65
Author: sevdokimov <sevdoki...@gridgain.com>
Authored: Tue May 5 14:14:47 2015 +0300
Committer: sevdokimov <sevdoki...@gridgain.com>
Committed: Tue May 5 14:14:47 2015 +0300

----------------------------------------------------------------------
 .../discovery/RingEndAwareCustomMessage.java    | 31 ++++++++++++++++++++
 .../spi/discovery/tcp/TcpDiscoverySpi.java      | 17 +++++++++++
 .../TcpDiscoveryCustomEventMessage.java         |  9 +++++-
 3 files changed, 56 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/f382ebca/modules/core/src/main/java/org/apache/ignite/internal/managers/discovery/RingEndAwareCustomMessage.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/managers/discovery/RingEndAwareCustomMessage.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/managers/discovery/RingEndAwareCustomMessage.java
new file mode 100644
index 0000000..41cee8e
--- /dev/null
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/managers/discovery/RingEndAwareCustomMessage.java
@@ -0,0 +1,31 @@
+/*
+ * 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.internal.managers.discovery;
+
+import org.apache.ignite.spi.*;
+import org.jetbrains.annotations.*;
+
+/**
+ *
+ */
+public interface RingEndAwareCustomMessage extends DiscoveryCustomMessage {
+    /**
+     *
+     */
+    @Nullable public DiscoveryCustomMessage 
newMessageOnRingEnd(IgniteSpiContext ctx);
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/f382ebca/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySpi.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySpi.java
 
b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySpi.java
index eba0528..5336738 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySpi.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySpi.java
@@ -4466,6 +4466,21 @@ public class TcpDiscoverySpi extends 
TcpDiscoverySpiAdapter implements TcpDiscov
                 if (msg.verified()) {
                     stats.onRingMessageReceived(msg);
 
+                    try {
+                        DiscoveryCustomMessage msgObj = 
marsh.unmarshal(msg.messageBytes(), U.gridClassLoader());
+
+                        if (msgObj instanceof RingEndAwareCustomMessage) {
+                            DiscoveryCustomMessage nextMsg = 
((RingEndAwareCustomMessage)msgObj)
+                                .newMessageOnRingEnd(getSpiContext());
+
+                            if (nextMsg != null)
+                                addMessage(new 
TcpDiscoveryCustomEventMessage(getLocalNodeId(), marsh.marshal(nextMsg)));
+                        }
+                    }
+                    catch (IgniteCheckedException e) {
+                        U.error(log, "Failed to unmarshal discovery custom 
message.", e);
+                    }
+
                     addMessage(new 
TcpDiscoveryDiscardMessage(getLocalNodeId(), msg.id()));
 
                     return;
@@ -4502,6 +4517,8 @@ public class TcpDiscoverySpi extends 
TcpDiscoverySpiAdapter implements TcpDiscov
                             snapshot,
                             hist,
                             msgObj);
+
+                        msg.messageBytes(marsh.marshal(msgObj));
                     }
                     catch (IgniteCheckedException e) {
                         U.error(log, "Failed to unmarshal discovery custom 
message.", e);

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/f382ebca/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/messages/TcpDiscoveryCustomEventMessage.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/messages/TcpDiscoveryCustomEventMessage.java
 
b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/messages/TcpDiscoveryCustomEventMessage.java
index a7e0fca..372aa18 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/messages/TcpDiscoveryCustomEventMessage.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/messages/TcpDiscoveryCustomEventMessage.java
@@ -31,7 +31,7 @@ public class TcpDiscoveryCustomEventMessage extends 
TcpDiscoveryAbstractMessage
     private static final long serialVersionUID = 0L;
 
     /** */
-    private final byte[] msgBytes;
+    private byte[] msgBytes;
 
     /**
      * @param creatorNodeId Creator node id.
@@ -50,6 +50,13 @@ public class TcpDiscoveryCustomEventMessage extends 
TcpDiscoveryAbstractMessage
         return msgBytes;
     }
 
+    /**
+     * @param msgBytes New message bytes.
+     */
+    public void messageBytes(byte[] msgBytes) {
+        this.msgBytes = msgBytes;
+    }
+
     /** {@inheritDoc} */
     @Override public String toString() {
         return S.toString(TcpDiscoveryCustomEventMessage.class, this, "super", 
super.toString());

Reply via email to