Mercurial > hg > Database > Alice
view src/main/java/alice/daemon/IncomingTcpConnection.java @ 528:6ebddfac7ff6 dispose
delete RecieveData.setCompressFlag
author | kazz <kazz@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 30 Apr 2015 20:52:21 +0900 |
parents | bfec2c3ff1b8 |
children | cb7c31848d16 |
line wrap: on
line source
package alice.daemon; import java.io.EOFException; import java.io.IOException; import java.nio.channels.ClosedChannelException; import alice.datasegment.*; import org.msgpack.MessagePack; import org.msgpack.unpacker.Unpacker; import alice.codesegment.SingletonMessage; import alice.topology.manager.keeparive.RespondData; public class IncomingTcpConnection extends Thread { private Connection connection; protected DataSegmentManager manager; protected String reverseKey; private LocalDataSegmentManager lmanager = DataSegment.getLocal(); private static final MessagePack packer = new MessagePack(); public IncomingTcpConnection(DataSegmentManager manager) { this.manager = manager; } public IncomingTcpConnection(Connection connection, DataSegmentManager manager, String reverseKey) { this.manager = manager; this.connection = connection; this.reverseKey = reverseKey; } public LocalDataSegmentManager getLocalDataSegmentManager(){ return lmanager; } /** * pipeline thread for receiving */ public void run() { Unpacker unpacker = null; try { unpacker = packer.createUnpacker(connection.socket.getInputStream()); } catch (IOException e) { e.printStackTrace(); } if (unpacker == null) { return; } while (true) { try { Command cmd = null; ReceiveData rData = null; CommandMessage msg = unpacker.read(CommandMessage.class); CommandType type = CommandType.getCommandTypeFromId(msg.type); switch (type) { case UPDATE: case PUT: System.out.println("in TCP PUT"); rData = new ReceiveData(unpacker.getSerializedByteArray(unpacker.readInt()), msg.compressed); if (msg.setTime) { rData.setTime = true; rData.time = msg.time; rData.depth = msg.depth; } cmd = new Command(type, null, null, rData, 0, 0, null, null, reverseKey); lmanager.getDataSegmentKey(msg.key).runCommand(cmd); break; case PEEK: case TAKE: System.out.println("in TCP TAKE"); cmd = new Command(type, null, null, null, msg.index, msg.seq, null, null, connection); lmanager.getDataSegmentKey(msg.key).runCommand(cmd); break; case REMOVE: cmd = new Command(type, null, null, null, 0, 0, null, null, ""); lmanager.getDataSegmentKey(msg.key).runCommand(cmd); break; case REPLY: System.out.println("in TCP REPLY"); cmd = manager.getAndRemoveCmd(msg.seq); rData = new ReceiveData(unpacker.getSerializedByteArray(unpacker.readInt()));//ここのコンストラクタでx Command rCmd = new Command(type, null, null, rData, msg.index, msg.seq, null, null, ""); cmd.cs.ids.reply(cmd.receiver, rCmd); break; case PING: if (DataSegment.contains(reverseKey)) DataSegment.get(reverseKey).response(msg.key); break; case RESPONSE: rData = new ReceiveData(new RespondData(reverseKey, System.currentTimeMillis())); DataSegment.getLocal().put(msg.key, rData, null); break; default: break; } } catch (ClosedChannelException e) { return; } catch (EOFException e) { return; } catch (IOException e) { return; } } } public void setReverseKey(String name) { this.reverseKey = name; setName(name+"-IncomingTcp"); } }