+ private ActorRef createTypedTransactionActor(CreateTransaction createTransaction) {
+ String transactionName = "shard-" + createTransaction.getTransactionId();
+ if(createTransaction.getTransactionType() ==
+ TransactionProxy.TransactionType.READ_ONLY.ordinal()) {
+ return getContext().actorOf(
+ ShardTransaction.props( chain.newReadOnlyTransaction(), getShardActor(),
+ schemaContext, datastoreContext, shardStats,
+ createTransaction.getTransactionId(),
+ createTransaction.getVersion()), transactionName);
+ } else if (createTransaction.getTransactionType() ==
+ TransactionProxy.TransactionType.READ_WRITE.ordinal()) {
+ return getContext().actorOf(
+ ShardTransaction.props( chain.newReadWriteTransaction(), getShardActor(),
+ schemaContext, datastoreContext, shardStats,
+ createTransaction.getTransactionId(),
+ createTransaction.getVersion()), transactionName);
+ } else if (createTransaction.getTransactionType() ==
+ TransactionProxy.TransactionType.WRITE_ONLY.ordinal()) {
+ return getContext().actorOf(
+ ShardTransaction.props( chain.newWriteOnlyTransaction(), getShardActor(),
+ schemaContext, datastoreContext, shardStats,
+ createTransaction.getTransactionId(),
+ createTransaction.getVersion()), transactionName);
+ } else {
+ throw new IllegalArgumentException (
+ "CreateTransaction message has unidentified transaction type=" +
+ createTransaction.getTransactionType());
+ }
+ }
+
+ private void createTransaction(CreateTransaction createTransaction) {
+
+ ActorRef transactionActor = createTypedTransactionActor(createTransaction);
+ getSender().tell(new CreateTransactionReply(transactionActor.path().toString(),
+ createTransaction.getTransactionId()).toSerializable(), getSelf());
+ }
+
+ public static Props props(DOMStoreTransactionChain chain, SchemaContext schemaContext,
+ DatastoreContext datastoreContext, ShardStats shardStats) {
+ return Props.create(new ShardTransactionChainCreator(chain, schemaContext,
+ datastoreContext, shardStats));
+ }
+
+ private static class ShardTransactionChainCreator implements Creator<ShardTransactionChain> {
+ private static final long serialVersionUID = 1L;
+
+ final DOMStoreTransactionChain chain;
+ final DatastoreContext datastoreContext;
+ final SchemaContext schemaContext;
+ final ShardStats shardStats;
+
+
+ ShardTransactionChainCreator(DOMStoreTransactionChain chain, SchemaContext schemaContext,
+ DatastoreContext datastoreContext, ShardStats shardStats) {
+ this.chain = chain;
+ this.datastoreContext = datastoreContext;
+ this.schemaContext = schemaContext;
+ this.shardStats = shardStats;
+ }
+
+ @Override
+ public ShardTransactionChain create() throws Exception {
+ return new ShardTransactionChain(chain, schemaContext, datastoreContext, shardStats);
+ }
+ }