Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
nixel2007 committed Jun 2, 2020
2 parents 9f44026 + 2c25f41 commit 88dca5e
Showing 1 changed file with 26 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;

@Slf4j
public class ServerContext {
Expand All @@ -51,6 +53,7 @@ public class ServerContext {
private final Map<URI, String> mdoRefs = Collections.synchronizedMap(new HashMap<>());
private final Map<String, Map<ModuleType, DocumentContext>> documentsByMDORef
= Collections.synchronizedMap(new HashMap<>());
private final ReadWriteLock contextLock = new ReentrantReadWriteLock();

public ServerContext() {
this(null);
Expand All @@ -76,16 +79,18 @@ public void populateContext() {

public void populateContext(Collection<File> uris) {
LOGGER.debug("Populating context...");
contextLock.writeLock().lock();

uris.parallelStream().forEach((File file) -> {
DocumentContext documentContext = getDocument(file.toURI());
if (documentContext == null) {
documentContext = addDocument(file);
documentContext = createDocumentContext(file);
documentContext.getSymbolTree();
documentContext.clearSecondaryData();
}
});

contextLock.writeLock().unlock();
LOGGER.debug("Context populated.");
}

Expand Down Expand Up @@ -115,24 +120,17 @@ public Map<ModuleType, DocumentContext> getDocuments(String mdoRef) {
return documentsByMDORef.getOrDefault(mdoRef, Collections.emptyMap());
}

@SneakyThrows
public DocumentContext addDocument(File file) {
String content = FileUtils.readFileToString(file, StandardCharsets.UTF_8);
return addDocument(file.toURI(), content);
}

public DocumentContext addDocument(URI uri, String content) {
URI absoluteURI = Absolute.uri(uri);
contextLock.readLock().lock();

DocumentContext documentContext = getDocument(absoluteURI);
DocumentContext documentContext = getDocument(uri);
if (documentContext == null) {
documentContext = new DocumentContext(absoluteURI, content, this);
documents.put(absoluteURI, documentContext);
addMdoRefByUri(absoluteURI, documentContext);
documentContext = createDocumentContext(uri, content);
} else {
documentContext.rebuild(content);
}

contextLock.readLock().unlock();
return documentContext;
}

Expand Down Expand Up @@ -161,6 +159,22 @@ public Configuration getConfiguration() {
return configurationMetadata.getOrCompute();
}

@SneakyThrows
private DocumentContext createDocumentContext(File file) {
String content = FileUtils.readFileToString(file, StandardCharsets.UTF_8);
return createDocumentContext(file.toURI(), content);
}

private DocumentContext createDocumentContext(URI uri, String content) {
URI absoluteURI = Absolute.uri(uri);

DocumentContext documentContext = new DocumentContext(absoluteURI, content, this);
documents.put(absoluteURI, documentContext);
addMdoRefByUri(absoluteURI, documentContext);

return documentContext;
}

private Configuration computeConfigurationMetadata() {
if (configurationRoot == null) {
return Configuration.create();
Expand Down

0 comments on commit 88dca5e

Please sign in to comment.