MaDKit forum

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

You are not logged in.

#2 Re: HowTo » Killing agents fail. » 2013-11-21 18:52:48

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.

#3 HowTo » Killing agents fail. » 2013-11-21 14:19:41

elnabo
Replies: 4

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;
                    }
                   
            }
    }

Board footer