Skip to content
This repository has been archived by the owner on Nov 14, 2024. It is now read-only.

Commit

Permalink
Use a Builder to create Transaction Managers (#2459)
Browse files Browse the repository at this point in the history
* introduce immutable options parameter for TM creation

* Clean up TransactionManagers via breaks

* fix metrics user agent regression

* move to builder

* fix readme and changelog

* un-break the APIs

* more un-breaking

* update release notes

* rename env to registrar

* checkstyle

* maybe fix docs issue

* use date for deprecation break
  • Loading branch information
tpetracca authored and gsheasby committed Oct 19, 2017
1 parent 9de3a16 commit 9d02b7f
Show file tree
Hide file tree
Showing 9 changed files with 217 additions and 141 deletions.
21 changes: 8 additions & 13 deletions atlasdb-config/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,10 @@ Creating a `TransactionManager`:
```java
AtlasDbConfig atlasConfig = ...
Schema atlasSchema = ...
Optional<SSLSocketFactory> sslSocketFactory = ...

SerializableTransactionManager tm = TransactionManagers.create(
atlasConfig,
sslSocketFactory,
atlasSchema,
(resource) -> {});
SerializableTransactionManager tm = TransactionManagers.builder()
.config(atlasConfig)
.schemas(ImmutableSet.of(atlasSchema))
.buildSerializable();
```

The last item is a consumer of resources meant to be exposed to as web
Expand Down Expand Up @@ -48,12 +45,10 @@ And initialization code to your run method:

```java
public void run(AtlasDbServerConfiguration config, Environment env) throws Exception {
TransactionManager transactionManager =
TransactionManagers.create(
config.getAtlas(),
Optional.<SSLSocketFactory>absent(),
ImmutableSet.<Schema>of(),
env.jersey()::register);
TransactionManager transactionManager = TransactionManagers.builder()
.config(config.getAtlas())
.registrar(env.jersey()::register)
.buildSerializable();
...
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.Executors;
import java.util.function.Consumer;

import javax.net.ssl.SSLSocketFactory;

Expand All @@ -36,7 +37,6 @@
import com.google.common.net.HostAndPort;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import com.palantir.atlasdb.config.LeaderConfig;
import com.palantir.atlasdb.factory.TransactionManagers.Environment;
import com.palantir.atlasdb.http.AtlasDbHttpClients;
import com.palantir.atlasdb.http.NotCurrentLeaderExceptionMapper;
import com.palantir.atlasdb.http.UserAgents;
Expand All @@ -62,22 +62,22 @@ private Leaders() {
* Creates a LeaderElectionService using the supplied configuration and
* registers appropriate endpoints for that service.
*/
public static LeaderElectionService create(Environment env, LeaderConfig config) {
public static LeaderElectionService create(Consumer<Object> env, LeaderConfig config) {
return create(env, config, UserAgents.DEFAULT_USER_AGENT);
}

public static LeaderElectionService create(Environment env, LeaderConfig config, String userAgent) {
public static LeaderElectionService create(Consumer<Object> env, LeaderConfig config, String userAgent) {
return createAndRegisterLocalServices(env, config, userAgent).leaderElectionService();
}

public static LocalPaxosServices createAndRegisterLocalServices(
Environment env, LeaderConfig config, String userAgent) {
Consumer<Object> env, LeaderConfig config, String userAgent) {
LocalPaxosServices localPaxosServices = createInstrumentedLocalServices(config, userAgent);

env.register(localPaxosServices.ourAcceptor());
env.register(localPaxosServices.ourLearner());
env.register(localPaxosServices.pingableLeader());
env.register(new NotCurrentLeaderExceptionMapper());
env.accept(localPaxosServices.ourAcceptor());
env.accept(localPaxosServices.ourLearner());
env.accept(localPaxosServices.pingableLeader());
env.accept(new NotCurrentLeaderExceptionMapper());
return localPaxosServices;
}

Expand Down
Loading

0 comments on commit 9d02b7f

Please sign in to comment.