Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7580907
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T18:02:24+00:00 2026-05-30T18:02:24+00:00

I have the code below: public class PatientAgent extends Agent { private final String

  • 0

I have the code below:

public class PatientAgent extends Agent {

  private final String HYPHEN = "-";

  private ArrayList<HashSet<Integer>> prefs;

  private AID provider ;

  private boolean hasAppointment;

  private int appointmentNo;

  @Override
  protected void setup() {

      hasAppointment = false;

      appointmentNo = 0; // A value of zero means agent does not have any 
                         // allocated appointments (yet)

      initPrefs(getArguments());

      System.out.println(prefs.toString());

      // Build the description used as template for the subscription
      DFAgentDescription template = new DFAgentDescription();
      ServiceDescription templateSd = new ServiceDescription();
      templateSd.setType("allocate-appointments");
      template.addServices(templateSd);


      SearchConstraints sc = new SearchConstraints();
      // We want to receive 10 results at most
      sc.setMaxResults(new Long(10));

      addBehaviour(new SubscriptionInitiator(this, DFService.createSubscriptionMessage(this, getDefaultDF(), template, sc)) {
          protected void handleInform(ACLMessage inform) {
              System.out.println("Agent "+getLocalName()+": Notification received from DF");
              try {
                  DFAgentDescription[] results = DFService.decodeNotification(inform.getContent());

                  if (results.length > 0) {

                      // Assume there is only one hospital agent
                      assert(results.length == 1);
                      DFAgentDescription dfd = results[0];


                      Iterator it = dfd.getAllServices();
                      while (it.hasNext()) {
                          ServiceDescription sd = (ServiceDescription) it.next();
                          if (sd.getType().equals("allocate-appointments")) {
                              provider = dfd.getName(); 
                              System.out.println("Allocate-appointments service found:");
                              System.out.println("- Service \""+sd.getName()+"\" provided by agent "+provider.getName());

                          }
                      }



                  }

              }
              catch (FIPAException fe) {
                  fe.printStackTrace();
              }
          }
      } );


public AID getProvider() { return provider; }

I clearly init provider with the line

   provider = dfd.getName();

However the line

       public AID getProvider() { return provider; }

returns null for it which I dont get why. Anyone has an idea about whats going on ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T18:02:25+00:00Added an answer on May 30, 2026 at 6:02 pm

    Assuming you are hitting your assignment statement, here are some things to consider:

    • Is getProvider() being called called before handleInform?

    • Are handleInform and getProvider() called on separate threads, creating a race or memory visibility issue?

    • Is the provider variable being overwritten some time between assignment in handleInform and retrieval with getProvider()?

    I can’t think of anything else. Your variable scoping looks OK. You should add a log statement to the getProvider() method to see when it’s being called with respect to handleInform, and log any other places in the program that may overwrite the variable’s value.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple code below: import java.util.ArrayList; public class BoidList extends ArrayList {
I have the code below : public class Anything { public int Data {
I have the Global.asax like the code below: public class MvcApplication : System.Web.HttpApplication {
I have a C# dll. The code is below: public class Calculate { public
I have a class ComponentItem which i simplified (pseudo code) below public class ComponentItem
I have the following question regarding the code below: public class GenericBridgeMethods <T> {
I have the code below: string SQL = select * from + TableName; using
Assuming the code below: public class DynamicAspxHandler : IHttpHandler { bool IHttpHandler.IsReusable { get
I have code below: <select id=testSelect> <option value=1>One</option> <option value=2>Two</option> </select> <asp:Button ID=btnTest runat=server
I have to code below - works great in IE and Opera, but does

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.