annotate src/main/java/alice/datasegment/DataSegment.java @ 650:4289b232b3fd

nulValue
author suruga
date Fri, 02 Feb 2018 18:26:49 +0900
parents 646f705e65b1
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
345
8f71c3e6f11d Change directory structure Maven standard
sugi
parents:
diff changeset
1 package alice.datasegment;
8f71c3e6f11d Change directory structure Maven standard
sugi
parents:
diff changeset
2
8f71c3e6f11d Change directory structure Maven standard
sugi
parents:
diff changeset
3 import java.util.concurrent.ConcurrentHashMap;
8f71c3e6f11d Change directory structure Maven standard
sugi
parents:
diff changeset
4
8f71c3e6f11d Change directory structure Maven standard
sugi
parents:
diff changeset
5 import alice.daemon.IncomingTcpConnection;
508
b7d02ea79850 change multicast Data Segment API
sugi
parents: 505
diff changeset
6 import alice.datasegment.MulticastDataSegmentManager.SocketType;
525
30a74eee59c7 working TestRemoteAlice
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents: 523
diff changeset
7 import org.apache.log4j.Logger;
345
8f71c3e6f11d Change directory structure Maven standard
sugi
parents:
diff changeset
8
8f71c3e6f11d Change directory structure Maven standard
sugi
parents:
diff changeset
9 public class DataSegment {
419
aefbe41fcf12 change tab to space
sugi
parents: 400
diff changeset
10
aefbe41fcf12 change tab to space
sugi
parents: 400
diff changeset
11 private static DataSegment dataSegment = new DataSegment();
aefbe41fcf12 change tab to space
sugi
parents: 400
diff changeset
12 private LocalDataSegmentManager local = new LocalDataSegmentManager();
538
8c17a9e66cc7 Compressed LDSM refactoring & flip refactoring
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents: 536
diff changeset
13 private CompressedLocalDataSegmentManager compressedLocal = new CompressedLocalDataSegmentManager(local);//追加
419
aefbe41fcf12 change tab to space
sugi
parents: 400
diff changeset
14 private ConcurrentHashMap<String, DataSegmentManager> dataSegmentManagers = new ConcurrentHashMap<String, DataSegmentManager>(); //TODO Over Head
aefbe41fcf12 change tab to space
sugi
parents: 400
diff changeset
15 private ConcurrentHashMap<String, IncomingTcpConnection> acceptHash = new ConcurrentHashMap<String, IncomingTcpConnection>();
641
646f705e65b1 setkey on remote
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 620
diff changeset
16 private static Logger log = Logger.getLogger(DataSegment.class);
419
aefbe41fcf12 change tab to space
sugi
parents: 400
diff changeset
17
aefbe41fcf12 change tab to space
sugi
parents: 400
diff changeset
18 private DataSegment() {
aefbe41fcf12 change tab to space
sugi
parents: 400
diff changeset
19 dataSegmentManagers.put("local", local);
533
b3c9554ccb1b change compressed API to set data specified DSM name
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents: 529
diff changeset
20 dataSegmentManagers.put("compressedlocal", compressedLocal);
419
aefbe41fcf12 change tab to space
sugi
parents: 400
diff changeset
21 }
aefbe41fcf12 change tab to space
sugi
parents: 400
diff changeset
22
aefbe41fcf12 change tab to space
sugi
parents: 400
diff changeset
23 public static DataSegmentManager get(String key) {
538
8c17a9e66cc7 Compressed LDSM refactoring & flip refactoring
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents: 536
diff changeset
24 if (key == null){
8c17a9e66cc7 Compressed LDSM refactoring & flip refactoring
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents: 536
diff changeset
25 return dataSegment.dataSegmentManagers.get("local");
8c17a9e66cc7 Compressed LDSM refactoring & flip refactoring
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents: 536
diff changeset
26 } else {
8c17a9e66cc7 Compressed LDSM refactoring & flip refactoring
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents: 536
diff changeset
27 return dataSegment.dataSegmentManagers.get(key);
8c17a9e66cc7 Compressed LDSM refactoring & flip refactoring
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents: 536
diff changeset
28 }
419
aefbe41fcf12 change tab to space
sugi
parents: 400
diff changeset
29 }
aefbe41fcf12 change tab to space
sugi
parents: 400
diff changeset
30
aefbe41fcf12 change tab to space
sugi
parents: 400
diff changeset
31 public static LocalDataSegmentManager getLocal() {
aefbe41fcf12 change tab to space
sugi
parents: 400
diff changeset
32 return dataSegment.local;
aefbe41fcf12 change tab to space
sugi
parents: 400
diff changeset
33 }
aefbe41fcf12 change tab to space
sugi
parents: 400
diff changeset
34
529
cb7c31848d16 add CompressedDSMs
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents: 526
diff changeset
35 public static CompressedLocalDataSegmentManager getCompressedLocal() {//追加
523
145c425db88d add CompressedLDSM
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents: 508
diff changeset
36 return dataSegment.compressedLocal;
145c425db88d add CompressedLDSM
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents: 508
diff changeset
37 }
145c425db88d add CompressedLDSM
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents: 508
diff changeset
38
419
aefbe41fcf12 change tab to space
sugi
parents: 400
diff changeset
39 public static void register(String key, DataSegmentManager manager) {
aefbe41fcf12 change tab to space
sugi
parents: 400
diff changeset
40 dataSegment.dataSegmentManagers.put(key, manager);
aefbe41fcf12 change tab to space
sugi
parents: 400
diff changeset
41 }
345
8f71c3e6f11d Change directory structure Maven standard
sugi
parents:
diff changeset
42
419
aefbe41fcf12 change tab to space
sugi
parents: 400
diff changeset
43 public static RemoteDataSegmentManager connect(String connectionKey, String reverseKey, String hostName, int port) {
533
b3c9554ccb1b change compressed API to set data specified DSM name
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents: 529
diff changeset
44 if (connectionKey.startsWith("compressed")){//compressedが含まれていたらエラーを返して終了
b3c9554ccb1b change compressed API to set data specified DSM name
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents: 529
diff changeset
45 System.out.println("You can't use 'compressed' for DataSegmentManager name.");
525
30a74eee59c7 working TestRemoteAlice
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents: 523
diff changeset
46 System.exit(0);
30a74eee59c7 working TestRemoteAlice
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents: 523
diff changeset
47 }
419
aefbe41fcf12 change tab to space
sugi
parents: 400
diff changeset
48 RemoteDataSegmentManager manager = new RemoteDataSegmentManager(connectionKey, reverseKey, hostName, port);
538
8c17a9e66cc7 Compressed LDSM refactoring & flip refactoring
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents: 536
diff changeset
49 CompressedRemoteDataSegmentManager compressedManager = new CompressedRemoteDataSegmentManager(manager);
525
30a74eee59c7 working TestRemoteAlice
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents: 523
diff changeset
50
419
aefbe41fcf12 change tab to space
sugi
parents: 400
diff changeset
51 register(connectionKey, manager);
536
d2f7d02c4976 remoteDSM refactoring
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents: 534
diff changeset
52 register("compressed" + connectionKey, compressedManager);
525
30a74eee59c7 working TestRemoteAlice
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents: 523
diff changeset
53
641
646f705e65b1 setkey on remote
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 620
diff changeset
54 log.info("connected to " + hostName + " DSMkey: " + connectionKey);
620
b6cbf3ca3d12 println
suruga
parents: 538
diff changeset
55
419
aefbe41fcf12 change tab to space
sugi
parents: 400
diff changeset
56 return manager;
aefbe41fcf12 change tab to space
sugi
parents: 400
diff changeset
57 }
aefbe41fcf12 change tab to space
sugi
parents: 400
diff changeset
58
508
b7d02ea79850 change multicast Data Segment API
sugi
parents: 505
diff changeset
59 public static MulticastDataSegmentManager connectMulticast(String connectionKey ,String MCSTADDR, int port, String nis, SocketType type){
b7d02ea79850 change multicast Data Segment API
sugi
parents: 505
diff changeset
60 MulticastDataSegmentManager manager = new MulticastDataSegmentManager(connectionKey ,MCSTADDR, port, nis, type);
b7d02ea79850 change multicast Data Segment API
sugi
parents: 505
diff changeset
61 if (type!=SocketType.Receiver)
b7d02ea79850 change multicast Data Segment API
sugi
parents: 505
diff changeset
62 register(connectionKey, manager);
419
aefbe41fcf12 change tab to space
sugi
parents: 400
diff changeset
63 return manager;
aefbe41fcf12 change tab to space
sugi
parents: 400
diff changeset
64 }
aefbe41fcf12 change tab to space
sugi
parents: 400
diff changeset
65
aefbe41fcf12 change tab to space
sugi
parents: 400
diff changeset
66 public static void setAccept(String key, IncomingTcpConnection incoming) {
aefbe41fcf12 change tab to space
sugi
parents: 400
diff changeset
67 dataSegment.acceptHash.put(key, incoming);
aefbe41fcf12 change tab to space
sugi
parents: 400
diff changeset
68 }
aefbe41fcf12 change tab to space
sugi
parents: 400
diff changeset
69
aefbe41fcf12 change tab to space
sugi
parents: 400
diff changeset
70 public static IncomingTcpConnection getAccept(String key) {
aefbe41fcf12 change tab to space
sugi
parents: 400
diff changeset
71 return dataSegment.acceptHash.get(key);
aefbe41fcf12 change tab to space
sugi
parents: 400
diff changeset
72 }
aefbe41fcf12 change tab to space
sugi
parents: 400
diff changeset
73
aefbe41fcf12 change tab to space
sugi
parents: 400
diff changeset
74 public static void remove(String key){
aefbe41fcf12 change tab to space
sugi
parents: 400
diff changeset
75 dataSegment.dataSegmentManagers.remove(key);
aefbe41fcf12 change tab to space
sugi
parents: 400
diff changeset
76 }
aefbe41fcf12 change tab to space
sugi
parents: 400
diff changeset
77
429
1b32ea1263f3 work but have bug
sugi
parents: 419
diff changeset
78 public static boolean contains(String key){
1b32ea1263f3 work but have bug
sugi
parents: 419
diff changeset
79 return dataSegment.dataSegmentManagers.containsKey(key);
1b32ea1263f3 work but have bug
sugi
parents: 419
diff changeset
80 }
345
8f71c3e6f11d Change directory structure Maven standard
sugi
parents:
diff changeset
81 }