KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > tribe > faultdetection > UDPPongThread


1 /**
2  * Tribe: Group communication library.
3  * Copyright (C) 2004 French National Institute For Research In Computer
4  * Science And Control (INRIA).
5  * Contact: tribe@objectweb.org
6  *
7  * This library is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as published by the
9  * Free Software Foundation; either version 2.1 of the License, or any later
10  * version.
11  *
12  * This library is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15  * for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with this library; if not, write to the Free Software Foundation,
19  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
20  *
21  * Initial developer(s): Nicolas Modrzyk.
22  * Contributor(s): ______________________.
23  */

24
25 package org.objectweb.tribe.faultdetection;
26
27 import java.io.IOException JavaDoc;
28 import java.net.DatagramSocket JavaDoc;
29
30 import org.objectweb.tribe.common.IpAddress;
31 import org.objectweb.tribe.messages.DatagramMessage;
32
33 /**
34  * This class defines a UDPPongThread. Send an echo message
35  *
36  * @author <a HREF="mailto:Nicolas.Modrzyk@inrialpes.fr">Nicolas Modrzyk </a>
37  * @version 1.0
38  */

39 public class UDPPongThread implements Runnable JavaDoc
40 {
41   private IpAddress src;
42   private IpAddress target;
43   private boolean quit;
44
45   /**
46    * Creates a new <code>UDPPongThread</code> object
47    *
48    * @param src
49    * @param target
50    */

51   public UDPPongThread(IpAddress src, IpAddress target)
52   {
53     super();
54     this.src = src;
55     this.target = target;
56   }
57
58   /**
59    * @see java.lang.Runnable#run()
60    */

61   public void run()
62   {
63     DatagramSocket JavaDoc socket = null;
64     while (!quit)
65     {
66       try
67       {
68         socket = new DatagramSocket JavaDoc(src.getPort());
69         DatagramMessage message = new DatagramMessage(src, target);
70         socket.receive(message.getDatagramPacket());
71         socket.send(message.getDatagramPacket());
72         socket.close();
73       }
74       catch (IOException JavaDoc e)
75       {
76         e.printStackTrace();
77         if (socket != null)
78           socket.close();
79       }
80
81     }
82   }
83
84   /**
85    * Sets the quit value.
86    *
87    * @param quit The quit to set.
88    */

89   public void setQuit(boolean quit)
90   {
91     this.quit = quit;
92   }
93 }
Popular Tags