Mercurial > hg > Database > Alice
annotate src/main/java/alice/daemon/Connection.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 | bfec2c3ff1b8 |
children | 0832af83583f 646f705e65b1 |
rev | line source |
---|---|
345 | 1 package alice.daemon; |
2 | |
3 import java.net.Socket; | |
4 import java.nio.ByteBuffer; | |
5 import java.util.concurrent.LinkedBlockingQueue; | |
6 | |
7 import alice.datasegment.Command; | |
417 | 8 import alice.datasegment.DataSegment; |
458 | 9 import alice.datasegment.ReceiveData; |
478 | 10 import alice.datasegment.SendOption; |
345 | 11 |
12 public class Connection { | |
13 | |
419 | 14 public Socket socket; |
470 | 15 public String name; |
419 | 16 public LinkedBlockingQueue<Command> sendQueue = new LinkedBlockingQueue<Command>(); |
478 | 17 public boolean sendManager = true; |
345 | 18 |
419 | 19 public Connection(Socket socket) { |
20 this.socket = socket; | |
21 } | |
417 | 22 |
419 | 23 public Connection() {} |
345 | 24 |
419 | 25 public void sendCommand(Command cmd) { |
26 try { | |
27 sendQueue.put(cmd); | |
28 } catch (InterruptedException e) { | |
29 e.printStackTrace(); | |
30 } | |
31 } | |
417 | 32 |
419 | 33 public String getInfoString() { |
34 return socket.getInetAddress().getHostName() | |
35 + ":" + socket.getPort(); | |
36 } | |
345 | 37 |
467 | 38 public synchronized void write(Command cmd) { |
443 | 39 ByteBuffer buffer = cmd.convert(); |
419 | 40 try { |
41 while (buffer.hasRemaining()) { | |
42 socket.getChannel().write(buffer); | |
43 } | |
527 | 44 } catch (Exception e) { |
45 } | |
419 | 46 } |
417 | 47 |
419 | 48 public void close(){ |
49 try { | |
50 socket.shutdownOutput(); | |
51 socket.shutdownInput(); | |
52 socket.close(); | |
496 | 53 } catch (Exception e) { } |
54 putConnectionInfo(); | |
417 | 55 |
419 | 56 } |
57 | |
58 public void putConnectionInfo() { | |
470 | 59 if (name!=null){ |
473 | 60 ConnectionInfo c = new ConnectionInfo(name, socket); |
525
30a74eee59c7
working TestRemoteAlice
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
524
diff
changeset
|
61 ReceiveData rData = new ReceiveData(c); |
533
b3c9554ccb1b
change compressed API to set data specified DSM name
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
527
diff
changeset
|
62 DataSegment.getLocal().put("_DISCONNECT", rData, false); |
478 | 63 if (sendManager) { |
533
b3c9554ccb1b
change compressed API to set data specified DSM name
Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
parents:
527
diff
changeset
|
64 DataSegment.get("manager").put("_DISCONNECTNODE", rData, false); |
527 | 65 sendManager = false; |
478 | 66 } |
470 | 67 } |
419 | 68 |
69 } | |
345 | 70 } |