/** * @param obj Object whose class to register. * @throws IgniteCheckedException If failed. */ public void registerClass(Object obj) throws IgniteCheckedException { if (obj == null) return; if (obj instanceof GridPeerDeployAware) { GridPeerDeployAware p = (GridPeerDeployAware)obj; registerClass(p.deployClass(), p.classLoader()); } else registerClass(obj instanceof Class ? (Class)obj : obj.getClass()); }
/** * Checks whether task class is annotated with {@link GridVisorManagementTask}. * * @param task Task. * @param taskCls Task class. * @return {@code True} if task is internal. */ public boolean visorManagementTask(@Nullable ComputeTask task, @NotNull Class<?> taskCls) { return annotation(task instanceof GridPeerDeployAware ? ((GridPeerDeployAware)task).deployClass() : taskCls, GridVisorManagementTask.class) != null; }
/** {@inheritDoc} */ @Override public ClassLoader classLoader() { if (pda == null) pda = U.detectPeerDeployAware(this); return pda.classLoader(); } }
/** {@inheritDoc} */ @Override public Class<?> deployClass() { if (pda == null) pda = U.detectPeerDeployAware(this); return pda.deployClass(); }
/** {@inheritDoc} */ @Override public ClassLoader classLoader() { if (pda == null) pda = U.detectPeerDeployAware(this); return pda.classLoader(); } }
/** * Check if all elements from the collection could be loaded with the same classloader as the given object. * * @param obj base object. * @param c collection to check elements from. * @return {@code true} if all elements could be loaded with {@code obj}'s classloader, {@code false} otherwise */ private static boolean hasCommonClassLoader(Object obj, Iterable<?> c) { assert obj != null; assert c != null; ClassLoader ldr = obj instanceof GridPeerDeployAware ? ((GridPeerDeployAware)obj).classLoader() : detectClassLoader(obj.getClass()); boolean found = true; for (Object obj2 : c) { if (obj2 == null || obj2 == obj) continue; // Obj2 class name. String clsName = obj2 instanceof GridPeerDeployAware ? ((GridPeerDeployAware)obj2).deployClass().getName() : obj2.getClass().getName(); if (!isLoadableBy(clsName, ldr)) { found = false; break; } } return found; }
/** {@inheritDoc} */ @Override public Class<?> deployClass() { if (pda == null) pda = U.detectPeerDeployAware(this); return pda.deployClass(); }
/** * Detects class loader for given object's class. * * @param obj Object to find class loader for class of. * @return Class loader for given object (possibly {@code null}). */ @Nullable public static ClassLoader detectObjectClassLoader(@Nullable Object obj) { if (obj == null) return null; if (obj instanceof GridPeerDeployAware) return ((GridPeerDeployAware)obj).classLoader(); return detectClassLoader(obj.getClass()); }
((GridPeerDeployAware)obj).classLoader() : obj.getClass().getClassLoader(); ((GridPeerDeployAware)obj2).deployClass().getName() : obj2.getClass().getName();
/** * Checks whether task class is annotated with {@link GridInternal}. * * @param task Task. * @param taskCls Task class. * @return {@code True} if task is internal. */ public boolean internalTask(@Nullable ComputeTask task, Class<?> taskCls) { assert taskCls != null; Boolean res = internalTasks.get(taskCls); if (res == null) { res = annotation(task instanceof GridPeerDeployAware ? ((GridPeerDeployAware)task).deployClass() : taskCls, GridInternal.class) != null; internalTasks.put(taskCls, res); } return res; }
/** {@inheritDoc} */ @Override public ClassLoader classLoader() { if (pda == null) pda = U.detectPeerDeployAware(this); return pda.classLoader(); } }
/** {@inheritDoc} */ @Override public void p2pMarshal(GridKernalContext ctx) throws IgniteCheckedException { assert ctx != null; assert ctx.config().isPeerClassLoadingEnabled(); if (topic != null) topicBytes = U.marshal(ctx.config().getMarshaller(), topic); predBytes = U.marshal(ctx.config().getMarshaller(), pred); // Deploy only listener, as it is very likely to be of some user class. GridPeerDeployAware pda = U.peerDeployAware(pred); clsName = pda.deployClass().getName(); GridDeployment dep = ctx.deploy().deploy(pda.deployClass(), pda.classLoader()); if (dep == null) throw new IgniteDeploymentCheckedException("Failed to deploy message listener."); depInfo = new GridDeploymentInfoBean(dep); depEnabled = true; }
return ((GridPeerDeployAware)obj).deployClass();
/** {@inheritDoc} */ @Override public ClassLoader classLoader() { if (pda == null) pda = U.detectPeerDeployAware(this); return pda.classLoader(); } }
/** * @throws Exception If test fails. */ @Test public void testDetectPeerDeployAwareInfiniteRecursion() throws Exception { Ignite g = startGrid(1); try { final SelfReferencedJob job = new SelfReferencedJob(g); GridPeerDeployAware d = U.detectPeerDeployAware(U.peerDeployAware(job)); assert d != null; assert SelfReferencedJob.class == d.deployClass(); assert d.classLoader() == SelfReferencedJob.class.getClassLoader(); } finally { stopGrid(1); } }
GridPeerDeployAware p = (GridPeerDeployAware)obj; if (!top && p.deployClass() != null) return p;
/** * Detects class loader for given object's class. * * @param obj Object to find class loader for class of. * @return Class loader for given object (possibly {@code null}). */ @Nullable public static ClassLoader detectObjectClassLoader(@Nullable Object obj) { if (obj == null) return null; if (obj instanceof GridPeerDeployAware) return ((GridPeerDeployAware)obj).classLoader(); return detectClassLoader(obj.getClass()); }
taskClsName = ((GridPeerDeployAware)task).deployClass().getName(); else taskClsName = task.getClass().getName(); GridPeerDeployAware depAware = (GridPeerDeployAware)task; cls = depAware.deployClass(); ldr = depAware.classLoader();
/** {@inheritDoc} */ @Override public Class<?> deployClass() { if (pda == null) pda = U.detectPeerDeployAware(this); return pda.deployClass(); }
/** * @param obj Object whose class to register. * @throws IgniteCheckedException If failed. */ public void registerClass(Object obj) throws IgniteCheckedException { if (obj == null) return; if (obj instanceof GridPeerDeployAware) { GridPeerDeployAware p = (GridPeerDeployAware)obj; registerClass(p.deployClass(), p.classLoader()); } else registerClass(obj instanceof Class ? (Class)obj : obj.getClass()); }