1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.openehealth.ipf.commons.ihe.hl7v2.storage;
17
18 import net.sf.ehcache.Ehcache;
19 import net.sf.ehcache.Element;
20 import org.apache.commons.lang3.Validate;
21
22 import static java.util.Objects.requireNonNull;
23
24
25
26
27
28 public class EhcacheUnsolicitedFragmentationStorage implements UnsolicitedFragmentationStorage {
29
30 private final Ehcache ehcache;
31
32 public EhcacheUnsolicitedFragmentationStorage(Ehcache ehcache) {
33 requireNonNull(ehcache);
34 this.ehcache = ehcache;
35 }
36
37 public void put(String key, StringBuilder accumulator) {
38 Element element = new Element(key, accumulator);
39 ehcache.put(element);
40 }
41
42 public StringBuilder getAndRemove(String key) {
43 Element element = ehcache.get(key);
44 if (element != null) {
45 ehcache.remove(key);
46 return (StringBuilder) element.getObjectValue();
47 }
48 return null;
49 }
50 }