Comments (2)
Are you interacting with it on the main thread?
Without some kind of executable sample it's going to be nearly impossible to know what's going on here.
from tape.
Hello Jake, i am posting the coding scenario here.
Queue is created by injection using Dagger. The add()
call is made in main thread. Application stops at super.add(entry)
in add(SampleTask entry)
of SampleTaskQueue
class.
DaggerModule.java
@Provides @Singleton
SampleTaskQueue provideTaskQueue(Gson gson) {
return SampleTaskQueue.create(app.getApplicationContext(), gson);
}
SampleFragment.java
...
@Inject
protected SampleTaskQueue queue;
...
void addTask(){
queue.add(new SampleTask( params ... ));
}
...
SampleTask.java
public class SampleTask implements Task<SampleTask.Callback> {
public SampleTask( params ... ) {
// Some initialization ...
}
@Override
public void execute(Callback callback) {
// Some task ...
}
interface Callback {
void onSuccess();
void onFailure();
}
}
SampleTaskService.java
public class SampleTaskService extends Service implements SampleTask.Callback {
@Inject
SampleTaskQueue queue;
private boolean isRunning = false;
@Override
public void onCreate() {
super.onCreate();
((SampleApplication) getApplication()).inject(this);
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
executeNext();
return START_STICKY;
}
private void executeNext() {
// Only one task at a time
if (isRunning) return;
SampleTask task = queue.peek();
if (task != null) {
isRunning = true;
task.execute(this);
} else {
stopSelf();
}
}
@Nullable
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public void onSuccess() {
isRunning = false;
queue.remove();
executeNext();
}
@Override
public void onFailure() {
isRunning = false;
}
}
SampleTaskQueue.java
public class SampleTaskQueue extends TaskQueue<SampleTask> {
private static final String FILENAME = "sample_task_queue";
private Context context;
public SampleTaskQueue(ObjectQueue<SampleTask> delegate, Context context) {
super(delegate);
this.context = context;
if (size() > 0) {
startService();
}
}
private void startService() {
context.startService(new Intent(context, SampleTaskService.class));
}
@Override
public void add(SampleTask entry) {
super.add(entry); // Application stops here
startService();
}
@Override
public void remove() {
super.remove();
}
public static SampleTaskQueue create(Context context, Gson gson) {
FileObjectQueue.Converter<SampleTask> converter = new GsonConverter<>(gson, SampleTask.class);
File queueFile = new File(context.getFilesDir(), FILENAME);
FileObjectQueue<SampleTask> delegate;
try {
delegate = new FileObjectQueue<>(queueFile, converter);
} catch (IOException e) {
throw new RuntimeException("Unable to create file queue.", e);
}
return new SampleTaskQueue(delegate, context);
}
}
from tape.
Related Issues (20)
- Is it thread safe? HOT 3
- Android module for android specific logic HOT 2
- A question about the evolution of this repository HOT 1
- Read/Write Benchmarks HOT 1
- Batched remove() - Using remove() less frequently than peek() HOT 6
- Remove java.io.OutputStream and the like from API?
- BlockingQueue implementation and other interfaces HOT 5
- Wrap QueueFile around an existing File? HOT 6
- Support addAll(Collection<byte[]>) for better performance with small records HOT 2
- Windows non-sync writes HOT 1
- Fail to read queue.
- Leak of file descriptor when creating QueueFile from corrupted queue file. HOT 1
- Not compatible with Gradle 5.1.1 HOT 6
- Why so slow?
- QueueFileTest.testSaturatedFileExpansionMovesElements hanged HOT 3
- Issues while writing and reading from different daemons with flock
- Consider DequeFile HOT 1
- Fail to Remove from FileObjectQueue
- Time to mark as deprecated? HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tape.