Does bukkit access playerdata (.dat) asynchronously?

Discussion in 'Plugin Development' started by bbq, May 8, 2015.

Thread Status:
Not open for further replies.
  1. Offline

    bbq

    Hello!

    I want to access the .dat files for players, as it seems to be the easy way to get full, encoded player data for transmission. My concern of course is reading or writing to these files as the server does. So, will craftbukkit's accessing of the playerdata folders happen in the same thread as my plugin events are executed in?
     
  2. Offline

    teej107

    @bbq I doubt it. Just do it on the main thread.
     
  3. Offline

    mythbusterma

    @bbq @teej107

    I would assume it doesn't, actually. It would make sense that it would do it in the same thread that AsyncPlayerPreLoginEvent is called from, although I couldn't say for sure.

    Why do you ask the question? As long as the same file is not open on multiple threads, the File API is thread-safe.

    All that means is that you have to make sure the player is not online (and has been offline for a seconds).
     
  4. Offline

    RawCode

    you will need custom build server to delay\suspend player.dat IO.

    thread-safe != thread blocking
     
  5. Offline

    teej107

    Hmm good point. I just have no idea what thread handles the data file reading.
     
  6. Offline

    Konato_K

    I found the line that loads the data in the PlayerList class, so I would say it's done synchronously.
     
  7. Offline

    mythbusterma

    @RawCode

    No, they're not equal.

    I don't see how that relates. At all. Make sure the player is not online when you're reading the file, and if they do log in, stop reading.
     
  8. Offline

    RawCode

    looks like you have no clue about how concurrency works...

    you are reading file, if they log (inside other thread), how you going to "stop reading"?
     
  9. Offline

    mythbusterma

    @RawCode

    Maybe it just happens that I know more about concurrency than you.

    Ever heard of "interrupts?" Probably not, honestly.
     
  10. Offline

    RawCode

    ok how you going to interrupt from thread implemented by code you do not "own" eh?

    please read my very first post in this thread and some book about java
    @mythbusterma
     
  11. Offline

    mythbusterma

    @RawCode

    You don't need to "own" anything to put a listener for the pre-login event.
     
  12. Offline

    1Rogue

    /me concurrently puts popcorn in mouth
     
  13. Offline

    fireblast709

    /me concurrently steals @1Rogue 's popcorn just before he eats it.
     
  14. Offline

    1Rogue

    Code:java
    1. new Thread("fireblast709").interrupt();
     
  15. Offline

    RawCode

    interrupt is not issue, issue is interrupting from right location at right time.
     
  16. Offline

    fireblast709

    Code:java
    1. if (Thread.interrupted()) {
    2. // Nope not interrupted
    3. synchronized (1rogue) {
    4. 1rogue.wait(); // Wait for more popcorn
    5. }
    6. }
     
  17. Offline

    1Rogue

    Code:java
    1. private native void byebyeFire(Thread th);
    2.  
    3. //...
    4. System.loadLibrary("keepPopcorn");
    5. this.byebyeFire(new Thread("fireblast709"));


    Code:c
    1. #include <jni.h>
    2. #include <stdio.h>
    3. #include <signal.h>
    4.  
    5. JNIEXPORT void JNICALL Java_com_codelanx_popcorn_Keep_byebyeFire
    6. (JNIEnv * env, jobject fire)
    7. {
    8. pthread_exit(&fire);
    9. }
     
    Last edited: May 12, 2015
    Thury and Konato_K like this.
Thread Status:
Not open for further replies.

Share This Page