/
ConnectionPersistenceOperationsActor.java
79 lines (66 loc) · 3.57 KB
/
ConnectionPersistenceOperationsActor.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
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
/*
* Copyright (c) 2017 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.ditto.services.connectivity.messaging.persistence;
import java.util.Collections;
import org.eclipse.ditto.services.connectivity.messaging.ConnectionActor;
import org.eclipse.ditto.services.utils.persistence.mongo.MongoClientWrapper;
import org.eclipse.ditto.services.utils.persistence.mongo.config.MongoDbConfig;
import org.eclipse.ditto.services.utils.persistence.mongo.ops.AbstractPersistenceOperationsActor;
import org.eclipse.ditto.services.utils.persistence.mongo.ops.EntityPersistenceOperations;
import org.eclipse.ditto.services.utils.persistence.mongo.ops.PersistenceOperationsConfiguration;
import org.eclipse.ditto.services.utils.persistence.mongo.ops.eventsource.MongoEntitiesPersistenceOperations;
import org.eclipse.ditto.services.utils.persistence.mongo.ops.eventsource.MongoEventSourceSettings;
import org.eclipse.ditto.signals.commands.connectivity.ConnectivityCommand;
import com.mongodb.reactivestreams.client.MongoDatabase;
import com.typesafe.config.Config;
import akka.actor.ActorRef;
import akka.actor.Props;
/**
* Ops for the event-sourcing persistence of things.
*/
public final class ConnectionPersistenceOperationsActor extends AbstractPersistenceOperationsActor {
public static final String ACTOR_NAME = "connectionOps";
private ConnectionPersistenceOperationsActor(final ActorRef pubSubMediator,
final EntityPersistenceOperations entitiesOps,
final MongoClientWrapper mongoClientWrapper,
final PersistenceOperationsConfiguration persistenceOperationsConfiguration) {
super(pubSubMediator,
ConnectivityCommand.RESOURCE_TYPE,
null,
entitiesOps,
Collections.singleton(mongoClientWrapper),
persistenceOperationsConfiguration);
}
/**
* Create Props of this actor.
*
* @param pubSubMediator Akka pub-sub mediator.
* @param mongoDbConfig the MongoDB configuration settings.
* @param config configuration with info about event journal, snapshot store, suffix-builder and database.
* @return a Props object.
*/
public static Props props(final ActorRef pubSubMediator, final MongoDbConfig mongoDbConfig, final Config config) {
return Props.create(ConnectionPersistenceOperationsActor.class, () -> {
final MongoEventSourceSettings eventSourceSettings =
MongoEventSourceSettings.fromConfig(config, ConnectionActor.PERSISTENCE_ID_PREFIX, false,
ConnectionActor.JOURNAL_PLUGIN_ID, ConnectionActor.SNAPSHOT_PLUGIN_ID);
final MongoClientWrapper mongoClient = MongoClientWrapper.newInstance(mongoDbConfig);
final MongoDatabase db = mongoClient.getDefaultDatabase();
final EntityPersistenceOperations entitiesOps = MongoEntitiesPersistenceOperations.of(db, eventSourceSettings);
final PersistenceOperationsConfiguration persistenceOperationsConfiguration =
PersistenceOperationsConfiguration.fromConfig(config);
return new ConnectionPersistenceOperationsActor(pubSubMediator, entitiesOps, mongoClient,
persistenceOperationsConfiguration);
});
}
}