Committed by
Thomas Vachuska
Using non-static serializers in Flow Rule Store
Change-Id: Ifacd9ca98d8c6d3bbf03b3b9784234f7eab458a5
Showing
1 changed file
with
23 additions
and
29 deletions
| ... | @@ -68,8 +68,6 @@ import org.onosproject.store.flow.ReplicaInfoEventListener; | ... | @@ -68,8 +68,6 @@ import org.onosproject.store.flow.ReplicaInfoEventListener; |
| 68 | import org.onosproject.store.flow.ReplicaInfoService; | 68 | import org.onosproject.store.flow.ReplicaInfoService; |
| 69 | import org.onosproject.store.impl.MastershipBasedTimestamp; | 69 | import org.onosproject.store.impl.MastershipBasedTimestamp; |
| 70 | import org.onosproject.store.serializers.KryoNamespaces; | 70 | import org.onosproject.store.serializers.KryoNamespaces; |
| 71 | -import org.onosproject.store.serializers.StoreSerializer; | ||
| 72 | -import org.onosproject.store.serializers.custom.DistributedStoreSerializers; | ||
| 73 | import org.onosproject.store.service.EventuallyConsistentMap; | 71 | import org.onosproject.store.service.EventuallyConsistentMap; |
| 74 | import org.onosproject.store.service.EventuallyConsistentMapEvent; | 72 | import org.onosproject.store.service.EventuallyConsistentMapEvent; |
| 75 | import org.onosproject.store.service.EventuallyConsistentMapListener; | 73 | import org.onosproject.store.service.EventuallyConsistentMapListener; |
| ... | @@ -183,13 +181,9 @@ public class DistributedFlowRuleStore | ... | @@ -183,13 +181,9 @@ public class DistributedFlowRuleStore |
| 183 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 181 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 184 | protected StorageService storageService; | 182 | protected StorageService storageService; |
| 185 | 183 | ||
| 186 | - protected static final StoreSerializer SERIALIZER = StoreSerializer.using( | 184 | + protected final Serializer serializer = Serializer.using(KryoNamespaces.API); |
| 187 | - KryoNamespace.newBuilder() | ||
| 188 | - .register(DistributedStoreSerializers.STORE_COMMON) | ||
| 189 | - .nextId(DistributedStoreSerializers.STORE_CUSTOM_BEGIN) | ||
| 190 | - .build("FlowRuleStore")); | ||
| 191 | 185 | ||
| 192 | - protected static final KryoNamespace.Builder SERIALIZER_BUILDER = KryoNamespace.newBuilder() | 186 | + protected final KryoNamespace.Builder serializerBuilder = KryoNamespace.newBuilder() |
| 193 | .register(KryoNamespaces.API) | 187 | .register(KryoNamespaces.API) |
| 194 | .register(MastershipBasedTimestamp.class); | 188 | .register(MastershipBasedTimestamp.class); |
| 195 | 189 | ||
| ... | @@ -223,7 +217,7 @@ public class DistributedFlowRuleStore | ... | @@ -223,7 +217,7 @@ public class DistributedFlowRuleStore |
| 223 | 217 | ||
| 224 | deviceTableStats = storageService.<DeviceId, List<TableStatisticsEntry>>eventuallyConsistentMapBuilder() | 218 | deviceTableStats = storageService.<DeviceId, List<TableStatisticsEntry>>eventuallyConsistentMapBuilder() |
| 225 | .withName("onos-flow-table-stats") | 219 | .withName("onos-flow-table-stats") |
| 226 | - .withSerializer(SERIALIZER_BUILDER) | 220 | + .withSerializer(serializerBuilder) |
| 227 | .withAntiEntropyPeriod(5, TimeUnit.SECONDS) | 221 | .withAntiEntropyPeriod(5, TimeUnit.SECONDS) |
| 228 | .withTimestampProvider((k, v) -> new WallClockTimestamp()) | 222 | .withTimestampProvider((k, v) -> new WallClockTimestamp()) |
| 229 | .withTombstonesDisabled() | 223 | .withTombstonesDisabled() |
| ... | @@ -331,17 +325,17 @@ public class DistributedFlowRuleStore | ... | @@ -331,17 +325,17 @@ public class DistributedFlowRuleStore |
| 331 | 325 | ||
| 332 | clusterCommunicator.addSubscriber(APPLY_BATCH_FLOWS, new OnStoreBatch(), executor); | 326 | clusterCommunicator.addSubscriber(APPLY_BATCH_FLOWS, new OnStoreBatch(), executor); |
| 333 | clusterCommunicator.<FlowRuleBatchEvent>addSubscriber( | 327 | clusterCommunicator.<FlowRuleBatchEvent>addSubscriber( |
| 334 | - REMOTE_APPLY_COMPLETED, SERIALIZER::decode, this::notifyDelegate, executor); | 328 | + REMOTE_APPLY_COMPLETED, serializer::decode, this::notifyDelegate, executor); |
| 335 | clusterCommunicator.addSubscriber( | 329 | clusterCommunicator.addSubscriber( |
| 336 | - GET_FLOW_ENTRY, SERIALIZER::decode, flowTable::getFlowEntry, SERIALIZER::encode, executor); | 330 | + GET_FLOW_ENTRY, serializer::decode, flowTable::getFlowEntry, serializer::encode, executor); |
| 337 | clusterCommunicator.addSubscriber( | 331 | clusterCommunicator.addSubscriber( |
| 338 | - GET_DEVICE_FLOW_ENTRIES, SERIALIZER::decode, flowTable::getFlowEntries, SERIALIZER::encode, executor); | 332 | + GET_DEVICE_FLOW_ENTRIES, serializer::decode, flowTable::getFlowEntries, serializer::encode, executor); |
| 339 | clusterCommunicator.addSubscriber( | 333 | clusterCommunicator.addSubscriber( |
| 340 | - REMOVE_FLOW_ENTRY, SERIALIZER::decode, this::removeFlowRuleInternal, SERIALIZER::encode, executor); | 334 | + REMOVE_FLOW_ENTRY, serializer::decode, this::removeFlowRuleInternal, serializer::encode, executor); |
| 341 | clusterCommunicator.addSubscriber( | 335 | clusterCommunicator.addSubscriber( |
| 342 | - REMOVE_FLOW_ENTRY, SERIALIZER::decode, this::removeFlowRuleInternal, SERIALIZER::encode, executor); | 336 | + REMOVE_FLOW_ENTRY, serializer::decode, this::removeFlowRuleInternal, serializer::encode, executor); |
| 343 | clusterCommunicator.addSubscriber( | 337 | clusterCommunicator.addSubscriber( |
| 344 | - FLOW_TABLE_BACKUP, SERIALIZER::decode, flowTable::onBackupReceipt, SERIALIZER::encode, executor); | 338 | + FLOW_TABLE_BACKUP, serializer::decode, flowTable::onBackupReceipt, serializer::encode, executor); |
| 345 | } | 339 | } |
| 346 | 340 | ||
| 347 | private void unregisterMessageHandlers() { | 341 | private void unregisterMessageHandlers() { |
| ... | @@ -386,8 +380,8 @@ public class DistributedFlowRuleStore | ... | @@ -386,8 +380,8 @@ public class DistributedFlowRuleStore |
| 386 | 380 | ||
| 387 | return Tools.futureGetOrElse(clusterCommunicator.sendAndReceive(rule, | 381 | return Tools.futureGetOrElse(clusterCommunicator.sendAndReceive(rule, |
| 388 | FlowStoreMessageSubjects.GET_FLOW_ENTRY, | 382 | FlowStoreMessageSubjects.GET_FLOW_ENTRY, |
| 389 | - SERIALIZER::encode, | 383 | + serializer::encode, |
| 390 | - SERIALIZER::decode, | 384 | + serializer::decode, |
| 391 | master), | 385 | master), |
| 392 | FLOW_RULE_STORE_TIMEOUT_MILLIS, | 386 | FLOW_RULE_STORE_TIMEOUT_MILLIS, |
| 393 | TimeUnit.MILLISECONDS, | 387 | TimeUnit.MILLISECONDS, |
| ... | @@ -412,8 +406,8 @@ public class DistributedFlowRuleStore | ... | @@ -412,8 +406,8 @@ public class DistributedFlowRuleStore |
| 412 | 406 | ||
| 413 | return Tools.futureGetOrElse(clusterCommunicator.sendAndReceive(deviceId, | 407 | return Tools.futureGetOrElse(clusterCommunicator.sendAndReceive(deviceId, |
| 414 | FlowStoreMessageSubjects.GET_DEVICE_FLOW_ENTRIES, | 408 | FlowStoreMessageSubjects.GET_DEVICE_FLOW_ENTRIES, |
| 415 | - SERIALIZER::encode, | 409 | + serializer::encode, |
| 416 | - SERIALIZER::decode, | 410 | + serializer::decode, |
| 417 | master), | 411 | master), |
| 418 | FLOW_RULE_STORE_TIMEOUT_MILLIS, | 412 | FLOW_RULE_STORE_TIMEOUT_MILLIS, |
| 419 | TimeUnit.MILLISECONDS, | 413 | TimeUnit.MILLISECONDS, |
| ... | @@ -460,7 +454,7 @@ public class DistributedFlowRuleStore | ... | @@ -460,7 +454,7 @@ public class DistributedFlowRuleStore |
| 460 | 454 | ||
| 461 | clusterCommunicator.unicast(operation, | 455 | clusterCommunicator.unicast(operation, |
| 462 | APPLY_BATCH_FLOWS, | 456 | APPLY_BATCH_FLOWS, |
| 463 | - SERIALIZER::encode, | 457 | + serializer::encode, |
| 464 | master) | 458 | master) |
| 465 | .whenComplete((result, error) -> { | 459 | .whenComplete((result, error) -> { |
| 466 | if (error != null) { | 460 | if (error != null) { |
| ... | @@ -607,8 +601,8 @@ public class DistributedFlowRuleStore | ... | @@ -607,8 +601,8 @@ public class DistributedFlowRuleStore |
| 607 | return Futures.getUnchecked(clusterCommunicator.sendAndReceive( | 601 | return Futures.getUnchecked(clusterCommunicator.sendAndReceive( |
| 608 | rule, | 602 | rule, |
| 609 | REMOVE_FLOW_ENTRY, | 603 | REMOVE_FLOW_ENTRY, |
| 610 | - SERIALIZER::encode, | 604 | + serializer::encode, |
| 611 | - SERIALIZER::decode, | 605 | + serializer::decode, |
| 612 | master)); | 606 | master)); |
| 613 | } | 607 | } |
| 614 | 608 | ||
| ... | @@ -633,7 +627,7 @@ public class DistributedFlowRuleStore | ... | @@ -633,7 +627,7 @@ public class DistributedFlowRuleStore |
| 633 | notifyDelegate(event); | 627 | notifyDelegate(event); |
| 634 | } else { | 628 | } else { |
| 635 | // TODO check unicast return value | 629 | // TODO check unicast return value |
| 636 | - clusterCommunicator.unicast(event, REMOTE_APPLY_COMPLETED, SERIALIZER::encode, nodeId); | 630 | + clusterCommunicator.unicast(event, REMOTE_APPLY_COMPLETED, serializer::encode, nodeId); |
| 637 | //error log: log.warn("Failed to respond to peer for batch operation result"); | 631 | //error log: log.warn("Failed to respond to peer for batch operation result"); |
| 638 | } | 632 | } |
| 639 | } | 633 | } |
| ... | @@ -642,7 +636,7 @@ public class DistributedFlowRuleStore | ... | @@ -642,7 +636,7 @@ public class DistributedFlowRuleStore |
| 642 | 636 | ||
| 643 | @Override | 637 | @Override |
| 644 | public void handle(final ClusterMessage message) { | 638 | public void handle(final ClusterMessage message) { |
| 645 | - FlowRuleBatchOperation operation = SERIALIZER.decode(message.payload()); | 639 | + FlowRuleBatchOperation operation = serializer.decode(message.payload()); |
| 646 | log.debug("received batch request {}", operation); | 640 | log.debug("received batch request {}", operation); |
| 647 | 641 | ||
| 648 | final DeviceId deviceId = operation.deviceId(); | 642 | final DeviceId deviceId = operation.deviceId(); |
| ... | @@ -657,7 +651,7 @@ public class DistributedFlowRuleStore | ... | @@ -657,7 +651,7 @@ public class DistributedFlowRuleStore |
| 657 | // TODO: we might want to wrap response in envelope | 651 | // TODO: we might want to wrap response in envelope |
| 658 | // to distinguish sw programming failure and hand over | 652 | // to distinguish sw programming failure and hand over |
| 659 | // it make sense in the latter case to retry immediately. | 653 | // it make sense in the latter case to retry immediately. |
| 660 | - message.respond(SERIALIZER.encode(allFailed)); | 654 | + message.respond(serializer.encode(allFailed)); |
| 661 | return; | 655 | return; |
| 662 | } | 656 | } |
| 663 | 657 | ||
| ... | @@ -736,8 +730,8 @@ public class DistributedFlowRuleStore | ... | @@ -736,8 +730,8 @@ public class DistributedFlowRuleStore |
| 736 | Set<DeviceId>> | 730 | Set<DeviceId>> |
| 737 | sendAndReceive(deviceFlowEntries, | 731 | sendAndReceive(deviceFlowEntries, |
| 738 | FLOW_TABLE_BACKUP, | 732 | FLOW_TABLE_BACKUP, |
| 739 | - SERIALIZER::encode, | 733 | + serializer::encode, |
| 740 | - SERIALIZER::decode, | 734 | + serializer::decode, |
| 741 | nodeId) | 735 | nodeId) |
| 742 | .whenComplete((backedupDevices, error) -> { | 736 | .whenComplete((backedupDevices, error) -> { |
| 743 | Set<DeviceId> devicesNotBackedup = error != null ? | 737 | Set<DeviceId> devicesNotBackedup = error != null ? |
| ... | @@ -769,12 +763,12 @@ public class DistributedFlowRuleStore | ... | @@ -769,12 +763,12 @@ public class DistributedFlowRuleStore |
| 769 | .withSerializer(new Serializer() { | 763 | .withSerializer(new Serializer() { |
| 770 | @Override | 764 | @Override |
| 771 | public <T> byte[] encode(T object) { | 765 | public <T> byte[] encode(T object) { |
| 772 | - return SERIALIZER.encode(object); | 766 | + return serializer.encode(object); |
| 773 | } | 767 | } |
| 774 | 768 | ||
| 775 | @Override | 769 | @Override |
| 776 | public <T> T decode(byte[] bytes) { | 770 | public <T> T decode(byte[] bytes) { |
| 777 | - return SERIALIZER.decode(bytes); | 771 | + return serializer.decode(bytes); |
| 778 | } | 772 | } |
| 779 | }) | 773 | }) |
| 780 | .build()); | 774 | .build()); | ... | ... |
-
Please register or login to post a comment