01: /*
02: * Copyright 2004-2006 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package org.compass.needle.coherence;
18:
19: import java.io.DataInput;
20: import java.io.DataOutput;
21: import java.io.IOException;
22:
23: import com.tangosol.io.ExternalizableLite;
24:
25: /**
26: * @author kimchy
27: */
28: public class FileLockKey implements FileKey, ExternalizableLite {
29:
30: private String indexName;
31:
32: private String lockName;
33:
34: // just here for serialization
35: public FileLockKey() {
36: }
37:
38: public FileLockKey(String indexName, String lockName) {
39: this .indexName = indexName;
40: this .lockName = lockName;
41: }
42:
43: public String getIndexName() {
44: return this .indexName;
45: }
46:
47: public String getLockName() {
48: return this .lockName;
49: }
50:
51: public String getFileName() {
52: return getLockName();
53: }
54:
55: public byte getType() {
56: return FILE_LOCK;
57: }
58:
59: public boolean equals(Object o) {
60: if (this == o)
61: return true;
62: if (((FileKey) o).getType() != getType())
63: return false;
64:
65: FileLockKey that = (FileLockKey) o;
66:
67: if (!lockName.equals(that.lockName))
68: return false;
69: if (!indexName.equals(that.indexName))
70: return false;
71:
72: return true;
73: }
74:
75: public int hashCode() {
76: int result = getType();
77: result = 17 * result + indexName.hashCode();
78: result = 17 * result + lockName.hashCode();
79: return result;
80: }
81:
82: public void readExternal(DataInput in) throws IOException {
83: indexName = in.readUTF();
84: lockName = in.readUTF();
85: }
86:
87: public void writeExternal(DataOutput out) throws IOException {
88: out.writeUTF(indexName);
89: out.writeUTF(lockName);
90: }
91:
92: public String toString() {
93: StringBuilder sb = new StringBuilder();
94: sb.append("fileLcokKey: indexName[").append(indexName).append(
95: "]");
96: sb.append(" lockName[").append(lockName).append("]");
97: return sb.toString();
98: }
99: }
|