KickJava   Java API By Example, From Geeks To Geeks.

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


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

35 public class KillNodeAndWait extends KillNode
36  implements GlobalLockInterceptor.FailureListener {
37     Set JavaDoc notHandled = new HashSet JavaDoc();
38     public KillNodeAndWait(String JavaDoc name, DistResServiceManager drsm, Object JavaDoc node,
39                            Serializable JavaDoc resId) {
40         super(name, drsm, node);
41         Set JavaDoc nodes = new HashSet JavaDoc(drsm.getLocalNodes());
42         nodes.remove(node);
43         for (Iterator JavaDoc it = nodes.iterator(); it.hasNext();) {
44             Object JavaDoc n = it.next();
45             notHandled.add(n);
46             Object JavaDoc ui = drsm.getUserService(n).getUser(resId);
47             ((UserInterceptor) ui).setFailureListener(this);
48
49         }
50     }
51
52     public synchronized void perform() throws Exception JavaDoc {
53         super.perform();
54         while (!notHandled.isEmpty()) {
55             wait();
56         }
57         em.notifyEvent(endEvent, true);
58     }
59
60     public synchronized void handle(Serializable JavaDoc resId, Serializable JavaDoc nodeId) {
61         notHandled.remove(nodeId);
62         if (notHandled.isEmpty()) notify();
63     }
64 }
65
Popular Tags