mirror of
https://github.com/usatiuk/dhfs.git
synced 2025-10-29 04:57:48 +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 org.apache.commons.codec.digest.DigestUtils;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
public class ChunkData extends JObject {
|
public class ChunkData extends JObject {
|
||||||
@@ -30,4 +31,17 @@ public class ChunkData extends JObject {
|
|||||||
public static String getNameFromHash(String hash) {
|
public static String getNameFromHash(String hash) {
|
||||||
return hash + "_data";
|
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 com.usatiuk.dhfs.storage.objects.repository.distributed.ConflictResolver;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
public class ChunkInfo extends JObject {
|
public class ChunkInfo extends JObject {
|
||||||
final String _hash;
|
final String _hash;
|
||||||
@@ -27,4 +29,17 @@ public class ChunkInfo extends JObject {
|
|||||||
public static String getNameFromHash(String hash) {
|
public static String getNameFromHash(String hash) {
|
||||||
return hash + "_info";
|
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 com.usatiuk.dhfs.storage.objects.repository.distributed.ConflictResolver;
|
||||||
import org.apache.commons.lang3.NotImplementedException;
|
import org.apache.commons.lang3.NotImplementedException;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.ObjectOutputStream;
|
|
||||||
import java.io.Serial;
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.concurrent.locks.ReadWriteLock;
|
import java.util.concurrent.locks.ReadWriteLock;
|
||||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||||
@@ -18,14 +15,4 @@ public abstract class JObject implements Serializable {
|
|||||||
public Class<? extends ConflictResolver> getConflictResolver() {
|
public Class<? extends ConflictResolver> getConflictResolver() {
|
||||||
throw new NotImplementedException();
|
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;
|
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 io.quarkus.logging.Log;
|
||||||
import jakarta.enterprise.context.ApplicationScoped;
|
import jakarta.enterprise.context.ApplicationScoped;
|
||||||
import jakarta.inject.Inject;
|
import jakarta.inject.Inject;
|
||||||
@@ -10,6 +8,7 @@ import lombok.Getter;
|
|||||||
import java.lang.ref.ReferenceQueue;
|
import java.lang.ref.ReferenceQueue;
|
||||||
import java.lang.ref.SoftReference;
|
import java.lang.ref.SoftReference;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
@ApplicationScoped
|
@ApplicationScoped
|
||||||
@@ -84,10 +83,7 @@ public class JObjectManagerImpl implements JObjectManager {
|
|||||||
|
|
||||||
synchronized (_map) {
|
synchronized (_map) {
|
||||||
var inMap = getFromMap(object.getName(), object.getClass());
|
var inMap = getFromMap(object.getName(), object.getClass());
|
||||||
if (inMap != null && inMap != object) {
|
if (inMap != null && inMap != object && !Objects.equals(inMap, object)) {
|
||||||
//FIXME:
|
|
||||||
if (object instanceof ChunkInfo) return;
|
|
||||||
if (object instanceof ChunkData) return;
|
|
||||||
throw new IllegalArgumentException("Trying to insert different object with same key");
|
throw new IllegalArgumentException("Trying to insert different object with same key");
|
||||||
} else if (inMap == null)
|
} else if (inMap == null)
|
||||||
_map.put(object.getName(), new NamedSoftReference(object, _refQueue));
|
_map.put(object.getName(), new NamedSoftReference(object, _refQueue));
|
||||||
|
|||||||
Reference in New Issue
Block a user