use of edu.berkeley.cs.amplab.carat.thrift.Sample._Fields in project carat by amplab.
the class CommunicationManager method uploadSamples.
public int uploadSamples(Collection<Sample> samples) {
CaratService.Client instance = null;
int succeeded = 0;
ArrayList<Sample> samplesLeft = new ArrayList<Sample>();
registerLocal();
try {
instance = ProtocolClient.open(a.getApplicationContext());
registerOnFirstRun(instance);
for (Sample s : samples) {
boolean success = false;
try {
success = instance.uploadSample(s);
} catch (Throwable th) {
Log.e(TAG, "Error uploading sample.", th);
}
if (success)
succeeded++;
else
samplesLeft.add(s);
}
safeClose(instance);
} catch (Throwable th) {
Log.e(TAG, "Error refreshing main reports.", th);
safeClose(instance);
}
// Do not try again. It can cause a massive sample attack on the server.
return succeeded;
}
use of edu.berkeley.cs.amplab.carat.thrift.Sample._Fields in project carat by amplab.
the class CaratSampleDB method queryOldestSamples.
public SortedMap<Long, Sample> queryOldestSamples(int howmany) {
SortedMap<Long, Sample> results = new TreeMap<Long, Sample>();
try {
synchronized (dbLock) {
if (db == null || !db.isOpen()) {
try {
db = helper.getWritableDatabase();
} catch (android.database.sqlite.SQLiteException ex) {
Log.e(TAG, "Could not open database", ex);
return results;
}
}
String[] columns = mColumnMap.keySet().toArray(new String[mColumnMap.size()]);
Cursor cursor = query(null, null, columns, null, null, COLUMN_TIMESTAMP + " ASC LIMIT " + howmany);
if (cursor == null) {
// There are no results
return results;
} else {
// Log.d("CaratSampleDB", "query is successfull!");
cursor.moveToFirst();
while (!cursor.isAfterLast()) {
Sample s = fillSample(cursor);
if (s != null) {
results.put(cursor.getLong(cursor.getColumnIndex(BaseColumns._ID)), s);
cursor.moveToNext();
}
}
cursor.close();
}
}
} catch (Throwable th) {
Log.e(TAG, "Failed to query oldest samples!", th);
}
return results;
}
use of edu.berkeley.cs.amplab.carat.thrift.Sample._Fields in project carat by amplab.
the class CaratSampleDB method fillSample.
/*
* Read a sample from the current position of the cursor. TODO: Needs to be
* updated when fields update.
*/
private Sample fillSample(Cursor cursor) {
Sample s = null;
byte[] sampleB = cursor.getBlob(cursor.getColumnIndex(CaratSampleDB.COLUMN_SAMPLE));
if (sampleB != null) {
ObjectInputStream oi;
try {
oi = new ObjectInputStream(new ByteArrayInputStream(sampleB));
Object o = oi.readObject();
if (o != null)
s = SampleReader.readSample(o);
} catch (StreamCorruptedException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
return s;
}
Aggregations