Package tvbrowser.core.data

Examples of tvbrowser.core.data.OnDemandDayProgramFile


  public ChannelDayProgram getDayProgram(Date date, Channel channel) {
    return getDayProgram(date, channel, false);
  }

  public void setDayProgramWasChangedByPlugin(Date date, Channel channel) {
    OnDemandDayProgramFile progFile = getCacheEntry(date, channel, false, false);

    if(progFile != null) {
      progFile.getDayProgram().setWasChangedByPlugin();
    }
  }
View Full Code Here


      progFile.getDayProgram().setWasChangedByPlugin();
    }
  }

  private ChannelDayProgram getDayProgram(Date date, Channel channel, boolean update) {
    OnDemandDayProgramFile progFile = getCacheEntry(date, channel, true, update);

    if (progFile != null) {
      return progFile.getDayProgram();
    } else {
      return null;
    }
  }
View Full Code Here

        backupFile = null;
      }
    }

    // Invalidate the old program file from the cache
    OnDemandDayProgramFile oldProgFile = getCacheEntry(date, channel, false, false);
    if (oldProgFile != null) {
      oldProgFile.setValid(false);

      // Remove the old entry from the cache (if it exists)
      removeCacheEntry(key);
    }

    // Create a new program file
    OnDemandDayProgramFile newProgFile = new OnDemandDayProgramFile(file, prog);

    // Put the new program file in the cache
    addCacheEntry(key, newProgFile);

    // Inform the listeners about adding the new program
    // NOTE: This must happen before saving to give the listeners the chance to
    // change the data and have those changes saved to disk.
    //fireDayProgramAdded(prog);

    // Save the new program
    try {
      // Save the day program
      newProgFile.saveDayProgram();

      // Delete the backup
      if (backupFile != null) {
        backupFile.delete();
      }
View Full Code Here

      Channel channel, boolean loadFromDisk, boolean update) {
    if(!loadFromDisk) {
      String key = getDayProgramKey(date, channel);

      //Try to get the program from the cache
      OnDemandDayProgramFile progFile =  mTvDataHash.get(key);

      if(progFile != null) {
        return progFile;
      }
    }
View Full Code Here

  private synchronized OnDemandDayProgramFile getCacheEntryBlocking(Date date,
      Channel channel, boolean loadFromDisk, boolean update) {
    String key = getDayProgramKey(date, channel);

    // Try to get the program from the cache
    OnDemandDayProgramFile progFile =  mTvDataHash.get(key);

    // Try to load the program from disk
    if (loadFromDisk && (progFile == null || (update && progFile.isTimeLimitationData()))) {
      progFile = loadDayProgram(date, channel, update);
      if (progFile != null && !update) {
        addCacheEntry(key, progFile);
      }
    }
View Full Code Here

    try {
      // Check whether this day program is known
      int version = (int) file.length();
      int knownStatus = mTvDataInventory.getKnownStatus(date, channel, version);

      OnDemandDayProgramFile oldProgFile = getCacheEntry(date, channel, false, false);
      MutableChannelDayProgram checkProg = (MutableChannelDayProgram)getDayProgram(date,channel,true);

      boolean somethingChanged = calculateMissingLengths(checkProg);

      Object oldProg = null;
      if((oldProg = mNewDayProgramsAfterUpdate.remove(key)) != null) {
        // Inform the listeners about deleting the old program
        if (oldProg instanceof ChannelDayProgram) {
          fireDayProgramDeleted((ChannelDayProgram)oldProg);
        }

        // Inform the listeners about adding the new program
        fireDayProgramAdded(checkProg);
      }
      else if(somethingChanged){
        fireDayProgramAdded(checkProg);
      }

      if (checkProg.getAndResetChangedByPluginState() || somethingChanged) {
        // Some missing lengths could now be calculated
        // -> Try to save the changes

        // We use a temporary file. If saving succeeds we rename it
        File tempFile = new File(file.getAbsolutePath() + ".changed");
        try {
          // Try to save the changed program
          OnDemandDayProgramFile newProgFile = new OnDemandDayProgramFile(
              tempFile, checkProg);
          newProgFile.saveDayProgram();

          // Saving the changed version succeed -> Delete the original
          file.delete();

          // Use the changed version now
          tempFile.renameTo(file);

          // If the old version was known -> Set the new version to known too
          if (knownStatus == TvDataInventory.KNOWN) {
            version = (int) file.length();
            mTvDataInventory.setKnown(date, channel, version);
          }
        } catch (Exception exc) {
          // Saving the changes failed
          // -> remove the temp file and keep the old one
          tempFile.delete();
        }

        // We have to load the file again to get the new data positions
        OnDemandDayProgramFile progFile = new OnDemandDayProgramFile(file, date, channel);
        progFile.loadDayProgram(false);

        // Invalidate the old program file from the cache
        if (oldProgFile != null) {
          oldProgFile.setValid(false);

          // Remove the old entry from the cache (if it exists)
          removeCacheEntry(key);
        }

        // Put the new program file in the real cache
        addCacheEntry(key, progFile);
      } else if(oldProgFile != null) {
        oldProgFile.calculateTimeLimits();
      }

      // Inform the listeners about adding the new program
      if(oldProg != null || somethingChanged) {
        OnDemandDayProgramFile dayProgramFile = getCacheEntry(date, channel, true, false);

        ChannelDayProgram dayProgram = dayProgramFile.getDayProgram();

        if(oldProg instanceof ChannelDayProgram) {
          fireDayProgramTouched((ChannelDayProgram)oldProg,dayProgram);
        }
        else {
View Full Code Here

      return null;
    }

    try {
      // Load the program file
      OnDemandDayProgramFile progFile = new OnDemandDayProgramFile(file, date,
          channel);
      progFile.loadDayProgram(update);

      return progFile;
    } catch (Exception exc) {
      mLog.log(Level.WARNING, "Loading program for " + channel + " from "
          + date + " failed. The file will be deleted...", exc);
View Full Code Here

TOP

Related Classes of tvbrowser.core.data.OnDemandDayProgramFile

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.