001: /*
002: * Copyright 2004-2006 the original author or authors.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package org.compass.needle.gigaspaces.store;
018:
019: import java.io.Externalizable;
020: import java.io.IOException;
021: import java.io.ObjectInput;
022: import java.io.ObjectOutput;
023:
024: import net.jini.core.entry.Entry;
025:
026: /**
027: * A file entry holds the meta data of a file, without its content.
028: *
029: * @author kimchy
030: */
031: public class FileEntry implements Entry, Externalizable {
032:
033: public String indexName;
034:
035: public String fileName;
036:
037: public Long lastModified;
038:
039: public Long size;
040:
041: public FileEntry() {
042:
043: }
044:
045: public FileEntry(String indexName, String fileName) {
046: this .indexName = indexName;
047: this .fileName = fileName;
048: }
049:
050: public FileEntry(String indexName, String fileName, long size) {
051: this .indexName = indexName;
052: this .fileName = fileName;
053: this .size = size;
054: this .lastModified = System.currentTimeMillis();
055: }
056:
057: public String getIndexName() {
058: return this .indexName;
059: }
060:
061: public String getFileName() {
062: return this .fileName;
063: }
064:
065: public long getLastModified() {
066: return this .lastModified;
067: }
068:
069: public long getSize() {
070: return this .size;
071: }
072:
073: public void touch() {
074: // we are using currentTime here, which should be sync between nodes (though some
075: // minor difference won't matter that much with Lucene).
076: this .lastModified = System.currentTimeMillis();
077: }
078:
079: public void writeExternal(ObjectOutput out) throws IOException {
080: out.writeUTF(indexName);
081: if (fileName == null) {
082: out.writeBoolean(false);
083: } else {
084: out.writeBoolean(true);
085: out.writeUTF(fileName);
086: }
087: if (size == null && lastModified == null) {
088: out.writeBoolean(false);
089: } else {
090: out.writeBoolean(true);
091: out.writeLong(size);
092: out.writeLong(lastModified);
093: }
094: }
095:
096: public void readExternal(ObjectInput in) throws IOException,
097: ClassNotFoundException {
098: indexName = in.readUTF();
099: if (in.readBoolean()) {
100: fileName = in.readUTF();
101: }
102: if (in.readBoolean()) {
103: size = in.readLong();
104: lastModified = in.readLong();
105: }
106: }
107:
108: public static String[] __getSpaceIndexedFields() {
109: // fileName is our routing index
110: return new String[] { "fileName" };
111: }
112: }
|