Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

68
LINES

< > BotCompany Repo | #1031008 // readLocally / readLocally2 with 2-threaded loading

JavaX fragment (include) [tags: use-pretranspiled]

Transpiled version (5925L) is out of date.

1  
scope readLocally.
2  
3  
static void readLocally(S progID, S varNames) {
4  
  readLocally2(mc(), progID, varNames);
5  
}
6  
7  
static void readLocally(S varNames) {
8  
  readLocally2(mc(), programID(), varNames);
9  
}
10  
11  
static void readLocally2(O obj, S varNames) {
12  
  readLocally2(obj, programID(), varNames);
13  
}
14  
15  
static int readLocally_stringLength;
16  
17  
static new ThreadLocal<Bool> readLocally2_allDynamic;
18  
static new ThreadLocal readLocally2_classFinder;
19  
20  
sbool #useTwoThreads = true;
21  
22  
// read a string variable from standard storage
23  
// does not overwrite variable contents if there is no file
24  
static void readLocally2(O obj, S progID, S varNames) ctex {
25  
  bool allDynamic = isTrue(getAndClearThreadLocal(readLocally2_allDynamic));
26  
  for (S variableName : javaTokC(varNames)) {
27  
    File textFile = new File(programDir(progID), variableName + ".text");
28  
    
29  
    S value = loadTextFile(textFile);
30  
    if (value != null)
31  
      set(main.class, variableName, value);
32  
    else {
33  
      File structureFile = new File(programDir(progID), variableName + ".structure");
34  
      value = loadTextFile(structureFile);
35  
      
36  
      if (value == null) {
37  
        File structureGZFile = new File(programDir(progID), variableName + ".structure.gz");
38  
        if (!structureGZFile.isFile()) ret;
39  
        temp new CloseablesHolder ch;
40  
        Producer<S> tokenizer = gzFileTokenReaderForUnstruct(structureGZFile, ch);
41  
        if (useTwoThreads) {
42  
          tokenizer = moveProducerToNewThread(tokenizer, ch);
43  
          ifdef readLocally_debug
44  
            tokenizer = debugProducer(tokenizer);
45  
          endifdef
46  
        }
47  
        O o = unstructure_tok(tokenizer, allDynamic, readLocally2_classFinder!);
48  
        readLocally_set(obj, variableName, o);
49  
        ret;
50  
      }
51  
      
52  
      readLocally_stringLength = l(value);
53  
      if (nempty(value))
54  
        readLocally_set(obj, variableName, unstructure(value, allDynamic, readLocally2_classFinder!));
55  
    }
56  
  }
57  
}
58  
59  
static void readLocally_set(O c, S varName, O value) {
60  
  O oldValue = get(c, varName);
61  
  if (oldValue instanceof List && !(oldValue instanceof ArrayList) && value != null) {
62  
    // Assume it's a synchroList.
63  
    value = synchroList((L) value);
64  
  }
65  
  set(c, varName, value);
66  
}
67  
68  
end scope

Author comment

Began life as a copy of #1001043

download  show line numbers  debug dex  old transpilations   

Travelled to 5 computer(s): bhatertpkbcr, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, vouqrxazstgt

No comments. add comment

Snippet ID: #1031008
Snippet name: readLocally / readLocally2 with 2-threaded loading
Eternal ID of this version: #1031008/2
Text MD5: c59f49cf64d2b2a3d999e1d4f8c2d90a
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-04-19 17:58:47
Source code size: 2267 bytes / 68 lines
Pitched / IR pitched: No / No
Views / Downloads: 97 / 929
Version history: 1 change(s)
Referenced in: [show references]