- private final DOMStoreWriteTransaction transaction;
- private final LoggingAdapter log =
- Logging.getLogger(getContext().system(), this);
- public ShardWriteTransaction(DOMStoreWriteTransaction transaction, ActorRef shardActor, SchemaContext schemaContext) {
- super( shardActor, schemaContext);
- this.transaction = transaction;
-
- }
-
- public ShardWriteTransaction(DOMStoreTransactionChain transactionChain, DOMStoreWriteTransaction transaction, ActorRef shardActor, SchemaContext schemaContext) {
- super(transactionChain, shardActor, schemaContext);
- this.transaction = transaction;
- }
-
- @Override
- public void handleReceive(Object message) throws Exception {
- if (WriteData.SERIALIZABLE_CLASS.equals(message.getClass())) {
- writeData(transaction, WriteData.fromSerializable(message, schemaContext));
- } else if (MergeData.SERIALIZABLE_CLASS.equals(message.getClass())) {
- mergeData(transaction, MergeData.fromSerializable(message, schemaContext));
- } else if (DeleteData.SERIALIZABLE_CLASS.equals(message.getClass())) {
- deleteData(transaction,DeleteData.fromSerizalizable(message));
- } else if (ReadyTransaction.SERIALIZABLE_CLASS.equals(message.getClass())) {
- readyTransaction(transaction,new ReadyTransaction());
- }else {
- super.handleReceive(message);
+
+ private int totalBatchedModificationsReceived;
+ private Exception lastBatchedModificationsException;
+ private final ReadWriteShardDataTreeTransaction transaction;
+
+ public ShardWriteTransaction(ReadWriteShardDataTreeTransaction transaction, ActorRef shardActor,
+ ShardStats shardStats, String transactionID) {
+ super(shardActor, shardStats, transactionID);
+ this.transaction = transaction;
+ }
+
+ @Override
+ protected ReadWriteShardDataTreeTransaction getDOMStoreTransaction() {
+ return transaction;
+ }
+
+ @Override
+ public void handleReceive(Object message) throws Exception {
+
+ if (message instanceof BatchedModifications) {
+ batchedModifications((BatchedModifications)message);
+ } else {
+ super.handleReceive(message);
+ }
+ }
+
+ private void batchedModifications(BatchedModifications batched) {
+ if (checkClosed()) {
+ if (batched.isReady()) {
+ getSelf().tell(PoisonPill.getInstance(), getSelf());
+ }
+ return;
+ }
+
+ try {
+ for(Modification modification: batched.getModifications()) {
+ modification.apply(transaction.getSnapshot());
+ }
+
+ totalBatchedModificationsReceived++;
+ if(batched.isReady()) {
+ if(lastBatchedModificationsException != null) {
+ throw lastBatchedModificationsException;
+ }
+
+ if(totalBatchedModificationsReceived != batched.getTotalMessagesSent()) {
+ throw new IllegalStateException(String.format(
+ "The total number of batched messages received %d does not match the number sent %d",
+ totalBatchedModificationsReceived, batched.getTotalMessagesSent()));
+ }
+
+ readyTransaction(false, batched.isDoCommitOnReady(), batched.getVersion());
+ } else {
+ getSender().tell(new BatchedModificationsReply(batched.getModifications().size()), getSelf());
+ }
+ } catch (Exception e) {
+ lastBatchedModificationsException = e;
+ getSender().tell(new akka.actor.Status.Failure(e), getSelf());
+
+ if(batched.isReady()) {
+ getSelf().tell(PoisonPill.getInstance(), getSelf());
+ }
+ }
+ }
+
+ protected final void dataExists(DataExists message) {
+ super.dataExists(transaction, message);
+ }
+
+ protected final void readData(ReadData message) {
+ super.readData(transaction, message);