Clear {@link #allMockEc2Instances} and restore it from given a collection of instances.

@param instances
collection of {@link #getMockEc2Instance(String)} to restore
321082
public void restoreAllMockEc2Instances(final Collection<AbstractMockEc2Instance> instances) {
        allMockEc2Instances.clear();
        if (null != instances) {
            for (AbstractMockEc2Instance instance : instances) {
                allMockEc2Instances.put(instance.getInstanceID(), instance);
                // re-initialize the internal timer
                instance.initializeInternalTimer();
            }
        }
    }
1256884
public List<InstanceStateChangeType> stopInstances(final Set<String> instanceIDs) {

        List<InstanceStateChangeType> ret = new ArrayList<InstanceStateChangeType>();

        Collection<AbstractMockEc2Instance> instances = getInstances(instanceIDs);
        for (AbstractMockEc2Instance instance : instances) {
            if (null != instance) {
                InstanceStateChangeType stateChange = new InstanceStateChangeType();
                stateChange.setInstanceId(instance.getInstanceID());

                InstanceStateType previousState = new InstanceStateType();
                previousState.setCode(instance.getInstanceState().getCode());
                previousState.setName(instance.getInstanceState().getName());
                stateChange.setPreviousState(previousState);

                instance.stop();

                InstanceStateType newState = new InstanceStateType();
                newState.setCode(instance.getInstanceState().getCode());
                newState.setName(instance.getInstanceState().getName());
                stateChange.setCurrentState(newState);

                ret.add(stateChange);
            }
        }

        return ret;

    }
387249
private void deleteAllTraits(AtlasVertex instanceVertex) throws AtlasException {
        List<String> traitNames = GraphHelper.getTraitNames(instanceVertex);

        if (LOG.isDebugEnabled()) {
            LOG.debug("Deleting traits {} for {}", traitNames, string(instanceVertex));
        }

        String typeName = GraphHelper.getTypeName(instanceVertex);

        for (String traitNameToBeDeleted : traitNames) {
            String relationshipLabel = GraphHelper.getTraitLabel(typeName, traitNameToBeDeleted);
            deleteEdgeReference(instanceVertex, relationshipLabel, DataTypes.TypeCategory.TRAIT, false);
        }
    }
936862
public void addInstance(InstanceInfo i) {
        instancesMap.put(i.getId(), i);
        synchronized (instances) {
            instances.remove(i);
            instances.add(i);
            isDirty = true;
        }
    }
1039191
public static function clearAll()
  {
    $names = array_keys(self::$_instances);
    foreach ($names as $name) {
      self::clearInstance($name);
    }
  }
656342
public void restoreAllMockRouteTable(final Collection<MockRouteTable> routeTables) {
        allMockRouteTables.clear();
        if (null != routeTables) {
            for (MockRouteTable instance : routeTables) {
                allMockRouteTables.put(instance.getRouteTableId(), instance);
            }
        }
    }
496345
public static synchronized void removeInstance() {
        if (instance != null) {
            instance.removeShutdownHook();
            instance.restoreOriginalSystemOutAndErr();
            if (instance.getReader() != null) {
                instance.getReader().shutdown();
            }
            instance = null;
        }
    }
363041
@Override
    public final void contextDestroyed(final ServletContextEvent sce) {

        Collection<AbstractMockEc2Instance> instances = MockEc2Controller.getInstance()
                    .getAllMockEc2Instances();

        for (AbstractMockEc2Instance instance : instances) {
                // cancel and destroy the internal timers for all instances on
                // web app stopping
            instance.destroyInternalTimer();
        }

        if (persistenceEnabled) {

            // put all instances into an array which is serializable and type-cast safe for persistence
            AbstractMockEc2Instance[] array = new AbstractMockEc2Instance[instances.size()];
            instances.toArray(array);
            PersistenceUtils.saveAll(array, PersistenceStoreType.EC2);


            Collection<MockVpc> vpcs = MockVpcController.getInstance()
                    .describeVpcs();
            MockVpc[] vpcArray = new MockVpc[vpcs.size()];
            vpcs.toArray(vpcArray);
            PersistenceUtils.saveAll(vpcArray, PersistenceStoreType.VPC);

            Collection<MockVolume> volumes = MockVolumeController.getInstance()
                    .describeVolumes();
            MockVolume[] volumeArray = new MockVolume[volumes.size()];
            volumes.toArray(volumeArray);
            PersistenceUtils.saveAll(volumeArray, PersistenceStoreType.VOLUME);

            Collection<MockTags> tags = MockTagsController.getInstance().describeTags();

            MockTags[] tagArray = new MockTags[tags.size()];
            tags.toArray(tagArray);
            PersistenceUtils.saveAll(tagArray, PersistenceStoreType.TAGS);

            Collection<MockSubnet> subnets = MockSubnetController.getInstance().describeSubnets();

            MockSubnet[] subnetArray = new MockSubnet[subnets.size()];
            subnets.toArray(subnetArray);
            PersistenceUtils.saveAll(subnetArray, PersistenceStoreType.SUBNET);

            Collection<MockRouteTable> routetables = MockRouteTableController.getInstance().describeRouteTables();

            MockRouteTable[] routetableArray = new MockRouteTable[routetables.size()];
            routetables.toArray(routetableArray);
            PersistenceUtils.saveAll(routetableArray, PersistenceStoreType.ROUTETABLE);

            Collection<MockInternetGateway> internetgateways = MockInternetGatewayController.getInstance()
                    .describeInternetGateways();

            MockInternetGateway[] internetgatewayArray = new MockInternetGateway[internetgateways.size()];
            internetgateways.toArray(internetgatewayArray);
            PersistenceUtils.saveAll(internetgatewayArray, PersistenceStoreType.INTERNETGATEWAY);
        }

        MockEc2Controller.getInstance().destroyCleanupTerminatedInstanceTimer();

        log.info("aws-mock stopped.");
    }
1105511
public <T> void removeListener(final Listener<T> listener, final Object instance) {
		final ListenerInstancePair<T> pair = new ListenerInstancePair<T>(listener, instance);
		this.listeners.remove(pair);
		for (final List<ListenerInstancePair<?>> entry : this.cachedListeners.values()) {
			entry.remove(pair);
		}
	}
995213
void restoreAllInstances() {

		// instancesMngr() instead of this.instancesMngr (for unit tests).
		this.logger.fine( "Restoring all the instance states from the current target handlers." );
		for( ManagedApplication ma : this.applicationMngr.getManagedApplications()) {

			// Build a new snapshot on every loop
			List<TargetHandler> snapshot = this.defaultTargetHandlerResolver.getTargetHandlersSnapshot();
			for( TargetHandler targetHandler : snapshot )
				instancesMngr().restoreInstanceStates( ma, targetHandler );
		}
	}
751841
public void setTerminatingInstances(java.util.Collection<InstanceStateChange> terminatingInstances) {
        if (terminatingInstances == null) {
            this.terminatingInstances = null;
            return;
        }

        this.terminatingInstances = new com.amazonaws.internal.SdkInternalList<InstanceStateChange>(terminatingInstances);
    }
1017294
private StartInstancesResponseType startInstances(final Set<String> instanceIDs) {
        StartInstancesResponseType ret = new StartInstancesResponseType();
        ret.setRequestId(UUID.randomUUID().toString());
        InstanceStateChangeSetType changeSet = new InstanceStateChangeSetType();
        changeSet.getItem().addAll(mockEc2Controller.startInstances(instanceIDs));
        ret.setInstancesSet(changeSet);
        return ret;

    }
927218
public void setInstanceFleets(java.util.Collection<InstanceFleet> instanceFleets) {
        if (instanceFleets == null) {
            this.instanceFleets = null;
            return;
        }

        this.instanceFleets = new com.amazonaws.internal.SdkInternalList<InstanceFleet>(instanceFleets);
    }
181181
public static List<InstanceStateChange> terminateInstances(final List<String> instanceIDs) {
        // pass any credentials as aws-mock does not authenticate them at all
        AWSCredentials credentials = new BasicAWSCredentials("foo", "bar");
        AmazonEC2Client amazonEC2Client = new AmazonEC2Client(credentials);

        // the mock endpoint for ec2 which runs on your computer
        String ec2Endpoint = "http://localhost:8000/aws-mock/ec2-endpoint/";
        amazonEC2Client.setEndpoint(ec2Endpoint);

        // send the terminate request with args as instance IDs
        TerminateInstancesRequest request = new TerminateInstancesRequest();
        request.withInstanceIds(instanceIDs);
        TerminateInstancesResult result = amazonEC2Client.terminateInstances(request);

        return result.getTerminatingInstances();
    }
87577
public void deleteEntities(Collection<AtlasVertex> instanceVertices) throws AtlasBaseException {
        RequestContextV1 requestContext = RequestContextV1.get();

        Set<AtlasVertex> deletionCandidateVertices = new HashSet<>();

        for (AtlasVertex instanceVertex : instanceVertices) {
            String              guid = AtlasGraphUtilsV1.getIdFromVertex(instanceVertex);
            AtlasEntity.Status state = AtlasGraphUtilsV1.getState(instanceVertex);

            if (state == AtlasEntity.Status.DELETED) {
                LOG.debug("Skipping deletion of {} as it is already deleted", guid);
                continue;
            }

            String typeName = AtlasGraphUtilsV1.getTypeName(instanceVertex);
            AtlasObjectId objId = new AtlasObjectId(guid, typeName);

            if (requestContext.getDeletedEntityIds().contains(objId)) {
                LOG.debug("Skipping deletion of {} as it is already deleted", guid);
                continue;
            }

            // Get GUIDs and vertices for all deletion candidates.
            Set<GraphHelper.VertexInfo> compositeVertices = getOwnedVertices(instanceVertex);

            // Record all deletion candidate GUIDs in RequestContext
            // and gather deletion candidate vertices.
            for (GraphHelper.VertexInfo vertexInfo : compositeVertices) {
                requestContext.recordEntityDelete(new AtlasObjectId(vertexInfo.getGuid(), vertexInfo.getTypeName()));
                deletionCandidateVertices.add(vertexInfo.getVertex());
            }
        }

        // Delete traits and vertices.
        for (AtlasVertex deletionCandidateVertex : deletionCandidateVertices) {
            deleteAllTraits(deletionCandidateVertex);
            deleteTypeVertex(deletionCandidateVertex, false);
        }
    }
136220
public void setDBInstances(java.util.Collection<DBInstance> dBInstances) {
        if (dBInstances == null) {
            this.dBInstances = null;
            return;
        }

        this.dBInstances = new com.amazonaws.internal.SdkInternalList<DBInstance>(dBInstances);
    }
340525
public void restoreAllMockSubnet(final Collection<MockSubnet> subnets) {
        allMockSubnets.clear();
        if (null != subnets) {
            for (MockSubnet instance : subnets) {
                allMockSubnets.put(instance.getSubnetId(), instance);
            }
        }
    }