annotate src/fdl/test/metaTransfer/MetaProtocolEngine_not.java @ 53:629b6cfbd37f

metaprotocol ring
author axmo
date Mon, 19 Jan 2009 17:49:14 +0900
parents
children 82a292aa41ad
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
53
629b6cfbd37f metaprotocol ring
axmo
parents:
diff changeset
1 package fdl.test.metaTransfer;
629b6cfbd37f metaprotocol ring
axmo
parents:
diff changeset
2
629b6cfbd37f metaprotocol ring
axmo
parents:
diff changeset
3 import java.io.IOException;
629b6cfbd37f metaprotocol ring
axmo
parents:
diff changeset
4 import java.nio.ByteBuffer;
629b6cfbd37f metaprotocol ring
axmo
parents:
diff changeset
5
629b6cfbd37f metaprotocol ring
axmo
parents:
diff changeset
6 import fdl.FederatedLinda;
629b6cfbd37f metaprotocol ring
axmo
parents:
diff changeset
7 import fdl.MetaEngine;
629b6cfbd37f metaprotocol ring
axmo
parents:
diff changeset
8 //import fdl.MetaReply;
629b6cfbd37f metaprotocol ring
axmo
parents:
diff changeset
9 import fdl.MetaLinda;
629b6cfbd37f metaprotocol ring
axmo
parents:
diff changeset
10 import fdl.PSXLinda;
629b6cfbd37f metaprotocol ring
axmo
parents:
diff changeset
11 import fdl.PSXReply;
629b6cfbd37f metaprotocol ring
axmo
parents:
diff changeset
12
629b6cfbd37f metaprotocol ring
axmo
parents:
diff changeset
13
629b6cfbd37f metaprotocol ring
axmo
parents:
diff changeset
14 public class MetaProtocolEngine_not implements MetaEngine {
629b6cfbd37f metaprotocol ring
axmo
parents:
diff changeset
15 private FederatedLinda fdlmeta;
629b6cfbd37f metaprotocol ring
axmo
parents:
diff changeset
16 private ByteBuffer data = ByteBuffer.allocate(1024);
629b6cfbd37f metaprotocol ring
axmo
parents:
diff changeset
17 private int id = 10;
629b6cfbd37f metaprotocol ring
axmo
parents:
diff changeset
18 private boolean running = true;
629b6cfbd37f metaprotocol ring
axmo
parents:
diff changeset
19
629b6cfbd37f metaprotocol ring
axmo
parents:
diff changeset
20 //ここからsend用宣言
629b6cfbd37f metaprotocol ring
axmo
parents:
diff changeset
21 private PSXLinda sendpsx,getpsx;
629b6cfbd37f metaprotocol ring
axmo
parents:
diff changeset
22 private String host = "127.0.0.1";
629b6cfbd37f metaprotocol ring
axmo
parents:
diff changeset
23 private int port;
629b6cfbd37f metaprotocol ring
axmo
parents:
diff changeset
24
629b6cfbd37f metaprotocol ring
axmo
parents:
diff changeset
25 public MetaProtocolEngine_not(MetaLinda fdlmeta, int port) {
629b6cfbd37f metaprotocol ring
axmo
parents:
diff changeset
26 this.port = port;
629b6cfbd37f metaprotocol ring
axmo
parents:
diff changeset
27 }
629b6cfbd37f metaprotocol ring
axmo
parents:
diff changeset
28
629b6cfbd37f metaprotocol ring
axmo
parents:
diff changeset
29 public void metaOpen(int sendport){
629b6cfbd37f metaprotocol ring
axmo
parents:
diff changeset
30 try{
629b6cfbd37f metaprotocol ring
axmo
parents:
diff changeset
31 sendpsx = fdlmeta.open(host, sendport);
629b6cfbd37f metaprotocol ring
axmo
parents:
diff changeset
32 }catch (IOException e) {
629b6cfbd37f metaprotocol ring
axmo
parents:
diff changeset
33 e.printStackTrace();
629b6cfbd37f metaprotocol ring
axmo
parents:
diff changeset
34 }
629b6cfbd37f metaprotocol ring
axmo
parents:
diff changeset
35 }
629b6cfbd37f metaprotocol ring
axmo
parents:
diff changeset
36
629b6cfbd37f metaprotocol ring
axmo
parents:
diff changeset
37 //meta部分のデータ取得
629b6cfbd37f metaprotocol ring
axmo
parents:
diff changeset
38 public void metaTrans() {
629b6cfbd37f metaprotocol ring
axmo
parents:
diff changeset
39 try {
629b6cfbd37f metaprotocol ring
axmo
parents:
diff changeset
40 getpsx = fdlmeta.open(host, 10001);
629b6cfbd37f metaprotocol ring
axmo
parents:
diff changeset
41 } catch (IOException e) {
629b6cfbd37f metaprotocol ring
axmo
parents:
diff changeset
42 e.printStackTrace();
629b6cfbd37f metaprotocol ring
axmo
parents:
diff changeset
43 }
629b6cfbd37f metaprotocol ring
axmo
parents:
diff changeset
44 PSXReply in = getpsx.in(id);
629b6cfbd37f metaprotocol ring
axmo
parents:
diff changeset
45 while (running) {
629b6cfbd37f metaprotocol ring
axmo
parents:
diff changeset
46 System.out.println(in);
629b6cfbd37f metaprotocol ring
axmo
parents:
diff changeset
47 System.out.println(in.ready());
629b6cfbd37f metaprotocol ring
axmo
parents:
diff changeset
48 if(in.ready()) {
629b6cfbd37f metaprotocol ring
axmo
parents:
diff changeset
49 data = in.getData();
629b6cfbd37f metaprotocol ring
axmo
parents:
diff changeset
50 sendpsx.out(id, data);
629b6cfbd37f metaprotocol ring
axmo
parents:
diff changeset
51 running = false;
629b6cfbd37f metaprotocol ring
axmo
parents:
diff changeset
52 break;
629b6cfbd37f metaprotocol ring
axmo
parents:
diff changeset
53 }
629b6cfbd37f metaprotocol ring
axmo
parents:
diff changeset
54 }
629b6cfbd37f metaprotocol ring
axmo
parents:
diff changeset
55 }
629b6cfbd37f metaprotocol ring
axmo
parents:
diff changeset
56
629b6cfbd37f metaprotocol ring
axmo
parents:
diff changeset
57
629b6cfbd37f metaprotocol ring
axmo
parents:
diff changeset
58 public void mainLoop() {
629b6cfbd37f metaprotocol ring
axmo
parents:
diff changeset
59 System.out.println("MetaProtocolEngine Start");
629b6cfbd37f metaprotocol ring
axmo
parents:
diff changeset
60 fdlmeta = FederatedLinda.init();
629b6cfbd37f metaprotocol ring
axmo
parents:
diff changeset
61 if( port == 10002 ) {
629b6cfbd37f metaprotocol ring
axmo
parents:
diff changeset
62 metaOpen(10003);
629b6cfbd37f metaprotocol ring
axmo
parents:
diff changeset
63 metaTrans();
629b6cfbd37f metaprotocol ring
axmo
parents:
diff changeset
64 try {
629b6cfbd37f metaprotocol ring
axmo
parents:
diff changeset
65 fdlmeta.sync();
629b6cfbd37f metaprotocol ring
axmo
parents:
diff changeset
66 } catch (IOException e) {
629b6cfbd37f metaprotocol ring
axmo
parents:
diff changeset
67 e.printStackTrace();
629b6cfbd37f metaprotocol ring
axmo
parents:
diff changeset
68 }
629b6cfbd37f metaprotocol ring
axmo
parents:
diff changeset
69 System.out.println("MetaProtocolEngine Connect");
629b6cfbd37f metaprotocol ring
axmo
parents:
diff changeset
70 }
629b6cfbd37f metaprotocol ring
axmo
parents:
diff changeset
71
629b6cfbd37f metaprotocol ring
axmo
parents:
diff changeset
72 }
629b6cfbd37f metaprotocol ring
axmo
parents:
diff changeset
73
629b6cfbd37f metaprotocol ring
axmo
parents:
diff changeset
74 }