- 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(final ReadWriteShardDataTreeTransaction transaction, final ActorRef shardActor,
+ final ShardStats shardStats) {
+ super(shardActor, shardStats, transaction.getIdentifier());
+ this.transaction = transaction;
+ }
+
+ @Override
+ protected ReadWriteShardDataTreeTransaction getDOMStoreTransaction() {
+ return transaction;
+ }
+
+ @Override
+ public void handleReceive(final Object message) {
+ if (message instanceof BatchedModifications) {
+ batchedModifications((BatchedModifications)message);
+ } else {
+ super.handleReceive(message);
+ }
+ }
+
+ @SuppressWarnings("checkstyle:IllegalCatch")
+ private void batchedModifications(final 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(batched);
+ } 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(final DataExists message) {
+ super.dataExists(transaction, message);
+ }
+
+ protected final void readData(final ReadData message) {
+ super.readData(transaction, message);