source: branches/supervisor/src/main/java/omq/common/broker/RemoteBrokerImpl.java

Last change on this file was 110, checked in by stoda, 11 years ago

Supervisor seems to work

File size: 1.8 KB
Line 
1package omq.common.broker;
2
3import java.io.IOException;
4import java.util.Properties;
5import java.util.Set;
6
7import omq.exception.RemoteException;
8import omq.exception.RetryException;
9import omq.server.RemoteObject;
10
11/**
12 *
13 * @author Sergi Toda <sergi.toda@estudiants.urv.cat>
14 *
15 */
16public class RemoteBrokerImpl extends RemoteObject implements RemoteBroker {
17
18        /**
19         *
20         */
21        private static final long serialVersionUID = 1L;
22
23        @Override
24        public Set<String> getRemoteObjects() {
25                return getBroker().getRemoteObjs().keySet();
26        }
27
28        @Override
29        public void spawnObject(String reference, String className, Properties env) throws Exception {
30                System.out.println("SPAWN broker = " + this.getUID());
31                RemoteObject remote = (RemoteObject) Class.forName(className).newInstance();
32                getBroker().bind(reference, remote, env);
33        }
34
35        @Override
36        public void spawnObject(String reference, String className) throws Exception {
37                System.out.println("SPAWN broker = " + this.getUID());
38                RemoteObject remote = (RemoteObject) Class.forName(className).newInstance();
39                getBroker().bind(reference, remote);
40        }
41
42        @Override
43        public void deleteObject(String reference) throws RemoteException, IOException {
44                getBroker().unbind(reference);
45        }
46
47        @Override
48        public boolean hasObject(String reference) throws RetryException {
49                return getBroker().getRemoteObjs().containsKey(reference);
50        }
51
52        @Override
53        public HasObject hasObjectInfo(String reference) throws RetryException {
54                System.out.println("Hola soc un broker" + getRef() + ", " + getUID() + ", fil: " + Thread.currentThread().getId());
55                if (getBroker().getRemoteObjs().containsKey(reference)) {
56                        RemoteObject r = getBroker().getRemoteObjs().get(reference);
57                        int numThreads = r.getPool().getWorkers().size();
58                        return new HasObject(this.getUID(), reference, true, numThreads);
59                }
60                return new HasObject(this.getUID(), reference, false, 0);
61        }
62
63}
Note: See TracBrowser for help on using the repository browser.