1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.river.reggie.proxy;
19
20 import java.io.IOException;
21 import java.io.InvalidObjectException;
22 import java.io.ObjectOutputStream;
23 import java.io.ObjectStreamException;
24 import java.rmi.RemoteException;
25 import net.jini.core.constraint.RemoteMethodControl;
26 import net.jini.core.lease.UnknownLeaseException;
27 import net.jini.core.lookup.ServiceID;
28 import net.jini.id.Uuid;
29 import org.apache.river.api.io.AtomicSerial;
30 import org.apache.river.api.io.AtomicSerial.GetArg;
31
32
33
34
35
36
37
38
39
40
41 @AtomicSerial
42 public class EventLease extends RegistrarLease {
43
44 private static final long serialVersionUID = 2L;
45
46 private static final String LEASE_TYPE = "event";
47
48
49
50
51
52
53 final long eventID;
54
55
56
57
58
59 public static EventLease getInstance(Registrar server,
60 ServiceID registrarID,
61 long eventID,
62 Uuid leaseID,
63 long expiration)
64 {
65 return (server instanceof RemoteMethodControl) ?
66 new ConstrainableEventLease(
67 server, registrarID, eventID, leaseID, expiration, null, true) :
68 new EventLease(server, registrarID, eventID, leaseID, expiration);
69 }
70
71 private static GetArg check(GetArg arg) throws IOException{
72 long eventID = arg.get("eventID", 0L);
73 return arg;
74 }
75
76 EventLease(GetArg arg) throws IOException{
77 super(check(arg));
78 eventID = arg.get("eventID", 0L);
79 }
80
81
82 EventLease(Registrar server,
83 ServiceID registrarID,
84 long eventID,
85 Uuid leaseID,
86 long expiration)
87 {
88 super(server, registrarID, leaseID, expiration);
89 this.eventID = eventID;
90 }
91
92
93 public void cancel() throws UnknownLeaseException, RemoteException {
94 server.cancelEventLease(eventID, leaseID);
95 }
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110 protected long doRenew(long duration)
111 throws UnknownLeaseException, RemoteException
112 {
113 return server.renewEventLease(eventID, leaseID, duration);
114 }
115
116
117 Object getRegID() {
118 return Long.valueOf(eventID);
119 }
120
121
122 String getLeaseType() {
123 return LEASE_TYPE;
124 }
125
126 private void writeObject(ObjectOutputStream out) throws IOException {
127 out.defaultWriteObject();
128 }
129
130
131
132
133 private void readObjectNoData() throws ObjectStreamException {
134 throw new InvalidObjectException("no data");
135 }
136 }