Package center.task.api

Examples of center.task.api.ITaskAPI


      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);
    }
  }
View Full Code Here


  private Map<String, ITaskAPI> api = new HashMap<String, ITaskAPI>();

  private ITaskAPI register(String alias, String cls_native,
      String alias_native) throws SysException {
    synchronized (api) {
      ITaskAPI ta = api.get(alias);
      if (ta == null) {
        ta = ATaskAPI.getInstance(cls_native, center.task.api.mem.TaskAPI.class,
              alias_native);
        if (ta == null)
          return null;
View Full Code Here

        alias = e.getAttribute("alias");
        cls_native = e.getAttribute("cls_native");
        alias_native = e.getAttribute("alias_native");
        System.out.print("Registering of TaskAPI (alias = "
            + alias + ", cls_native = " + cls_native + ", alias_native = " + alias_native + ") ... ");
        ITaskAPI ta = register(alias
            , cls_native
            , alias_native);
        System.out.print((ta == null) ? "ERROR" : "OK");
      }
     
View Full Code Here

  }

  public Object calculate(TimeList tl, Context cntxthrows CalculateException {
    try {
      tl.addPointTime(TimeList.Type.START);
      ITaskAPI ta = cntx.ta;
      Long tid = null;
      tl.addPointTime(TimeList.Type.WAIT);
      if (id != null)
        if (id instanceof Prm)
          tid = Long.getLong(((Prm) id).getString(cntx));
        else
          tid = Long.getLong(Strings.getString(id));
      if (tid == null)
        tid = cntx.id_task;
      String nm = Strings.getString(name);
      tl.addPointTime(TimeList.Type.END_WAIT);
      if ("id".equalsIgnoreCase(nm))// Если идентификатор задачи, то к сервису не обращаемся
        return tid;
      if (tid == cntx.id_task)
        try {
          return cntx.getPrm("tsk", nm, 0);
        } catch (CalculateException e) {
          throw e;
        } catch (Throwable e) {
          throw new CalculateException(owner, e);
        }
      return ta.getParamTask(tid, nm);
    } catch (SysException e) {
      throw new CalculateException(owner, e);
    } finally {
      tl.addPointTime(TimeList.Type.END);
    }
View Full Code Here

    }
  }

  private void sendLog(State st) throws SysException {
    TaskInfo info = (TaskInfo) getTaskInfo();
    ITaskAPI ta = getTaskAPI();
    long id_task = getTaskID();
    if (info != null && info.mails != null) {
      TaskInfo.MailInfo mi = (TaskInfo.MailInfo) info.mails.get(st.name());
      if (mi != null) {
        File x;
        try {
          x = Process.getTempFile();
        } catch (IOException e) {
          throw new SysException(e);
        }
        try {

          MailSender ms = new MailSender();
          ms.setInitProperty("mail.smtp.host", mi.smtphost);
          ms.setInitProperty("mail.smtp.port", mi.smtpport);
          ms.setInitProperty("mail.smtp.user", mi.smtpuser);
          ms.setInitProperty("mail.smtp.pwd", mi.smtppwd);
          ms.init();

          ta.writeLogToFile(id_task, x, "UTF-8");

          if (mi.to != null)
            ms.setStepProperty("recipient", mi.to);
          if (mi.bcc != null)
            ms.setStepProperty("h_recipient", mi.bcc);
View Full Code Here

  public final void processing(Object p) throws Throwable {
    if (ai == null)
      ai = ApplicationManager.getCurrentAppInfo();
    Process.currentProcess().getTempInterface()
        .setTmpDir(ai.getTmpDir(), ai.isTmpDeleteOnExit());
    ITaskAPI ta = cntx.ta;
    long id_task = cntx.id_task;
    try {
      if (ta.setProcessing(id_processor, id_task) == id_task) {
        ta.log(id_processor, id_task, "Processing...");
        try {
          cntx.info.calculate(
              TimeState.getInstance(TimeState.Time.before, State.PROCESSING),
              cntx);
          saveParams(Saved.TIME.before);
        } catch (Throwable e) {
          e.printStackTrace();
        }
        State st;
        try {
          st = process(cntx);
          cntx.info.calculate(
              TimeState.getInstance(TimeState.Time.after, State.PROCESSING),
              cntx);
        } catch (Throwable e) {
          e.printStackTrace();
          throw e;
        }
        ta.log(id_processor, id_task,
            "The task was completed with " + st.name() + " status");
        saveParams(Saved.TIME.after);
        ta.setState(id_processor, id_task, st, null);
      } else {
        ta.setTaskError(cntx.id_task, new SysException(
            "It is impossible processing"));
        saveParams(Saved.TIME.after);
        ta.setCanceled(id_processor, id_task);
      }
    } catch (RuntimeException ex) {
      ex.printStackTrace();
      try {
        State st = State.DONE_ERR;
        ta.log(id_processor, id_task, ex.toString());
        ta.log(id_processor, id_task,
            "The task was completed with " + st.name() + " status");
        ta.setTaskError(id_task, ex);
        saveParams(Saved.TIME.after);
        ta.setDoneErr(id_processor, id_task);
      } catch (SysException ex1) {
        try {
          ta.log(id_processor, id_task, ex1.toString());
        } catch (SysException ex3) {
          System.out.println(ex1);
        }
        try {
          ta.setTaskError(cntx.id_task, ex1);
        } catch (SysException ex3) {
          System.out.println(ex1);
        }
      }
    } catch (SysException ex) {
      ex.printStackTrace();
      try {
        State st = State.DONE_ERR;
        ta.log(id_processor, id_task, ex.toString());
        ta.log(id_processor, id_task,
            "The task was completed with " + st.name() + " status");
        ta.setTaskError(id_task, ex);
        saveParams(Saved.TIME.after);
        ta.setDoneErr(id_processor, id_task);
      } catch (SysException ex1) {
        try {
          ta.log(id_processor, id_task, ex1.toString());
        } catch (SysException ex3) {
          System.out.println(ex1);
        }
      }
    } catch (TaskException ex) {
      State st = ex.getState();
      try {
        ta.log(id_processor, id_task, ex.toString());
        ta.log(id_processor, id_task,
            "The task was completed with " + st.name() + " status");
        ta.setTaskError(id_task, ex);
      } catch (SysException ex1) {
        try {
          ta.log(id_processor, id_task, ex1.toString());
        } catch (SysException ex3) {
          System.out.println(ex1);
        }
        try {
          ta.setTaskError(id_task, ex1);
        } catch (SysException ex3) {
          System.out.println(ex1);
        }
      }
      try {
        saveParams(Saved.TIME.after);
        ta.setState(id_processor, id_task, st, null);
      } catch (SysException e) {
        e.printStackTrace(); // To change body of catch statement use File |
        // Settings | File Templates.
        try {
          ta.setTaskError(id_task, e);
        } catch (SysException ex3) {
          System.out.println(ex3);
        }
      }
    } catch (Exception ex) {
      ex.printStackTrace(); // !!!
    }

    try {
      State st = null;
      try {
        st = ta.getState(id_task);
        sendLog(st);
      } catch (SysException ex) {
        try {
          ta.log(id_processor, id_task, ex.toString());
        } catch (SysException ex2) {
          System.out.println(ex);
        }
      }
      /*
 
View Full Code Here

  }

  public final void save(Context cntx) throws SysException {
    if (gl_name.indexOf("prm.") != 0)
      return;
    ITaskAPI ta = cntx.ta;
    long id_task = cntx.id_task;
    Object val = cntx.getPrmByFullName(fullname);
    if (val != null) {
      if (val instanceof Prm) {
        Prm p = (Prm)val;
        try {
          val = p.getObject(cntx);
        } catch (CalculateException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
      } else if (val instanceof WaitValue) {
        WaitValue p = (WaitValue)val;
        try {
          val = p.getValueWait();
        } catch (Throwable e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
      }
    }
    TimeList tl = cntx.getTimeList(gl_name, this);
    long w = tl.getWaitTime();
    long c = tl.getWorkTime();
    long sc = tl.getSystemCallTime();
    ta.setParamObject(id_task, fullname, val, w, c, sc);
  }
View Full Code Here

    ai = prms;
    Manager.setContainer(ai.getContainer());
    Element el = ai.getDocInfo();
    loadFromXML(null, el);

    ITaskAPI ta = TaskAPI.getInstance(dbAlias);
    id_processor = ta.getSubject(0);
    child.createAndReadyTask(ta, null, id_processor, null, null);
  }
View Full Code Here

      return FactoryMsgProcessed.this;
    }

    public void processing(ByteMsg prms) throws Throwable {
      getContext().log(false, "Start processing message ", prms.getKey());
      ITaskAPI ta = getTaskAPI();
      long id_processor = getProcessorID();
      Context child;
      Context cntx = getContext();
      Process cp = Process.currentProcess();
      try {
View Full Code Here

  private static Map<String, ITaskAPI> helpers = new TreeMap<String, ITaskAPI>();

  public static ITaskAPI getInstance(String alias) throws SysException {
    synchronized (helpers) {
      ITaskAPI obj = helpers.get(alias);
      if (obj != null) {
        return obj;
      } else {
        TaskAPI o = new TaskAPI(alias);
        helpers.put(alias, o);
View Full Code Here

TOP

Related Classes of center.task.api.ITaskAPI

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.