How to destroy a resource after it has been used - anylogic

I've been trying to find a way to destroy a resource after the task it has been seized for has been completed, but I could not do it.
I'm following the Nurse-Ultrasound example in the AnyLogic Help, so for example I have a moving resource (worker) which seizes another resource (portable, say a box or something like that), and when the worker is done with the task I want the box to be destroyed (possibly when the worker is released). Note that I don't want the worker to go back to the box initial position.
I add a picture of what I've done, the whole resourceTaskEnd thing it's not working though.
Picture

Don't know if I understand... but try this on the "on release" action of the resourcePool:
self.set_capacity(self.capacity-1);
and in the resourcePool properties, destroy units when capacity decreases...

Related

Agent disappears when reaching an attractor

I have a set of agents who should be parking at 4 attractors. I use the moveTo block.
I followed the method suggested in this thread AnyLogic how to set attractor choice to both free and random. The snapshot is below.
My agents disappeared on reaching the attractors. But when I chose "is placed (jumps) to" the agents stayed put but I couldn't proceed to the next state (I'm using statechart to control the movement of the agent).
Is there additional step that I should do to either keep the agent in place or get it to move out of the flowchart?
moveTo
Author found the answer herself:
I found the issue why the agents disappeared. It was caused by the service block that receives the agent in the next flowchart.

Why does release block do not free the resource?

Hi i have a source linked with a seize block,which contains 3 resources (see image)
I want the resource "motrice" be the first to be released, so i used two release blocks. (see image)
the problem is that the release1 block does not free the resource and i do not know why.
As you can see from the last two images, after the agent go trough the release1 block, the resource "motrice" is still linked to the agent.What is the error?Thanks
I created similar model with two options:
one with pickup before seizing the resources;
one with pickup after seizing the resources.
As you can see from the below screenshots, it does release "motrice" in both cases. It might be due to the pickup/dropoff or the resource is seized somewhere else, not related to these blocks that you have mentioned.

How to wait until dam update asset workflow is completed instead of thread dot sleep

In AEM CQ , I am using asset manager api to write content(images uploaded from) in dam. This triggers out of the box Dam Update Asset workflow. I require to read renditions and asset properties that would be written available once the workflow is completed.
My question is how to wait until the workflow is completed for reading the asset properties instead of thread.sleep.
I tried with a recursive function call to iterate while the asset property is present. This gave null pointer exception. But when I put a thread.sleep of 50 ms inside the iteration it works for me.
Another approach I tried to get the workflow object inside the service to read workflow status but found that it takes few milliseconds for the ootb workflow to start after the content is written. Here also had to give thread.sleep.
One more attempt to use a event handler to listen workflow events. We are able to enter the event type as workflow completed. How to notify the service or jsp that the workflow is completed and we can read the asset properties and renditions?
It would be great if someone can share their suggestions feedback on the approach. Thank you.
You have the wrong approach to solve this problem. In my eyes you have exactly 2 reasonable solutions on this.
Create workflow process/step and extend the Dam Update Asset Workflow with your custom step.
OR
Create JCR observation listener and listen for Event.PROPERTY_ADDED for example or use the higher sling APIs and create event handler with the appropriate topic and than execute your business logic as soon the property you look for is added or changed.
Why not to use Thread.sleep() or other similar solution:
you don't know when the workflow is executed exactly. it may be
delayed if many asssets are uploaded or just get stuck
you cannot assure that your thread will be able to execute it's
logic. the instance may be stopped for example
creating a new tread for every resource uploaded may be expensive task. you also waste resources when you create an infinite loop and put those threads to sleep, than wake them and check again and again ... and so on until eventually the thread is able to do it's job

SpriteKit: Callback after all nodes finished actions

Simplified problem (in Swift but I think also in Objective-C): I've got two nodes where actions have started. The information about the initial runtime of the action is not available (got lost). I'd like to be informed after both actions have been performed.
After performing additional actions will be assigned according to the current state (which is not available in advance).
Any simple solution known?

How to delay modificactions to the resource tree when it is locked

I'm getting the exception:
org.eclipse.core.internal.resources.ResourceException: The resource tree is locked for modifications.
After some searching I found out, that this comes from the fact that I am trying to add markers to a file. I'm doing this, when I am notified of a file change. So when my modification code is called the workspace is still in the middle of the notifying process and does not allow modifications to the resource tree.
How can I save markers so that I can add them to the file later or what would be another way to delay this changes?
You can't modify the resource tree from a resource delta event handler (imagine the potential for complete chaos if you could). The most common approach that I know of is to schedule a Job and make the modifications within the run() method of the Job. This means you need to remember the modifications that you want to make so that they can be done within the Job. It also means you can't make too many assumptions about the state of the resource tree because theoretically some other Job might run before yours that makes changes to the tree.
Change IResourceChangeEvent.PRE_BUILD will solve this problem.. Worked for me