Skip to content

Commit

Permalink
Minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
tomas-pluskal committed Sep 7, 2015
1 parent 8788ffc commit 6305631
Show file tree
Hide file tree
Showing 25 changed files with 378 additions and 121 deletions.
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,12 @@
<version>1.7.2</version>
</dependency>

<dependency>
<groupId>com.nfsdb</groupId>
<artifactId>nfsdb-core</artifactId>
<version>2.0.0</version>
</dependency>

</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import io.github.msdk.datamodel.peaklists.FeatureDataPointList;
import io.github.msdk.datamodel.rawdata.ChromatogramDataPointList;
import io.github.msdk.datamodel.rawdata.SpectrumDataPointList;
import io.github.msdk.datamodel.rawdata.MsSpectrumDataPointList;

/**
* Represents a storage mechanism for data points represented by DataPointList.
Expand All @@ -39,7 +39,7 @@ public interface DataPointStore {
* @return Storage ID for the newly stored data.
*/
@Nonnull
Object storeDataPoints(@Nonnull SpectrumDataPointList dataPoints);
Object storeDataPoints(@Nonnull MsSpectrumDataPointList dataPoints);

@Nonnull
Object storeDataPoints(@Nonnull ChromatogramDataPointList dataPoints);
Expand All @@ -59,7 +59,7 @@ public interface DataPointStore {
* @throws IllegalIllegalArgumentException
* If the given id is not present in this store.
*/
void readDataPoints(@Nonnull Object id, @Nonnull SpectrumDataPointList list);
void readDataPoints(@Nonnull Object id, @Nonnull MsSpectrumDataPointList list);

void readDataPoints(@Nonnull Object id, @Nonnull ChromatogramDataPointList list);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@

package io.github.msdk.datamodel.datapointstore;

import io.github.msdk.MSDKException;
import io.github.msdk.datamodel.datapointstore.DataPointStore;

import javax.annotation.Nonnull;

import io.github.msdk.MSDKException;

/**
* Data store provider
*/
Expand All @@ -35,4 +34,9 @@ public class DataPointStoreFactory {
return new TmpFileDataPointStore();
}

public static final @Nonnull DataPointStore getNFSDBDataPointStore()
throws MSDKException {
return new NFSDBDataPointStore();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import io.github.msdk.datamodel.impl.MSDKObjectBuilder;
import io.github.msdk.datamodel.peaklists.FeatureDataPointList;
import io.github.msdk.datamodel.rawdata.ChromatogramDataPointList;
import io.github.msdk.datamodel.rawdata.SpectrumDataPointList;
import io.github.msdk.datamodel.rawdata.MsSpectrumDataPointList;

/**
* A DataPointStore implementation that stores the data points in memory. Use
Expand All @@ -45,13 +45,13 @@ class MemoryDataPointStore implements DataPointStore {
*/
@Override
public @Nonnull Integer storeDataPoints(
@Nonnull SpectrumDataPointList dataPoints) {
@Nonnull MsSpectrumDataPointList dataPoints) {

if (storageMap == null)
throw new IllegalStateException("This object has been disposed");

// Clone the given list for storage
final SpectrumDataPointList newList = MSDKObjectBuilder
final MsSpectrumDataPointList newList = MSDKObjectBuilder
.getSpectrumDataPointList();
newList.copyFrom(dataPoints);

Expand Down Expand Up @@ -124,7 +124,7 @@ class MemoryDataPointStore implements DataPointStore {
*/
@Override
synchronized public void readDataPoints(@Nonnull Object ID,
@Nonnull SpectrumDataPointList list) {
@Nonnull MsSpectrumDataPointList list) {

if (storageMap == null)
throw new IllegalStateException("This object has been disposed");
Expand All @@ -135,10 +135,10 @@ synchronized public void readDataPoints(@Nonnull Object ID,

// Get the stored DataPointList
final Object storedObject = storageMap.get(ID);
if (!(storedObject instanceof SpectrumDataPointList))
if (!(storedObject instanceof MsSpectrumDataPointList))
throw new MSDKRuntimeException(
"Object stored under ID " + ID + " is not of correct type");
final SpectrumDataPointList storedList = (SpectrumDataPointList) storedObject;
final MsSpectrumDataPointList storedList = (MsSpectrumDataPointList) storedObject;

// Copy data
list.copyFrom(storedList);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,247 @@
/*
* (C) Copyright 2015 by MSDK Development Team
*
* This software is dual-licensed under either
*
* (a) the terms of the GNU Lesser General Public License version 2.1
* as published by the Free Software Foundation
*
* or (per the licensee's choosing)
*
* (b) the terms of the Eclipse Public License v1.0 as published by
* the Eclipse Foundation.
*/

package io.github.msdk.datamodel.datapointstore;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.HashMap;

import javax.annotation.Nonnull;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.nfsdb.journal.factory.JournalFactory;

import io.github.msdk.MSDKException;
import io.github.msdk.MSDKRuntimeException;
import io.github.msdk.datamodel.impl.MSDKObjectBuilder;
import io.github.msdk.datamodel.peaklists.FeatureDataPointList;
import io.github.msdk.datamodel.rawdata.ChromatogramDataPointList;
import io.github.msdk.datamodel.rawdata.MsSpectrumDataPointList;

/**
* A DataPointStore implementation that stores the data points in memory. Use
* with caution. When DataPointLists are stored or retrieved, they are not
* referenced but copied, so the original list can be used for other purpose.
*
* The methods of this class are synchronized, therefore it can be safely used
* by multiple threads.
*/
class NFSDBDataPointStore implements DataPointStore {

private final Logger logger = LoggerFactory.getLogger(this.getClass());

private HashMap<Object, Object> storageMap = new HashMap<>();

private int lastStorageId = 0;
private final File tmpDataFileName;

NFSDBDataPointStore() throws MSDKException {

try {
tmpDataFileName = Files.createTempDirectory("msdk_nfsdb").toFile();

logger.debug("Initializing a new NFSDB journal factory in "
+ tmpDataFileName);

JournalFactory factory = new JournalFactory(tmpDataFileName);


} catch (IOException e) {
throw new MSDKException(e);
}

}


/**
* Stores new array of data points.
*
* @return Storage ID for the newly stored data.
*/
@Override
public @Nonnull Integer storeDataPoints(
@Nonnull MsSpectrumDataPointList dataPoints) {

if (storageMap == null)
throw new IllegalStateException("This object has been disposed");

// Clone the given list for storage
final MsSpectrumDataPointList newList = MSDKObjectBuilder
.getSpectrumDataPointList();
newList.copyFrom(dataPoints);

// Save the reference to the new list
synchronized (storageMap) {
// Increase the storage ID
lastStorageId++;
storageMap.put(lastStorageId, newList);
}

return lastStorageId;
}

/**
* Stores new array of data points.
*
* @return Storage ID for the newly stored data.
*/
@Override
public @Nonnull Integer storeDataPoints(
@Nonnull ChromatogramDataPointList dataPoints) {

if (storageMap == null)
throw new IllegalStateException("This object has been disposed");

// Clone the given list for storage
final ChromatogramDataPointList newList = MSDKObjectBuilder
.getChromatogramDataPointList();
newList.copyFrom(dataPoints);

// Save the reference to the new list
synchronized (storageMap) {
// Increase the storage ID
lastStorageId++;
storageMap.put(lastStorageId, newList);
}

return lastStorageId;
}

/**
* Stores new array of data points.
*
* @return Storage ID for the newly stored data.
*/
@Override
public @Nonnull Integer storeDataPoints(
@Nonnull FeatureDataPointList dataPoints) {

if (storageMap == null)
throw new IllegalStateException("This object has been disposed");

// Clone the given list for storage
final FeatureDataPointList newList = MSDKObjectBuilder
.getFeatureDataPointList();
newList.copyFrom(dataPoints);

// Save the reference to the new list
synchronized (storageMap) {
// Increase the storage ID
lastStorageId++;
storageMap.put(lastStorageId, newList);
}

return lastStorageId;
}

/**
* Reads the data points associated with given ID.
*/
@Override
synchronized public void readDataPoints(@Nonnull Object ID,
@Nonnull MsSpectrumDataPointList list) {

if (storageMap == null)
throw new IllegalStateException("This object has been disposed");

if (!storageMap.containsKey(ID))
throw new IllegalArgumentException(
"ID " + ID + " not found in storage");

// Get the stored DataPointList
final Object storedObject = storageMap.get(ID);
if (!(storedObject instanceof MsSpectrumDataPointList))
throw new MSDKRuntimeException(
"Object stored under ID " + ID + " is not of correct type");
final MsSpectrumDataPointList storedList = (MsSpectrumDataPointList) storedObject;

// Copy data
list.copyFrom(storedList);

}

/**
* Reads the data points associated with given ID.
*/
@Override
synchronized public void readDataPoints(@Nonnull Object ID,
@Nonnull ChromatogramDataPointList list) {

if (storageMap == null)
throw new IllegalStateException("This object has been disposed");

if (!storageMap.containsKey(ID))
throw new IllegalArgumentException(
"ID " + ID + " not found in storage");

// Get the stored DataPointList
final Object storedObject = storageMap.get(ID);
if (!(storedObject instanceof ChromatogramDataPointList))
throw new MSDKRuntimeException(
"Object stored under ID " + ID + " is not of correct type");
final ChromatogramDataPointList storedList = (ChromatogramDataPointList) storedObject;

// Copy data
list.copyFrom(storedList);

}

/**
* Reads the data points associated with given ID.
*/
@Override
synchronized public void readDataPoints(@Nonnull Object ID,
@Nonnull FeatureDataPointList list) {

if (storageMap == null)
throw new IllegalStateException("This object has been disposed");

if (!storageMap.containsKey(ID))
throw new IllegalArgumentException(
"ID " + ID + " not found in storage");

// Get the stored DataPointList
final Object storedObject = storageMap.get(ID);
if (!(storedObject instanceof FeatureDataPointList))
throw new MSDKRuntimeException(
"Object stored under ID " + ID + " is not of correct type");
final FeatureDataPointList storedList = (FeatureDataPointList) storedObject;

// Copy data
list.copyFrom(storedList);

}

/**
* Remove data associated with given storage ID.
*/
@Override
synchronized public void removeDataPoints(@Nonnull Object ID) {

if (storageMap == null)
throw new IllegalStateException("This object has been disposed");

storageMap.remove(ID);
}

@Override
synchronized public void dispose() {
storageMap = null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import io.github.msdk.datamodel.rawdata.ChromatogramDataPointList;
import io.github.msdk.datamodel.rawdata.ChromatographyInfo;
import io.github.msdk.datamodel.rawdata.SeparationType;
import io.github.msdk.datamodel.rawdata.SpectrumDataPointList;
import io.github.msdk.datamodel.rawdata.MsSpectrumDataPointList;

/**
* A DataPointStore implementation that stores the data points in a temporary
Expand Down Expand Up @@ -98,7 +98,7 @@ class TmpFileDataPointStore implements DataPointStore {
*/
@Override
synchronized public @Nonnull Integer storeDataPoints(
@Nonnull SpectrumDataPointList dataPoints) {
@Nonnull MsSpectrumDataPointList dataPoints) {

if (byteBuffer == null)
throw new IllegalStateException("This object has been disposed");
Expand Down Expand Up @@ -257,7 +257,7 @@ class TmpFileDataPointStore implements DataPointStore {
*/
@Override
synchronized public void readDataPoints(@Nonnull Object ID,
@Nonnull SpectrumDataPointList list) {
@Nonnull MsSpectrumDataPointList list) {

if (byteBuffer == null)
throw new IllegalStateException("This object has been disposed");
Expand Down
Loading

0 comments on commit 6305631

Please sign in to comment.