Add/replace instance in current instance map. Work on a copy of the current map and replace it atomically.

@param instanceName
The name of the provider
@param instance
The instance
513867
public static void put(String instanceName, Driver instance) {
        // Copy current instances
        Map<String, Driver> newInstances = new HashMap<>();
        synchronized (instances) {
            Set<String> keys = instances.getInstances().keySet();

            for (String key : keys) {
                newInstances.put(key, instances.getInstances().get(key));
            }
        }

        // Add new instance
        newInstances.put(instanceName, instance);

        instances = new IndexedInstances(newInstances);
    }
832891
public void updateServiceInstance(ProvidedServiceInstance instance, final RegistrationCallback cb, Object context){
        ProtocolHeader header = new ProtocolHeader();
        header.setType(ProtocolType.UpdateServiceInstance);

        UpdateServiceInstanceProtocol p = new UpdateServiceInstanceProtocol(instance);
        ProtocolCallback pcb = new ProtocolCallback(){

            @Override
            public void call(boolean result, Response response,
                    ErrorCode error, Object ctx) {
                cb.call(result, error, ctx);
            }

        };
        connection.submitCallbackRequest(header, p, pcb, context);
    }
1091940
def add_instance(self, instance):
        

        assert isinstance(instance, dict)

        item = defaults["common"].copy()
        item.update(defaults["instance"])

        item.update(instance["data"])
        item.update(instance)

        item["itemType"] = "instance"
        item["isToggled"] = instance["data"].get("publish", True)
        item["hasCompatible"] = True
        item["category"] = item["category"] or item["family"]

        self.add_section(item["category"])

        # Visualised in Perspective
        families = [instance["data"]["family"]]
        families.extend(instance["data"].get("families", []))
        item["familiesConcatenated"] += ", ".join(families)

        item = self.add_item(item)
        self.instances.append(item)
1044448
public void updateServiceInstanceUri(String serviceName, String instanceId, String uri){
        ProtocolHeader header = new ProtocolHeader();
        header.setType(ProtocolType.UpdateServiceInstanceUri);

        UpdateServiceInstanceUriProtocol p = new UpdateServiceInstanceUriProtocol(serviceName, instanceId, uri);
        connection.submitRequest(header, p, null);
    }
760665
void updateProviders(ConsumerConfig config, List<Instance> instances) {
        if (LOGGER.isInfoEnabled(config.getAppName())) {
            LOGGER.infoWithApp(config.getAppName(),
                "Receive update provider: serviceName={}, size={}, data={}", config.getInterfaceId(), instances.size(),
                instances);
        }
        List<ProviderInfoListener> providerInfoListeners = providerListenerMap.get(config);
        if (CommonUtils.isNotEmpty(providerInfoListeners)) {
            List<ProviderInfo> providerInfos = NacosRegistryHelper.convertInstancesToProviders(instances);
            List<ProviderInfo> matchProviders = RegistryUtils.matchProviderInfos(config, providerInfos);

            for (ProviderInfoListener providerInfoListener : providerInfoListeners) {
                providerInfoListener
                    .updateAllProviders(Collections.singletonList(new ProviderGroup().addAll(matchProviders)));
            }
        }
    }
998974
@Override
    public void deleteInstance(String instanceId) {
        modifyInstance(instanceId, map -> {
            Instance deletedInstance = map.remove(instanceId);
            getDeletedInstancesByIdMap().put(deletedInstance.getId(), deletedInstance);
        });
    }
1036281
public void setInstanceInfos(java.util.Collection<InstanceInfo> instanceInfos) {
        if (instanceInfos == null) {
            this.instanceInfos = null;
            return;
        }

        this.instanceInfos = new com.amazonaws.internal.SdkInternalList<InstanceInfo>(instanceInfos);
    }
46268
public function setInstance(Instance $instance)
    {
        $this->instance = $instance;
        $this->exception = null;
        $this->connect();
        
        return $this;
    }
1168251
public void registerServiceInstance(ProvidedServiceInstance instance){

        ProtocolHeader header = new ProtocolHeader();
        header.setType(ProtocolType.RegisterServiceInstance);

        RegisterServiceInstanceProtocol p = new RegisterServiceInstanceProtocol(instance);

        connection.submitRequest(header, p, null);

    }
11131
public static void deleteInstanceResources( Instance instance )	throws IOException {
		File dir = InstanceHelpers.findInstanceDirectoryOnAgent( instance );
		Utils.deleteFilesRecursively( dir );
	}
