<commit_before>/*
  $Log$
  Revision 1.13  1998/10/11 19:32:30  rimassa
  In method bornAgent() a sensible strategy has been implemented to
  recover from agent name collisions. When a new agent has a name
  already present in Global Agent Table, a name clash exception is
  raised, unless the old agent's container crashed, in which case the
  newer agent simply replaces the older one.
  Now lookup() method is able to distinguish between an unknown agent
  and an agent whose container has crashed, writing a suitable error
  message in the NotFoundException it raises.
  Fixed a missing toLowerCase().

  Revision 1.12  1998/10/07 22:16:21  Giovanni
  Changed code in various places to make agent descriptor tables
  case-insensitive. Now upper or lower case in agent names and addresses
  make no more difference; this is to comply with FIPA specification.

  Revision 1.11  1998/10/04 18:01:01  rimassa
  Added a 'Log:' field to every source file.

*/

package jade.core;

import java.io.BufferedWriter;
import java.io.OutputStreamWriter;

import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Vector;

import java.rmi.*;
import java.rmi.server.UnicastRemoteObject;

import jade.domain.ams;
import jade.domain.acc;
import jade.domain.df;
import jade.domain.AgentManagementOntology;

import jade.domain.FIPAException;
import jade.domain.AgentAlreadyRegisteredException;

public class AgentPlatformImpl extends AgentContainerImpl implements AgentPlatform {

  // Initial size of agent hash table
  private static final int GLOBALMAP_SIZE = 100;

  // Load factor of agent hash table
  private static final float GLOBALMAP_LOAD_FACTOR = 0.25f;

  private ams theAMS;
  private acc theACC;
  private df defaultDF;

  private Vector containers = new Vector();
  private Hashtable platformAgents = new Hashtable(GLOBALMAP_SIZE, GLOBALMAP_LOAD_FACTOR);

  private void initAMS() {

    System.out.print("Starting AMS... ");
    theAMS = new ams(this, "ams");

    // Subscribe as a listener for the AMS agent
    theAMS.addCommListener(this);

    // Insert AMS into local agents table
    localAgents.put("ams", theAMS);

    AgentDescriptor desc = new AgentDescriptor();
    desc.setDemux(myDispatcher);

    platformAgents.put("ams", desc);
    System.out.println("AMS OK");
  }

  private void initACC() {
    System.out.print("Starting ACC... ");
    theACC = new acc(this);

    // Subscribe as a listener for the AMS agent
    theACC.addCommListener(this);

    // Insert AMS into local agents table
    localAgents.put("acc", theACC);

    AgentDescriptor desc = new AgentDescriptor();
    desc.setDemux(myDispatcher);

    platformAgents.put("acc", desc);

    System.out.println("ACC OK");
  }

  private void initDF() {
    System.out.print("Starting Default DF... ");
    defaultDF = new df();

    // Subscribe as a listener for the AMS agent
    defaultDF.addCommListener(this);

    // Insert DF into local agents table
    localAgents.put("df", defaultDF);

    AgentDescriptor desc = new AgentDescriptor();
    desc.setDemux(myDispatcher);

    platformAgents.put("df", desc);
    System.out.println("DF OK");

  }

  public AgentPlatformImpl() throws RemoteException {
    initAMS();
    initACC();
    initDF();
  }

  public void addContainer(AgentContainer ac) throws RemoteException {
    containers.addElement(ac);
  }

  public void removeContainer(AgentContainer ac) throws RemoteException {
    containers.removeElement(ac);
  }

  public void bornAgent(String name, AgentDescriptor desc) throws RemoteException, NameClashException {
    System.out.println("Born agent " + name);
    Object old = platformAgents.put(name.toLowerCase(), desc);

    // If there's already an agent with name 'name' throw a name clash
    // exception unless the old agent's container is dead.
    if(old != null) {
      AgentDescriptor ad = (AgentDescriptor)old;
      MessageDispatcher md = ad.getDemux();
      try {
	md.ping(); // Make sure container is alive, then raise a name clash exception
	throw new NameClashException("Agent " + name + " already present in the platform ");
      }
      catch(RemoteException re) {
	System.out.println("Replacing a dead agent ...");
      }
    }
  }

