KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > perseus > concurrency > distributed > globallock > GlobalLockInterceptor


1 package org.objectweb.perseus.concurrency.distributed.globallock;
2
3 import org.objectweb.perseus.concurrency.distributed.globallock.api.DeadLockException;
4 import org.objectweb.perseus.concurrency.distributed.globallock.api.GlobalLock;
5 import org.objectweb.perseus.concurrency.distributed.globallock.api.GlobalLockWaiter;
6 import org.objectweb.perseus.concurrency.distributed.globallock.lib.GlobalLockUser;
7 import org.objectweb.perseus.distribution.util.MessageEventListener;
8 import org.objectweb.perseus.distribution.util.MessageEventListenerRegistry;
9
10 import java.io.Serializable JavaDoc;
11
12 /**
13  * Copyright (C) 2003-2004
14  * - France Telecom R&D
15  *
16  * This library is free software; you can redistribute it and/or
17  * modify it under the terms of the GNU Lesser General Public
18  * License as published by the Free Software Foundation; either
19  * version 2 of the License, or (at your option) any later version.
20  *
21  * This library is distributed in the hope that it will be useful,
22  * but WITHOUT ANY WARRANTY; without even the implied warranty of
23  * MERCHANTABILITY or FITNESS FOR AE PARTICULAR PURPOSE. See the GNU
24  * Lesser General Public License for more details.
25  *
26  * You should have received a copy of the GNU Lesser General Public
27  * License along with this library; if not, write to the Free Software
28  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29  *
30  * Release: 1.0
31  *
32  * Authors: lobry
33  * Date: 27 mai 2004
34  * Time: 17:57:10
35  */

36 public class GlobalLockInterceptor implements GlobalLock {
37
38
39     static final public boolean trace = false;
40
41     MessageEventListenerRegistry reg;
42
43     GlobalLockUser glu;
44     //DistResUser dru;
45
//DistResUserService drus;
46
String JavaDoc name;
47     //UserInterceptor lowPart;
48

49     public interface FailureListener {
50         void handle(Serializable JavaDoc resId, Serializable JavaDoc nodeId);
51     }
52
53     public GlobalLockInterceptor(GlobalLockUser glu,
54                                  //DistResUser dru,
55
//DistResUserService drus,
56
//UserInterceptor lowPart,
57
MessageEventListenerRegistry reg) {
58         this.glu = glu;
59         //this.dru = dru;
60
//this.drus = drus;
61
//this.lowPart = lowPart;
62
this.reg = reg;
63     }
64
65
66     public GlobalLockWaiter upgrade(byte lck, boolean sync, long timeout)
67             throws DeadLockException, InterruptedException JavaDoc {
68         GlobalLockWaiter w = glu.upgrade(lck, false, timeout);
69         MessageEventListener l = reg.getListener();
70         if (l != null) l.handledByUser();
71         if (sync && (w != null)) {
72             boolean ok = w.waitLock(timeout);
73             if (!ok) {
74                     if (trace) trace("WAKE UP TIMED OUT (Waiting: " + lck + ")");
75                     throw new DeadLockException();
76             }
77
78             if (trace) trace("WAKE UP (Waiting: " + lck + ")");
79             w.signalHandled();
80             return null;
81         } else {
82             return w;
83         }
84
85     }
86
87     public void downgrade(byte lck) {
88         glu.downgrade(lck);
89     }
90
91     public byte getGrantable() {
92         return glu.getGrantable();
93     }
94
95     public void uncache() {
96         glu.uncache();
97     }
98
99
100
101
102     public MessageEventListenerRegistry getReg() {
103         return reg;
104     }
105
106     public void setReg(MessageEventListenerRegistry reg) {
107         this.reg = reg;
108     }
109     public synchronized String JavaDoc toString() {
110         return glu.toString();
111     }
112
113     protected void trace(String JavaDoc s) {
114         System.out.println(this + " " + s);
115     }
116
117     void setName(String JavaDoc s) {
118         name = s;
119     }
120
121     String JavaDoc getName() {
122         return name;
123     }
124
125
126 }
127
Popular Tags