comparison src/main/java/christie/codegear/CodeGearManager.java @ 6:3dcfe63d6394

set type to DataGear by Annotation
author Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
date Wed, 27 Dec 2017 00:06:50 +0900
parents 5be6647b87d2
children 21372a589bd3
comparison
equal deleted inserted replaced
5:5be6647b87d2 6:3dcfe63d6394
2 2
3 import christie.datagear.DataGearManager; 3 import christie.datagear.DataGearManager;
4 import christie.datagear.LocalDataGearManager; 4 import christie.datagear.LocalDataGearManager;
5 import christie.datagear.RemoteDataGearManager; 5 import christie.datagear.RemoteDataGearManager;
6 6
7 import java.util.ArrayList; 7 import java.util.concurrent.ConcurrentHashMap;
8 import java.util.HashMap;
9 import java.util.concurrent.LinkedBlockingQueue;
10 import java.util.concurrent.ThreadFactory;
11 import java.util.concurrent.ThreadPoolExecutor; 8 import java.util.concurrent.ThreadPoolExecutor;
12 import java.util.concurrent.TimeUnit;
13 9
14 /** 10 /**
15 * Created by e125769 on 12/7/17. 11 * Created by e125769 on 12/7/17.
16 * CodeGearの実行 12 * CodeGearの実行
17 */ 13 */
18 public class CodeGearManager{ 14 public class CodeGearManager{
19 private HashMap<String, DataGearManager> dataGearManagers = new HashMap<String, DataGearManager>(); 15 private ConcurrentHashMap<String, DataGearManager> dataGearManagers = new ConcurrentHashMap<String, DataGearManager>();
20 private ThreadPoolExecutor codeGearExecutor; 16 private ThreadPoolExecutor codeGearExecutor;
21 17
22 public CodeGearManager(ThreadPoolExecutor exe) { 18 public CodeGearManager(ThreadPoolExecutor exe) {
23 dataGearManagers.put("local", new LocalDataGearManager()); 19 dataGearManagers.put("local", new LocalDataGearManager());
24 codeGearExecutor = exe; 20 codeGearExecutor = exe;
25 } 21 }
26 22
27 public void submit(CodeGear cg){ 23 public DataGearManager getDGM(){
28 codeGearExecutor.setThreadFactory(makeThreadFactory(Thread.MAX_PRIORITY)); 24 return dataGearManagers.get("local");
29 codeGearExecutor.execute(cg);
30 }
31
32 private ThreadFactory makeThreadFactory(final int priority) {
33 return new ThreadFactory() {
34 @Override
35 public Thread newThread(Runnable r) {
36 Thread thread = new Thread(r);
37 thread.setPriority(priority);
38 return thread;
39 }
40 };
41 } 25 }
42 26
43 public DataGearManager getDGM(String dest){ 27 public DataGearManager getDGM(String dest){
44 return dataGearManagers.get(dest); 28 return dataGearManagers.get(dest);
45 } 29 }
46 30
47 public void createRemoteDataGeareManager(String dist){ 31 public void createRemoteDataGeareManager(String dist){
48 dataGearManagers.put(dist, new RemoteDataGearManager()); 32 dataGearManagers.put(dist, new RemoteDataGearManager());
49 } 33 }
34
35 public void submit(CodeGear cg){
36 codeGearExecutor.execute(cg);
37 }
38
50 } 39 }