Synchronized or ReentrantLock in smartfox?

Post here your questions about SFS2X. Here we discuss all server-side matters. For client API questions see the dedicated forums.

Moderators: Lapo, Bax

moris
Posts: 52
Joined: 17 Aug 2012, 11:11

Synchronized or ReentrantLock in smartfox?

Postby moris » 05 Nov 2015, 17:02

Hello.
Can I use synchronized or reentrantlock in smartfox, if so, where store objects of locks, and if not then what alternative solution to this problem? Thx.
User avatar
Lapo
Site Admin
Posts: 23026
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Synchronized or ReentrantLock in smartfox?

Postby Lapo » 06 Nov 2015, 09:36

Hi,
of course you can.

if so, where store objects of locks, and if not then what alternative solution to this problem? Thx.

It mostly depends on what your code does and the scope of your lock(s).

Maybe you could give us more details as to what you're trying to do?
Lapo
--
gotoAndPlay()
...addicted to flash games
moris
Posts: 52
Joined: 17 Aug 2012, 11:11

Re: Synchronized or ReentrantLock in smartfox?

Postby moris » 09 Nov 2015, 12:07

I have game rooms. After the game in the same room to move players to other rooms(if other rooms have free place), this operation must be performed for every room synchronized. I find Singleton solution and use it. What do you think is a good solution?
User avatar
Lapo
Site Admin
Posts: 23026
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Synchronized or ReentrantLock in smartfox?

Postby Lapo » 09 Nov 2015, 14:08

I am not sure why moving a User from a Room to another Room should be synchronized. The operation is already thread safe.
Lapo

--

gotoAndPlay()

...addicted to flash games
moris
Posts: 52
Joined: 17 Aug 2012, 11:11

Re: Synchronized or ReentrantLock in smartfox?

Postby moris » 09 Nov 2015, 14:21

For example:
Have 2 rooms,
Room1 - 8 players
Room2 - 9 players

Room1 end game, and 6 players leave the game, 2 players must be moved to other room - Room2. At that time Room2 also end game, and can move users. So, movement must be held in a queue and can not execute multiple threads simultaneously
User avatar
Lapo
Site Admin
Posts: 23026
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Synchronized or ReentrantLock in smartfox?

Postby Lapo » 09 Nov 2015, 17:51

I am not sure I entirely understand the use case, but in any case I don't think you need any Singleton to do what you're asking.

If you're joining users in Rooms you must be working at Zone level, therefore you can keep references to your lock objects in the Zone Extension, which is a global object if you will.
Lapo

--

gotoAndPlay()

...addicted to flash games
moris
Posts: 52
Joined: 17 Aug 2012, 11:11

Re: Synchronized or ReentrantLock in smartfox?

Postby moris » 10 Nov 2015, 14:00

Rooms can finish the game at a time and begin to move the players to each other, in this case, instead of merging the rooms (if possible) will exchange players or some players will be moved, and some - not. Each room should conduct this operation successively.
I tried to use a zone setProperty and getProperty, but in this case getting ClassCastException after reload extension.
And if create objects in the Zone, then the reload they will be re-created.
User avatar
Lapo
Site Admin
Posts: 23026
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Synchronized or ReentrantLock in smartfox?

Postby Lapo » 10 Nov 2015, 14:17

You always have the option to use the extensions/__lib__/ folder avoid class loading options, but you will have to restart the server to reload changes in the re-deployed code.
http://docs2x.smartfoxserver.com/Advanc ... assLoading

cheers
Lapo

--

gotoAndPlay()

...addicted to flash games
moris
Posts: 52
Joined: 17 Aug 2012, 11:11

Re: Synchronized or ReentrantLock in smartfox?

Postby moris » 11 Nov 2015, 08:48

Okey, thx.

Return to “SFS2X Questions”

Who is online

Users browsing this forum: Google [Bot] and 100 guests