View Javadoc

1   /*
2    *  XNap - A P2P framework and client.
3    *
4    *  See the file AUTHORS for copyright information.
5    *
6    *  This program is free software; you can redistribute it and/or modify
7    *  it under the terms of the GNU General Public License as published by
8    *  the Free Software Foundation.
9    *
10   *  This program is distributed in the hope that it will be useful,
11   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   *  GNU General Public License for more details.
14   *
15   *  You should have received a copy of the GNU General Public License
16   *  along with this program; if not, write to the Free Software
17   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18   */
19  
20  package org.xnap.plugin.joscar.msg;
21  
22  import org.apache.log4j.Logger;
23  
24  import JOscarLib.Core.OscarConnection;
25  
26  /***
27   * 
28   */
29  public class JOscarMessageSender implements Runnable
30  {
31  	//--- Constant(s) ---
32  
33  	//--- Data field(s) ---
34  
35  	private boolean die = false;
36  	private JOscarMessageQueue queue;
37  	private OscarConnection connection;
38  	private Thread t = null;
39  
40      private static Logger logger = Logger.getLogger(JOscarMessageQueue.class);
41  	
42  	//--- Constructor(s) ---
43  
44      public JOscarMessageSender(JOscarMessageQueue queue)
45  							   
46  	{
47  		this.queue = queue;
48  	}
49  
50      //--- Method(s) ---
51  
52  	public void setConnection(OscarConnection connection)
53  	{
54  		this.connection = connection;
55  	}
56  
57  	public void start()
58  	{
59  		die = false;
60  		t = new Thread(this, "JOscarMessageSender");
61  		t.start();
62  	}
63  
64  	public void stop()
65  	{
66  		die = true;
67  		if (t != null) {
68  			t.interrupt();
69  		}
70  	}
71  
72  	public void run()
73  	{
74  		while (!die) {
75  			JOscarMessage msg = null;
76  			try {
77  				msg = queue.getMessage();
78  			}
79  			catch (InterruptedException ie) {
80  				continue;
81  			}
82  			msg.send(connection);
83  		}
84  	}
85  }