1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package mirrormap.commands;
17
18 import java.io.Serializable;
19 import java.util.logging.Level;
20 import java.util.logging.Logger;
21
22 import mirrormap.MirrorMap;
23
24
25
26
27
28
29 public class AddCommand extends AbstractCommand
30 {
31 private final static Logger LOGGER =
32 Logger.getLogger(AddCommand.class.getName());
33
34 private static final long serialVersionUID = 1L;
35
36
37 protected Serializable value;
38
39 public AddCommand()
40 {
41 super();
42 }
43
44 public AddCommand(String mirrorMapName, Serializable key, Serializable value)
45 {
46 super();
47 this.mirrorMapName = mirrorMapName;
48 this.key = key;
49 this.value = value;
50 }
51
52 public final void execute()
53 {
54 final MirrorMap<Serializable, Serializable> mirrorMap =
55 MirrorMap.get(this.mirrorMapName);
56 if (mirrorMap != null)
57 {
58 if (shouldExecute(mirrorMap))
59 {
60 mirrorMap.put(this.key, this.value);
61 }
62 else
63 {
64 if (LOGGER.isLoggable(Level.FINEST))
65 {
66 LOGGER.finest("Ignoring " + this + " for "
67 + this.mirrorMapName);
68 }
69 }
70 }
71 else
72 {
73 if (LOGGER.isLoggable(Level.FINEST))
74 {
75 LOGGER.finest("No map found for " + this.mirrorMapName);
76 }
77 }
78 }
79
80
81
82
83
84
85
86
87
88
89
90 protected boolean shouldExecute(
91 final MirrorMap<Serializable, Serializable> mirrorMap)
92 {
93 return !mirrorMap.containsKey(this.key);
94 }
95 }