Mercurial > hg > Database > Alice
view src/main/java/alice/datasegment/DataSegment.java @ 655:1c93e82e05c6 default tip
fix timestamp
author | suruga |
---|---|
date | Sat, 17 Feb 2018 00:33:00 +0900 |
parents | 646f705e65b1 |
children |
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(local);//追加 private ConcurrentHashMap<String, DataSegmentManager> dataSegmentManagers = new ConcurrentHashMap<String, DataSegmentManager>(); //TODO Over Head private ConcurrentHashMap<String, IncomingTcpConnection> acceptHash = new ConcurrentHashMap<String, IncomingTcpConnection>(); private static Logger log = Logger.getLogger(DataSegment.class); private DataSegment() { dataSegmentManagers.put("local", local); dataSegmentManagers.put("compressedlocal", compressedLocal); } public static DataSegmentManager get(String key) { if (key == null){ return dataSegment.dataSegmentManagers.get("local"); } else { 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(manager); register(connectionKey, manager); register("compressed" + connectionKey, compressedManager); log.info("connected to " + hostName + " DSMkey: " + connectionKey); 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); } }