use of org.apache.ignite.compute.ComputeJobContext in project ignite by apache.
the class PriorityQueueCollisionSpi method getJobPriority.
/**
* Gets job priority. At first tries to get from job context. If job context has no priority,
* then tries to get from task session. If task session has no priority default one will be used.
*
* @param ctx Collision job context.
* @return Job priority.
*/
private int getJobPriority(CollisionJobContext ctx) {
assert ctx != null;
Integer p = null;
ComputeJobContext jctx = ctx.getJobContext();
try {
p = (Integer) jctx.getAttribute(jobPriAttrKey);
} catch (ClassCastException e) {
LT.error(log, e, "Type of job context priority attribute '" + jobPriAttrKey + "' is not java.lang.Integer [type=" + jctx.getAttribute(jobPriAttrKey).getClass() + ']');
}
if (p == null) {
ComputeTaskSession ses = ctx.getTaskSession();
try {
p = (Integer) ses.getAttribute(taskPriAttrKey);
} catch (ClassCastException e) {
LT.error(log, e, "Type of task session priority attribute '" + taskPriAttrKey + "' is not java.lang.Integer [type=" + ses.getAttribute(taskPriAttrKey).getClass() + ']');
}
if (p == null) {
if (log.isDebugEnabled()) {
log.debug("Failed get priority from job context attribute '" + jobPriAttrKey + "' and task session attribute '" + taskPriAttrKey + "' (will use default priority): " + dfltPri);
}
p = dfltPri;
}
}
assert p != null;
return p;
}
use of org.apache.ignite.compute.ComputeJobContext in project ignite by apache.
the class GridClosureSerializationTest method testAttributesSerializationFailure.
/**
* @throws Exception If failed.
*/
@SuppressWarnings({ "ThrowableResultOfMethodCallIgnored", "Convert2Lambda" })
public void testAttributesSerializationFailure() throws Exception {
final IgniteEx ignite0 = grid(0);
final IgniteEx ignite1 = grid(1);
GridTestUtils.assertThrows(null, new Callable<Object>() {
@JobContextResource
private ComputeJobContext jobCtx;
@Override
public Object call() throws Exception {
ignite1.compute(ignite1.cluster().forNode(ignite0.localNode())).call(new IgniteCallable<Object>() {
@Override
public Object call() throws Exception {
jobCtx.setAttribute("test-attr", new BrokenAttribute());
return null;
}
});
return null;
}
}, IgniteException.class, null);
}
use of org.apache.ignite.compute.ComputeJobContext in project ignite by apache.
the class GridTaskExecutionSelfTest method testJobIdCollision.
/**
* Test for https://issues.apache.org/jira/browse/IGNITE-1384
*
* @throws Exception If failed.
*/
public void testJobIdCollision() throws Exception {
fail("Test refactoring is needed: https://issues.apache.org/jira/browse/IGNITE-4706");
long locId = IgniteUuid.lastLocalId();
ArrayList<IgniteFuture<Object>> futs = new ArrayList<>(2016);
IgniteCompute compute = grid(1).compute(grid(1).cluster().forNodeId(grid(3).localNode().id()));
for (int i = 0; i < 1000; i++) {
futs.add(compute.callAsync(new IgniteCallable<Object>() {
@JobContextResource
ComputeJobContext ctx;
boolean held;
@Override
public Object call() throws Exception {
if (!held) {
ctx.holdcc(1000);
held = true;
}
return null;
}
}));
}
info("Finished first loop.");
AtomicLong idx = U.field(IgniteUuid.class, "cntGen");
idx.set(locId);
IgniteCompute compute1 = grid(2).compute(grid(2).cluster().forNodeId(grid(3).localNode().id()));
for (int i = 0; i < 100; i++) {
futs.add(compute1.callAsync(new IgniteCallable<Object>() {
@JobContextResource
ComputeJobContext ctx;
boolean held;
@Override
public Object call() throws Exception {
if (!held) {
ctx.holdcc(1000);
held = true;
}
return null;
}
}));
}
for (IgniteFuture<Object> fut : futs) fut.get();
}
Aggregations