3b3f91a6a0a625143ab73611d193c199826ad7d9
[dcaegen2/services/sdk.git] /
1 /*
2  * ============LICENSE_START=======================================================
3  * DCAEGEN2-SERVICES-SDK
4  * ================================================================================
5  * Copyright (C) 2019 Nokia. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20 package org.onap.dcaegen2.services.sdk.services.hvves.client.producer.api;
21
22 import org.jetbrains.annotations.NotNull;
23
24 /**
25  * <p>
26  *     Factory for High-Volume VES Producer.
27  * </p>
28  *
29  * <p>
30  *     Sample usage:
31  * </p>
32  *
33  * <pre>
34  *     {@link HvVesProducer} producer = HvVesProducerFactory.create(
35  *          {@link ImmutableProducerOptions}.builder().
36  *              ...
37  *              .build())
38  * </pre>
39  *
40  * @author <a href="mailto:piotr.jaszczyk@nokia.com">Piotr Jaszczyk</a>
41  * @since 1.1.1
42  */
43 public abstract class HvVesProducerFactory {
44
45     /**
46      * Should not be used directly by client code. It is invoked internally by
47      * {@link HvVesProducerFactory#create(ProducerOptions)}.
48      *
49      * @param options the options to be used when creating a producer
50      * @return non-null HvVesProducer instance
51      * @since 1.1.1
52      */
53     protected abstract @NotNull HvVesProducer createProducer(ProducerOptions options);
54
55     /**
56      * Creates an instance of {@link HvVesProducer}. Under the hood it first loads the HvVesProducerFactory instance
57      * using {@link java.util.ServiceLoader} facility. In order for this to work the implementation module should be present at the class
58      * path. Otherwise a runtime exception is thrown.
59      *
60      * @param options the options to be used when creating a producer
61      * @return non-null {@link HvVesProducer} instance
62      * @since 1.1.1
63      */
64     public static @NotNull HvVesProducer create(ProducerOptions options) {
65         return FactoryLoader.findInstance(HvVesProducerFactory.class).createProducer(options);
66     }
67 }