Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
3e4bd71a6dd32677d3c578e1fa5e16a8ecc7b161
[jaceP2P.git] / src / jaceP2P / SenderRmi.java
1 package jaceP2P;
2
3 public class SenderRmi extends Sender {
4
5         // attributes
6         static SenderRmi Instance = null;
7
8         // constructors
9         public static SenderRmi Instance() {
10                 if (Instance == null) {
11                         Instance = new SenderRmi();
12                 }
13                 return Instance;
14         }
15
16         public SenderRmi() {
17                 setPriority(MAX_PRIORITY);
18                 running = true;
19                 buffer = new JaceBuffer();
20                 Instance = this;
21         }
22
23         // methods
24         public void kill() {
25                 Instance = null;
26         }
27
28         public void run() {
29                 msg = null ;
30                 int site_delay = 0 ;
31
32                 while (running) {
33                         // consumme the msg to send (doing a wait, so the msg is processed
34                         // immediately)
35
36                         msg = buffer.get();
37
38                         if (msg.getReceiver() == null) {
39 //                              System.out.println("in jaceSend recv = null !!!!!");
40
41                                 System.out.println("Recv is null in msg of SENDER "
42                                                 + LocalHost.Instance().getName());
43                         }
44
45                         if (msg.getReceiver().getHostStub() == null) {
46                                 System.out.println("SENDER : the destination is null, so I send nothing, the msg is simply lost");
47                                 yield();
48                         }
49
50                         // if there is a destinatory,
51                         else {
52                                 msgIsSent = false;
53
54                                 stub = msg.getReceiver().getHostStub();
55
56                                 try {
57                                         // For simulating latency in network
58                                         msg.getReceiver() ;
59                                         Thread.sleep( site_delay ) ;
60                                         
61                                         // Send the message
62                                         stub.iSendYou(msg);
63
64                                         msgIsSent = true;
65
66                                         yield();
67                                 } catch (Exception e) {
68                                         System.out
69                                                         .println("Can't send the messgae to "
70                                                                         + msg.getReceiver().getHostName()
71                                                                         + ". Error: " + e);
72                                         yield();
73                                 }
74                         }
75                 }
76         }
77 }