source: branches/objectmq-1.0/src/omq/common/remote/RemoteListener.java

Last change on this file was 33, checked in by amoreno, 11 years ago

new release version

File size: 1.5 KB
Line 
1package omq.common.remote;
2
3import java.io.FileInputStream;
4import java.io.IOException;
5import java.util.Properties;
6
7import omq.common.util.OmqConnectionFactory;
8
9import com.rabbitmq.client.Channel;
10import com.rabbitmq.client.Connection;
11import com.rabbitmq.client.QueueingConsumer;
12
13/**
14 *
15 * @author Sergi Toda <sergi.toda@estudiants.urv.cat>
16 *
17 */
18//TODO aquesta classe es pot eliminar
19public abstract class RemoteListener extends Thread {
20        private static String defaultXml = "eventListener.xml";
21
22        protected Connection connection;
23        protected Channel channel;
24        protected QueueingConsumer consumer;
25        protected boolean killed = false;
26
27        protected RemoteListener() throws Exception {
28                // Load the default environment
29                FileInputStream fis = new FileInputStream(defaultXml);
30                Properties env = new Properties();
31                env.loadFromXML(fis);
32                fis.close();
33
34                startConnection(env);
35        }
36
37        protected RemoteListener(Properties env) throws Exception {
38                startConnection(env);
39        }
40
41        private void startConnection(Properties env) throws Exception {
42                connection = OmqConnectionFactory.getNewConnection(env);
43                channel = connection.createChannel();
44        }
45
46        public synchronized Channel getChannel() throws Exception {
47                return connection.createChannel();
48        }
49
50        /**
51         * Interrupt and kill the Thread
52         *
53         * @throws IOException
54         */
55        public void kill() throws IOException {
56                interrupt();
57                killed = true;
58                channel.close();
59                connection.close();
60        }
61
62        /**
63         * TODO RESTART CONNECTION FAULT TOLERANCE
64         */
65
66}
Note: See TracBrowser for help on using the repository browser.