Source code: com/aendvari/hermes/broker/MessageBrokerContext.java
1 /*
2 * MessageBrokerContext.java
3 *
4 * Copyright (c) 2001, 2002 Aendvari, Ltd. All Rights Reserved.
5 *
6 * See the file LICENSE for terms of use.
7 *
8 */
9
10 package com.aendvari.hermes.broker;
11
12 import com.aendvari.common.properties.Properties;
13
14 /**
15 * <p>Provides context information for a {@link MessageBroker}.</p>
16 *
17 * <p>A context may have several properties. The properties are stored in a
18 * ({@link Properties}) object, which allows them to be stored in a hierarchy.</p>
19 *
20 * <p>The <code>MessageBrokerContext</code> may be subclassed to provide application specific
21 * information (for example, HTTP information, see {@link com.aendvari.hermes.broker.http.HttpMessageBrokerContext}).
22 *
23 * @author Trevor Milne
24 *
25 */
26
27 public class MessageBrokerContext
28 {
29 /** The {@link MessageBroker} that this context is for. */
30 protected MessageBroker broker;
31
32 /** The ({@link Properties}) object that properties are stored in. */
33 protected Properties properties;
34
35
36 /* Constructors. */
37
38
39 /**
40 * Constructs a <code>MessageBrokerContext</code>.
41 *
42 */
43
44 public MessageBrokerContext()
45 {
46 properties = new Properties();
47 }
48
49
50 /* Accessors. */
51
52
53 /**
54 * Returns the {@link MessageBroker} for this context.
55 *
56 * @return The {@link MessageBroker} for this context.
57 *
58 */
59
60 public MessageBroker getBroker()
61 {
62 return broker;
63 }
64
65 /**
66 * Sets the {@link MessageBroker} for this context.
67 *
68 * @param setBroker The {@link MessageBroker} for this context.
69 *
70 */
71
72 protected void setBroker(MessageBroker setBroker)
73 {
74 broker = setBroker;
75 }
76
77 /**
78 * Returns the {@link Properties} object for the storage and retrieval of context properties.
79 *
80 * @return The {@link Properties} object for this context.
81 *
82 */
83
84 public Properties getProperties()
85 {
86 return properties;
87 }
88
89
90 /* Connection management. */
91
92
93 /**
94 * Creates a {@link MessageBrokerConnection} for the broker of this context.
95 *
96 * @return The {@link MessageBrokerConnection} for this context.
97 *
98 */
99
100 public MessageBrokerConnection createConnection()
101 {
102 // get a connection from the broker
103 MessageBrokerConnection connection = broker.createConnection();
104
105 // set this as the context
106 connection.setContext(this);
107
108 return connection;
109 }
110 }
111