aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/main/java/org/onap/policy/apex/plugins/event/carrier/jms/JmsCarrierTechnologyParameters.java
blob: d4647b584c8cb0b803c2cc5d782ec2ae5be2c397 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
/*-
 * ============LICENSE_START=======================================================
 *  Copyright (C) 2016-2018 Ericsson. All rights reserved.
 *  Modifications Copyright (C) 2019,2021 Nordix Foundation.
 *  Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * SPDX-License-Identifier: Apache-2.0
 * ============LICENSE_END=========================================================
 */

package org.onap.policy.apex.plugins.event.carrier.jms;

import java.util.Properties;
import javax.naming.Context;
import org.onap.policy.apex.service.parameters.carriertechnology.CarrierTechnologyParameters;
import org.onap.policy.common.parameters.annotations.Min;
import org.onap.policy.common.parameters.annotations.NotBlank;
import org.onap.policy.common.parameters.annotations.NotNull;

/**
 * Apex parameters for JMS as an event carrier technology.
 *
 * <p>The parameters for this plugin are:
 * <ol>
 * <li>initialContextFactory: JMS uses a naming {@link Context} object to look up the locations of JMS servers and JMS
 * topics. An Initial Context Factory is used to when creating a {@link Context} object that can be used for JMS
 * lookups. The value of this parameter is passed to the {@link Context} with the label
 * {@link Context#INITIAL_CONTEXT_FACTORY}. Its value must be the full canonical path to a class that implements the
 * {@code javax.naming.spi.InitialContextFactory} interface. The parameter defaults to the string value
 * {@code org.jboss.naming.remote.client.InitialContextFactory}.
 * <li>providerURL: The location of the server to use for naming context lookups. The value of this parameter is passed
 * to the {@link Context} with the label {@link Context#PROVIDER_URL}. Its value must be a URL that identifies the JMS
 * naming server. The parameter defaults to the string value {@code remote://localhost:4447}.
 * <li>securityPrincipal: The user name to use for JMS access. The value of this parameter is passed to the
 * {@link Context} with the label {@link Context#SECURITY_PRINCIPAL}. Its value must be the user name of a user defined
 * on the JMS server. The parameter defaults to the string value {@code userid}.
 * <li>securityCredentials:The password to use for JMS access. The value of this parameter is passed to the
 * {@link Context} with the label {@link Context#SECURITY_CREDENTIALS}. Its value must be the password of a suer defined
 * on the JMS server. The parameter defaults to the string value {@code password}.
 * <li>connectionFactory: JMS uses a {@link javax.jms.ConnectionFactory} instance to create connections towards a JMS
 * server. The connection factory to use is held in the JMS {@link Context} object. This parameter specifies the label
 * to use to look up the {@link javax.jms.ConnectionFactory} instance from the JMS {@link Context}.
 * <li>producerTopic: JMS uses a {@link javax.jms.Topic} instance to for sending and receiving messages. The topic to
 * use for sending events to JMS from an Apex producer is held in the JMS {@link Context} object. This parameter
 * specifies the label to use to look up the {@link javax.jms.Topic} instance in the JMS {@link Context} for the JMS
 * server. The topic must, of course, also be defined on the JMS server. The parameter defaults to the string value
 * {@code apex-out}.
 * <li>consumerTopic: The topic to use for receiving events from JMS in an Apex consumer is held in the JMS
 * {@link Context} object. This parameter specifies the label to use to look up the {@link javax.jms.Topic} instance in
 * the JMS {@link Context} for the JMS server. The topic must, of course, also be defined on the JMS server. The
 * parameter defaults to the string value {@code apex-in}.
 * <li>consumerWaitTime: The amount of milliseconds a JMS consumer should wait between checks of its thread execution
 * status. The parameter defaults to the long value {@code 100}.
 * <li>objectMessageSending: A flag that indicates whether Apex producers should send JMS messages as
 * {@link javax.jms.ObjectMessage} instances for java objects (value {@code true}) or as {@link javax.jms.TextMessage}
 * instances for strings (value {@code false}) . The parameter defaults to the boolean value {@code true}.
 * </ol>
 *
 * @author Liam Fallon (liam.fallon@ericsson.com)
 */
