1 |
/* |
/* |
2 |
Copyright (c) 1996, 1997, 1998, 1999 Free Software Foundation, Inc. |
Copyright (c) 1996, 1997, 1998, 1999, 2002 Free Software Foundation, Inc. |
3 |
|
|
4 |
This file is part of GNU Classpath. |
This file is part of GNU Classpath. |
5 |
|
|
46 |
import java.rmi.server.RMISocketFactory; |
import java.rmi.server.RMISocketFactory; |
47 |
import gnu.java.rmi.server.UnicastServerRef; |
import gnu.java.rmi.server.UnicastServerRef; |
48 |
|
|
49 |
|
import java.util.Hashtable; |
50 |
|
|
51 |
|
/** |
52 |
|
* I let DGCImpl to extend UnicastServerRef, but not |
53 |
|
* UnicastRemoteObject, because UnicastRemoteObject must |
54 |
|
* exportObject automatically. |
55 |
|
*/ |
56 |
public class DGCImpl |
public class DGCImpl |
57 |
extends UnicastRemoteObject implements DGC { |
extends UnicastServerRef implements DGC { |
58 |
|
|
59 |
private static final long leaseValue = 600000L; |
private static final long LEASE_VALUE = 600000L; |
60 |
|
// leaseCache caches a LeaseRecord associated with a vmid |
61 |
|
private Hashtable leaseCache = new Hashtable(); |
62 |
|
|
63 |
public DGCImpl() throws RemoteException { |
public DGCImpl() throws RemoteException { |
64 |
super(new UnicastServerRef(new ObjID(ObjID.DGC_ID), 0, RMISocketFactory.getSocketFactory())); |
super(new ObjID(ObjID.DGC_ID), 0, RMISocketFactory.getSocketFactory()); |
65 |
} |
} |
66 |
|
|
67 |
public Lease dirty(ObjID[] ids, long sequenceNum, Lease lease) throws RemoteException { |
public Lease dirty(ObjID[] ids, long sequenceNum, Lease lease) throws RemoteException { |
68 |
VMID vmid = lease.getVMID(); |
VMID vmid = lease.getVMID(); |
69 |
|
if (vmid == null) |
70 |
|
vmid = new VMID(); |
71 |
|
long leaseValue = LEASE_VALUE; |
72 |
|
//long leaseValue = lease.getValue(); |
73 |
lease = new Lease(vmid, leaseValue); |
lease = new Lease(vmid, leaseValue); |
74 |
System.out.println("DGCImpl.dirty - not completely implemented"); |
synchronized(leaseCache){ |
75 |
|
LeaseRecord lr = (LeaseRecord)leaseCache.get(vmid); |
76 |
|
if (lr != null) |
77 |
|
lr.reset(leaseValue); |
78 |
|
else{ |
79 |
|
lr = new LeaseRecord(vmid, leaseValue); |
80 |
|
leaseCache.put(vmid, lr); |
81 |
|
} |
82 |
|
} |
83 |
|
|
84 |
return (lease); |
return (lease); |
85 |
} |
} |
86 |
|
|
87 |
public void clean(ObjID[] ids, long sequenceNum, VMID vmid, boolean strong) throws RemoteException { |
public void clean(ObjID[] ids, long sequenceNum, VMID vmid, boolean strong) throws RemoteException { |
88 |
System.out.println("DGCImpl.clean - not implemented"); |
// Not implemented |
89 |
} |
} |
90 |
|
|
91 |
|
/** |
92 |
|
* LeaseRecord associates a vmid to expireTime. |
93 |
|
*/ |
94 |
|
private static class LeaseRecord{ |
95 |
|
private VMID vmid; |
96 |
|
private long expireTime; |
97 |
|
|
98 |
|
LeaseRecord(VMID vmid, long leaseValue){ |
99 |
|
this.vmid = vmid; |
100 |
|
reset(leaseValue); |
101 |
|
} |
102 |
|
|
103 |
|
// reset expireTime |
104 |
|
void reset(long leaseValue){ |
105 |
|
long l = System.currentTimeMillis(); |
106 |
|
expireTime = l + leaseValue; |
107 |
|
} |
108 |
|
|
109 |
|
boolean isExpired(){ |
110 |
|
long l = System.currentTimeMillis(); |
111 |
|
if ( l > expireTime) |
112 |
|
return true; |
113 |
|
return false; |
114 |
|
} |
115 |
|
|
116 |
|
} //End of LeaseRecord |
117 |
|
|
118 |
} |
} //End of DGCImpl |