Anylogic - access variables from other agents - java

I am trying to model a production infrastructure in anylogic which consists of several agents. One of it is a "steam network" (system dynamics) which starts with a flow from nowhere. The dynamic value of this flow is supposed to be the steam output of another agent. Unfortunately, I can't figure out how to link the flow to the steam production (dynamic variable) of my agent "machine".
I appreciate all your help.

To clarify the model navigation, take this example model I made:
It has 2 different agents embedded on main. "OtherAgent" has 1 variable v_DefiningFlowRate of type double, set to 12.
The second agent on Main "SysDynAgent" has a flow object that pulls the flow rate from "OtherAgent" by navigating to it correctly:
this is what you need to adapt to in your model

The flow object allows you to set the flow to be anything (it is a Java field) so you can easily link it to your agent's variable as below:
The actual code depends on your model structure, i.e. how the steam agent is embedded relative to the myAgent feeding it with flow. In my example, "MyAgent" is simply embedded in the steam engine, but yours might vary. If that is the problem, check the Help's section Where am I and how do I get to...

Related

How to display the states on Corda terminal

I am new to Corda and am designing a Cordap. I want to display the states onto the terminal based on some arguments passed during initiating the flow.
My approach was I created a List of type StateAndRef storing all the states. Now I loop through the list and display the state based on if else condition.
But the issue I am facing is somethimes all the states the printed and sometimes only few of them are printed. Please help me to solve this problem. My main motive is I should be able to display on the screen those states which have name Car.
PS: I am using Java for designing the Cordapp.
You don't really need a flow to display states. You con using vaultQuery to do so:
run vaultQuery contractStateType: <fully-qualified name of the state type>
Refer documentation here for: https://docs.corda.net/docs/corda-os/4.4/shell.html#examples
In case you want to do complex querying, it's not supported in the CRaSH shell. However, you could do so in the RPC Client using the vault Query API. The VaultQuery API is very flexible and provide a number of mechanisms to access the vault.
Check the documentation here: https://docs.corda.net/docs/corda-os/4.4/api-vault-query.html#api-vault-query
As Ashutosh has already mentioned, complex querying doesn't seem to be supported yet. However a way to accomplish querying a subset of all states would be to create another class for those states.
For Ex - CARState for the subset you want to query on and the other states can be CAR2State, and then just use the
run vaultQuery contractStateType: com.template.CARState
Im not sure if this helps since I don't know for what reasons you want to use arguments passed in the flow. But the RPC client is the way to achieve complex queries, unfortunately that is not covered in my course on Udemy.

How to use multi-threading to call number of services?

I am working on currency card website which shows dashboard once user logs in.
Dashboard consists of following sections:
(1) Transaction Details of card holder. (Grid with transaction details)
(2) Currencies available in my purse(card).
(3) Currency to currency conversion rates.
(4) Reward points against my card.
Now, all these 4 points have service written for that which my business logic (Java class) file calls.
Now, here I can make use of multithreading to make the performance of my dashboard page good. I want to call all these services asynchronously so that my page will loaded faster.
Can you guys please suggest me topics to search on google to achieve my above functionality.
P.S : I want to achieve above functionality in Java not in any JS framework (as per requirement)
Considering that each of your 4 sections has a different service call, you may utilize ExecutorService#invokeAll to concurrently execute all service calls and then consolidating the result as per your need.

How to Monitor/inspect data/attribute flow in Java code

