mirror of
https://github.com/deltachat/deltachat-android.git
synced 2025-10-03 01:39:18 +02:00
remove unused RequirementListener/RequirementProvider
This commit is contained in:
parent
ddee52171e
commit
6c0c7f358d
5 changed files with 3 additions and 132 deletions
|
@ -147,8 +147,6 @@ public class ApplicationContext extends MultiDexApplication implements DefaultLi
|
|||
}
|
||||
|
||||
private void initializeJobManager() {
|
||||
this.jobManager = JobManager.newBuilder(this)
|
||||
.withConsumerThreads(5)
|
||||
.build();
|
||||
this.jobManager = new JobManager(this, 5);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,11 +3,6 @@ package org.thoughtcrime.securesms.jobmanager;
|
|||
import android.content.Context;
|
||||
import android.os.PowerManager;
|
||||
|
||||
import org.thoughtcrime.securesms.jobmanager.requirements.RequirementListener;
|
||||
import org.thoughtcrime.securesms.jobmanager.requirements.RequirementProvider;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
|
@ -16,40 +11,22 @@ import java.util.concurrent.Executors;
|
|||
* that are executed once a Job's {@link org.thoughtcrime.securesms.jobmanager.requirements.Requirement}s
|
||||
* are met.
|
||||
*/
|
||||
public class JobManager implements RequirementListener {
|
||||
public class JobManager {
|
||||
|
||||
private final JobQueue jobQueue = new JobQueue();
|
||||
private final Executor eventExecutor = Executors.newSingleThreadExecutor();
|
||||
|
||||
private final Context context;
|
||||
private final List<RequirementProvider> requirementProviders;
|
||||
|
||||
private JobManager(Context context,
|
||||
List<RequirementProvider> requirementProviders,
|
||||
int consumers)
|
||||
public JobManager(Context context, int consumers)
|
||||
{
|
||||
this.context = context;
|
||||
this.requirementProviders = requirementProviders;
|
||||
|
||||
if (requirementProviders != null && !requirementProviders.isEmpty()) {
|
||||
for (RequirementProvider provider : requirementProviders) {
|
||||
provider.setListener(this);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i=0;i<consumers;i++) {
|
||||
new JobConsumer("JobConsumer-" + i, jobQueue).start();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param context An Android {@link android.content.Context}.
|
||||
* @return a {@link org.thoughtcrime.securesms.jobmanager.JobManager.Builder} used to construct a JobManager.
|
||||
*/
|
||||
public static Builder newBuilder(Context context) {
|
||||
return new Builder(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Queue a {@link org.thoughtcrime.securesms.jobmanager.Job} to be executed.
|
||||
*
|
||||
|
@ -69,16 +46,6 @@ public class JobManager implements RequirementListener {
|
|||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequirementStatusChanged() {
|
||||
eventExecutor.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
jobQueue.onRequirementStatusChanged();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private PowerManager.WakeLock acquireWakeLock(Context context, String name, long timeout) {
|
||||
PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
|
||||
PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, name);
|
||||
|
@ -88,39 +55,4 @@ public class JobManager implements RequirementListener {
|
|||
|
||||
return wakeLock;
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private final Context context;
|
||||
private List<RequirementProvider> requirementProviders;
|
||||
private int consumerThreads;
|
||||
|
||||
Builder(Context context) {
|
||||
this.context = context;
|
||||
this.consumerThreads = 5;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the number of threads dedicated to consuming Jobs from the queue and executing them.
|
||||
*
|
||||
* @param consumerThreads The number of threads.
|
||||
* @return The builder.
|
||||
*/
|
||||
public Builder withConsumerThreads(int consumerThreads) {
|
||||
this.consumerThreads = consumerThreads;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return A constructed JobManager.
|
||||
*/
|
||||
public JobManager build() {
|
||||
if (requirementProviders == null) {
|
||||
requirementProviders = new LinkedList<>();
|
||||
}
|
||||
|
||||
return new JobManager(context, requirementProviders,
|
||||
consumerThreads);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -20,7 +20,6 @@ import androidx.annotation.NonNull;
|
|||
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -29,10 +28,6 @@ class JobQueue {
|
|||
private final Map<String, Job> activeGroupIds = new HashMap<>();
|
||||
private final LinkedList<Job> jobQueue = new LinkedList<>();
|
||||
|
||||
synchronized void onRequirementStatusChanged() {
|
||||
notifyAll();
|
||||
}
|
||||
|
||||
synchronized void add(Job job) {
|
||||
jobQueue.add(job);
|
||||
processJobAddition(job);
|
||||
|
|
|
@ -1,21 +0,0 @@
|
|||
/**
|
||||
* Copyright (C) 2014 Open Whisper Systems
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.thoughtcrime.securesms.jobmanager.requirements;
|
||||
|
||||
public interface RequirementListener {
|
||||
public void onRequirementStatusChanged();
|
||||
}
|
|
@ -1,33 +0,0 @@
|
|||
/**
|
||||
* Copyright (C) 2014 Open Whisper Systems
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.thoughtcrime.securesms.jobmanager.requirements;
|
||||
|
||||
/**
|
||||
* Notifies listeners when a {@link org.thoughtcrime.securesms.jobmanager.requirements.Requirement}'s
|
||||
* state is likely to have changed.
|
||||
*/
|
||||
public interface RequirementProvider {
|
||||
|
||||
/**
|
||||
* The {@link org.thoughtcrime.securesms.jobmanager.requirements.RequirementListener} to call when
|
||||
* a {@link org.thoughtcrime.securesms.jobmanager.requirements.Requirement}'s status is likely to
|
||||
* have changed.
|
||||
*
|
||||
* @param listener The listener to call.
|
||||
*/
|
||||
public void setListener(RequirementListener listener);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue