lib/sup/source.rb in sup-0.14.1.1 vs lib/sup/source.rb in sup-0.15.0

- old
+ new

@@ -1,6 +1,7 @@ require "sup/rfc2047" +require "monitor" module Redwood class SourceError < StandardError def initialize *a @@ -51,25 +52,25 @@ ## pummelled from multiple threads at once. ## ## Examples for you to look at: mbox.rb and maildir.rb. bool_accessor :usual, :archived - attr_reader :uri - attr_accessor :id, :poll_lock + attr_reader :uri, :usual + attr_accessor :id def initialize uri, usual=true, archived=false, id=nil raise ArgumentError, "id must be an integer: #{id.inspect}" unless id.is_a? Fixnum if id @uri = uri @usual = usual @archived = archived @id = id - @poll_lock = Mutex.new + @poll_lock = Monitor.new end - ## overwrite me if you have a disk incarnation (currently used only for sup-sync-back) + ## overwrite me if you have a disk incarnation (currently used only for sup-sync-back-mbox) def file_path; nil end def to_s; @uri.to_s; end def == o; o.uri == uri; end def is_source_for? uri; uri == @uri; end @@ -79,18 +80,45 @@ ## release resources that are easy to reacquire. it is called ## after processing a source (e.g. polling) to prevent resource ## leaks (esp. file descriptors). def go_idle; end + ## Returns an array containing all the labels that are natively + ## supported by this source + def supported_labels?; [] end + + ## Returns an array containing all the labels that are currently in + ## the location filename + def labels? info; [] end + ## Yields values of the form [Symbol, Hash] ## add: info, labels, progress ## delete: info, progress def poll unimplemented end def valid? info true + end + + def synchronize &block + @poll_lock.synchronize &block + end + + def try_lock + acquired = @poll_lock.try_enter + if acquired + debug "lock acquired for: #{self}" + else + debug "could not acquire lock for: #{self}" + end + acquired + end + + def unlock + @poll_lock.exit + debug "lock released for: #{self}" end ## utility method to read a raw email header from an IO stream and turn it ## into a hash of key-value pairs. minor special semantics for certain headers. ##