1 | package org.dcache.vehicles; |
2 | |
3 | import diskCacheV111.vehicles.*; |
4 | import diskCacheV111.util.PnfsId; |
5 | import org.dcache.namespace.FileAttribute; |
6 | import java.util.Set; |
7 | |
8 | |
9 | /** |
10 | * Vehicle for get files combined attributes. |
11 | * |
12 | * @since 1.9.4 |
13 | */ |
14 | public class PnfsGetFileAttributes extends PnfsMessage { |
15 | |
16 | private static final long serialVersionUID = -6750531802534981651L; |
17 | |
18 | protected FileAttributes _fileAttributes; |
19 | protected Set<FileAttribute> _attributes; |
20 | |
21 | /** |
22 | * Construct request by PnfsId. |
23 | * |
24 | * @param pnfsid |
25 | * @param attr |
26 | */ |
27 | public PnfsGetFileAttributes(PnfsId pnfsid, Set<FileAttribute> attr) { |
28 | super(pnfsid); |
29 | _attributes = attr; |
30 | } |
31 | |
32 | /** |
33 | * Construct request by path. |
34 | * |
35 | * @param path |
36 | * @param attr |
37 | */ |
38 | public PnfsGetFileAttributes(String path, Set<FileAttribute> attr) { |
39 | super(); |
40 | setPnfsPath(path); |
41 | _attributes = attr; |
42 | } |
43 | |
44 | /** |
45 | * Set file attributes. |
46 | * |
47 | * @param fileAttributes |
48 | */ |
49 | public void setFileAttributes(FileAttributes fileAttributes) { |
50 | _fileAttributes = fileAttributes; |
51 | } |
52 | |
53 | /** |
54 | * Get requested attributes. Note that PnfsManager may return less attributes than requested. |
55 | * |
56 | * @return |
57 | */ |
58 | public FileAttributes getFileAttributes() { |
59 | return _fileAttributes; |
60 | } |
61 | |
62 | /** |
63 | * Get set of requested {@link FileAttributes}. An empty set |
64 | * indicates that client interested in file existence only. |
65 | * @return |
66 | */ |
67 | public Set<FileAttribute> getRequestedAttributes() { |
68 | return _attributes; |
69 | } |
70 | |
71 | @Override |
72 | public boolean invalidates(Message message) |
73 | { |
74 | return false; |
75 | } |
76 | |
77 | @Override |
78 | public boolean fold(Message message) |
79 | { |
80 | if (message instanceof PnfsGetFileAttributes) { |
81 | PnfsId pnfsId = getPnfsId(); |
82 | String path = getPnfsPath(); |
83 | Set<FileAttribute> requested = getRequestedAttributes(); |
84 | PnfsGetFileAttributes other = |
85 | (PnfsGetFileAttributes) message; |
86 | if ((pnfsId == null || pnfsId.equals(other.getPnfsId())) && |
87 | (path == null || path.equals(other.getPnfsPath())) && |
88 | (getSubject().equals(other.getSubject())) && |
89 | (other.getRequestedAttributes().containsAll(requested))) { |
90 | setPnfsId(other.getPnfsId()); |
91 | setPnfsPath(other.getPnfsPath()); |
92 | setFileAttributes(other.getFileAttributes()); |
93 | return true; |
94 | } |
95 | } |
96 | |
97 | return false; |
98 | } |
99 | |
100 | @Override |
101 | public String toString() |
102 | { |
103 | return super.toString() + ";" + |
104 | ((_fileAttributes == null) |
105 | ? "[noMetaData]" |
106 | : _fileAttributes.toString()); |
107 | } |
108 | } |