Commits

NIG authored fdc8c96d859
[CR-21]: Review Comments
No tags

cbs-datacache-invalidator/src/main/java/dk/sundhedsdatastyrelsen/cbs/datacache/invalidation/impl/InMemoryNasSubscriptionRepository.java

Deleted
1 -/*
2 - * The MIT License
3 - *
4 - * Original work sponsored and donated by The Danish Health Data Authority (http://www.sundhedsdatastyrelsen.dk)
5 - *
6 - * Copyright (C) 2021 The Danish Health Data Authority (http://www.sundhedsdatastyrelsen.dk)
7 - *
8 - *
9 - * Permission is hereby granted, free of charge, to any person obtaining a copy of
10 - * this software and associated documentation files (the "Software"), to deal in
11 - * the Software without restriction, including without limitation the rights to
12 - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
13 - * of the Software, and to permit persons to whom the Software is furnished to do
14 - * so, subject to the following conditions:
15 - *
16 - *
17 - * The above copyright notice and this permission notice shall be included in all
18 - * copies or substantial portions of the Software.
19 - *
20 - *
21 - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22 - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24 - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26 - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27 - * SOFTWARE.
28 - */
29 -package dk.sundhedsdatastyrelsen.cbs.datacache.invalidation.impl;
30 -
31 -import dk.sundhedsdatastyrelsen.cbs.nas.facade.EndpointReferences;
32 -import dk.sundhedsdatastyrelsen.cbs.nas.facade.NasClient;
33 -import dk.sundhedsdatastyrelsen.cbs.nas.facade.NasSubscriptionRepository;
34 -import org.apache.log4j.Logger;
35 -
36 -import javax.xml.ws.wsaddressing.W3CEndpointReference;
37 -import java.util.HashMap;
38 -import java.util.Map;
39 -import java.util.UUID;
40 -
41 -public class InMemoryNasSubscriptionRepository implements NasSubscriptionRepository {
42 -
43 - private static final Logger log = Logger.getLogger(InMemoryNasSubscriptionRepository.class);
44 -
45 - private final NasClient nasClient;
46 -
47 - private final Map<String, String> pullPointMap = new HashMap<>();
48 - private final Map<String, UUID> messageIdMap = new HashMap<>();
49 -
50 -
51 - public InMemoryNasSubscriptionRepository(NasClient nasClient) {
52 - this.nasClient = nasClient;
53 - }
54 -
55 - @Override
56 - public W3CEndpointReference getPullPoint(String topic) {
57 - if (pullPointMap.containsKey(topic)) {
58 - String address = pullPointMap.get(topic);
59 -
60 - log.info(String.format("Found saved PullPoint (%s)", address));
61 -
62 - return EndpointReferences.newEndpointReference(address);
63 - } else {
64 - log.info("No PullPoint found");
65 -
66 - W3CEndpointReference pullPoint = nasClient.createPullPoint();
67 - nasClient.subscribe(pullPoint, topic);
68 - String address = EndpointReferences.extractAddress(pullPoint);
69 -
70 - log.info(String.format("Created new PullPoint (%s)", address));
71 -
72 - pullPointMap.put(topic, address);
73 - return pullPoint;
74 - }
75 - }
76 -
77 - @Override
78 - public UUID getNextMessageId(String topic) {
79 - if (messageIdMap.containsKey(topic)) {
80 - UUID messageId = messageIdMap.get(topic);
81 - log.info(String.format("Found saved MessageId (%s)", messageId));
82 - return messageId;
83 - } else {
84 - UUID messageId = UUID.randomUUID();
85 - messageIdMap.put(topic, messageId);
86 - log.info(String.format("Created new MessageId (%s)", messageId));
87 - return messageId;
88 - }
89 - }
90 -
91 - @Override
92 - public void commit(String topic) {
93 - log.info(String.format("Commit on topic '%s'", topic));
94 -
95 - messageIdMap.remove(topic);
96 - }
97 -}

Everything looks good. We'll let you know here if there's anything you should know about.

Add shortcut