resourceAcquired
Class: matlab.DiscreteEventSystem
Namespace: matlab
Event action upon successful resource acquisition
Syntax
[entity,event,...
out1,...] = resourceAcquired(obj,...
storage,...entity,resources,tag,in1,...)
Description
[
specifies event action for a discrete-event System object™ upon successful acquisition of a resource. Resource acquisition is successful
only if all of the specified resources are acquired.entity
,event
,...
out1
,...] = resourceAcquired(obj
,...
storage
,...entity
,resources
,tag
,in1
,...)
Input Arguments
obj
— Discrete-event System object
MATLAB® object
Discrete-event System object.
storage
— Storage that the entity resides in
double
Index of the storage element.
entity
— Entity that is acquiring the resources
MATLAB structure
Entity that acquires the resource. Entity has these fields:
sys
(MATLABstructure
) consisting of:id
(double
) — Entity IDpriority
(double
) — Entity priority
data
— Entity data
resources
— Acquired resources
MATLAB structure
An array of structures that specifies the resources that have been acquired.
tag
— Tag of the resource acquisition event
character vector
Tag of the currently executing resource acquisition event.
in1
— First data input
character vector
First data input.
Output Arguments
entity
— Entity with changed value
MATLAB structure
Entity acquiring the resource.
event
— Events to be scheduled
vector of MATLAB structures
Events to be scheduled. Use matlab.DiscreteEventSystem
class methods to create events. Each event has
these fields:
type
(character vector
) — Type of the eventdelay
(double
) — Delay before the eventpriority
(double
) — Priority of the eventstorage
(double
) — Index of the storage elementtag
(character vector
) — Event taglocation
(MATLABstructure
) — Source or destination (see source)
out1
— First data output
character vector
First data output.
Examples
Event Action on Resource Acquisition
Suppose that an entity acquires resources successfully with a
scheduled eventAcquireResource
and the tag of this event is
MyResourceAcquireEvent
. Then this acquisition invokes the
resourceAcquired
method to forward entities to the output.
function [entity,events] = entry(obj, storage, entity, source) % On entry, acquire one resource of type Resource1. resRequest = obj.resourceSpecification('Resource1', 1); events = obj.eventAcquireResource(resRequest, 'MyResourceAcquireEvent'); end function [entity,events] = resourceAcquired(obj, storage,... entity, resources, tag) % After resource acquisition, forward the entity to the output. events = obj.eventForward('output', storage, 0.0); end
Custom Resource Acquirer
This example shows how to use resource management methods to create a custom entity storage block in which entities acquire resources from specified Resource Pool blocks.
Suppose that you manage a facility that produces parts from two different materials,
material 1
and material 2
, to fulfill orders.
After a part is produced, it is evaluated for quality assurance.
Two testing methods for quality control are:
Test 1 is used for parts that are produced from material
1
.Test 2 is used for parts that are produced from material
2
After the production phase, parts are tagged based on their material to apply the correct test.
For more information, see Create a Custom Resource Acquirer Block.
classdef CustomBlockAcquireResources < matlab.DiscreteEventSystem % Custom resource acquire block example. methods(Access = protected) function num = getNumInputsImpl(obj) num = 1; end function num = getNumOutputsImpl(obj) num = 1; end function entityTypes = getEntityTypesImpl(obj) entityTypes(1) = obj.entityType('Part'); end function [input, output] = getEntityPortsImpl(obj) input = {'Part'}; output = {'Part'}; end function [storageSpec, I, O] = getEntityStorageImpl(obj) storageSpec(1) = obj.queueFIFO('Part', 1); I = 1; O = 1; end function resNames = getResourceNamesImpl(obj) % Define the names of the resources to be acquired. resNames = obj.resourceType('Part', {'Test1', 'Test2'}) ; end end methods function [entity,events] = entry(obj, storage, entity, source) % On entity entry, acquire a resource from the specified pool. if entity.data.Test == 1 % If the entity is produced from Material1, request Test1. resReq = obj.resourceSpecification('Test1', 1); else % If the entity is produced from Material2, request Test2. resReq = obj.resourceSpecification('Test2', 1); end % Acquire the resource from the corresponding pool. events = obj.eventAcquireResource(resReq, 'TestTag'); end function [entity,events] = resourceAcquired(obj, storage,... entity, resources, tag) % After the resource acquisition, forward the entity to the output. events = obj.eventForward('output', storage, 0.0); end end end
Version History
Introduced in R2019a
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)