Adding a behavior outside of the setup()

View: New views
2 Messages — Rating Filter:   Alert me  

Adding a behavior outside of the setup()

by Hutchinson, Matt :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,
 
I read in the documentation that it is possible to use the .addBehavior() method outside of the agent's setup() method. I have a valid agent object, but when I try to add a behavior it just does nothing: no exceptions or errors, but also no result.
 
If I'm adding the behavior outside of an agent's setup() method, do I have to use another command to "pull the trigger" so to speak and actually make the behavior run?
 
Not only is behavior being added from outside the setup() method, but it is being added from another class.
 
 
 
So inside my TestBehavior.java file is:
 

import jade.core.behaviours.OneShotBehaviour;

import java.sql.*;

public class TestBehavior extends OneShotBehaviour

{

public void action()

{

System.out.println("Executing the test behavior in thread: " + Thread.currentThread().getId() );

}

}

 

 

And then snippets from the calling java class:

private ThreadedBehaviourFactory tbf = new ThreadedBehaviourFactory();

TestBehavior testb = new TestBehavior();

System.out.println("the agent ID inside BrokerAgentTask: " + agent_obj.getAID().getName() );

agent_obj.addBehaviour(tbf.wrap(testb) );

 

 

The agent_obj is my own agent class which extends Agent.

 

 

Thanks,

Matt

 


_______________________________________________
jade-develop mailing list
jade-develop@...
https://avalon.cselt.it/mailman/listinfo/jade-develop
UNSUBSCRIBE INSTRUCTIONS AT
http://jade.tilab.com/community-mailinglist.htm

RE: Adding a behavior outside of the setup()

by Caire Giovanni-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.

Hi,

 

Of course your agent must be alive. For instance if you do

 

Agent a = new MyAgentClass();

Behaviour b = new MyBehaviourClass();

a.addBehaviour(b);

 

Nothing will happen. Agents must be alive to execute tasks i.e. they must be started by a container.

 

Bye,

 

Giovanni

 


From: jade-develop-bounces@... [mailto:jade-develop-bounces@...] On Behalf Of Hutchinson, Matt
Sent: giovedì 17 luglio 2008 22.49
To: jade-develop@...
Subject: [jade-develop] Adding a behavior outside of the setup()

 

Hi,

 

I read in the documentation that it is possible to use the .addBehavior() method outside of the agent's setup() method. I have a valid agent object, but when I try to add a behavior it just does nothing: no exceptions or errors, but also no result.

 

If I'm adding the behavior outside of an agent's setup() method, do I have to use another command to "pull the trigger" so to speak and actually make the behavior run?

 

Not only is behavior being added from outside the setup() method, but it is being added from another class.

 

 

 

So inside my TestBehavior.java file is:

 

import jade.core.behaviours.OneShotBehaviour;

import java.sql.*;

public class TestBehavior extends OneShotBehaviour

{

public void action()

{

System.out.println("Executing the test behavior in thread: " + Thread.currentThread().getId() );

}

}

 

 

And then snippets from the calling java class:

private ThreadedBehaviourFactory tbf = new ThreadedBehaviourFactory();

TestBehavior testb = new TestBehavior();

System.out.println("the agent ID inside BrokerAgentTask: " + agent_obj.getAID().getName() );

agent_obj.addBehaviour(tbf.wrap(testb) );

 

 

The agent_obj is my own agent class which extends Agent.

 

 

Thanks,

Matt

 


_______________________________________________
jade-develop mailing list
jade-develop@...
https://avalon.cselt.it/mailman/listinfo/jade-develop
UNSUBSCRIBE INSTRUCTIONS AT
http://jade.tilab.com/community-mailinglist.htm
LightInTheBox - Buy quality products at wholesale price