  public void deadAgent(String name) throws RemoteException {
    System.out.println("Dead agent " + name);<commit_msg>Added a line to restore platform state when a new agent has a name clashing with a previous agent's name.<commit_after>/*
  $Log$
  Revision 1.14  1998/10/14 21:24:11  Giovanni
  Added a line to restore platform state when a new agent has a name
  clashing with a previous agent's name.

  Revision 1.13  1998/10/11 19:32:30  rimassa
  In method bornAgent() a sensible strategy has been implemented to
  recover from agent name collisions. When a new agent has a name
  already present in Global Agent Table, a name clash exception is
  raised, unless the old agent's container crashed, in which case the
  newer agent simply replaces the older one.
  Now lookup() method is able to distinguish between an unknown agent
  and an agent whose container has crashed, writing a suitable error
  message in the NotFoundException it raises.
  Fixed a missing toLowerCase().

  Revision 1.12  1998/10/07 22:16:21  Giovanni
  Changed code in various places to make agent descriptor tables
  case-insensitive. Now upper or lower case in agent names and addresses
  make no more difference; this is to comply with FIPA specification.

  Revision 1.11  1998/10/04 18:01:01  rimassa
  Added a 'Log:' field to every source file.

*/

package jade.core;

import java.io.BufferedWriter;
import java.io.OutputStreamWriter;

import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Vector;

import java.rmi.*;
import java.rmi.server.UnicastRemoteObject;

import jade.domain.ams;
import jade.domain.acc;
import jade.domain.df;
import jade.domain.AgentManagementOntology;

import jade.domain.FIPAException;
import jade.domain.AgentAlreadyRegisteredException;

public class AgentPlatformImpl extends AgentContainerImpl implements AgentPlatform {

  // Initial size of agent hash table
  private static final int GLOBALMAP_SIZE = 100;

  // Load factor of agent hash table
  private static final float GLOBALMAP_LOAD_FACTOR = 0.25f;

  private ams theAMS;
  private acc theACC;
  private df defaultDF;

  private Vector containers = new Vector();
  private Hashtable platformAgents = new Hashtable(GLOBALMAP_SIZE, GLOBALMAP_LOAD_FACTOR);

  private void initAMS() {

    System.out.print("Starting AMS... ");
    theAMS = new ams(this, "ams");

    // Subscribe as a listener for the AMS agent
    theAMS.addCommListener(this);

    // Insert AMS into local agents table
    localAgents.put("ams", theAMS);

    AgentDescriptor desc = new AgentDescriptor();
    desc.setDemux(myDispatcher);

    platformAgents.put("ams", desc);
    System.out.println("AMS OK");
  }

  private void initACC() {
    System.out.print("Starting ACC... ");
    theACC = new acc(this);

    // Subscribe as a listener for the AMS agent
    theACC.addCommListener(this);

    // Insert AMS into local agents table
    localAgents.put("acc", theACC);

    AgentDescriptor desc = new AgentDescriptor();
    desc.setDemux(myDispatcher);

    platformAgents.put("acc", desc);

    System.out.println("ACC OK");
  }

  private void initDF() {
    System.out.print("Starting Default DF... ");
    defaultDF = new df();

    // Subscribe as a listener for the AMS agent
    defaultDF.addCommListener(this);

    // Insert DF into local agents table
    localAgents.put("df", defaultDF);

    AgentDescriptor desc = new AgentDescriptor();
    desc.setDemux(myDispatcher);

    platformAgents.put("df", desc);
    System.out.println("DF OK");

  }

  public AgentPlatformImpl() throws RemoteException {
    initAMS();
    initACC();
    initDF();
  }

  public void addContainer(AgentContainer ac) throws RemoteException {
    containers.addElement(ac);
  }

  public void removeContainer(AgentContainer ac) throws RemoteException {
    containers.removeElement(ac);
  }

  public void bornAgent(String name, AgentDescriptor desc) throws RemoteException, NameClashException {
    System.out.println("Born agent " + name);
    Object old = platformAgents.put(name.toLowerCase(), desc);

    // If there's already an agent with name 'name' throw a name clash
    // exception unless the old agent's container is dead.
    if(old != null) {
      AgentDescriptor ad = (AgentDescriptor)old;
      MessageDispatcher md = ad.getDemux();
      try {
	md.ping(); // Make sure container is alive, then raise a name clash exception
	platformAgents.put(name.toLowerCase(), ad);
	throw new NameClashException("Agent " + name + " already present in the platform ");
      }
      catch(RemoteException re) {
	System.out.println("Replacing a dead agent ...");
      }
    }
  }

  public void deadAgent(String name) throws RemoteException {
    System.out.println("Dead agent " + name);
{'fraction_non_alphanumeric': 0.09074713283598708, 'fraction_numerical': 0.014586348958913262, 'mean_word_length': 3.634674922600619, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '393347', 'n_tokens_mistral': 2726, 'n_tokens_neox': 2524, 'n_words': 895}