-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
subhra74
committed
Jul 5, 2019
1 parent
e472260
commit 678d1b4
Showing
14 changed files
with
747 additions
and
718 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
93 changes: 45 additions & 48 deletions
93
app/src/main/java/webshell/app/files/SearchOperations.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,45 @@ | ||
/** | ||
* | ||
*/ | ||
package webshell.app.files; | ||
|
||
import java.util.Map; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
import java.util.concurrent.ExecutorService; | ||
import java.util.concurrent.Executors; | ||
import java.util.stream.Collectors; | ||
|
||
import org.springframework.stereotype.Component; | ||
|
||
import webshell.app.files.search.SearchResult; | ||
import webshell.app.files.search.SearchTask; | ||
|
||
/** | ||
* @author subhro | ||
* | ||
*/ | ||
@Component | ||
public class SearchOperations { | ||
private final Map<String, SearchTask> pendingOperations = new ConcurrentHashMap<>(); | ||
private final ExecutorService threadPool = Executors.newFixedThreadPool(5); | ||
|
||
public String createSearchTask(String folder, String searchText) { | ||
SearchTask task = new SearchTask(folder, searchText); | ||
pendingOperations.put(task.getId(), task); | ||
threadPool.submit(task); | ||
return task.getId(); | ||
} | ||
|
||
public SearchResult getSearchResult(String id, int fileIndex, | ||
int folderIndex) { | ||
SearchTask task = pendingOperations.get(id); | ||
SearchResult res = new SearchResult(task.isDone(), | ||
task.getFiles().stream().skip(fileIndex) | ||
.collect(Collectors.toList()), | ||
task.getFolders().stream().skip(folderIndex) | ||
.collect(Collectors.toList())); | ||
return res; | ||
} | ||
|
||
public void cancelSearch(String id) { | ||
SearchTask task = pendingOperations.get(id); | ||
task.stop(); | ||
} | ||
} | ||
/** | ||
* | ||
*/ | ||
package webshell.app.files; | ||
|
||
import java.util.Map; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
import java.util.concurrent.ExecutorService; | ||
import java.util.concurrent.Executors; | ||
import java.util.stream.Collectors; | ||
|
||
import org.springframework.stereotype.Component; | ||
|
||
import webshell.app.files.search.SearchResult; | ||
import webshell.app.files.search.SearchTask; | ||
|
||
/** | ||
* @author subhro | ||
* | ||
*/ | ||
@Component | ||
public class SearchOperations { | ||
private final Map<String, SearchTask> pendingOperations = new ConcurrentHashMap<>(); | ||
private final ExecutorService threadPool = Executors.newFixedThreadPool(5); | ||
|
||
public String createSearchTask(String folder, String searchText) { | ||
SearchTask task = new SearchTask(folder, searchText); | ||
pendingOperations.put(task.getId(), task); | ||
threadPool.submit(task); | ||
return task.getId(); | ||
} | ||
|
||
public SearchResult getSearchResult(String id, int fileIndex, | ||
int folderIndex) { | ||
SearchTask task = pendingOperations.get(id); | ||
SearchResult res = new SearchResult(task.isDone(), task.getFiles() | ||
.stream().skip(fileIndex).collect(Collectors.toList())); | ||
return res; | ||
} | ||
|
||
public void cancelSearch(String id) { | ||
SearchTask task = pendingOperations.get(id); | ||
task.stop(); | ||
} | ||
} |
128 changes: 57 additions & 71 deletions
128
app/src/main/java/webshell/app/files/search/SearchResult.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,71 +1,57 @@ | ||
/** | ||
* | ||
*/ | ||
package webshell.app.files.search; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* @author subhro | ||
* | ||
*/ | ||
public class SearchResult { | ||
/** | ||
* @param isDone | ||
* @param files | ||
* @param folders | ||
*/ | ||
public SearchResult(boolean isDone, List<String> files, | ||
List<String> folders) { | ||
super(); | ||
this.isDone = isDone; | ||
this.files = files; | ||
this.folders = folders; | ||
} | ||
|
||
private boolean isDone; | ||
private List<String> files = new ArrayList<>(), folders = new ArrayList<>(); | ||
|
||
/** | ||
* @return the isDone | ||
*/ | ||
public boolean isDone() { | ||
return isDone; | ||
} | ||
|
||
/** | ||
* @param isDone the isDone to set | ||
*/ | ||
public void setDone(boolean isDone) { | ||
this.isDone = isDone; | ||
} | ||
|
||
/** | ||
* @return the files | ||
*/ | ||
public List<String> getFiles() { | ||
return files; | ||
} | ||
|
||
/** | ||
* @param files the files to set | ||
*/ | ||
public void setFiles(List<String> files) { | ||
this.files = files; | ||
} | ||
|
||
/** | ||
* @return the folders | ||
*/ | ||
public List<String> getFolders() { | ||
return folders; | ||
} | ||
|
||
/** | ||
* @param folders the folders to set | ||
*/ | ||
public void setFolders(List<String> folders) { | ||
this.folders = folders; | ||
} | ||
} | ||
/** | ||
* | ||
*/ | ||
package webshell.app.files.search; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import webshell.app.files.FileInfo; | ||
|
||
/** | ||
* @author subhro | ||
* | ||
*/ | ||
public class SearchResult { | ||
/** | ||
* @param isDone | ||
* @param files | ||
* @param folders | ||
*/ | ||
public SearchResult(boolean isDone, List<FileInfo> files) { | ||
super(); | ||
this.isDone = isDone; | ||
this.files = files; | ||
} | ||
|
||
private boolean isDone; | ||
private List<FileInfo> files = new ArrayList<>(); | ||
|
||
/** | ||
* @return the isDone | ||
*/ | ||
public boolean isDone() { | ||
return isDone; | ||
} | ||
|
||
/** | ||
* @param isDone the isDone to set | ||
*/ | ||
public void setDone(boolean isDone) { | ||
this.isDone = isDone; | ||
} | ||
|
||
/** | ||
* @return the files | ||
*/ | ||
public List<FileInfo> getFiles() { | ||
return files; | ||
} | ||
|
||
/** | ||
* @param files the files to set | ||
*/ | ||
public void setFiles(List<FileInfo> files) { | ||
this.files = files; | ||
} | ||
} |
Oops, something went wrong.