Search in sources :

Example 1 with ResourceNotFoundException

use of io.bitsquare.storage.ResourceNotFoundException in project bitsquare by bitsquare.

the class P2PDataStorage method init.

private void init(File storageDir) {
    sequenceNumberMapStorage.setNumMaxBackupFiles(5);
    persistedEntryMapStorage.setNumMaxBackupFiles(1);
    HashMap<ByteArray, MapValue> persistedSequenceNumberMap = sequenceNumberMapStorage.<HashMap<ByteArray, MapValue>>initAndGetPersistedWithFileName("SequenceNumberMap");
    if (persistedSequenceNumberMap != null)
        sequenceNumberMap = getPurgedSequenceNumberMap(persistedSequenceNumberMap);
    final String storageFileName = "PersistedP2PStorageData";
    File dbDir = new File(storageDir.getAbsolutePath());
    if (!dbDir.exists() && !dbDir.mkdir())
        log.warn("make dir failed.\ndbDir=" + dbDir.getAbsolutePath());
    final File destinationFile = new File(Paths.get(storageDir.getAbsolutePath(), storageFileName).toString());
    if (!destinationFile.exists()) {
        try {
            FileUtil.resourceToFile(storageFileName, destinationFile);
        } catch (ResourceNotFoundException | IOException e) {
            e.printStackTrace();
            log.error("Could not copy the " + storageFileName + " resource file to the db directory.\n" + e.getMessage());
        }
    } else {
        log.debug(storageFileName + " file exists already.");
    }
    HashMap<ByteArray, ProtectedStorageEntry> persisted = persistedEntryMapStorage.<HashMap<ByteArray, MapValue>>initAndGetPersistedWithFileName(storageFileName);
    if (persisted != null) {
        persistedMap = persisted;
        map.putAll(persistedMap);
        // In case another object is already listening...
        map.values().stream().forEach(protectedStorageEntry -> hashMapChangedListeners.stream().forEach(e -> e.onAdded(protectedStorageEntry)));
    }
}
Also used : Version(io.bitsquare.app.Version) KeyPair(java.security.KeyPair) java.util(java.util) io.bitsquare.p2p.storage.payload(io.bitsquare.p2p.storage.payload) ProtectedStorageEntry(io.bitsquare.p2p.storage.storageentry.ProtectedStorageEntry) Hex(org.spongycastle.util.encoders.Hex) LoggerFactory(org.slf4j.LoggerFactory) Timer(io.bitsquare.common.Timer) Tuple2(io.bitsquare.common.util.Tuple2) CryptoException(io.bitsquare.common.crypto.CryptoException) StringUtils(org.apache.commons.lang3.StringUtils) io.bitsquare.p2p.network(io.bitsquare.p2p.network) ResourceNotFoundException(io.bitsquare.storage.ResourceNotFoundException) Nullable(javax.annotation.Nullable) Log(io.bitsquare.app.Log) Hash(io.bitsquare.common.crypto.Hash) BroadcastHandler(io.bitsquare.p2p.peers.BroadcastHandler) Utilities(io.bitsquare.common.util.Utilities) FileUtil(io.bitsquare.storage.FileUtil) Logger(org.slf4j.Logger) ProtectedMailboxStorageEntry(io.bitsquare.p2p.storage.storageentry.ProtectedMailboxStorageEntry) UserThread(io.bitsquare.common.UserThread) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Message(io.bitsquare.p2p.Message) NodeAddress(io.bitsquare.p2p.NodeAddress) IOException(java.io.IOException) PublicKey(java.security.PublicKey) CopyOnWriteArraySet(java.util.concurrent.CopyOnWriteArraySet) Collectors(java.util.stream.Collectors) File(java.io.File) Sig(io.bitsquare.common.crypto.Sig) Serializable(java.io.Serializable) io.bitsquare.p2p.storage.messages(io.bitsquare.p2p.storage.messages) TimeUnit(java.util.concurrent.TimeUnit) Payload(io.bitsquare.common.wire.Payload) Broadcaster(io.bitsquare.p2p.peers.Broadcaster) Paths(java.nio.file.Paths) Storage(io.bitsquare.storage.Storage) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Persistable(io.bitsquare.common.persistance.Persistable) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) IOException(java.io.IOException) ResourceNotFoundException(io.bitsquare.storage.ResourceNotFoundException) File(java.io.File) ProtectedStorageEntry(io.bitsquare.p2p.storage.storageentry.ProtectedStorageEntry)

Aggregations

VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Log (io.bitsquare.app.Log)1 Version (io.bitsquare.app.Version)1 Timer (io.bitsquare.common.Timer)1 UserThread (io.bitsquare.common.UserThread)1 CryptoException (io.bitsquare.common.crypto.CryptoException)1 Hash (io.bitsquare.common.crypto.Hash)1 Sig (io.bitsquare.common.crypto.Sig)1 Persistable (io.bitsquare.common.persistance.Persistable)1 Tuple2 (io.bitsquare.common.util.Tuple2)1 Utilities (io.bitsquare.common.util.Utilities)1 Payload (io.bitsquare.common.wire.Payload)1 Message (io.bitsquare.p2p.Message)1 NodeAddress (io.bitsquare.p2p.NodeAddress)1 io.bitsquare.p2p.network (io.bitsquare.p2p.network)1 BroadcastHandler (io.bitsquare.p2p.peers.BroadcastHandler)1 Broadcaster (io.bitsquare.p2p.peers.Broadcaster)1 io.bitsquare.p2p.storage.messages (io.bitsquare.p2p.storage.messages)1 io.bitsquare.p2p.storage.payload (io.bitsquare.p2p.storage.payload)1 ProtectedMailboxStorageEntry (io.bitsquare.p2p.storage.storageentry.ProtectedMailboxStorageEntry)1