| 1 | // $Id: PnfsGetFileMetaDataMessage.java,v 1.4 2004-11-05 12:07:19 tigran Exp $ |
| 2 | package diskCacheV111.vehicles ; |
| 3 | |
| 4 | import diskCacheV111.util.FileMetaData; |
| 5 | import diskCacheV111.util.PnfsId; |
| 6 | import java.util.Set; |
| 7 | import org.dcache.util.Checksum; |
| 8 | import org.dcache.vehicles.PnfsGetFileAttributes; |
| 9 | import org.dcache.vehicles.FileAttributes; |
| 10 | import org.dcache.namespace.FileAttribute; |
| 11 | |
| 12 | import static org.dcache.namespace.FileAttribute.*; |
| 13 | |
| 14 | public class PnfsGetFileMetaDataMessage extends PnfsGetFileAttributes |
| 15 | { |
| 16 | private FileMetaData _metaData = null ; |
| 17 | private boolean _resolve = true ; |
| 18 | private boolean _checksumsRequested = false ; |
| 19 | |
| 20 | private Set<Checksum> _checksums = null; |
| 21 | |
| 22 | private static final long serialVersionUID = 1591894346369251468L; |
| 23 | |
| 24 | public PnfsGetFileMetaDataMessage() |
| 25 | { |
| 26 | super((PnfsId) null, FileMetaData.getKnownFileAttributes()); |
| 27 | setReplyRequired(true); |
| 28 | } |
| 29 | |
| 30 | public PnfsGetFileMetaDataMessage(Set<FileAttribute> attr) |
| 31 | { |
| 32 | super((PnfsId) null, FileMetaData.getKnownFileAttributes()); |
| 33 | _attributes.addAll(attr); |
| 34 | setReplyRequired(true); |
| 35 | } |
| 36 | |
| 37 | public PnfsGetFileMetaDataMessage(PnfsId pnfsId) |
| 38 | { |
| 39 | super(pnfsId, FileMetaData.getKnownFileAttributes()); |
| 40 | setReplyRequired(true); |
| 41 | } |
| 42 | |
| 43 | @Override |
| 44 | public void setFileAttributes(FileAttributes fileAttributes) |
| 45 | { |
| 46 | /* For backwards compatibility with old versions we set these |
| 47 | * fields. We do this even though we don't use these fields. |
| 48 | */ |
| 49 | _metaData = new FileMetaData(fileAttributes); |
| 50 | if (fileAttributes.isDefined(CHECKSUM)) { |
| 51 | _checksums = fileAttributes.getChecksums(); |
| 52 | } |
| 53 | |
| 54 | /* For backwards compatibility with old versions, we do not |
| 55 | * set the file attributes unless they have actually been |
| 56 | * requested. This avoid deserialization problems with clients |
| 57 | * that cannot handle all values in the FileAttribute enum. |
| 58 | */ |
| 59 | if (_attributes != null) { |
| 60 | super.setFileAttributes(fileAttributes); |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | public FileMetaData getMetaData() |
| 65 | { |
| 66 | return |
| 67 | (_fileAttributes == null) |
| 68 | ? null |
| 69 | : new FileMetaData(_fileAttributes); |
| 70 | } |
| 71 | |
| 72 | public void setResolve( boolean resolve ){ _resolve = resolve ; } |
| 73 | public boolean resolve(){ return _resolve ; } |
| 74 | |
| 75 | public Set<Checksum> getChecksums() |
| 76 | { |
| 77 | return |
| 78 | (_fileAttributes == null || !_fileAttributes.isDefined(CHECKSUM)) |
| 79 | ? null |
| 80 | : _fileAttributes.getChecksums(); |
| 81 | } |
| 82 | |
| 83 | public boolean isChecksumsRequested() { |
| 84 | return _checksumsRequested; |
| 85 | } |
| 86 | |
| 87 | public void setChecksumsRequested(boolean checksumsRequested) |
| 88 | { |
| 89 | _checksumsRequested = checksumsRequested; |
| 90 | if (checksumsRequested) { |
| 91 | _attributes.add(CHECKSUM); |
| 92 | } else { |
| 93 | _attributes.remove(CHECKSUM); |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | public void requestChecksum() |
| 98 | { |
| 99 | _checksumsRequested = true; |
| 100 | _attributes.add(CHECKSUM); |
| 101 | } |
| 102 | |
| 103 | /* To ensure backwards compatibility with pre 1.9.6 clients, we |
| 104 | * explicitly add attributes compatible with |
| 105 | * PnfsGetFileMetaDataMessage to the set of requested attributes |
| 106 | * if the attribute set is null. |
| 107 | */ |
| 108 | @Override |
| 109 | public Set<FileAttribute> getRequestedAttributes() |
| 110 | { |
| 111 | Set<FileAttribute> attributes = _attributes; |
| 112 | if (attributes == null) { |
| 113 | attributes = FileMetaData.getKnownFileAttributes(); |
| 114 | if (_checksumsRequested) { |
| 115 | attributes.add(CHECKSUM); |
| 116 | } |
| 117 | } |
| 118 | return attributes; |
| 119 | } |
| 120 | |
| 121 | @Override |
| 122 | public boolean invalidates(Message message) |
| 123 | { |
| 124 | return false; |
| 125 | } |
| 126 | |
| 127 | @Override |
| 128 | public boolean fold(Message message) |
| 129 | { |
| 130 | if (message.getClass().equals(PnfsGetFileMetaDataMessage.class)) { |
| 131 | PnfsGetFileMetaDataMessage other = |
| 132 | (PnfsGetFileMetaDataMessage) message; |
| 133 | if (other.resolve() == resolve()) { |
| 134 | return super.fold(message); |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | return false; |
| 139 | } |
| 140 | } |