public class JmsCarrierTechnologyParameters extends CarrierTechnologyParameters {
    /** The label of this carrier technology. */
    public static final String JMS_CARRIER_TECHNOLOGY_LABEL = "JMS";

    /** The producer plugin class for the JMS carrier technology. */
    public static final String JMS_EVENT_PRODUCER_PLUGIN_CLASS = ApexJmsProducer.class.getName();

    /** The consumer plugin class for the JMS carrier technology. */
    public static final String JMS_EVENT_CONSUMER_PLUGIN_CLASS = ApexJmsConsumer.class.getName();

    // @formatter:off

    // Default parameter values
    private static final String  DEFAULT_CONNECTION_FACTORY    = "jms/RemoteConnectionFactory";
    private static final String  DEFAULT_INITIAL_CTXT_FACTORY  = "org.jboss.naming.remote.client.InitialContextFactory";
    private static final String  DEFAULT_PROVIDER_URL          = null;
    private static final String  DEFAULT_SECURITY_PRINCIPAL    = null;
    private static final String  DEFAULT_SECURITY_CREDENTIALS  = null;
    private static final String  DEFAULT_CONSUMER_TOPIC        = "apex-in";
    private static final String  DEFAULT_PRODUCER_TOPIC        = "apex-out";
    private static final int     DEFAULT_CONSUMER_WAIT_TIME    = 100;
    private static final boolean DEFAULT_TO_OBJECT_MSG_SENDING = true;

    // Parameter property map tokens
    private static final String PROPERTY_INITIAL_CONTEXT_FACTORY  = Context.INITIAL_CONTEXT_FACTORY;
    private static final String PROPERTY_PROVIDER_URL             = Context.PROVIDER_URL;
    private static final String PROPERTY_SECURITY_PRINCIPAL       = Context.SECURITY_PRINCIPAL;
    private static final String PROPERTY_SECURITY_CREDENTIALS     = Context.SECURITY_CREDENTIALS;

    // JMS carrier parameters
    private String  connectionFactory     = DEFAULT_CONNECTION_FACTORY;
    @NotNull @NotBlank
    private String  initialContextFactory = DEFAULT_INITIAL_CTXT_FACTORY;
    @NotNull @NotBlank
    private String  providerUrl           = DEFAULT_PROVIDER_URL;
    @NotNull @NotBlank
    private String  securityPrincipal     = DEFAULT_SECURITY_PRINCIPAL;
    @NotNull @NotBlank
    private String  securityCredentials   = DEFAULT_SECURITY_CREDENTIALS;
    @NotNull @NotBlank
    private String  producerTopic         = DEFAULT_PRODUCER_TOPIC;
    @NotNull @NotBlank
    private String  consumerTopic         = DEFAULT_CONSUMER_TOPIC;
    @Min(0)
    private int     consumerWaitTime      = DEFAULT_CONSUMER_WAIT_TIME;
    private boolean objectMessageSending  = DEFAULT_TO_OBJECT_MSG_SENDING;
    // @formatter:on

    /**
     * Constructor to create a jms carrier technology parameters instance and register the instance with the parameter
     * service.
     */
    public JmsCarrierTechnologyParameters() {
        super();

        // Set the carrier technology properties for the JMS carrier technology
        this.setLabel(JMS_CARRIER_TECHNOLOGY_LABEL);
        this.setEventProducerPluginClass(JMS_EVENT_PRODUCER_PLUGIN_CLASS);
        this.setEventConsumerPluginClass(JMS_EVENT_CONSUMER_PLUGIN_CLASS);
    }

    /**
     * Gets the JMS producer properties.
     *
     * @return the JMS producer properties
     */
    public Properties getJmsProducerProperties() {
        return getJmsProperties();
    }

    /**
     * Gets the jms consumer properties.
     *
     * @return the jms consumer properties
     */
    public Properties getJmsConsumerProperties() {
        return getJmsProperties();
    }

