public void Run() { try { // add SI again in C.I if (1) it was not removed (2) is is not running (by some other reason) -- but this test does not apply to atomic intentions --, and (3) this wait was not dropped if (c.RemovePendingIntention(sEvt) == si && (si.IsAtomic() || !c.HasRunningIntention(si)) && !dropped) { if (stopByTimeout && (te != null || formula != null) && elapsedTimeTerm == null) { // fail the .wait by timeout if (si.IsSuspended()) { // if the intention was suspended by .suspend IPlanBody body = si.Peek().GetPlan().GetBody(); body.Add(1, new PlanBodyImpl(BodyType.Body_Type.internalAction, new InternalActionLiteral(".fail"))); c.AddPendingIntention(SuspendStdLib.SUSPENDED_INT + si.GetID(), si); } else { rs.GenerateDesireDeletion(si, (List <ITerm>)JasonityException.CreateBasicErrorAnnots("wait_timeout", "timeout in .wait")); } } else if (!si.IsFinished()) { si.Peek().RemoveCurrentStep(); if (elapsedTimeTerm != null) { long elapsedTime = DateTime.Now.Millisecond - startTime; //long elapsedTime = System.currentTimeMillis() - startTime; un.Unifies(elapsedTimeTerm, new NumberTermImpl(elapsedTime)); } if (si.IsSuspended()) { // if the intention was suspended by .suspend c.AddPendingIntention(SuspendStdLib.SUSPENDED_INT + si.GetID(), si); } else { c.ResumeIntention(si); } } } } catch (Exception e) { //rs.getLogger().log(Level.SEVERE, "Error at .wait thread", e); } }