-
Notifications
You must be signed in to change notification settings - Fork 461
/
DotPubSubProviderLocator.java
34 lines (25 loc) · 1.44 KB
/
DotPubSubProviderLocator.java
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
package com.dotcms.dotpubsub;
import com.dotmarketing.exception.DotRuntimeException;
import com.dotmarketing.util.Config;
import io.vavr.Lazy;
import io.vavr.control.Try;
public class DotPubSubProviderLocator {
public final static String DOT_PUBSUB_PROVIDER_OVERRIDE = "DOT_PUBSUB_PROVIDER_OVERRIDE";
public final static String DOT_PUBSUB_USE_QUEUE = "DOT_PUBSUB_USE_QUEUE";
/**
* Default provider is JDBCPubSubImpl, can be overriden by setting config: DOT_PUBSUB_PROVIDER_OVERRIDE
* DOT_PUBSUB_USE_QUEUE is a boolean, and will wrap the Pubsub in a queue
*/
public static Lazy<DotPubSubProvider> provider = Lazy.of(() -> {
final boolean useQueue = System.getProperty(DOT_PUBSUB_USE_QUEUE) != null
? Boolean.valueOf(System.getProperty(DOT_PUBSUB_USE_QUEUE))
: Config.getBooleanProperty(DOT_PUBSUB_USE_QUEUE, true);
final String pubsubClazz = System.getProperty(DOT_PUBSUB_PROVIDER_OVERRIDE) != null
? System.getProperty(DOT_PUBSUB_PROVIDER_OVERRIDE)
: Config.getStringProperty(DOT_PUBSUB_PROVIDER_OVERRIDE,
JDBCPubSubImpl.class.getCanonicalName());
DotPubSubProvider provider = (DotPubSubProvider) Try.of(() -> Class.forName(pubsubClazz).newInstance())
.getOrElseThrow(e -> new DotRuntimeException(e));
return (useQueue) ? new QueuingPubSubWrapper(provider) : provider;
});
}