Class: ParticipantRegistry

composer-runtime. ParticipantRegistry

An participant registry manages a set of participants.


new ParticipantRegistry()

Do not attempt to create an instance of this class.

You must use the getParticipantRegistry
method instead.

Source:

Methods


add(participant)

Add the specified participant to this participant registry.

Parameters:
Name Type Description
participant Resource

The participants to add to this participant registry.

Source:
Returns:

A promise. The promise is resolved when the participant has
been added to this participant registry. If the participant cannot be added to this
participant registry, or if the participant already exists in the participant registry,
then the promise will be rejected with an error that describes the problem.

Type
Promise
Example
// Get the driver participant registry.
return getParticipantRegistry('org.acme.Driver')
  .then(function (driverParticipantRegistry) {
    // Get the factory for creating new participant instances.
    var factory = getFactory();
    // Create the driver.
    var driver = factory.newInstance('org.acme', 'Driver', 'VEHICLE_1');
    driver.location = 'Southampton';
    // Add the driver to the driver participant registry.
    return driverParticipantRegistry.add(driver);
  })
  .catch(function (error) {
    // Add optional error handling here.
  });

addAll(participants)

Add all of the specified participants to this participant registry.

Parameters:
Name Type Description
participants Array.<Resource>

The participants to add to this participant registry.

Source:
Returns:

A promise. The promise is resolved when all of the
participants have been added to this participant registry. If the participants cannot be
added to this participant registry, or if the participants already exist in the
participant registry, then the promise will be rejected with an error
that describes the problem.

Type
Promise
Example
// Get the driver participant registry.
return getParticipantRegistry('org.acme.Driver')
  .then(function (driverParticipantRegistry) {
    // Get the factory for creating new participant instances.
    var factory = getFactory();
    // Create the first driver.
    var driver1 = factory.newInstance('org.acme', 'Driver', 'VEHICLE_1');
    driver1.location = 'Southampton';
    // Create the second driver.
    var driver2 = factory.newInstance('org.acme', 'Driver', 'VEHICLE_2');
    driver2.location = 'GREEN';
    // Add the drivers to the driver participant registry.
    return driverParticipantRegistry.addAll([driver1, driver2]);
  })
  .catch(function (error) {
    // Add optional error handling here.
  });

get(id)

Get the specified participant in this participant registry using the unique identifier
of the participant.

Parameters:
Name Type Description
id string

The ID of the participant.

Source:
Returns:

A promise. The promise is resolved with a Resource
instance representing the specified participant in this participant registry. If the
specified participant does not exist, or the current user does not have access
to the specified participant, then the promise will be rejected with an error
that describes the problem.

Type
Promise
Example
// Get the driver participant registry.
return getParticipantRegistry('org.acme.Driver')
  .then(function (driverParticipantRegistry) {
    // Get the specific driver from the driver participant registry.
    return participantRegistry.get('VEHICLE_1');
  })
  .then(function (driver) {
    // Process the the driver object.
    console.log(driver.driverId);
  })
  .catch(function (error) {
    // Add optional error handling here.
  });

getAll()

Get a list of all of the existing participants in this participant registry.

Source:
Returns:

A promise. The promise is resolved with an array of
Resource instances representing all of the participants stored in this
participant registry. If the participant registry does not exist, or the current
user does not have access to the participant registry, then the promise will
be rejected with an error that describes the problem.

Type
Promise
Example
// Get the driver participant registry.
return getParticipantRegistry('org.acme.Driver')
  .then(function (driverParticipantRegistry) {
    // Get all of the drivers in the driver participant registry.
    return participantRegistry.getAll();
  })
  .then(function (drivers) {
    // Process the array of driver objects.
    drivers.forEach(function (driver) {
      console.log(driver.driverId);
    });
  })
  .catch(function (error) {
    // Add optional error handling here.
  });

remove(participant)

Remove the specified participant from this participant registry.

Parameters:
Name Type Description
participant string | Resource

The participant, or ID of the participant, to remove
from this participant registry.

Source:
Returns:

A promise. The promise is resolved when the participant
has been removed from this participant registry. If the participant cannot be
removed from this participant registry, or if the participant does not exist in the
participant registry, then the promise will be rejected with an error that
describes the problem.

Type
Promise
Example
// The existing driver that has come from elsewhere.
var driver;
// Get the driver participant registry.
return getParticipantRegistry('org.acme.Driver')
  .then(function (driverParticipantRegistry) {
    // Get the factory for creating new participant instances.
    var factory = getFactory();
    // Remove the driver from the driver participant registry.
    return driverParticipantRegistry.remove(driver);
  })
  .catch(function (error) {
    // Add optional error handling here.
  });

removeAll(participants)

Remove all of the specified participants from this participant registry.

Parameters:
Name Type Description
participants Array.<string> | Array.<Resource>

The participants, or the IDs of the participants,
to remove from this participant registry.

Source:
Returns:

A promise. The promise is resolved when all of the
participants have been removed from this participant registry. If the participants cannot be
removed from this participant registry, or if the participants do not exist in the
participant registry, then the promise will be rejected with an error that
describes the problem.

Type
Promise
Example
// The existing drivers that have come from elsewhere.
var driver1;
// Get the driver participant registry.
return getParticipantRegistry('org.acme.Driver')
  .then(function (driverParticipantRegistry) {
    // Get the factory for creating new participant instances.
    var factory = getFactory();
    // Remove the drivers from the driver participant registry. Note that
    // one driver is specified as a driver instance, and the other
    // driver is specified by the ID of the driver.
    return driverParticipantRegistry.removeAll([driver1, 'VEHICLE_2']);
  })
  .catch(function (error) {
    // Add optional error handling here.
  });

update(participant)

Update the specified participant in this participant registry.

Parameters:
Name Type Description
participant Resource

The participant to update in this participant registry.

Source:
Returns:

A promise. The promise is resolved when the participant
have been updated in this participant registry. If the participant cannot be
updated in this participant registry, or if the participant does not exist in the
participant registry, then the promise will be rejected with an error that
describes the problem.

Type
Promise
Example
// The existing driver that has come from elsewhere.
var driver;
// Get the driver participant registry.
return getParticipantRegistry('org.acme.Driver')
  .then(function (driverParticipantRegistry) {
    // Get the factory for creating new participant instances.
    var factory = getFactory();
    // Modify the properties of the driver.
    driver.location = 'Hursley';
    // Update the driver in the driver participant registry.
    return driverParticipantRegistry.update(driver);
  })
  .catch(function (error) {
    // Add optional error handling here.
  });

updateAll(participants)

Update all of the specified participants in this participant registry.

Parameters:
Name Type Description
participants Array.<Resource>

The participants to update in this participant registry.

Source:
Returns:

A promise. The promise is resolved when all of the
participants have been updated in this participant registry. If the participants cannot be
updated in this participant registry, or if the participants do not exist in the
participant registry, then the promise will be rejected with an error that
describes the problem.

Type
Promise
Example
// The existing drivers that have come from elsewhere.
var driver1;
var driver2;
// Get the driver participant registry.
return getParticipantRegistry('org.acme.Driver')
  .then(function (driverParticipantRegistry) {
    // Get the factory for creating new participant instances.
    var factory = getFactory();
    // Modify the properties of the first driver.
    driver1.location = 'Hursley';
    // Modify the properties of the second driver.
    driver2.location = 'London';
    // Update the drivers in the driver participant registry.
    return driverParticipantRegistry.updateAll([driver1, driver2]);
  })
  .catch(function (error) {
    // Add optional error handling here.
  });