Mercurial > hg > Database > Alice
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 |
rev | line source |
---|---|
345 | 1 package alice.datasegment; |
2 | |
3 import java.util.concurrent.ConcurrentHashMap; | |
4 | |
5 import alice.daemon.IncomingTcpConnection; | |
508 | 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 | 8 |
9 public class DataSegment { | |
419 | 10 |
11 private static DataSegment dataSegment = new DataSegment(); | |
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 | 14 private ConcurrentHashMap<String, DataSegmentManager> dataSegmentManagers = new ConcurrentHashMap<String, DataSegmentManager>(); //TODO Over Head |
15 private ConcurrentHashMap<String, IncomingTcpConnection> acceptHash = new ConcurrentHashMap<String, IncomingTcpConnection>(); | |
641 | 16 private static Logger log = Logger.getLogger(DataSegment.class); |
419 | 17 |
18 private DataSegment() { | |
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 | 21 } |
22 | |
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 | 29 } |
30 | |
31 public static LocalDataSegmentManager getLocal() { | |
32 return dataSegment.local; | |
33 } | |
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 | 39 public static void register(String key, DataSegmentManager manager) { |
40 dataSegment.dataSegmentManagers.put(key, manager); | |
41 } | |
345 | 42 |
419 | 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 | 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 | 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 | 54 log.info("connected to " + hostName + " DSMkey: " + connectionKey); |
620 | 55 |
419 | 56 return manager; |
57 } | |
58 | |
508 | 59 public static MulticastDataSegmentManager connectMulticast(String connectionKey ,String MCSTADDR, int port, String nis, SocketType type){ |
60 MulticastDataSegmentManager manager = new MulticastDataSegmentManager(connectionKey ,MCSTADDR, port, nis, type); | |
61 if (type!=SocketType.Receiver) | |
62 register(connectionKey, manager); | |
419 | 63 return manager; |
64 } | |
65 | |
66 public static void setAccept(String key, IncomingTcpConnection incoming) { | |
67 dataSegment.acceptHash.put(key, incoming); | |
68 } | |
69 | |
70 public static IncomingTcpConnection getAccept(String key) { | |
71 return dataSegment.acceptHash.get(key); | |
72 } | |
73 | |
74 public static void remove(String key){ | |
75 dataSegment.dataSegmentManagers.remove(key); | |
76 } | |
77 | |
429 | 78 public static boolean contains(String key){ |
79 return dataSegment.dataSegmentManagers.containsKey(key); | |
80 } | |
345 | 81 } |