KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > petals > kernel > registry > thread > FullUpdateThread


1 /**
2  * PETALS - PETALS Services Platform.
3  * Copyright (c) 2005 EBM Websourcing, http://www.ebmwebsourcing.com/
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * -------------------------------------------------------------------------
19  * $Id: ElectMasterThread.java 9:32:39 AM ddesjardins $
20  * -------------------------------------------------------------------------
21  */

22 package org.objectweb.petals.kernel.registry.thread;
23
24 import java.util.ArrayList JavaDoc;
25 import java.util.List JavaDoc;
26 import java.util.Map JavaDoc;
27
28 import org.objectweb.petals.kernel.admin.ContainerInformation;
29 import org.objectweb.petals.kernel.registry.RegistryServer;
30 import org.objectweb.petals.kernel.registry.msg.request.FullUpdateRequest;
31 import org.objectweb.petals.kernel.registry.msg.request.RegistryRequest;
32 import org.objectweb.petals.util.LoggingUtil;
33
34 /**
35  * ElectMasterThread
36  *
37  * @author ddesjardins - eBMWebsourcing
38  */

39 public class FullUpdateThread extends Thread JavaDoc {
40
41     protected RegistryServer server;
42
43     protected LoggingUtil log;
44
45     protected long sender;
46
47     public FullUpdateThread(RegistryServer server) {
48         super("ElectMasterThread"
49             + server.getStartTime());
50         this.server = server;
51         sender = server.getStartTime();
52     }
53
54     public void run() {
55         log = server.getLog();
56         int counter = 0;
57         log.call();
58         try {
59             Thread.sleep(1000);
60         } catch (InterruptedException JavaDoc e2) {
61             // do nothing
62
}
63         if (server.getChannel().getCurrentGroup().getMembers().size() > 1) {
64             RegistryRequest electRequest = new FullUpdateRequest(sender, 0);
65             try {
66                 server.getChannel().send(electRequest);
67             } catch (Exception JavaDoc e) {
68                 log.error("Problem while sending full update request", e);
69             }
70             counter = 0;
71             while (!server.isFullyUpdated()
72                 && counter < 10) {
73                 try {
74                     Thread.sleep(300);
75                     counter++;
76                 } catch (InterruptedException JavaDoc e) {
77                     // do nothing
78
}
79             }
80
81             Map JavaDoc<String JavaDoc, Object JavaDoc> contMap = server.getData().get("/containers/");
82             if (contMap != null) {
83                 List JavaDoc<ContainerInformation> contList = new ArrayList JavaDoc<ContainerInformation>();
84                 for (Object JavaDoc object : contMap.values()) {
85                     contList.add((ContainerInformation) object);
86                 }
87                 server.getConfigurationService().setContainers(contList);
88             }
89         } else {
90             server.setFullyUpdated(true);
91         }
92         server.getConfigurationService().setUpConfiguration();
93     }
94
95 }
96
Popular Tags