Exemplo n.º 1
0
            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);
                }
            }
Exemplo n.º 2
0
        public void AddPendingIntention(string id, Intention i)
        {
            if (i.IsAtomic())
            {
                SetAtomicIntention(i);
                atomicIntSuspended = true;
            }
            PI.Add(id, i);
            i.SetSuspendedReason(id);

            if (listeners != null)
            {
                foreach (ICircumstanceListener el in listeners)
                {
                    el.IntentionSuspended(i, id);
                }
            }
        }
Exemplo n.º 3
0
        public void AddRunningIntention(Intention i)
        {
            if (i.IsAtomic())
            {
                SetAtomicIntention(i);
            }
            else
            {
                I.Add(i);
            }

            // Notify
            if (listeners != null)
            {
                foreach (ICircumstanceListener el in listeners)
                {
                    el.IntentionAdded(i);
                }
            }
        }