mirror of
https://github.com/usatiuk/dhfs.git
synced 2025-10-28 20:47:49 +01:00
remove hack for objects write
This commit is contained in:
@@ -6,6 +6,7 @@ import lombok.Getter;
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
|
||||
@Getter
|
||||
public class ChunkData extends JObject {
|
||||
@@ -30,4 +31,17 @@ public class ChunkData extends JObject {
|
||||
public static String getNameFromHash(String hash) {
|
||||
return hash + "_data";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
ChunkData chunkData = (ChunkData) o;
|
||||
return Objects.equals(_hash, chunkData._hash);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(_hash);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@ import com.usatiuk.dhfs.storage.objects.jrepository.JObject;
|
||||
import com.usatiuk.dhfs.storage.objects.repository.distributed.ConflictResolver;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
@Getter
|
||||
public class ChunkInfo extends JObject {
|
||||
final String _hash;
|
||||
@@ -27,4 +29,17 @@ public class ChunkInfo extends JObject {
|
||||
public static String getNameFromHash(String hash) {
|
||||
return hash + "_info";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
ChunkInfo chunkInfo = (ChunkInfo) o;
|
||||
return Objects.equals(_hash, chunkInfo._hash) && Objects.equals(_size, chunkInfo._size);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(_hash, _size);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,9 +3,6 @@ package com.usatiuk.dhfs.storage.objects.jrepository;
|
||||
import com.usatiuk.dhfs.storage.objects.repository.distributed.ConflictResolver;
|
||||
import org.apache.commons.lang3.NotImplementedException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.util.concurrent.locks.ReadWriteLock;
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||
@@ -18,14 +15,4 @@ public abstract class JObject implements Serializable {
|
||||
public Class<? extends ConflictResolver> getConflictResolver() {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@Serial
|
||||
private void writeObject(ObjectOutputStream oos) throws IOException {
|
||||
_lock.readLock().lock();
|
||||
try {
|
||||
oos.defaultWriteObject();
|
||||
} finally {
|
||||
_lock.readLock().unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package com.usatiuk.dhfs.storage.objects.jrepository;
|
||||
|
||||
import com.usatiuk.dhfs.storage.files.objects.ChunkData;
|
||||
import com.usatiuk.dhfs.storage.files.objects.ChunkInfo;
|
||||
import io.quarkus.logging.Log;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
@@ -10,6 +8,7 @@ import lombok.Getter;
|
||||
import java.lang.ref.ReferenceQueue;
|
||||
import java.lang.ref.SoftReference;
|
||||
import java.util.HashMap;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
@ApplicationScoped
|
||||
@@ -84,10 +83,7 @@ public class JObjectManagerImpl implements JObjectManager {
|
||||
|
||||
synchronized (_map) {
|
||||
var inMap = getFromMap(object.getName(), object.getClass());
|
||||
if (inMap != null && inMap != object) {
|
||||
//FIXME:
|
||||
if (object instanceof ChunkInfo) return;
|
||||
if (object instanceof ChunkData) return;
|
||||
if (inMap != null && inMap != object && !Objects.equals(inMap, object)) {
|
||||
throw new IllegalArgumentException("Trying to insert different object with same key");
|
||||
} else if (inMap == null)
|
||||
_map.put(object.getName(), new NamedSoftReference(object, _refQueue));
|
||||
|
||||
Reference in New Issue
Block a user