Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Commit

Permalink
Merge branch 'feature/Fix-Sending-Bug' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin Reimold committed Jun 16, 2015
2 parents d985ffb + bde81f6 commit e3b51e7
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ protected static Channel getInstance() {
*/
protected void synchronize() {
this.queue.flush();
Sender.getInstance().sendNextFile();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ protected void persist(String[] data, Boolean highPriority) {
isSuccess = this.writeToDisk(serializedData, highPriority);
if (isSuccess) {
Sender sender = Sender.getInstance();
if (sender != null) {
if (sender != null && !highPriority) {
sender.sendNextFile();
}
}
Expand All @@ -142,13 +142,17 @@ protected boolean writeToDisk(String data, Boolean highPriority) {
if (highPriority) {
filesDir = new File(filesDir + AI_SDK_DIRECTORY + HIGH_PRIO_DIRECTORY + uuid);
outputStream = new FileOutputStream(filesDir, true);
InternalLogging.warn(TAG, "Saving data" + "HIGH PRIO");
} else {
filesDir = new File(filesDir + AI_SDK_DIRECTORY + REGULAR_PRIO_DIRECTORY + uuid);
outputStream = new FileOutputStream(filesDir, true);
InternalLogging.warn(TAG, "Saving data" + "REGULAR PRIO");
}
outputStream.write(data.getBytes());
outputStream.close();
isSuccess = true;
InternalLogging.warn(TAG, "Saved data");

} catch (Exception e) {
//Do nothing
InternalLogging.warn(TAG, "Failed to save data with exception: " + e.toString());
Expand Down Expand Up @@ -193,12 +197,16 @@ protected String load(File file) {
* @return the next available file.
*/
protected File nextAvailableFile() {
File file = this.nextHighPrioFile();
if (file != null) {
return file;
} else {
return this.nextRegularPrioFile();
synchronized (Persistence.LOCK) {
File file = this.nextHighPrioFile();
if (file != null) {
return file;
} else {
InternalLogging.info(TAG, "High prio file was empty", "(That's the default if no crashes present");
return this.nextRegularPrioFile();
}
}

}


Expand All @@ -207,6 +215,8 @@ private File nextHighPrioFile() {
if (context != null) {
String path = context.getFilesDir() + AI_SDK_DIRECTORY + HIGH_PRIO_DIRECTORY;
File directory = new File(path);
InternalLogging.info(TAG, "Returning High Prio File: ", path);

return this.nextAvailableFileInDirectory(directory);
}

Expand All @@ -220,6 +230,7 @@ private File nextRegularPrioFile() {
if (context != null) {
String path = context.getFilesDir() + AI_SDK_DIRECTORY + REGULAR_PRIO_DIRECTORY;
File directory = new File(path);
InternalLogging.info(TAG, "Returning Regular Prio File: " + path);
return this.nextAvailableFileInDirectory(directory);
}

Expand All @@ -236,18 +247,29 @@ private File nextAvailableFileInDirectory(File directory) {
if (directory != null) {
File[] files = directory.listFiles();
File file;

if ((files != null) && (files.length > 0)) {
for (int i = 0; i < files.length - 1; i++) {
for (int i = 0; i <= files.length - 1; i++) {
InternalLogging.info(TAG, "The directory " + directory.toString(), " ITERATING over " + files.length + " files" );

file = files[i];
InternalLogging.info(TAG, "The directory " +file.toString(), " FOUND" );

if (!this.servedFiles.contains(file)) {
InternalLogging.info(TAG, "The directory " + file.toString(), " ADDING TO SERVED AND RETURN" );

this.servedFiles.add(file);
return file;//we haven't served the file, return it
}
else {
InternalLogging.info(TAG, "The directory " + file.toString(), " WAS ALREADY SERVED" );
}
}

}
}
InternalLogging.info(TAG, "The directory " + directory.toString(), " NO FILES" );

}
InternalLogging.info(TAG, "The directory " + directory.toString(), "Did not contain any unserved files" );
return null; //no files in directory or no directory
}
}
Expand Down

0 comments on commit e3b51e7

Please sign in to comment.