KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > carol > cmi > ClusterRegistryImpl_Cluster


1 /*
2  * Copyright (C) 2002-2003, Simon Nieuviarts
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or any later version.
8  *
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
17  * USA
18  */

19 package org.objectweb.carol.cmi;
20
21 import java.rmi.AlreadyBoundException JavaDoc;
22 import java.rmi.ConnectException JavaDoc;
23 import java.rmi.ConnectIOException JavaDoc;
24 import java.rmi.NotBoundException JavaDoc;
25 import java.rmi.Remote JavaDoc;
26 import java.rmi.RemoteException JavaDoc;
27
28 /**
29  * Cluster standard stub for ClusterRegistryImpl
30  */

31 public class ClusterRegistryImpl_Cluster
32     implements ClusterStub, ClusterRegistryInternal {
33     private ClusterStubData csd;
34     private StubLB lb;
35
36     // constructor
37
public ClusterRegistryImpl_Cluster(ClusterStubData csd)
38         throws RemoteException JavaDoc {
39         this.csd = csd;
40         lb = csd.getRandom();
41     }
42
43     private void setLB() {
44         if (lb == null) {
45             lb = csd.getRandom();
46         }
47     }
48
49     public String JavaDoc[] list() throws RemoteException JavaDoc {
50         setLB();
51         StubData sd = lb.get();
52         ClusterRegistryInternal stub = (ClusterRegistryInternal) sd.getStub();
53         StubLBFilter filter = null;
54         do {
55             try {
56                 java.lang.String JavaDoc[] result = stub.list();
57                 return result;
58             } catch (RemoteException JavaDoc e) {
59                 if (!(e instanceof ConnectException JavaDoc)
60                     && !(e instanceof ConnectIOException JavaDoc)) {
61                     throw e;
62                 }
63                 if (csd.isStubDebug()) {
64                     csd.debug("Connection to registry refused, retry");
65                 }
66                 if (filter == null) {
67                     filter = new StubLBFilter();
68                 }
69                 filter.add(sd);
70                 sd = lb.get(filter);
71                 stub = (ClusterRegistryInternal) sd.getStub();
72             }
73         } while (true);
74     }
75
76     /* Used only to test if a registry is started.
77      */

78     public void test() throws RemoteException JavaDoc {
79         setLB();
80         StubData sd = lb.get();
81         ClusterRegistryInternal stub = (ClusterRegistryInternal) sd.getStub();
82         StubLBFilter filter = null;
83         do {
84             try {
85                 stub.test();
86             } catch (RemoteException JavaDoc e) {
87                 if (!(e instanceof ConnectException JavaDoc)
88                     && !(e instanceof ConnectIOException JavaDoc)) {
89                     throw e;
90                 }
91                 if (csd.isStubDebug()) {
92                     csd.debug("Connection to registry refused, retry");
93                 }
94                 if (filter == null) {
95                     filter = new StubLBFilter();
96                 }
97                 filter.add(sd);
98                 sd = lb.get(filter);
99                 stub = (ClusterRegistryInternal) sd.getStub();
100             }
101         } while (true);
102     }
103
104     public Object JavaDoc lookup(String JavaDoc name)
105         throws NotBoundException JavaDoc, RemoteException JavaDoc {
106         setLB();
107         StubData sd = lb.get();
108         ClusterRegistryInternal stub = (ClusterRegistryInternal) sd.getStub();
109         StubLBFilter filter = null;
110         do {
111             try {
112                 return stub.lookup(name);
113             } catch (RemoteException JavaDoc e) {
114                 if (!(e instanceof ConnectException JavaDoc)
115                     && !(e instanceof ConnectIOException JavaDoc)) {
116                     throw e;
117                 }
118                 if (csd.isStubDebug()) {
119                     csd.debug("Connection to registry refused, retry");
120                 }
121                 if (filter == null) {
122                     filter = new StubLBFilter();
123                 }
124                 filter.add(sd);
125                 sd = lb.get(filter);
126                 stub = (ClusterRegistryInternal) sd.getStub();
127             }
128         } while (true);
129     }
130
131     public void bindSingle(String JavaDoc name, Remote JavaDoc obj)
132         throws AlreadyBoundException JavaDoc, RemoteException JavaDoc {
133         throw new RemoteException JavaDoc("Can't bind into multiple servers");
134     }
135
136     public void rebindSingle(String JavaDoc name, Remote JavaDoc obj)
137         throws RemoteException JavaDoc {
138         throw new RemoteException JavaDoc("Can't rebind into multiple servers");
139     }
140
141     public void bindCluster(String JavaDoc name, byte[] obj)
142         throws AlreadyBoundException JavaDoc, RemoteException JavaDoc {
143         csd.getLocal();
144         throw new RemoteException JavaDoc("Can't bind into multiple servers");
145         // ClusterRegistryInternal stub = (ClusterRegistryInternal) getFirst();
146
// stub.bind(name, obj);
147
}
148
149     public void rebindCluster(String JavaDoc name, byte[] obj)
150         throws RemoteException JavaDoc {
151         csd.getLocal();
152         throw new RemoteException JavaDoc("Can't rebind into multiple servers");
153         // ClusterRegistryInternal stub = (ClusterRegistryInternal) getFirst();
154
// stub.rebind(name, obj);
155
}
156
157     public void unbind(java.lang.String JavaDoc name)
158         throws NotBoundException JavaDoc, RemoteException JavaDoc {
159         csd.getLocal();
160         throw new RemoteException JavaDoc("Can't unbind from multiple servers");
161         // ClusterRegistryInternal stub = (ClusterRegistryInternal) getFirst();
162
// stub.unbind(name);
163
}
164 }
165
Popular Tags