-public class ShardTransactionChain extends UntypedActor{
-
- private final DOMStoreTransactionChain chain;
-
- public ShardTransactionChain(DOMStoreTransactionChain chain) {
- this.chain = chain;
- }
-
- @Override
- public void onReceive(Object message) throws Exception {
- if(message instanceof CreateTransaction){
- DOMStoreReadWriteTransaction transaction = chain.newReadWriteTransaction();
- ActorRef transactionActor = getContext().actorOf(ShardTransaction.props(transaction));
- getSender().tell(new CreateTransactionReply(transactionActor.path()), getSelf());
- } else if (message instanceof CloseTransactionChain){
- chain.close();
- getSender().tell(new CloseTransactionChainReply(), getSelf());
+public class ShardTransactionChain extends AbstractUntypedActor {
+
+ private final ShardDataTreeTransactionChain chain;
+ private final DatastoreContext datastoreContext;
+ private final ShardStats shardStats;
+
+ public ShardTransactionChain(ShardDataTreeTransactionChain chain, DatastoreContext datastoreContext,
+ ShardStats shardStats) {
+ this.chain = Preconditions.checkNotNull(chain);
+ this.datastoreContext = datastoreContext;
+ this.shardStats = shardStats;
+ }
+
+ @Override
+ public void handleReceive(Object message) throws Exception {
+ if (message.getClass().equals(CreateTransaction.SERIALIZABLE_CLASS)) {
+ CreateTransaction createTransaction = CreateTransaction.fromSerializable( message);
+ createTransaction(createTransaction);
+ } else if (message.getClass().equals(CloseTransactionChain.SERIALIZABLE_CLASS)) {
+ chain.close();
+ getSender().tell(CloseTransactionChainReply.INSTANCE.toSerializable(), getSelf());
+ }else{
+ unknownMessage(message);
+ }
+ }
+
+ private ActorRef getShardActor(){
+ return getContext().parent();
+ }
+
+ private ActorRef createTypedTransactionActor(CreateTransaction createTransaction) {
+ String transactionName = "shard-" + createTransaction.getTransactionId();
+
+ final TransactionType type = TransactionType.fromInt(createTransaction.getTransactionType());
+ final AbstractShardDataTreeTransaction<?> transaction;
+ switch (type) {
+ case READ_ONLY:
+ transaction = chain.newReadOnlyTransaction(transactionName);
+ break;
+ case READ_WRITE:
+ case WRITE_ONLY:
+ transaction = chain.newReadWriteTransaction(transactionName);
+ break;
+ default:
+ throw new IllegalArgumentException("Unhandled transaction type " + type);
+ }
+
+ return getContext().actorOf(
+ ShardTransaction.props(type, transaction, getShardActor(),
+ datastoreContext, shardStats, createTransaction.getTransactionId(),
+ createTransaction.getVersion()), transactionName);