diff --git a/modules/core/src/main/java/org/apache/ignite/internal/GridTopic.java b/modules/core/src/main/java/org/apache/ignite/internal/GridTopic.java index eab5c01c28c6e..0795b0865b59f 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/GridTopic.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/GridTopic.java @@ -177,7 +177,7 @@ public enum GridTopic { * @param id Topic ID. * @return Grid message topic with specified ID. */ - public Object topic(IgniteUuid id) { + public T1 topic(IgniteUuid id) { return new T1(this, id); } @@ -250,35 +250,33 @@ public Object topic(String id1, UUID id2, int id3, long id4) { return new T7(this, UUID.nameUUIDFromBytes(id1.getBytes(DFLT_CHARSET)), id2, id3, id4); } - /** - * - */ - private static class T1 implements Externalizable { - /** */ - private static final long serialVersionUID = 0L; - + /** */ + public static class T1 { /** */ private GridTopic topic; /** */ private IgniteUuid id; - /** - * No-arg constructor needed for {@link Serializable}. - */ - public T1() { - // No-op. - } - /** * @param topic Topic. * @param id ID. */ - private T1(GridTopic topic, IgniteUuid id) { + public T1(GridTopic topic, IgniteUuid id) { this.topic = topic; this.id = id; } + /** */ + public GridTopic topic() { + return topic; + } + + /** */ + public IgniteUuid id() { + return id; + } + /** {@inheritDoc} */ @Override public int hashCode() { return topic.ordinal() + id.hashCode(); @@ -295,18 +293,6 @@ private T1(GridTopic topic, IgniteUuid id) { return false; } - /** {@inheritDoc} */ - @Override public void writeExternal(ObjectOutput out) throws IOException { - out.writeByte(topic.ordinal()); - U.writeIgniteUuid(out, id); - } - - /** {@inheritDoc} */ - @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { - topic = fromOrdinal(in.readByte()); - id = U.readIgniteUuid(in); - } - /** {@inheritDoc} */ @Override public String toString() { return S.toString(T1.class, this); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/managers/deployment/GridDeploymentCommunication.java b/modules/core/src/main/java/org/apache/ignite/internal/managers/deployment/GridDeploymentCommunication.java index 6de75ab20899c..c83d39e4bf90d 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/managers/deployment/GridDeploymentCommunication.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/managers/deployment/GridDeploymentCommunication.java @@ -29,6 +29,7 @@ import org.apache.ignite.events.DiscoveryEvent; import org.apache.ignite.events.Event; import org.apache.ignite.internal.GridKernalContext; +import org.apache.ignite.internal.GridTopic; import org.apache.ignite.internal.cluster.ClusterTopologyCheckedException; import org.apache.ignite.internal.managers.communication.GridIoPolicy; import org.apache.ignite.internal.managers.communication.GridMessageListener; @@ -137,7 +138,7 @@ private void processDeploymentRequest(UUID nodeId, Object msg) { try { GridDeploymentRequest req = (GridDeploymentRequest)msg; - if (req.isUndeploy()) + if (req.undeploy()) processUndeployRequest(nodeId, req); else { assert activeReqNodeIds.get() == null; @@ -186,18 +187,6 @@ private void processResourceRequest(UUID nodeId, GridDeploymentRequest req) { if (log.isDebugEnabled()) log.debug("Received peer class/resource loading request [originatingNodeId=" + nodeId + ", req=" + req + ']'); - if (req.responseTopic() == null) { - try { - req.finishUnmarshal(marsh, U.resolveClassLoader(ctx.config())); - } - catch (IgniteCheckedException e) { - U.error(log, "Failed to process deployment request (will ignore) [" + - "originatingNodeId=" + nodeId + ", req=" + req + ']', e); - - return; - } - } - GridDeploymentResponse res = new GridDeploymentResponse(); GridDeployment dep = ctx.deploy().getDeployment(req.classLoaderId()); @@ -361,7 +350,7 @@ void sendUndeployRequest(String rsrcName, Collection rmtNodes) thro ctx.io().sendToGridTopic( rmtNodes, TOPIC_CLASSLOAD, - new GridDeploymentRequest(null, null, rsrcName, true), + new GridDeploymentRequest(rsrcName), GridIoPolicy.P2P_POOL); } } @@ -393,9 +382,9 @@ GridDeploymentResponse sendResourceRequest(final String rsrcName, IgniteUuid cls ", requesters=" + nodeIds + ']'); } - Object resTopic = TOPIC_CLASSLOAD.topic(IgniteUuid.fromUuid(ctx.localNodeId())); + GridTopic.T1 resTopic = TOPIC_CLASSLOAD.topic(IgniteUuid.fromUuid(ctx.localNodeId())); - GridDeploymentRequest req = new GridDeploymentRequest(resTopic, clsLdrId, rsrcName, false); + GridDeploymentRequest req = new GridDeploymentRequest(resTopic, clsLdrId, rsrcName); // Send node IDs chain with request. req.nodeIds(nodeIds); @@ -417,9 +406,6 @@ GridDeploymentResponse sendResourceRequest(final String rsrcName, IgniteUuid cls long start = U.currentTimeMillis(); - if (req.responseTopic() != null && !ctx.localNodeId().equals(dstNode.id())) - req.prepareMarshal(marsh); - ctx.io().sendToGridTopic(dstNode, TOPIC_CLASSLOAD, req, GridIoPolicy.P2P_POOL); if (log.isDebugEnabled()) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/managers/deployment/GridDeploymentRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/managers/deployment/GridDeploymentRequest.java index 00890882e0590..31484637bed7e 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/managers/deployment/GridDeploymentRequest.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/managers/deployment/GridDeploymentRequest.java @@ -19,37 +19,34 @@ import java.util.Collection; import java.util.UUID; -import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.internal.GridTopic; import org.apache.ignite.internal.Order; import org.apache.ignite.internal.util.tostring.GridToStringInclude; import org.apache.ignite.internal.util.typedef.internal.S; -import org.apache.ignite.internal.util.typedef.internal.U; import org.apache.ignite.lang.IgniteUuid; -import org.apache.ignite.marshaller.Marshaller; import org.apache.ignite.plugin.extensions.communication.Message; +import org.jetbrains.annotations.Nullable; /** * Deployment request. */ public class GridDeploymentRequest implements Message { /** Response topic. Response should be sent back to this topic. */ - private Object resTopic; - - /** Serialized topic. */ + /** */ @Order(0) - byte[] resTopicBytes; + @Nullable GridTopic topic; - /** Requested class name. */ + /** */ @Order(1) - String rsrcName; + @Nullable IgniteUuid topicId; - /** Class loader ID. */ + /** Requested class name. */ @Order(2) - IgniteUuid ldrId; + String rsrcName; - /** Undeploy flag. */ + /** Class loader ID. */ @Order(3) - boolean isUndeploy; + @Nullable IgniteUuid ldrId; /** Nodes participating in request (chain). */ @Order(4) @@ -64,22 +61,26 @@ public GridDeploymentRequest() { } /** - * Creates new request. + * Creates deploy request. * - * @param resTopic Response topic. + * @param topic Response topic. * @param ldrId Class loader ID. * @param rsrcName Resource name that should be found and sent back. - * @param isUndeploy Undeploy property. */ - GridDeploymentRequest(Object resTopic, IgniteUuid ldrId, String rsrcName, boolean isUndeploy) { - assert isUndeploy || resTopic != null; - assert isUndeploy || ldrId != null; - assert rsrcName != null; - - this.resTopic = resTopic; + GridDeploymentRequest(GridTopic.T1 topic, IgniteUuid ldrId, String rsrcName) { + this.topic = topic.topic(); + topicId = topic.id(); this.ldrId = ldrId; this.rsrcName = rsrcName; - this.isUndeploy = isUndeploy; + } + + /** + * Creates undeploy request. + * + * @param rsrcName Resource name that should be found and sent back. + */ + GridDeploymentRequest(String rsrcName) { + this.rsrcName = rsrcName; } /** @@ -87,8 +88,10 @@ public GridDeploymentRequest() { * * @return Response topic name. */ - Object responseTopic() { - return resTopic; + @Nullable GridTopic.T1 responseTopic() { + assert topic == null && topicId == null || topic != null && topicId != null; + + return topic == null ? null : new GridTopic.T1(topic, topicId); } /** @@ -105,7 +108,7 @@ public String resourceName() { * * @return Property class loader ID. */ - public IgniteUuid classLoaderId() { + public @Nullable IgniteUuid classLoaderId() { return ldrId; } @@ -114,8 +117,10 @@ public IgniteUuid classLoaderId() { * * @return Property undeploy. */ - public boolean isUndeploy() { - return isUndeploy; + public boolean undeploy() { + assert topic == null && topicId == null || topic != null && topicId != null; + + return topic == null; } /** @@ -134,26 +139,6 @@ public void nodeIds(Collection nodeIds) { this.nodeIds = nodeIds; } - /** - * @param marsh Marshaller. - */ - public void prepareMarshal(Marshaller marsh) throws IgniteCheckedException { - if (resTopic != null && resTopicBytes == null) - resTopicBytes = U.marshal(marsh, resTopic); - } - - /** - * @param marsh Marshaller. - * @param ldr Class loader. - */ - public void finishUnmarshal(Marshaller marsh, ClassLoader ldr) throws IgniteCheckedException { - if (resTopicBytes != null && resTopic == null) { - resTopic = U.unmarshal(marsh, resTopicBytes, ldr); - - resTopicBytes = null; - } - } - /** {@inheritDoc} */ @Override public short directType() { return 11; diff --git a/modules/core/src/main/resources/META-INF/classnames.properties b/modules/core/src/main/resources/META-INF/classnames.properties index 501daa170d1fd..bda798f48b0cd 100644 --- a/modules/core/src/main/resources/META-INF/classnames.properties +++ b/modules/core/src/main/resources/META-INF/classnames.properties @@ -232,7 +232,6 @@ org.apache.ignite.internal.GridTaskCancelRequest org.apache.ignite.internal.GridTaskNameHashKey org.apache.ignite.internal.GridTaskSessionRequest org.apache.ignite.internal.GridTopic -org.apache.ignite.internal.GridTopic$T1 org.apache.ignite.internal.GridTopic$T2 org.apache.ignite.internal.GridTopic$T3 org.apache.ignite.internal.GridTopic$T4 diff --git a/modules/core/src/test/java/org/apache/ignite/internal/GridTopicExternalizableSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/GridTopicExternalizableSelfTest.java index d34f1461c1ad4..41d69815aa568 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/GridTopicExternalizableSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/GridTopicExternalizableSelfTest.java @@ -53,9 +53,11 @@ public void testSerializationTopicCreatedByIgniteUuid() throws Exception { info("Test GridTopic externalization [marshaller=" + marsh + ']'); for (GridTopic topic : GridTopic.values()) { - Externalizable msgOut = (Externalizable)topic.topic(A_IGNITE_UUID); + if (topic.topic(A_IGNITE_UUID) instanceof Externalizable) { + Externalizable msgOut = (Externalizable)topic.topic(A_IGNITE_UUID); - assertEquals(msgOut, GridTestIoUtils.externalize(msgOut, marsh)); + assertEquals(msgOut, GridTestIoUtils.externalize(msgOut, marsh)); + } } } } diff --git a/modules/core/src/test/java/org/apache/ignite/internal/managers/deployment/DeploymentRequestOfUnknownClassProcessingTest.java b/modules/core/src/test/java/org/apache/ignite/internal/managers/deployment/DeploymentRequestOfUnknownClassProcessingTest.java index 356e81477b3de..6abf93cd8fcca 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/managers/deployment/DeploymentRequestOfUnknownClassProcessingTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/managers/deployment/DeploymentRequestOfUnknownClassProcessingTest.java @@ -21,10 +21,12 @@ import java.util.UUID; import java.util.concurrent.TimeUnit; import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.internal.GridTopic; import org.apache.ignite.internal.IgniteEx; import org.apache.ignite.internal.managers.communication.GridIoPolicy; import org.apache.ignite.internal.managers.communication.GridMessageListener; import org.apache.ignite.internal.util.future.GridFutureAdapter; +import org.apache.ignite.lang.IgniteUuid; import org.apache.ignite.testframework.GridTestExternalClassLoader; import org.apache.ignite.testframework.ListeningTestLogger; import org.apache.ignite.testframework.LogListener; @@ -38,9 +40,6 @@ * Tests the processing of deployment request with an attempt to load a class with an unknown class name. */ public class DeploymentRequestOfUnknownClassProcessingTest extends GridCommonAbstractTest { - /** */ - private static final String TEST_TOPIC_NAME = "TEST_TOPIC_NAME"; - /** */ private static final String UNKNOWN_CLASS_NAME = "unknown.UnknownClassName"; @@ -100,7 +99,9 @@ public void testResponseReceivingOnDeploymentRequestOfUnknownClass() throws Exce remNodeLog.registerListener(remNodeLogLsnr); - locNode.context().io().addMessageListener(TEST_TOPIC_NAME, new GridMessageListener() { + GridTopic.T1 topic = TOPIC_CLASSLOAD.topic(IgniteUuid.fromUuid(locNode.localNode().id())); + + locNode.context().io().addMessageListener(topic, new GridMessageListener() { @Override public void onMessage(UUID nodeId, Object msg, byte plc) { try { assertTrue(msg instanceof GridDeploymentResponse); @@ -124,10 +125,7 @@ public void testResponseReceivingOnDeploymentRequestOfUnknownClass() throws Exce } }); - GridDeploymentRequest req = new GridDeploymentRequest(TEST_TOPIC_NAME, locDep.classLoaderId(), - UNKNOWN_CLASS_NAME, false); - - req.prepareMarshal(locNode.context().marshaller()); + GridDeploymentRequest req = new GridDeploymentRequest(topic, locDep.classLoaderId(), UNKNOWN_CLASS_NAME); locNode.context().io().sendToGridTopic(remNode.localNode(), TOPIC_CLASSLOAD, req, GridIoPolicy.P2P_POOL);