1

I'm developing a multiprocess solution with Android SyncAdapter and Domain Driven Design (DDD) comcepts.

Just after login It's necessary to download some data to continue. Then I start the SyncAdapter manually and (the intention) await ultil it ends.

The SyncAdapter are running in a different Process and I need to show an undeterminated progress for the user until the sync ends. After it I closes the progress and the lifes continues wonderfully... But !!!

At the Sync Process I create a file in order to inform others processes that a processing is in progress:

@Override
    public Locker lock(String lockerName) {
        final File file = context.getFileStreamPath(lockerName);
        try {
            final RandomAccessFile lockFile = new RandomAccessFile(file, "rws");
            final FileLock fileLock = lockFile.getChannel().lock();
...

Ok, this works wonderfully... In the app process, in the verification Thread (RxJava Interval) I do this:

@Override
    public boolean isLocked(String lockerName) {
        final File file = context.getFileStreamPath(lockerName);
        try {
            final RandomAccessFile lockFile = new RandomAccessFile(file, "rws");
            final FileLock fileLock = lockFile.getChannel().tryLock();
            boolean result = fileLock == null;
...

And I get the following result/exception:

java.io.IOException: fcntl failed: EAGAIN (Try again) at java.nio.FileChannelImpl.basicLock(FileChannelImpl.java:123) at java.nio.FileChannelImpl.tryLock(FileChannelImpl.java:181) at java.nio.channels.FileChannel.tryLock(FileChannel.java:584) at ch4k4uw.easysale.domain.service.SimpleInterProcessSyncAccessDomainService.isLocked(SimpleInterProcessSyncAccessDomainService.java:69)

...

android.system.ErrnoException: fcntl failed: EAGAIN (Try again) at libcore.io.Posix.fcntlFlock(Native Method) at libcore.io.ForwardingOs.fcntlFlock(ForwardingOs.java:70) at java.nio.FileChannelImpl.basicLock(FileChannelImpl.java:121) at java.nio.FileChannelImpl.tryLock(FileChannelImpl.java:181) at java.nio.channels.FileChannel.tryLock(FileChannel.java:584) at ch4k4uw.easysale.domain.service.SimpleInterProcessSyncAccessDomainService.isLocked(SimpleInterProcessSyncAccessDomainService.java:69)

Should the FileLock::tryLock() return null whether the lock fails right?

Am I doing something wrong? Are there any another way to do this interprocess communication following the DDD concepts without use Android Services?

Thanks.

PS: I'm using the Samsung Galaxy J7 METAL Device for the tests.

0 Answers0