123
-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987 0|646|0 -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=-
Socoder -> C/C++/C#/Other -> asyncronous chat in java.....concurrency....

Wed, 27 Feb 2013, 14:46
Orion Pax
Sorry guys for being gone again. Sorta out of work and had to search like my life depended on it for another job. And still jobless....lol. And been busy with my minecraft server and making plugins for them.

At any rate I have came across an issue. We needed our own admin chat plugin as one of the mods we had (which had it) we decided to remove it. I made one but not 100% sure about my implementation of concurrency and asyncronous events in java. This isnt JUST a minecraft/bukkit plugin thing. Its actually a java implementation of concurrency and that is way above my head, but i think i have it figured out but not sure.

I hope you guys can shed some light on this and let me know.

https://github.com/Paxination/OasisChat

There is my code on github. Let me know what you think. And ask me any other questions that would help with my problem.

Oh I just need to know if I have made sure that my chat event stays synchronized with bukkit.

And a link to the async player chat event....
https://jd.bukkit.org/rb/apidocs/org/bukkit/event/player/AsyncPlayerChatEvent.html
Wed, 27 Feb 2013, 21:34
Afr0
Uhm... looks legit.
But the thing is tiny!
Seems to me that if Bukkit is async, so your code should be.

-=-=-
Afr0 Games

Project Dollhouse on Github - Please fork!
Wed, 27 Feb 2013, 23:01
Orion Pax
Most of bukkit is asynchronous, but using asynchronous chat is supposedly not very safe unless you make it RESYNC with the main thread. The only thing changed during my chat event is a variable that marks whether or not staff has ADMIN CHAT ONLY toggled on or off. That is it. I fount the

synchronized(variable)(blah blah blah)

method in the java docs about concurrency. but i am just not sure if I implemented it correctly. I dont get errors but does it do what I need it to do.

I appreciate your help afro.
Wed, 27 Feb 2013, 23:29
Afr0
I dont get errors but does it do what I need it to do


I'd say the best way to determine that would be by testing it.

-=-=-
Afr0 Games

Project Dollhouse on Github - Please fork!
Thu, 28 Feb 2013, 12:21
Orion Pax
Allready have tested and have been using it. But since we updated several other plugins and bukkit server the time we started using it, we have had issues. And I am trying to rule out this plugin. We cant run the server for more than 24 hours or it crashes completely. And this weird lag on and off.
Thu, 28 Feb 2013, 14:23
Afr0
Think you should ask on the bukkit forums or something. Seems you'd be more likely to get a better answer there.

-=-=-
Afr0 Games

Project Dollhouse on Github - Please fork!
Sat, 02 Mar 2013, 13:46
Orion Pax
Not really. They just tell me to read up on the concurrency stuff in java. Which is very complicated in my understanding.

And I dont really care for their attitudes. They tend to be cocky and not straight to the point.
Sat, 02 Mar 2013, 14:34
Afr0
I know what you mean.
But ultimately, if you can't get your answer(s) from others (for whatever reason), you need to do your own research.
I'll bet at least 1/4 of my time working on Project Dollhouse has been spent on research.

-=-=-
Afr0 Games

Project Dollhouse on Github - Please fork!
Sat, 02 Mar 2013, 14:36
Jayenkai
Yeah, official forum tend to have sickening amounts of elitism. Bah, humbug.

... On the other hand.. Sorry, Pax, I haven't the foggiest idea how to even begin doing anything like that! I think the number of oddities in this site should suggest that!!

-=-=-
''Load, Next List!''
Sun, 03 Mar 2013, 02:11
Afr0
The only thing I notice when looking a second time at your code, ia that you're doing:



I have no idea if it'll make any difference, but try accessing Bukkit.getServer.getOnlinePlayers() directly, and looping through it in a regular fashion. Instance variables in threaded code can sometimes have unexpected sideeffects. As a general rule (though it isn't applicable to this piece of code), variables that need to be accessed by multiple threads must be static. If nothing else, doing it the way I suggested should be marginally faster.

Also, I noticed:



Your code is running on a separate thread? o.O
That could cause issues like you wouldn't believe...

-=-=-
Afr0 Games

Project Dollhouse on Github - Please fork!
Sun, 03 Mar 2013, 04:56
CodersRule
I'm not too experienced, but wouldn't calling getOnlinePlayers() make it LESS thread-safe? The for loop will call that method every time it iterates, making it take longer; and if a player were to log out in the middle of the for loop's execution, the iteration might get messed up. Those problems should be solved by getting the online players directly before executing the loop:


Sun, 03 Mar 2013, 08:08
Afr0
and if a player were to log out in the middle of the for loop's execution, the iteration might get messed up.


That's why I said: loop through it in a regular fashion, I.E:



-=-=-
Afr0 Games

Project Dollhouse on Github - Please fork!
Sun, 03 Mar 2013, 08:42
CodersRule
You'd have the same problem, though: since you're getting the online players on every iteration, the iteration could fail if a player logs off halfway through.

If the server has, for example, 100 people online, and the loop has made it through the first 50 people, what happens when the 25th person (who has already been counted) logs off? The next time you request the array, you'll find that all of the players have been shifted over one index to the left, and you'll end up skipping the 51st player. That's avoided by getting the array once and shoving it into a variable, and then iterating over the variable.

I also don't think the order of the players in getOnlinePlayers() is defined, so you shouldn't rely on it remaining the same for each iteration.
Sun, 03 Mar 2013, 09:59
Afr0
That's avoided by getting the array once and shoving it into a variable, and then iterating over the variable.


Which is still problematic though, because, as you say, the array could have changed halfway through, so in the best possible situation you end up sending the message to only the players that were present when you entered the function.

In other words, Orion should probably add some code to check if the array/list has changed after he's finished looping through the local instance.

-=-=-
Afr0 Games

Project Dollhouse on Github - Please fork!
Thu, 07 Mar 2013, 16:22
Orion Pax


My plugin isnt run in multiple threads. But as I said the event AsyncPlayerChatEvent is asynchronous from the main thread and according to bukkits docs, accessing the event and changing anything during that event can cause problems. So I am hoping the above code fixes that issue. Which was my original question. Does the above code keep my array synchronized with the main thread?

Yeah eventually I will go back and clean up my code and add some checks to my loops.

Also, I've done research on the synchronized method and concurrency. I havent got much of an idea about it all yet. From what I see and read, that this is all I need to do, but not 100% sure.
Thu, 07 Mar 2013, 20:32
Orion Pax
[url=https://forums.bukkit.org/threads/plugin-help-info-on-help-in-game.133458/#post-1577854][/url]

This is the stupid shit I hate about them. This retarded one line, completely useless basically its just frickin trolling messages.

Make a plugin.yml file.....IS HE FRICKEN RETARDED! My plugin would not even LOAD WITH OUT IT! OF COURSE I HAVE ONE. SOrry, needed to rage and if I did it there, yeah you guys know. This is why I have come here. Your better than this. Unless the author of the thread is just being retarded then yeah treat them as so....lol.