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


##########
modules/core/src/main/java/org/apache/ignite/internal/managers/deployment/GridDeploymentManager.java:
##########
@@ -402,6 +404,76 @@ private GridDeployment checkDeployment(GridDeployment 
deployment, String store)
         return locStore.getDeployment(meta);
     }
 
+    /**
+     * Resolves the class loader the classes of a message must be read with. 
Blocks when the deployment has to be
+     * requested from its owner, so it must not be called from a 
socket-reading thread.
+     *
+     * @param msg Message carrying its own deployment.
+     * @return Class loader of the carried deployment, or the local one if the 
message carries none.
+     * @throws IgniteDeploymentCheckedException If the deployment cannot be 
obtained.
+     */
+    public ClassLoader classLoader(DeploymentAware msg) throws 
IgniteDeploymentCheckedException {
+        return classLoader(msg.deploymentInfo(), msg.deployedClassName());
+    }
+
+    /**
+     * Resolves the class loader classes described by {@code depInfo} must be 
read with. Blocks when the deployment has
+     * to be requested from its owner, so it must not be called from a 
socket-reading thread.
+     *
+     * @param depInfo Deployment of the classes, or {@code null} when they 
carry none.
+     * @param clsName Name of a class the deployment must be able to load.
+     * @return Class loader of the deployment, or the local one when there is 
no deployment.
+     * @throws IgniteDeploymentCheckedException If the deployment cannot be 
obtained.
+     */
+    public ClassLoader classLoader(@Nullable GridDeploymentInfo depInfo, 
String clsName)
+        throws IgniteDeploymentCheckedException {
+        if (depInfo == null)
+            return U.resolveClassLoader(ctx.config());
+
+        return U.resolveClassLoader(globalDeployment(depInfo, 
clsName).classLoader(), ctx.config());
+    }
+
+    /**
+     * Resolves the deployment {@code depInfo} describes, for the classes of 
{@code clsName}. The sender of those
+     * classes is the node that created the class loader, or a participant 
when the deployment has any.
+     *
+     * @param depInfo Deployment of the classes, as it came with the message 
carrying them.
+     * @param clsName Name of a class the deployment must be able to load.
+     * @return The deployment the classes are loaded with.
+     * @throws IgniteDeploymentCheckedException If the deployment is gone or 
peer class loading is off.
+     */
+    public GridDeployment globalDeployment(GridDeploymentInfo depInfo, String 
clsName)
+        throws IgniteDeploymentCheckedException {
+        GridDeployment dep = globalDeployment(depInfo, clsName, clsName);
+
+        if (dep == null) {
+            throw new IgniteDeploymentCheckedException("Failed to obtain 
deployment for class (is peer class " +
+                "loading turned on?): " + clsName);
+        }
+
+        return dep;
+    }
+
+    /**
+     * Resolves the deployment {@code depInfo} describes, as {@link 
#globalDeployment(GridDeploymentInfo, String)}
+     * does, but under {@code rsrcName} (a task may be deployed under a name 
of its own) and returns {@code null}
+     * instead of throwing, for callers that have somewhere else to look.
+     *
+     * @param depInfo Deployment of the classes, as it came with the message 
carrying them.
+     * @param rsrcName Name the classes are deployed under.
+     * @param clsName Name of a class the deployment must be able to load.
+     * @return The deployment, or {@code null} when there is none.
+     */
+    @Nullable public GridDeployment globalDeployment(GridDeploymentInfo 
depInfo, String rsrcName, String clsName) {
+        return getGlobalDeployment(depInfo.deployMode(),
+            rsrcName,
+            clsName,
+            depInfo.userVersion(),

Review Comment:
   Is `depInfo` guaranteed to be non-null here? In some places it seems that it 
can be null, for example in 
`org.apache.ignite.internal.managers.communication.GridIoUserMessage#deploymentInfo`.



-- 
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