MaDKit forum

Welcome All !
Please, use explicit topic names when creating new threads. Thanks.

You are not logged in.

#1 2013-11-21 14:19:41

elnabo
Member
Registered: 2013-11-21
Posts: 3

Killing agents fail.

Hi,

I'm trying to reduce the number of agent on my MadKit applications.

When my launcher recieve a message, he update the number of living agents.
When he tries to delete some agents I got this error message

[MadkitKernel-0] SEVERE : ********************** KERNEL PROBLEM, please bug report Kill failed: Robot-5 (ACTIVATED)
** java.util.concurrent.ExecutionException: java.lang.NullPointerException
at madkit.kernel.MadkitKernel.killAgent(Unknown Source)
at Lanceur.delAgent(Lanceur.java:49)
at Lanceur.live(Lanceur.java:91)
Caused by: java.lang.NullPointerException
at madkit.kernel.MadkitKernel.killThreadedAgent(Unknown Source)
at madkit.kernel.MadkitKernel.killingAgent(Unknown Source)
at madkit.kernel.MadkitKernel.access$500(Unknown Source)
at madkit.kernel.MadkitKernel$13.call(Unknown Source)
at madkit.kernel.MadkitKernel$13.call(Unknown Source)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)

I'm not able to see what can cause this error. Especially since the delete part (which cause the bug) is a copy of the one in the Bee example.

Any idea of what can cause that ?


Portion of the code used

    private ArrayList<AbstractAgent> robotsList = new ArrayList<>(5);	

    @Override
    protected void live()
    {
            while (true)
            {
                    if(! isMessageBoxEmpty() )
                    {
                            Message m = purgeMailbox();
                            @SuppressWarnings("unchecked")
                            Integer nbAgentWanted = ((ObjectMessage<Integer>)m).getContent();
                           
                            int diff = nbAgentWanted - numberOfAgent;
                            if (diff > 0)
                            {
                                    addAgent(diff);
                            }                              
                            else if (diff < 0)
                            {
                                    delAgent(-1*diff);
                            }
                            numberOfAgent = nbAgentWanted;
                    }
            }
    }
     
    synchronized private void delAgent(int nb)
    {
            int j = 0;
            for(final Iterator<AbstractAgent> i = robotsList.iterator();i.hasNext() && j < nb;j++)
            {
                    if (j % 100 == 0) {
                            Thread.yield();
                    }
                   
                    final AbstractAgent a = i.next();
                    if(a != null)
                    {
                            i.remove();
                            killAgent(a,0);
                    }
                    else
                    {
                            break;
                    }
                   
            }
    }

Last edited by elnabo (2013-11-21 14:20:07)

Offline

#2 2013-11-21 15:37:09

fmichel
Administrator
From: Montpellier
Registered: 2009-03-24
Posts: 176
Website

Re: Killing agents fail.

Hi,

Hard to say something now. Could you please send me a zip of your project so that I can check it ?

Offline

#3 2013-11-21 18:52:48

elnabo
Member
Registered: 2013-11-21
Posts: 3

Re: Killing agents fail.

You can get a small version of it here

https://www.dropbox.com/s/13964p07fve5i … illing.zip

The bugged part is the deletion of agent with the slider.

Thanks for your time.

Last edited by elnabo (2013-11-21 19:25:11)

Offline

#4 2013-11-22 15:30:40

fmichel
Administrator
From: Montpellier
Registered: 2009-03-24
Posts: 176
Website

Re: Killing agents fail.

Hi,

Just make the Robot class inherit from the AbstractAgent class and your issue will be solved : public class Robot extends AbstractAgent.
In fact the bucket launch is supposed to be used for launching a lot of agents, and thus they were supposed to be AbstractAgent (not threaded), "simulation mode agent".
This is unchecked for now so that your launched threaded agents were not initialized correctly, making the kill failed.
I am working on a fix.

Offline

#5 2013-11-22 18:15:07

elnabo
Member
Registered: 2013-11-21
Posts: 3

Re: Killing agents fail.

Thanks a lot for that.

Offline

Board footer