source: trunk/objectmq/src/omq/common/broker/Broker.java @ 9

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

First commit

File size: 1.8 KB
Line 
1package omq.common.broker;
2
3import java.util.Properties;
4
5import omq.Remote;
6import omq.client.proxy.Proxymq;
7import omq.client.remote.response.ResponseListener;
8import omq.common.remote.OmqConnectionFactory;
9import omq.exception.RemoteException;
10import omq.server.remote.request.RemoteObject;
11
12import com.rabbitmq.client.Channel;
13import com.rabbitmq.client.Connection;
14
15public class Broker {
16        private static Connection connection;
17        private static Channel channel;
18        private static Properties environment;
19
20        public static void initBroker(Properties env) throws Exception {
21                if (environment == null) {
22                        environment = env;
23                        connection = OmqConnectionFactory.getConnection(env);
24                        channel = connection.createChannel();
25                }
26        }
27
28        // TODO: what happens if the connection is not set
29        public static Connection getConnection() throws Exception {
30                return connection;
31        }
32
33        public static Channel getChannel() throws Exception {
34                return channel;
35        }
36
37        public static Remote lookup(String reference, Class<?> contract) throws RemoteException {
38                try {
39                        if (ResponseListener.isVoid()) {
40                                ResponseListener.init(environment);
41                        }
42                        if (!Proxymq.containsProxy(reference)) {
43                                Proxymq proxy = new Proxymq(reference, contract, environment);
44                                Class<?>[] array = { contract };
45                                return (Remote) Proxymq.newProxyInstance(contract.getClassLoader(), array, proxy);
46                        }
47                        return (Remote) Proxymq.getInstance(reference);
48
49                } catch (Exception e) {
50                        throw new RemoteException(e);
51                }
52        }
53
54        public static void bind(String reference, RemoteObject remote) throws RemoteException {
55                try {
56                        remote.start(reference, environment);
57                } catch (Exception e) {
58                        throw new RemoteException(e);
59                }
60        }
61
62        public static void unbind(String reference) throws RemoteException {
63
64        }
65
66        public void rebind(String name, Remote obj) throws RemoteException {
67
68        }
69
70}
Note: See TracBrowser for help on using the repository browser.