Mercurial > hg > Database > Alice
view src/main/java/alice/datasegment/DataSegment.java @ 533:b3c9554ccb1b dispose
change compressed API to set data specified DSM name
author | Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 04 May 2015 16:02:22 +0900 |
parents | cb7c31848d16 |
children | 82cc94d40628 |
line wrap: on
line source
package alice.datasegment; import java.util.concurrent.ConcurrentHashMap; import alice.daemon.IncomingTcpConnection; import alice.datasegment.MulticastDataSegmentManager.SocketType; import org.apache.log4j.Logger; public class DataSegment { private static DataSegment dataSegment = new DataSegment(); private LocalDataSegmentManager local = new LocalDataSegmentManager(); private CompressedLocalDataSegmentManager compressedLocal = new CompressedLocalDataSegmentManager();//追加 private ConcurrentHashMap<String, DataSegmentManager> dataSegmentManagers = new ConcurrentHashMap<String, DataSegmentManager>(); //TODO Over Head private ConcurrentHashMap<String, IncomingTcpConnection> acceptHash = new ConcurrentHashMap<String, IncomingTcpConnection>(); private DataSegment() { dataSegmentManagers.put("local", local); dataSegmentManagers.put("compressedlocal", compressedLocal); } public static DataSegmentManager get(String key) { return dataSegment.dataSegmentManagers.get(key); } public static LocalDataSegmentManager getLocal() { return dataSegment.local; } public static CompressedLocalDataSegmentManager getCompressedLocal() {//追加 return dataSegment.compressedLocal; } public static void register(String key, DataSegmentManager manager) { dataSegment.dataSegmentManagers.put(key, manager); } public static RemoteDataSegmentManager connect(String connectionKey, String reverseKey, String hostName, int port) { if (connectionKey.startsWith("compressed")){//compressedが含まれていたらエラーを返して終了 System.out.println("You can't use 'compressed' for DataSegmentManager name."); System.exit(0); } RemoteDataSegmentManager manager = new RemoteDataSegmentManager(connectionKey, reverseKey, hostName, port); CompressedRemoteDataSegmentManager compressedManager = new CompressedRemoteDataSegmentManager(connectionKey + "!", reverseKey, hostName, port); register(connectionKey, manager); register("compressed" + connectionKey, compressedManager); return manager; } public static MulticastDataSegmentManager connectMulticast(String connectionKey ,String MCSTADDR, int port, String nis, SocketType type){ MulticastDataSegmentManager manager = new MulticastDataSegmentManager(connectionKey ,MCSTADDR, port, nis, type); if (type!=SocketType.Receiver) register(connectionKey, manager); return manager; } public static void setAccept(String key, IncomingTcpConnection incoming) { dataSegment.acceptHash.put(key, incoming); } public static IncomingTcpConnection getAccept(String key) { return dataSegment.acceptHash.get(key); } public static void remove(String key){ dataSegment.dataSegmentManagers.remove(key); } public static boolean contains(String key){ return dataSegment.dataSegmentManagers.containsKey(key); } }