- }
-
- private void readData(ReadData message) {
- final ActorRef sender = getSender();
- final ActorRef self = getSelf();
- final InstanceIdentifier path = message.getPath();
- final ListenableFuture<Optional<NormalizedNode<?, ?>>> future = transaction.read(path);
-
- future.addListener(new Runnable() {
- @Override
- public void run() {
- try {
- Optional<NormalizedNode<?, ?>> optional = future.get();
- if(optional.isPresent()){
- sender.tell(new ReadDataReply(optional.get()), self);
- } else {
- //TODO : Need to decide what to do here
- }
- } catch (InterruptedException | ExecutionException e) {
- log.error(e, "An exception happened when reading data from path : " + path.toString());
+
+
+
+ public static Props props(final DOMStoreReadWriteTransaction transaction,
+ final ActorRef shardActor, final SchemaContext schemaContext) {
+ return Props.create(new Creator<ShardTransaction>() {
+
+ @Override
+ public ShardTransaction create() throws Exception {
+ return new ShardTransaction(transaction, shardActor, schemaContext);
+ }
+ });
+ }
+
+ public static Props props(final DOMStoreTransactionChain transactionChain, final DOMStoreReadWriteTransaction transaction,
+ final ActorRef shardActor, final SchemaContext schemaContext) {
+ return Props.create(new Creator<ShardTransaction>() {
+
+ @Override
+ public ShardTransaction create() throws Exception {
+ return new ShardTransaction(transactionChain, transaction, shardActor, schemaContext);
+ }
+ });
+ }
+
+
+ @Override
+ public void handleReceive(Object message) throws Exception {
+ if (ReadData.SERIALIZABLE_CLASS.equals(message.getClass())) {
+ readData(ReadData.fromSerializable(message));
+ } else if (WriteData.SERIALIZABLE_CLASS.equals(message.getClass())) {
+ writeData(WriteData.fromSerializable(message, schemaContext));
+ } else if (MergeData.SERIALIZABLE_CLASS.equals(message.getClass())) {
+ mergeData(MergeData.fromSerializable(message, schemaContext));
+ } else if (DeleteData.SERIALIZABLE_CLASS.equals(message.getClass())) {
+ deleteData(DeleteData.fromSerizalizable(message));
+ } else if (ReadyTransaction.SERIALIZABLE_CLASS.equals(message.getClass())) {
+ readyTransaction(new ReadyTransaction());
+ } else if (message.getClass().equals(CloseTransaction.SERIALIZABLE_CLASS)) {
+ closeTransaction(new CloseTransaction());
+ } else if (message instanceof GetCompositedModification) {
+ // This is here for testing only
+ getSender().tell(new GetCompositeModificationReply(
+ new ImmutableCompositeModification(modification)), getSelf());
+ }else{
+ throw new Exception ("Shard:handleRecieve received an unknown message"+message);