Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove strange enum from ServiceControl #427

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public void runServices(Intent intent,

// do we have data network?
if (isConnected()) {
SchedulerInstance.INSTANCE.getScheduler(mContext, mFileManager, intent, requestCode)
getScheduler(intent, requestCode)
.updateScheduler(interval);
}
}
Expand All @@ -173,7 +173,7 @@ public void runServices(Intent intent,
*/
public void stopServices(Intent intent, int requestCode) {
Logger.log(CLASS_TAG, "Stopping services");
SchedulerInstance.INSTANCE.getScheduler(mContext, mFileManager, intent, requestCode)
getScheduler(intent, requestCode)
.stopScheduler();
}

Expand Down Expand Up @@ -207,13 +207,8 @@ public boolean isConnected() {
return Utility.isConnected(mContext);
}

public enum SchedulerInstance {
INSTANCE;

private Scheduler getScheduler(Context context, FileManager fileManager, Intent intent,
int requestCode) {
return new Scheduler(context, fileManager, intent, requestCode,
PendingIntent.FLAG_UPDATE_CURRENT);
}
private Scheduler getScheduler(Intent intent, int requestCode) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is to make the Scheduler a Singleton. More thread-safety this way.

Copy link
Contributor Author

@alxndrsn alxndrsn Apr 22, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yeah, I obviously missed the singletoning - sorry!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More thread-safety this way.

Surely something's thread-safe or it's not - the area between the two is scary (and not thread-safe)!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Though this is convenient, it increases the method counts on Android. Android has a limitation on method count so usually I think twice before declaring new methods

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to know! Looks like both implementations have the same number of methods, though :¬p

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make more sense for Scheduler itself to enforce the singletonism? Any use of Scheduler outside ServiceControl can quite easily create new instances. In fact, that's happening in

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh :-) In that case let's maintain your private Scheduler getScheduler(Intent intent, int requestCode) { . And yes it makes more sense to enforce the singletonism ( Is this actually a word? Just curious ;-) ) in the Scheduler class itself.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me check this before you merge. If it's meant to be a singleton, then we should enforce that everywhere; if it's not then this change should be fine.

return new Scheduler(mContext, mFileManager, intent, requestCode,
PendingIntent.FLAG_UPDATE_CURRENT);
}
}