1 | //$Id: PnfsMessage.java,v 1.5 2004-11-05 12:07:19 tigran Exp $ |
2 | |
3 | package diskCacheV111.vehicles; |
4 | import diskCacheV111.util.PnfsId ; |
5 | import org.dcache.acl.enums.AccessMask; |
6 | import java.util.Set; |
7 | import java.util.Collections; |
8 | import java.io.IOException; |
9 | import java.io.ObjectInputStream; |
10 | |
11 | /** |
12 | * Base class for messages to PnfsManager. |
13 | */ |
14 | public class PnfsMessage extends Message { |
15 | |
16 | private PnfsId _pnfsId = null; |
17 | private String _path = null ; |
18 | private Set<AccessMask> _mask = Collections.emptySet(); |
19 | |
20 | private static final long serialVersionUID = -3686370854772807059L; |
21 | |
22 | public PnfsMessage(PnfsId pnfsId){ |
23 | _pnfsId = pnfsId ; |
24 | } |
25 | |
26 | public PnfsMessage(){ } |
27 | |
28 | public void setPnfsPath( String pnfsPath ){ _path = pnfsPath ; } |
29 | public String getPnfsPath(){ return _path ;} |
30 | |
31 | public PnfsId getPnfsId(){ |
32 | return _pnfsId; |
33 | } |
34 | |
35 | public void setPnfsId(PnfsId pnfsId){ |
36 | _pnfsId = pnfsId ; |
37 | } |
38 | |
39 | public void setAccessMask(Set<AccessMask> mask) |
40 | { |
41 | if (mask == null) { |
42 | throw new IllegalArgumentException("Null argument not allowed"); |
43 | } |
44 | _mask = mask; |
45 | } |
46 | |
47 | public Set<AccessMask> getAccessMask() |
48 | { |
49 | return _mask; |
50 | } |
51 | |
52 | public String toString(){ |
53 | return _pnfsId==null? |
54 | (_path==null?"NULL":("Path="+_path)): |
55 | ("PnfsId="+_pnfsId.toString()) ; |
56 | } |
57 | |
58 | protected final boolean genericInvalidatesForPnfsMessage(Message message) |
59 | { |
60 | /* Conservatively assume that a PnfsMessage invalidates any |
61 | * non PnfsMessage. |
62 | */ |
63 | if (!(message instanceof PnfsMessage)) { |
64 | return true; |
65 | } |
66 | |
67 | PnfsMessage msg = (PnfsMessage) message; |
68 | |
69 | /* Conservatively assume that this PnfsMessage invalidates |
70 | * another PnfsMessage if we cannot compare them because one |
71 | * message is by path and the other by ID or if either the |
72 | * PNFS IDs or paths are the same. |
73 | */ |
74 | return |
75 | ((getPnfsId() == null || msg.getPnfsId() == null) && |
76 | (getPnfsPath() == null || msg.getPnfsPath() == null)) || |
77 | (getPnfsId() != null && msg.getPnfsId() != null && |
78 | getPnfsId().equals(msg.getPnfsId())) || |
79 | (getPnfsPath() != null && msg.getPnfsPath() != null && |
80 | getPnfsPath().equals(msg.getPnfsPath())); |
81 | } |
82 | |
83 | @Override |
84 | public boolean invalidates(Message message) |
85 | { |
86 | return genericInvalidatesForPnfsMessage(message); |
87 | } |
88 | |
89 | /** |
90 | * For compatibility with pre-1.9.6 installations, we fill in the |
91 | * _mask field if it is missing. |
92 | */ |
93 | private void readObject(ObjectInputStream stream) |
94 | throws IOException, ClassNotFoundException |
95 | { |
96 | stream.defaultReadObject(); |
97 | if (_mask == null) { |
98 | _mask = Collections.emptySet(); |
99 | } |
100 | } |
101 | } |
102 | |
103 | |
104 | |