private synchronized void checkTimeUpdate(long localTime, long utcTime) throws Exception {
    // broadcast
    _props.setProperty("utc", String.valueOf(utcTime));
    _props.setProperty("local", String.valueOf(localTime));

    TimeUpdateNotification notification =
        new TimeUpdateNotification(TimeUpdateNotification.UPDATE_UTC_TIME, _props);

    Notifier.getInstance().broadcast(notification);

    // wait
    try {
      wait(30000L); // 30 seconds
    } catch (Exception ex) {
    }

    // refreshTimeServer();
    // checkSuccess(_event, _sessions[0], _sm[0], IErrorCode.NO_ERROR);

    long offset = utcTime - localTime;
    Logger.debug("Input UTC Time = " + new Timestamp(utcTime));
    Logger.debug("Input Local Time = " + new Timestamp(localTime));
    Logger.debug("Expected offset: " + offset);

    // check local to utc
    Timestamp ts = TimeUtil.localToUtcTimestamp(_testDate);
    Logger.debug("Converted local to UTc timestamp: " + ts);
    assertEquals("LocalToUtc conversion fail", offset, ts.getTime() - _testDate.getTime());

    // check utc to local
    ts = TimeUtil.utcToLocalTimestamp(_testDate);
    Logger.debug("Converted utc to local timestamp: " + ts);
    assertEquals("UtcToLocal conversion fail", offset, _testDate.getTime() - ts.getTime());
  }
  protected void prepareTestData() throws java.lang.Exception {
    long currentTime = TimeUtil.getCurrentLocalTimeMillis();
    long oneHour = 3600000;
    long positive = 8 * oneHour + currentTime;
    long negative = -5 * oneHour + currentTime;

    _times =
        new long[][] {
          {positive, currentTime},
          {currentTime, currentTime},
          {negative, currentTime},
        };

    Calendar cal = GregorianCalendar.getInstance();
    cal.set(2002, 9, 19, 5, 5, 29);
    _testDate = new Timestamp(cal.getTime().getTime());

    Logger.debug("Test date (ts)= " + _testDate);
    Logger.debug("Test date (ms)= " + _testDate.getTime());

    _timeServer = UtcTimeServer.getInstance();

    TimeUtil.setTimeServer(_timeServer);

    _event = new GetUtcTimeEvent();

    //    createSessions(1);
    //    createStateMachines(1);

  }
 public synchronized boolean isProcessing() {
   if (_processing) {
     if (_processingTime > TimeUtil.localToUtc()) return true;
     else _processing = false;
   }
   return _processing;
 }
 public static synchronized void clearExpiredMetaInfoInMem() {
   Enumeration fileIdList = allMetaInfo.keys();
   Vector expiredFileIdList = new Vector();
   MetaInfo metaInfo = null;
   String fileId = null;
   while (fileIdList.hasMoreElements()) {
     fileId = (String) fileIdList.nextElement();
     metaInfo = (MetaInfo) allMetaInfo.get(fileId);
     if ((metaInfo.getTimeLastAction() + 300000) < TimeUtil.localToUtc())
       expiredFileIdList.add(fileId);
   }
   for (int i = 0; i < expiredFileIdList.size(); i++) {
     fileId = (String) expiredFileIdList.get(i);
     removeMetaInfoInMem(fileId);
   }
 }
 private synchronized void storeMetaInfoIntoFile() throws FileAccessException {
   _timeLastAction = TimeUtil.localToUtc();
   File tmpFile = new File(META_INFO_FILENAME);
   FileWriter file = null;
   BufferedWriter bw = null;
   PrintWriter pw = null;
   try {
     file = new FileWriter(tmpFile);
     bw = new BufferedWriter(file);
     pw = new PrintWriter(bw);
     pw.println(_blockSize);
     pw.println(parseBlockReceivedToString());
     pw.println(_totalBlocks);
     pw.println(_fileId);
     pw.println(_lastBlock);
     pw.println(_lastBlockSent);
     pw.println(_lastBlockSize);
     pw.println(_subPath);
     pw.println(_thresholdSize);
     pw.println(_transId);
     pw.println(parseBlockFilenameToString());
     pw.println(_timeCreated);
     pw.println(_originalEventId);
     pw.println(_GNCI);
     pw.println(_finishedOnce);
     int originalDataLen = (_originalData == null) ? -1 : _originalData.length;
     pw.println(originalDataLen);
     for (int i = 0; i < originalDataLen; i++) {
       if (_originalData[i] != null) pw.println(_originalData[i]);
       else pw.println(NULL_DELIMITER);
     }
     pw.println(_timeLastAction);
     close(pw);
     if (FileHelper.exist(IPackagingConstants.PACKAGING_PATH, _subPath, META_INFO_FILENAME))
       FileHelper.replace(
           IPackagingConstants.PACKAGING_PATH, _subPath, META_INFO_FILENAME, tmpFile);
     else
       FileHelper.create(
           IPackagingConstants.PACKAGING_PATH, _subPath, META_INFO_FILENAME, tmpFile);
     tmpFile.delete();
   } catch (IOException ioe) {
     throw new FileAccessException("Unable to store meta info to file.");
   } finally {
     close(pw);
   }
 }
 public synchronized void setProcessing(boolean flag) {
   _processingTime = TimeUtil.localToUtc() + 60000;
   _processing = true;
 }
 /**
  * This method is initialize the meta info during sending. It calculates the total block size and
  * the last block size and initialize the block filenames and the block received status. It also
  * stores the UTC time that the meta info is created.
  */
 private synchronized void createMetaInfo() throws FileAccessException {
   initBlockReceived(_totalBlocks);
   _lastBlock = _totalBlocks;
   _timeCreated = TimeUtil.localToUtcTimestamp().toString();
 }