forked from micw/php-java-bridge
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSession.java
More file actions
80 lines (65 loc) · 1.59 KB
/
Copy pathSession.java
File metadata and controls
80 lines (65 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*-*- mode: Java; tab-width:8 -*-*/
package php.java.bridge;
import java.util.Hashtable;
import java.util.Map;
import java.util.Iterator;
public class Session{
Hashtable map;
private String name;
private static int sessionCount=0;
boolean isNew=true;
long startTime, timeout;
public Object get(Object ob) {
return map.get(ob);
}
public void put(Object ob1, Object ob2) {
map.put(ob1, ob2);
}
public Object remove(Object ob) {
return map.remove(ob);
}
public Session(String name) {
this.name=name;
Session.sessionCount++;
this.map=new Hashtable();
this.startTime=System.currentTimeMillis();
this.timeout=1440000;
}
public void setTimeout(long timeout) {
this.timeout=timeout;
}
public long getTimeout() {
return timeout;
}
public int getSessionCount() {
return sessionCount;
}
public boolean isNew() {
return isNew;
}
public void destroy() {
sessionCount--;
synchronized(JavaBridge.sessionHash) {
if(JavaBridge.sessionHash!=null)
JavaBridge.sessionHash.remove(name);
}
}
public void destroySession() {
destroy();
}
public void putAll(Map vars) {
map.putAll(vars);
}
static void expire() {
if(JavaBridge.sessionHash==null) return;
synchronized(JavaBridge.sessionHash) {
for(Iterator e = JavaBridge.sessionHash.values().iterator(); e.hasNext(); ) {
Session ref = (Session)e.next();
if((ref.timeout !=0) && (ref.startTime+ref.timeout<=System.currentTimeMillis())) {
sessionCount--;
JavaBridge.sessionHash.remove(ref.name);
}
}
}
}
}