    /**
     * Gets the JMS consumer properties.
     *
     * @return the jms consumer properties
     */
    private Properties getJmsProperties() {
        final Properties jmsProperties = new Properties();

        jmsProperties.put(PROPERTY_INITIAL_CONTEXT_FACTORY, initialContextFactory);

        if (providerUrl != null) {
            jmsProperties.put(PROPERTY_PROVIDER_URL, providerUrl);
        }

        if (securityPrincipal != null) {
            jmsProperties.put(PROPERTY_SECURITY_PRINCIPAL, securityPrincipal);
        }

        if (securityCredentials != null) {
            jmsProperties.put(PROPERTY_SECURITY_CREDENTIALS, securityCredentials);
        }

        return jmsProperties;
    }

    /**
     * Gets the connection factory.
     *
     * @return the connection factory
     */
    public String getConnectionFactory() {
        return connectionFactory;
    }

    /**
     * Gets the initial context factory.
     *
     * @return the initial context factory
     */
    public String getInitialContextFactory() {
        return initialContextFactory;
    }

    /**
     * Gets the provider URL.
     *
     * @return the provider URL
     */
    public String getProviderUrl() {
        return providerUrl;
    }

    /**
     * Gets the security principal.
     *
     * @return the security principal
     */
    public String getSecurityPrincipal() {
        return securityPrincipal;
    }

    /**
     * Gets the security credentials.
     *
     * @return the security credentials
     */
    public String getSecurityCredentials() {
        return securityCredentials;
    }

    /**
     * Gets the producer topic.
     *
     * @return the producer topic
     */
    public String getProducerTopic() {
        return producerTopic;
    }

    /**
     * Gets the consumer topic.
     *
     * @return the consumer topic
     */
    public String getConsumerTopic() {
        return consumerTopic;
    }

    /**
     * Gets the consumer wait time.
     *
     * @return the consumer wait time
     */
    public long getConsumerWaitTime() {
        return consumerWaitTime;
    }

    /**
     * Sets the connection factory.
     *
     * @param connectionFactory the connection factory
     */
    public void setConnectionFactory(final String connectionFactory) {
        this.connectionFactory = connectionFactory;
    }

    /**
     * Sets the initial context factory.
     *
     * @param initialContextFactory the initial context factory
     */
    public void setInitialContextFactory(final String initialContextFactory) {
        this.initialContextFactory = initialContextFactory;
    }

    /**
     * Sets the provider URL.
     *
     * @param providerUrl the provider URL
     */
    public void setProviderUrl(final String providerUrl) {
        this.providerUrl = providerUrl;
    }

    /**
     * Sets the security principal.
     *
     * @param securityPrincipal the security principal
     */
    public void setSecurityPrincipal(final String securityPrincipal) {
        this.securityPrincipal = securityPrincipal;
    }

    /**
     * Sets the security credentials.
     *
     * @param securityCredentials the security credentials
     */
    public void setSecurityCredentials(final String securityCredentials) {
        this.securityCredentials = securityCredentials;
    }

    /**
     * Sets the producer topic.
     *
     * @param producerTopic the producer topic
     */
    public void setProducerTopic(final String producerTopic) {
        this.producerTopic = producerTopic;
    }

    /**
     * Sets the consumer topic.
     *
     * @param consumerTopic the consumer topic
     */
    public void setConsumerTopic(final String consumerTopic) {
        this.consumerTopic = consumerTopic;
    }

    /**
     * Sets the consumer wait time.
     *
     * @param consumerWaitTime the consumer wait time
     */
    public void setConsumerWaitTime(final int consumerWaitTime) {
        this.consumerWaitTime = consumerWaitTime;
    }

    /**
     * Checks if is object message sending.
     *
     * @return true, if checks if is object message sending
     */
    public boolean isObjectMessageSending() {
        return objectMessageSending;
    }

    /**
     * Sets the object message sending.
     *
     * @param objectMessageSending the object message sending
     */
    public void setObjectMessageSending(final boolean objectMessageSending) {
        this.objectMessageSending = objectMessageSending;
    }
}