KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sellwin > domain > ChatConnInfo


1 package sellwin.domain;
2
3 // SellWin http://sourceforge.net/projects/sellwincrm
4
//Contact support@open-app.com for commercial help with SellWin
5
//This software is provided "AS IS", without a warranty of any kind.
6

7
8 import java.io.*;
9 import java.net.*;
10 import java.util.*;
11
12 /**
13  * information about a Chat user's connection, this class
14  * is stored in a global list by the ChatServer and is used
15  * as a reference to see who is logged on and who is not
16  */

17 public class ChatConnInfo {
18     /** the sender or user ID of a chat client */
19     public String JavaDoc sender;
20
21     public String JavaDoc getSender() { return sender; }
22
23     /** the sender's output stream, used to write back messages */
24     public ObjectOutputStream oos;
25     public ObjectOutputStream getOOS() { return oos; }
26
27     /** the last date known about a chat user's connection */
28     public java.util.Date JavaDoc connectedSince;
29     public java.util.Date JavaDoc getConnectedSince() { return connectedSince; }
30
31     /**
32     * construct the chat info
33     */

34     public ChatConnInfo(String JavaDoc sender, ObjectOutputStream oos, java.util.Date JavaDoc dt) {
35         this.sender = sender;
36         this.oos = oos;
37         connectedSince = dt;
38     }
39
40     /**
41     * test to see if the user is still connected, compare
42     * against the last known time and a maximum
43     * @return true if the user is deemed as still connected and
44     * online, false if not
45     */

46     public boolean stillConnected() {
47         java.util.Date JavaDoc rightNow = new java.util.Date JavaDoc();
48         long TIME_MAX = 1000 * 60 * 2; //2 minute
49
long rightNowMillis = rightNow.getTime();
50         long connectedMillis = connectedSince.getTime();
51         long diff = rightNowMillis - connectedMillis;
52         if (diff > TIME_MAX)
53             return false;
54         else
55             return true;
56     }
57 }
58
Popular Tags