if (task_api == null)
task_api = cntx.ta.getClass().getCanonicalName();
} catch (CalculateException e1) {
throw new SysException(e1);
}
ITaskAPI ta = ATaskAPI.getInstance(task_api, cntx.ta.getClass(), alias);
if (ta == null)
ta = cntx.ta;
long id_task;
Context parent_context = cntx.parent;
Long id_processor;
if (!ta.equals(cntx.ta)) {
id_processor = ATaskAPI.getApplicationSubject(ta);
if (id_processor == 0L) {
boolean waiting = true;
do {
try {
id_processor = ta.getSubject(0);
waiting = false;
} catch (SysException e) {
System.out.println("Waiting interface...");
try {
Thread.sleep(1000);// TODO нужен параметр
} catch (InterruptedException e1) {
throw new SysException(e1);
}
}
} while (waiting);
ATaskAPI.setApplicationSubject(ta, id_processor);
}
} else
id_processor = cntx.id_subject;
try {
// Получить класс задания
String cls = (String) classname.getValue(cntx);
// Если класс задания не определен,
if (Null.equ(cls) || cls.equals("")) {
cntx.id_task = -1;
return cntx;
}
// Создадим запись о задании
id_task = ta
.createTask(
id_processor,
cls,
(ta.equals(cntx.ta) && parent_context != null) ? parent_context.id_task
: 0);
} catch (CalculateException e) {
throw new SysException(e);
}
Context res;
if (ta.equals(cntx.ta)) {
res = cntx;
res.id_task = id_task;
} else
res = new Context(parent_context, id_processor, id_task, ta, this);
Set<Entry<String, Object>> s = prms.entrySet();
for (Entry<String, Object> x : s)
try {
Object v = x.getValue();
if (Null.equ(v))
continue;
String name = x.getKey();
if (v instanceof IDependentParam) {
IDependentParam d = (IDependentParam) v;
if (!d.isNoSave()) {
TimeList tl = cntx.getTimeList(d.getGLName(), d);
Object vl = d.getValue(cntx);
if (Null.equ(vl))
continue;
long wait = tl.getWaitTime();
long calc = tl.getWorkTime();
long sc = tl.getSystemCallTime();
// ta.setTaskParamObject(id_task, x.getKey(),
// d.getValue(cntx));
ta.setParamObject(id_task, name, vl, wait, calc, sc);
}
} else {
// ta.setTaskParamString(id_task, x.getKey(), v.toString());
ta.setParamObject(id_task, name, v);
}
} catch (CalculateException e) {
throw new SysException(e);
}
// Установить доп. параметры в задании
if (!Null.equ(addprms))
if (addprms instanceof Map) {
Map<String, Object> aprms = (Map<String, Object>) addprms;
for (Entry<String, Object> e : aprms.entrySet()) {
String n = (grp == null) ? e.getKey() : grp + "/"
+ e.getKey();
// ta.setTaskParamObject(id_task, n, e.getValue());
ta.setParamObject(id_task, n, e.getValue());
}
} else if (addprms instanceof PrmInterface) {
PrmInterface aprms = (PrmInterface) addprms;
for (String k : aprms.getFieldNames()) {
String n = (grp == null) ? k : grp + "/" + k;
// ta.setTaskParamString(id_task, n, aprms.getField(k));
ta.setParamObject(id_task, n, aprms.getField(k));
}
} else if (addprms instanceof ByteMsg) {
ByteMsg msg = (ByteMsg) addprms;
PrmInterface aprms = msg.getPrmInterface();
for (String k : aprms.getFieldNames()) {
String n = (grp == null) ? k : grp + "/" + k;
// ta.setTaskParamString(id_task, n, aprms.getField(k));
ta.setParamObject(id_task, n, aprms.getField(k));
}
}
try {
String finish_duration = Strings
.getString((this.finish_duration != null) ? this.finish_duration
.getValue(cntx) : null);
String block_duration = Strings
.getString((this.block_duration != null) ? this.block_duration
.getValue(cntx) : null);
Double arch_day = Strings
.parseDouble((this.arch_day != null) ? this.arch_day
.getValue(cntx) : null);
ta.setTaskDT(id_task, null, finish_duration, block_duration,
arch_day);
// Будет обрабатывать текущий обработчик?
if (this.processor_id != null)
res.id_task = ta.setReady(id_processor, id_task,
Strings.parseLong(processor_id.getValue(cntx)));
else
res.id_task = ta.setReady(id_processor, id_task, null);
return res;
} catch (CalculateException e) {
throw new SysException(e);
}
}