I have a use case when I need to capture the data flow from one API to another. For example my code reads data from database using hibernate and during the data processing I convert one POJO to another and perform some more processing and then finally convert into final result hibernate object. In a nutshell something like POJO1 to POJO2 to POJO3.
In Java is there a way where I can deduce that an attribute from POJO3 was made/transformed from this attribute of POJO1. I want to look something where I can capture data flow from one model to another. This tool can be either compile time or runtime, I am ok with both.
I am looking for a tool which can run in parallel with code and provide data lineage details on each run basis.
Now instead of Pojos I will call them States! You are having a start position you iterate and transform your model through different states. At the end you have a final terminal state that you would like to persist to the database
stream(A).map(P1).map(P2).map(P3)....-> set of B
If you use a technic known as Event sourcing you can deduce it yes. How would this look like then? Instead of mapping directly A to state P1 and state P1 to state P2 you will queue all your operations that are necessary and enough to map A to P1 and P1 to P2 and so on... If you want to recover P1 or P2 at any time, it will be just a product of the queued operations. You can at any time rewind forward or rewind backwards as long as you have not yet chaged your DB state. P1,P2,P3 can act as snapshots.
This way you will be able to rebuild the exact mapping flow for this attribute. How fine grained you will queue your oprations, if it is going to be as fine as attribute level , or more course grained it is up to you.
Here is a good article that depicts event sourcing and how it works: https://kickstarter.engineering/event-sourcing-made-simple-4a2625113224
UPDATE:
I can think of one more technic to capture the attribute changes. You can instument your Pojo-s, it is pretty much the same technic used by Hibernate to enhance Pojos and same technic profiles use to for tracing. Then you can capture and react to each setter invocation on the Pojo1,Pojo2,Pojo3. Not sure if I would have gone that way though....
Here is some detiled readin about the byte code instrumentation if https://www.cs.helsinki.fi/u/pohjalai/k05/okk/seminar/Aarniala-instrumenting.pdf
I would imagine two reasons, either the code is not developed by you and therefore you want to understand the flow of data along with combinations to convert input to output OR your code is behaving in a way that you are not expecting.
I think you need to log the values of all the pojos, inputs and outputs to any place that you can inspect later for each run.
Example: A database table if you might need after hundred of runs, but if its one time may be to a log in appropriate form. Then you need to yourself manually use those data values layer by later to map to the next layer. I think with availability of code that would be easy. If you have a different need pls. explain.
Please accept and like if you appreciate my gesture to help with my ideas n experience.
There are "time travelling debuggers". For Java, a quick search did only spill this out:
Chronon Time Travelling Debugger, see this screencast how it might help you .
Since your transformations probably use setters and getters this tool might also be interesting: Flow
Writing your own java agent for tracking this is probably not what you want. You might be able to use AspectJ to add some stack trace logging to getters and setters. See here for a quick introduction.

rrd4j with java

I am currently developing a program with Java that collect and illustrate IP traffic from similar information and draw the graph of this information.
So I must use rrd4j rrd with java to save the data flow from a JTable in another table first and then use RRDTool to draw the graph .
but my problem is how to have the info stored in rrd and also how to create database RRD4J
thank you
First of all I would check rrd4j project home page and check some documentation. On the main page there is usage example of how you create the database and I think it's quite clear and no needed to be explained, since it would be copy+paste.
Now what about storing the information.. First of all you need to define how much and what type of data you want to store. For example in the project I'm working, we are aggregating data daily, weekly, monthly and yearly. You also need to specify what is the frequence of data collection: because it really makes difference if it's 5 seconds or 5 minutes.
You should also have a look at former rrd project homepage and ganglia, the part where you defining the RRD files creation, it will really help you to understand how RRDTool and data storing works.

Limiting/controlling the users ability to print in Java

I am looking to right an application that limits the number of times a user can print something, its there anything in Java that will allow me to control the printing dialogue to this aim?
Im going to look into these:
http://www.wildcrest.com/Software/J2PrinterWorks/documentation/J2Printer14.html
http://www.softframeworks.com/products/products.php
This is probably something you'll need to implement yourself as it is too-specific a requirement to have been included in the JDK's API.
Assuming you've developed a standalone Swing application you could consider using the Preferences class to store the number of times a user has printed a document for a given date. On Windows this translates to storing information in the registry and is therefore "hidden" from the user to a certain extent, but would allow you to reset the value in an emergency using regedit.
The advantage of this approach is that the user cannot circumvent the print-threshold by simply restarting the application.
I decided to go with J2Printer. I allows the suppression of the print dialogue.

Categories

Resources