Anylogic error "the constructor is undefined" in a resource pool - javascript

I was trying to do a simulation of distribution center model using the tips from anylogic to our own, cause they work in similar ways but diferent products and warehouses, so the thing is when a truck came to our center we have to unload in a determinated area thats why we use the "Muelle" agent to determine all the parameters involved in this operation, and when we call this new recourse unit in the resource pool for the unload process the error appears
Code use in a resource pool:
I got the same problem y two resource pool's
Problems
Im relatively new in this program and dont know how to fix this cause for the java description, i tought the variable was already defined cause i name it and was giving every value for each parameter so i dont understand.
I attach the file so if someone requires and can inquire more to solve this ill appreciate it so much
https://drive.google.com/file/d/1uBQyLr_LyjN9J07y_J_44ha4CSskVP8y/view?usp=sharing

If Muelle is an agent, you cannot create/instantiate them like Java objects (i.e. new Muelle(...).
You must use the agent constructor that AnyLogic provides: For every agent population, you get add_myPopulation(...) and remove_MyPopulation(...) methods. You must use those.
So create an empty (?) agent population and use that. Then, call add_MyPopulationOfMuelle(...)
Check the help for more info on agent creation and populations

Related

Recovering identity in Blazor application

I have a Blazor server side application with a custom identityprovider.
Whenever I need to recover the identity I do so from the session storage using javascript.
This all works well.
But now I have added an upload control and I have embedded it with <CascadingAuthenticationState> to see if the identity was still known until that point, which it is.
Once I try to upload a file it makes a call to a controller using routing and that's where it goes haywire.
Once I enter the constructor of the controller the identity is null.
All attempts to recover it using javascript result in
JavaScript interop calls cannot be issued at this time. This is
because the component is being statically rendered
While I am familiar with this error message, I am puzzled why this happens because the render mode of the application is Server and not ServerPrerendered.
Is it because I am in a post event?
I've also played with several ways passing the httpcontext but that's also null.
Basically what I'm trying to accomplish is that I need my token there to call an API, but I've lost all track of who I am at that point.
I can think of ugly solutions like passing it in the URL, but that's not safe at all.
Or store it in a singleton with a lock or something like that, but those are all fugly solutions.
Can anyone kick me into right direction? I feel like I'm running into a very large, very dark forest now.
The vendor of the component added a new event to add custom headers, so now my problem is solved.

Discord.js client.on guildMemberAdd firing multiple times

As the title explain, i have a function on discord.js (v12) bot which takes care of welcoming users, and imposing a specific role on them, this:
client.on("guildMemberAdd", member => {
member.roles.add('604250195001081859');
member.guild.channels.cache.get("707323130523418686").send(`Hi ${member.user} blabla`);
console.log(member.user.id + ' is in da house');
});
Now, I have a problem: every time someone join server it's like this event is triggered many times over and over again, flooding the channel.
Obviously this does not happen if I set "client.once" but in that case the message is given only at the first access of a user, the second does not receive it anymore.
I've been looking everywhere for answers, but I seem to be the only run into this issues, I hope someone can help me.
p.s.
I want to clarify haven't other active instances of the bot, and that it is hosted on a small vultr's vps.
Ok after a bit i found the problem... if you run into this check in entire project to find this method call:
client.login(<token>)
If it's called within a keepalive function, or in any case in a function called several times after/ouside the server startup, it creates a new instance of the bot and each of them will respond to events, effectively creating a flood of messages (in case of chat messages, but any operation inside the function is repeated for the number of instances created).
In short, the login() method only needs to be called once to avoid creating new instances.
And Yes, You can throw me all the rotten tomatoes you want now.
This happens to me a lot go to the discord dev portal and generate a new token and paste the new token into your code. For some reason its running multiple instances of your bot at the same time and generating a new token should fix that issue. I know you said you dont have multiple instances running but you will not be able to see the instances, its a weird bug.

Accessing properties of object using JXA

I'm trying to access the properties of an object in an app called Papers3 using JXA. I'm new to JXA and this is proving challenging, especially because of the lack of documentation.
Here is a shot of the dictionary for the object I'm trying to look at
I'm trying to get the IDs for the currently displayed windows in the app.
My attempt at this is:
var Papers = Application('Papers');
Papers.includeStandardAdditions = true
Papers.libraryWindow.displayedPublications()
Running it throws an error and the output is:
Error on line 4: TypeError: Papers.libraryWindow.displayedPublications is not a function. (In 'Papers.libraryWindow.displayedPublications()', 'Papers.libraryWindow.displayedPublications' is undefined)
Error -2700: Script error.
Also, if I call just Papers.libraryWindow
The result is:
[function anonymous] {
"name":"",
"prototype":{"constructor":[function anonymous]}
}
I'm not sure what to do.
Well, JXA is broken obfuscated moribund junk and AS not much better off either, but the key thing to understand here is that Apple event IPC is not OOP, it is RPC + simple first-class relational queries. Despite the syntactic sugar, its closest relative is actually SQL database programming, not browser DOM manipulation, so once you get your head around that it’ll [hopefully] start to make a bit more sense.
An “AppleScriptable” application presents its data as a heavily abstracted relational graph—an “Apple Event Object Model”—where each node is related to other nodes by one-to-one and/or one-to-many relationships. There’s no such thing as “classes” or “objects” in the OO sense; it’s just the jargon that got attached for documentation purposes. Thus what an application’s dictionary calls a “property” is either a simple attribute containing a primitive value (number, string, list, etc; e.g. the name property of a Finder file) or a one-to-one relationship (e.g. the current track property of iTunes’ application), and what it calls “elements” is a one-to-many relationship (in your case, the libraryWindows elements of Papers’ application object).
For example, Papers.libraryWindows.displayedPublications.get() should return a list of the displayed publications of every library window in Papers (though whether that actually works in practice depends on how well implemented an app’s AEOM is, not to mention JXA’s own implementation issues); or you can use various reference forms (by-index, by-name, etc; though several are broken/unsupported in JXA) to narrow your query to, say, just the first library window, e.g. Papers.libraryWindows[0].displayedPublications.get().
You might get some insight from browsing the NodeAutomation documentation, which includes a rough overview of AEOM and how to assemble queries which you then send to it via commands (remote procedure calls) to resolve and process as it sees fit. JXA syntax isn’t as pretty, and various operations that work perfectly in AS barf in JXA, but it’ll give you a rough idea.
That said, I strongly recommend sticking to AppleScript. The language is a mess, but at least it has some documentation and user community to help you find your way around it (even if they don’t deeply understand it either).
It's a little detail, I think. libraryWindow needs to be plural and it's necessary to specify which one. You can use several forms:
Index form eg. libraryWindows[0]
ByName eg. libraryWindows.byName('Papers')
So, to access the first library window, you use: libraryWindows[0].
Try this:
(() => {
'use strict'
const app = Application('Papers');
const oWin = app.libraryWindows[0]
return oWin.displayedPublications()
})();
For Papers 3 specific JXA examples, see:
mac-scripting - Automation scripts for macOS
For more general info, see:
JXA Resources

LoopBack REST Middleware Modify Object Before Response

Just looking for a bit of theory here as going through the Strongloop documentation doesn't seem to help with my problem.
What I'd like to do is set up some middleware that can combine the requested object with other details; effectively what I have is objects that contain a user's ID and I'd like to have the server query the username and a couple of other details and collate the information into one object and respond with the new object.
So far I've literally just got some middleware running upon every API endpoint call and able to tell which route it is, but I don't know where to go from there. The REST response object is seemingly disconnected and I'm not sure how to access it. I'm not even sure it's been created at this point; is that where the routes:after phase might be used?
Many thanks in advance for any help, completely lost right now.

Meteor: Check how many clients are subscribed to a certain publish function

Is there a way of checking the number of currently subscribed clients to a certain publish function? Problem is that I have different groups where every group has its own unique ghash.
When a user chooses to leave a group and enters a new one, this ghash changes and THE SAME publish function is subscribed, although with a different ghash of course.
So I am looking for a way to check how many clients are subscribed to each group/ghash at a time (at the server side). I've been fiddeling around all day with stuff like this but it does not work that well to be honest. I am also listening for the "unsub" event of sockets and all that but still ... this is all buggy as hell.
If some one's interested in my whole code, you can find it here! (I found it too long to paste it here into my post.)
I really hope someone can help! :-)
cheers, P
EDIT: Or in other words: Is there a way to count the number of clients currently connected to a sockjs websocket where all these websockets were called with the same params?
=========================================================================
EDIT 2:
New version: LINK
For some reason this is not working at all ... No inserts are made because the ghash provided to the subscription is NEVER equal to any of the actual socket subscriptions (--> see lin 20: ghash is never equal to ghash2). I just don't understand how this is possible? the whole subscription function is called each time the Session ghash changes. How can this var never be equal to the param submitted to the actual socket (submission)? (it's always also a ghash, but always a ghash of another group).
I am really lost here! :-(
I now see you are doing straight old node style socket.io programming. I've done similar things in node projects. This is maybe the real question. On the docs for Meteor they don't even use the word socket. Maybe someone else would get into that new question with you, but this question about tracking subscribers is answered by this answer.
I think meteor is a new world, and will handle such stuff for you, if you adapt to its way of thinking. For example, make a collection of messages, with a field for chatroom. Each client picks their chatroom, finds those messages.find({chatroom:'box5'}), and displays them. A new message automatically goes to every client that is listening to that chatroom. Let Meteor use sockets for you.
Answer to counting clients subscribed to something:
Pseudo code:
Make an object to hold the counts of each subscription signature
counts = {}
on signup, Make a string that represents the subscription uniquely, add it to your counting object.
counts['params as string'] += 1;
on signout
counts['params as string'] -= 1;
The logic to know when no one is still subscribed is this:
done = (0 == counts['params as string'] )
Apparently as I know as of now it is not possible to do this.
I did some research and tried many things but for some reason sometimes multiple websockets are opened for trasnfering the same data to the same client. --> counting the number of clients connected is impossible via this approach.
Just triggering an event when my ghash changes is also not good enough as a close of the browser window would not trigger it.
I think having a functionality to count the number of clients "viewing the same data changes" (can't think of a better way to put it) would be awesome. Maybe some meteor core dev can just put his/her 2 cents in here so we know if this is even possible at all.
I hope someone can come up with a solution at some point .. I can't! :(
My user-status package tracks the number of clients connected to a Meteor app by tracking the number of subscriptions to a global publish function. You may be able to draw some inspiration from it. It's not granular at the per-publication level, but you can certainly do the same thing for publications that you are interested in.
https://github.com/mizzao/meteor-user-status
The main points to note are
each open session will call the subscription (users may have more than one tab open)
each time a user logs in our out, the subscription will update
you can read the per-session id in the publish function
you can listen to the close event for the SockJS socket for browser tabs being closed, etc.
I don't think it would be too hard to do this for groups; I am doing the same thing for another project.

Categories