|
17 | 17 | package com.couchbase.transactions; |
18 | 18 |
|
19 | 19 | import com.couchbase.client.core.annotation.Stability; |
20 | | -import com.couchbase.transactions.config.MergedTransactionConfig; |
21 | | -import com.couchbase.transactions.config.PerTransactionConfig; |
22 | | -import com.couchbase.transactions.config.PerTransactionConfigBuilder; |
23 | | -import com.couchbase.transactions.config.TransactionConfig; |
24 | | -import com.couchbase.transactions.forwards.Supported; |
25 | | -import com.couchbase.transactions.log.TransactionLogger; |
| 20 | +import com.couchbase.client.core.transaction.log.CoreTransactionLogger; |
| 21 | +import com.couchbase.client.java.transactions.ReactiveTransactionAttemptContext; |
| 22 | +import com.couchbase.client.java.transactions.TransactionAttemptContext; |
| 23 | +import org.springframework.transaction.reactive.TransactionContext; |
26 | 24 |
|
27 | 25 | import java.time.Duration; |
28 | 26 | import java.time.temporal.ChronoUnit; |
29 | 27 | import java.util.Optional; |
30 | 28 | import java.util.UUID; |
31 | 29 |
|
32 | 30 | /** |
33 | | - * To access the AttemptContextReactive held by AttemptContext |
| 31 | + * To access the ReactiveTransactionAttemptContext held by TransactionAttemptContext |
34 | 32 | * |
35 | 33 | * @author Michael Reiche |
36 | 34 | */ |
37 | 35 | public class AttemptContextReactiveAccessor { |
38 | 36 |
|
39 | | - public static AttemptContextReactive getACR(AttemptContext attemptContext) { |
40 | | - return attemptContext.ctx(); |
| 37 | + public static ReactiveTransactionAttemptContext getACR(TransactionAttemptContext attemptContext) { |
| 38 | + // return attemptContext.ctx(); |
| 39 | + // todo gp is this access needed. Could hold the raw CoreTransactionAttemptContext instead. |
| 40 | + return null; |
41 | 41 | } |
42 | 42 |
|
43 | | - public static AttemptContext from(AttemptContextReactive attemptContextReactive) { |
44 | | - return new AttemptContext(attemptContextReactive); |
| 43 | + public static TransactionAttemptContext from(ReactiveTransactionAttemptContext attemptContextReactive) { |
| 44 | + // todo gp needed? |
| 45 | + return null; |
| 46 | +// return new TransactionAttemptContext(attemptContextReactive); |
45 | 47 | } |
46 | 48 |
|
47 | | - public static TransactionLogger getLogger(AttemptContextReactive attemptContextReactive){ |
48 | | - return attemptContextReactive.LOGGER; |
49 | | - } |
50 | | - @Stability.Internal |
51 | | - public static AttemptContextReactive newAttemptContextReactive(TransactionsReactive transactions){ |
52 | | - PerTransactionConfig perConfig = PerTransactionConfigBuilder.create().build(); |
53 | | - MergedTransactionConfig merged = new MergedTransactionConfig(transactions.config(), Optional.of(perConfig)); |
54 | | - |
55 | | - TransactionContext overall = new TransactionContext( |
56 | | - transactions.cleanup().clusterData().cluster().environment().requestTracer(), |
57 | | - transactions.cleanup().clusterData().cluster().environment().eventBus(), |
58 | | - UUID.randomUUID().toString(), now(), Duration.ZERO, merged); |
59 | | - |
60 | | - String txnId = UUID.randomUUID().toString(); |
61 | | - overall.LOGGER.info(configDebug(transactions.config(), perConfig)); |
62 | | - return transactions.createAttemptContext(overall, merged, txnId); |
| 49 | + public static CoreTransactionLogger getLogger(ReactiveTransactionAttemptContext attemptContextReactive){ |
| 50 | + // todo gp needed? |
| 51 | + return null; |
| 52 | + //return attemptContextReactive; |
63 | 53 | } |
| 54 | + // todo gp needed? |
| 55 | +// @Stability.Internal |
| 56 | +// public static ReactiveTransactionAttemptContext newAttemptContextReactive(TransactionsReactive transactions){ |
| 57 | +// return null; |
| 58 | +// PerTransactionConfig perConfig = PerTransactionConfigBuilder.create().build(); |
| 59 | +// MergedTransactionConfig merged = new MergedTransactionConfig(transactions.config(), Optional.of(perConfig)); |
| 60 | +// |
| 61 | +// TransactionContext overall = new TransactionContext( |
| 62 | +// transactions.cleanup().clusterData().cluster().environment().requestTracer(), |
| 63 | +// transactions.cleanup().clusterData().cluster().environment().eventBus(), |
| 64 | +// UUID.randomUUID().toString(), now(), Duration.ZERO, merged); |
| 65 | +// |
| 66 | +// String txnId = UUID.randomUUID().toString(); |
| 67 | +// overall.LOGGER.info(configDebug(transactions.config(), perConfig)); |
| 68 | +// return transactions.createAttemptContext(overall, merged, txnId); |
| 69 | +// } |
64 | 70 |
|
65 | 71 | private static Duration now() { |
66 | 72 | return Duration.of(System.nanoTime(), ChronoUnit.NANOS); |
67 | 73 | } |
68 | 74 |
|
69 | | - static private String configDebug(TransactionConfig config, PerTransactionConfig perConfig) { |
70 | | - StringBuilder sb = new StringBuilder(); |
71 | | - sb.append("library version: "); |
72 | | - sb.append(TransactionsReactive.class.getPackage().getImplementationVersion()); |
73 | | - sb.append(" config: "); |
74 | | - sb.append("atrs="); |
75 | | - sb.append(config.numAtrs()); |
76 | | - sb.append(", metadataCollection="); |
77 | | - sb.append(config.metadataCollection()); |
78 | | - sb.append(", expiry="); |
79 | | - sb.append(perConfig.expirationTime().orElse(config.transactionExpirationTime()).toMillis()); |
80 | | - sb.append("msecs durability="); |
81 | | - sb.append(config.durabilityLevel()); |
82 | | - sb.append(" per-txn config="); |
83 | | - sb.append(" durability="); |
84 | | - sb.append(perConfig.durabilityLevel()); |
85 | | - sb.append(", supported="); |
86 | | - sb.append(Supported.SUPPORTED); |
87 | | - return sb.toString(); |
88 | | - } |
| 75 | + // todo gp if needed let's expose in the SDK |
| 76 | +// static private String configDebug(TransactionConfig config, PerTransactionConfig perConfig) { |
| 77 | +// StringBuilder sb = new StringBuilder(); |
| 78 | +// sb.append("library version: "); |
| 79 | +// sb.append(TransactionsReactive.class.getPackage().getImplementationVersion()); |
| 80 | +// sb.append(" config: "); |
| 81 | +// sb.append("atrs="); |
| 82 | +// sb.append(config.numAtrs()); |
| 83 | +// sb.append(", metadataCollection="); |
| 84 | +// sb.append(config.metadataCollection()); |
| 85 | +// sb.append(", expiry="); |
| 86 | +// sb.append(perConfig.expirationTime().orElse(config.transactionExpirationTime()).toMillis()); |
| 87 | +// sb.append("msecs durability="); |
| 88 | +// sb.append(config.durabilityLevel()); |
| 89 | +// sb.append(" per-txn config="); |
| 90 | +// sb.append(" durability="); |
| 91 | +// sb.append(perConfig.durabilityLevel()); |
| 92 | +// sb.append(", supported="); |
| 93 | +// sb.append(Supported.SUPPORTED); |
| 94 | +// return sb.toString(); |
| 95 | +// } |
89 | 96 |
|
90 | 97 | } |
0 commit comments