Example #1
0
        /// <summary>
        /// Creates a new SelfManagingResource. A resource is created with a capacity, and is granted in portions
        /// of that capacity, or if atomic, all-or-nothing. The IResourceRequest will specify a desired
        /// amount. If the IResourceRequest specifies a desired quantity less than the resource's capacity,
        /// and the resource is atomic, the IResourceRequest will be granted the full capacity of the
        /// resource. A self-managing resource is a resource that is responsible for granting access to itself.
        /// </summary>
        /// <param name="model">The model to which the Resource will belong.</param>
        /// <param name="name">The name of the Resource.</param>
        /// <param name="guid">The guid of the Resource.</param>
        /// <param name="capacity">The capacity of the Resource. How much there <b>can be</b> to be granted.</param>
        /// <param name="available">The availability of the Resource. How much there <b>is, at start,</b> to be granted.</param>
        /// <param name="isAtomic">True if the Resource is atomic. Atomicity infers that the resource is granted all-or-nothing.</param>
        /// <param name="isDiscrete">True if the Resource is discrete. Discreteness infers that the resource is granted in unitary amounts.</param>
        /// <param name="isPersistent">True if the Resource is persistent. Atomicity infers that the resource, once granted, must be returned to the pool.</param>
        /// <param name="supportsPriorities">True if this resource is able ot treat resource requests in a prioritized order.</param>
        public SelfManagingResource(IModel model, string name, Guid guid, double capacity, double available, bool isAtomic, bool isDiscrete, bool isPersistent, bool supportsPriorities = false)
        {
            m_baseResource        = new Resource(model, name, guid, capacity, available, isAtomic, isDiscrete, isPersistent, this);
            m_baseResourceManager = new ResourceManager(model, name, guid, supportsPriorities)
            {
                m_baseResource
            };
            IModelWithResources modelWithResources = model as IModelWithResources;

            modelWithResources?.OnNewResourceCreated(this);
        }
Example #2
0
 /// <summary>
 /// Creates a new SelfManagingResource. A resource is created with a capacity, and is granted in portions
 /// of that capacity, or if atomic, all-or-nothing. The IResourceRequest will specify a desired
 /// amount. If the IResourceRequest specifies a desired quantity less than the resource's capacity,
 /// and the resource is atomic, the IResourceRequest will be granted the full capacity of the
 /// resource. A self-managing resource is a resource that is responsible for granting access to itself.
 /// </summary>
 /// <param name="model">The model to which the Resource will belong.</param>
 /// <param name="name">The name of the Resource.</param>
 /// <param name="guid">The guid of the Resource.</param>
 /// <param name="capacity">The capacity of the Resource. How much there is to be granted. This API infers that the resource,
 /// at creation has its full capacity available.</param>
 /// <param name="isAtomic">True if the Resource is atomic. Atomicity infers that the resource is granted all-or-nothing.</param>
 /// <param name="isDiscrete">True if the Resource is discrete. Discreteness infers that the resource is granted in unitary amounts.</param>
 /// <param name="isPersistent">True if the Resource is persistent. Atomicity infers that the resource, once granted, must be returned to the pool.</param>
 /// <param name="supportsPriorities">True if this resource is able to treat resource requests in a prioritized order.</param>
 public SelfManagingResource(IModel model, string name, Guid guid, double capacity, bool isAtomic, bool isDiscrete, bool isPersistent, bool supportsPriorities = false)
 {
     m_baseResource = new Resource(model, name, guid, capacity, capacity, isAtomic, isDiscrete, isPersistent, this);
     model?.ModelObjects.Remove(guid);
     m_baseResourceManager = new ResourceManager(model, name, guid, supportsPriorities);
     model?.ModelObjects.Remove(guid);
     m_baseResourceManager.Add(m_baseResource);
     if (model != null)
     {
         IModelWithResources resources = model as IModelWithResources;
         resources?.OnNewResourceCreated(this);
         model.ModelObjects.Add(guid, this);
     }
 }
Example #3
0
        /// <summary>
        /// Creates a new Resource. A resource is created with a capacity, and initial quantity available, and is
        /// granted in portions of that capacity, or if atomic, all-or-nothing. The IResourceRequest will specify
        /// a desired amount. If the IResourceRequest specifies a desired quantity less than the resource's capacity,
        /// and the resource is atomic, the IResourceRequest will be granted the full capacity of the resource.
        /// A self-managing resource is a resource that is responsible for granting access to itself.<p>This constructor
        /// allows the initial capacities and quantities available to be different from each other.</p>
        /// </summary>
        /// <param name="model">The model to which the Resource will belong.</param>
        /// <param name="name">The name of the Resource.</param>
        /// <param name="guid">The guid by which this resource will be known.</param>
        /// <param name="capacity">The capacity of the Resource. How much there is to be granted.</param>
        /// <param name="availability">The amount of this resource that is initially available.</param>
        /// <param name="isAtomic">True if the Resource is atomic. Atomicity infers that the resource is granted all-or-nothing.</param>
        /// <param name="isDiscrete">True if the Resource is discrete. Discreteness infers that the resource is granted in unitary amounts.</param>
        /// <param name="isPersistent">True if the Resource is persistent. Persistence infers that the resource, once granted, must be returned to the pool.</param>
        public Resource(IModel model, string name, Guid guid, double capacity, double availability, bool isAtomic, bool isDiscrete, bool isPersistent)
        {
            m_model          = model;
            m_name           = name;
            m_guid           = guid;
            Capacity         = capacity;
            InitialCapacity  = capacity;
            Available        = availability;
            InitialAvailable = availability;
            IsAtomic         = isAtomic;
            IsDiscrete       = isDiscrete;
            IsPersistent     = isPersistent;
            m_wrappedByWhom  = this;
            if (m_model == null)
            {
                return;
            }

            IModelWithResources resources = m_model as IModelWithResources;

            resources?.OnNewResourceCreated(this);
            m_model.ModelObjects.Add(guid, this);
        }