394670
def _iparam_instancename(instancename):
        

        if isinstance(instancename, CIMInstanceName):
            instancename = instancename.copy()
            instancename.host = None
            instancename.namespace = None
        elif instancename is None:
            pass
        else:
            raise TypeError(
                _format("The 'InstanceName' argument of the WBEMConnection "
                        "operation has invalid type {0} (must be None, a "
                        "string, or a CIMInstanceName)",
                        type(instancename)))
        return instancename
878840
public <T> void addListener(final Listener<T> listener, final Object instance) {
		final ListenerInstancePair<T> pair = new ListenerInstancePair<T>(listener, instance);
		this.listeners.add(pair);
		final Type observableType = GenericsUtil.getEntityGenericType(listener.getClass(), 0, Listener.class);
		final Class<?> observable = GenericsUtil.guessClazz(observableType);
		if (!this.cachedListeners.containsKey(observable)) {
			this.cachedListeners.put(observable, new LinkedList<ListenerInstancePair<?>>());
		}
		for (final Map.Entry<Class<?>, List<ListenerInstancePair<?>>> entry : this.cachedListeners.entrySet()) {
			final Class<?> type = entry.getKey();
			if (observable.isAssignableFrom(type)) {
				entry.getValue().add(pair);
			}
		}
	}
519806
public void setInstanceId (final String instanceId)
  {
    if (instanceId == null || instanceId.trim ().length () == 0)
    {
      throw new IllegalArgumentException ("Scheduler instanceId cannot be empty.");
    }

    m_sInstanceId = instanceId;
  }
1013830
public <V> void setIdValue(T instance, V value) {
        setColumnValue(instance, idFieldName, value);
    }
866671
void updateInstance(T instance) {
        T oldInstance = this.instance.getAndSet(Preconditions.checkNotNull(instance, "instance"));
        if (oldInstance != null && oldInstance != instance) {
            oldInstance.close();
        }
    }
187230
public void updateServiceInstance(ProvidedServiceInstance instance){
        ProtocolHeader header = new ProtocolHeader();
        header.setType(ProtocolType.UpdateServiceInstance);

        UpdateServiceInstanceProtocol p = new UpdateServiceInstanceProtocol(instance);
        connection.submitRequest(header, p, null);
    }
1036325
@Override
	public Response addInstance( String applicationName, String parentInstancePath, Instance instance ) {

		if( parentInstancePath == null )
			this.logger.fine( "Request: add root instance " + instance.getName() + " in " + applicationName + "." );
		else
			this.logger.fine( "Request: add instance " + instance.getName() + " under " + parentInstancePath + " in " + applicationName + "." );

		String lang = lang( this.manager );
		Response response;
		try {
			ManagedApplication ma = this.manager.applicationMngr().findManagedApplicationByName( applicationName );
			if( ma == null ) {
				response = handleError(
						Status.NOT_FOUND,
						new RestError( REST_INEXISTING, application( applicationName )),
						lang ).build();

			} else {
				Graphs graphs = ma.getApplication().getTemplate().getGraphs();
				String componentName = null;
				if( instance.getComponent() != null )
					componentName = instance.getComponent().getName();

				// The deserialized instance is not the real one, but just hints
				// (e.g. only the component name is pertinent, and all the exports - included overridden ones - are
				// serialized in the same map...). Now let's make this "fictional" instance real (fix it)!
				Component realComponent;
				if( componentName == null ) {
					response = handleError(
							Status.NOT_FOUND,
							new RestError( REST_MISSING_PROPERTY, value( "component" )),
							lang ).build();

				} else if((realComponent = ComponentHelpers.findComponent( graphs, componentName )) == null ) {
					response = handleError(
							Status.NOT_FOUND,
							new RestError( REST_INEXISTING, component( componentName )),
							lang ).build();

				} else {
					instance.setComponent( realComponent );
					InstanceHelpers.fixOverriddenExports( instance );

					Instance parentInstance = InstanceHelpers.findInstanceByPath( ma.getApplication(), parentInstancePath );
					this.manager.instancesMngr().addInstance( ma, parentInstance, instance );
					response = Response.ok().build();
				}
			}

		} catch( ImpossibleInsertionException | IOException e ) {
			response = RestServicesUtils.handleError(
					Status.FORBIDDEN,
					new RestError( ErrorCode.REST_UNDETAILED_ERROR, e ),
					lang ).build();
		}

		return response;
	}