Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
radpin
Posts: 21
Registered: ‎07-15-2008
My Device: Not Specified
Accepted Solution

FileSystemJournalListener; am I crazy or what?

Pretty much scooped from the demo, I can't seem to get this guy to work. The order of events (I think?) is supposed to be:

 

1) Screen constructor loads.

2) Screen class has a private member of the FileExplorerDemoJournalListener class that implements FileSystemJournalListener.

3) FileExplorerDemoJournalListener class has a constructor which takes the screen as its argument, and maintains it in a private variable.

4) Screen class goes into the background (or otherwise stays alive), and so the FileExplorerDemoJournalListener class lives on watching the file system.

 

Not sure what I'm missing, but I should be getting log entries from this, and I'm getting nothing.

 

 

 

 

 

 

 

import net.rim.device.api.io.file.FileSystemJournal;
import net.rim.device.api.io.file.FileSystemJournalEntry;
import net.rim.device.api.io.file.FileSystemJournalListener;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.Dialog;

/**
 * Listener to determine when files have been added to the file system.
 */
/*package*/ final class FileExplorerDemoJournalListener implements FileSystemJournalListener
{
    private JTrackScreen _screen;
    private long _lastUSN; // = 0;
   
   
    /**
     * Constructor.
     *
     * @param screen The screen to update when events occur.
     */
    FileExplorerDemoJournalListener(JTrackScreen screen)
    {
        _screen = screen;
    }

   
    /**
     * Notified when FileSystem event occurs.
     */
    public void fileJournalChanged()
    {
        long nextUSN = FileSystemJournal.getNextUSN();
        String msg = null;
       
        for (long lookUSN = nextUSN - 1; lookUSN >= _lastUSN && msg == null; --lookUSN)
        {
            FileSystemJournalEntry entry = FileSystemJournal.getEntry(lookUSN);
           
            // We didn't find an entry.
            if (entry == null)
            {
                break;
            }

          // Check if this entry was added or deleted.
            String path = entry.getPath();
           
            if (path != null)
            {
                switch (entry.getEvent())
                {
                    case FileSystemJournalEntry.FILE_ADDED:
                        msg = "File was added.";
                        break;
                       
                    case FileSystemJournalEntry.FILE_DELETED:
                        msg = "File was deleted.";
                        break;
                }
            }
        }
       
        // _lastUSN must be updated before calling showMessage() because that method
        // pushes a modal screen onto the display stack, which blocks this thread.
        // If the modal screen's thread then processes a file journal event on this
        // application's behalf, the for loop above can end up processing the same
        // event that we are blocking on.  Updating _lastUSN before blocking prevents
        // the same file journal event from being processed twice, and thus prevents
        // the same dialog from being displayed twice.
        _lastUSN = nextUSN;
       
        if ( msg != null )
        {
            //showMessage(msg);
            //_screen.updateList();
            _screen.WriteLog(msg);
        }
    }
   
   
    /**
     * Displays the provided message in a dialog box.
     *
     * @param msg The message to display.
     */
    private void showMessage(String msg)
    {
        synchronized (UiApplication.getApplication().getAppEventLock())
        {
            Dialog.alert(msg);
        }
    }
}

 

 

BlackBerry Development Advisor
MSohm
Posts: 14,757
Registered: ‎07-09-2008
My Device: BlackBerry Passport

Re: FileSystemJournalListener; am I crazy or what?

Are you calling Application.addFileSystemJournalListener to register your FileSystemJournalListener?
Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Developer
radpin
Posts: 21
Registered: ‎07-15-2008
My Device: Not Specified

Re: FileSystemJournalListener; am I crazy or what?

Solved the problem! Thanks so much. I've saved some files (pictures / video / voice), and I'm seeing the filenames in my eventlog now. Whoohoo! One problem down, 21987435345 more to go. :-)