Example #1
0
  private void retrievePTN() {
    if (retryIntervals != null && retryIntervals.length > 0) {
      TnTelephonyManager.getInstance().startMMSAtBackground(destination, token);

      while (retryCount < retryIntervals.length) {
        if (isCancelled) break;

        synchronized (mutex_get_ptn) {
          try {
            writeLog(
                "DimProvider - retry time:"
                    + retryCount
                    + ", interval:"
                    + retryIntervals[retryCount]
                    + "ms");
            mutex_get_ptn.wait(retryIntervals[retryCount]);
          } catch (InterruptedException e) {
            Logger.log(this.getClass().getName(), e);
          }
        }

        if (isCancelled) break;

        writeLog("DimProvider - retry time:" + retryCount + ", start request PTN !!!");

        dimProxy =
            (JsonDimProxy)
                ServerProxyFactory.getInstance()
                    .createDimProxy(null, CommManager.getInstance().getComm(), this, null);
        dimProxy.requestGetPtn(token, isPtnEncrypted, (byte) 0, 30000);

        synchronized (mutex_retry) {
          try {
            writeLog(
                "DimProvider - retry time:" + retryCount + ", request work wait:" + timeout + "ms");
            mutex_retry.wait(timeout);
          } catch (InterruptedException e) {
            Logger.log(this.getClass().getName(), e);
          }
        }

        dimProxy.cancel();

        writeLog("DimProvider - retry time:" + retryCount + ", request work wait, wake up now!!!");

        retryCount++;
      }
    }
    notifyDimFinish();
  }
 public void setNotificationId(String notificationId) {
   this.notificationId = notificationId;
   Logger.log(
       Logger.INFO,
       this.getClass().getName(),
       "MarketBilling: setNotificationId " + notificationId);
 }
  protected synchronized void stopGps() {
    if (!isGettingGps) return;

    Logger.log(Logger.INFO, this.getClass().getName(), "GpsRecorderImpl: stopGps");
    if (TnLocationManager.getInstance() != null) TnLocationManager.getInstance().reset(provider);
    isGettingGps = false;
  }
Example #4
0
  /* (non-Javadoc)
   * @see com.telenav.framework.data.INode#getStringAt(int)
   */
  public String getStringAt(int index) {
    if (this.msgs != null && index < this.msgs.length && this.msgs[index] != null) {
      return this.msgs[index];
    } else {
      if (this.msgsBuff != null && index < this.msgsBuff.length) {
        synchronized (this) {
          // move collapsed child to expanded
          if (this.msgs == null) {
            this.msgs = new String[msgsBuff.length];
          } else if (this.msgs.length < this.msgsBuff.length) {
            String[] temp = new String[msgsBuff.length];
            System.arraycopy(msgs, 0, temp, 0, msgs.length);
            msgs = temp;
          }

          if (msgsBuff[index] != null) {
            try {
              this.msgs[index] = new String(msgsBuff[index], UTF_8);
            } catch (Throwable e) {
              Logger.log(this.getClass().getName(), e);
            }
          }

          return this.msgs[index];
        }
      }
    }

    return null;
  }
Example #5
0
  /* (non-Javadoc)
   * @see com.telenav.framework.data.INode#addString(java.lang.String)
   */
  public void addString(String str) {
    synchronized (this) {
      if (this.msgsBuff == null) {
        this.msgsBuff = new byte[INIT_MSG_SIZE][];
      } else if (this.msgsBuff.length <= nMsgs) {
        // we copy only references here, the binaries themselves do not move
        byte[][] temp = new byte[nMsgs + INIT_MSG_SIZE][];
        System.arraycopy(msgsBuff, 0, temp, 0, msgsBuff.length);
        msgsBuff = temp;
      }

      try {
        if (str != null) {
          msgsBuff[nMsgs] = str.getBytes(UTF_8);
        } else {
          msgsBuff[nMsgs] = null;
        }
      } catch (Throwable e) {
        msgsBuff[nMsgs] = null;
        Logger.log(this.getClass().getName(), e);
      }

      nMsgs++;
    }
  }
Example #6
0
  private String toString(int level) {
    StringBuffer buf = new StringBuffer();
    StringBuffer prefix = new StringBuffer();
    for (int i = 0; i < level; i++) prefix.append("\t");

    String offset = prefix.toString();

    try {

      buf.append(offset + "------------ TxNode55 -----------\n");
      buf.append(offset + "Values:\n");
      for (int i = 0; i < getValuesSize(); i++) {
        buf.append(offset + "[" + i + "]=" + getValueAt(i) + "\n");
      }

      buf.append(offset + "binary exists ? = " + (binData != null) + "\n");
      if (getStringsSize() > 0) {
        buf.append(offset + "------------ messages -----------\n");
        for (int j = 0; j < getStringsSize(); j++) buf.append(offset + getStringAt(j) + "\n");
      }
      if (getChildrenSize() > 0) {
        buf.append(offset + "------------ children -----------\n");
        for (int j = 0; j < getChildrenSize(); j++) {
          Node child = (Node) getChildAt(j);
          if (child != null) buf.append(child.toString(level + 1) + "\n");
          else buf.append(offset + "\tNULL CHILD\n");
        }
      }
      buf.append(offset + "------------ end of TxNode55 ------\n");

    } catch (Throwable e) {
      Logger.log(this.getClass().getName(), e);
    }
    return buf.toString();
  }
  protected synchronized void startGps() {
    if (isGettingGps) return;

    Logger.log(Logger.INFO, this.getClass().getName(), "GpsRecorderImpl: startGps");
    if (TnLocationManager.getInstance() != null)
      TnLocationManager.getInstance().requestLocationUpdates(provider, 0, 0, 60000, 0, this);
    isGettingGps = true;
  }
 public void stop() {
   Logger.log(Logger.INFO, this.getClass().getName(), "stop() enter");
   isRunning = false;
   synchronized (mutex) {
     mutex.notify();
   }
   stopGps();
   this.fixCounter = 0;
   this.startTime = 0;
 }
  public void onLocationChanged(TnLocationProvider provider, TnLocation location) {
    Logger.log(Logger.INFO, this.getClass().getName(), "GpsRecorderImpl: gps received");

    if (location == null || !location.isValid()) return;

    // looks like there is no synchronization problem here
    if (fixCounter < this.sampleSize) {
      fixCounter++;
      gpsBuffer.addLocation(location);
      Logger.log(
          Logger.INFO,
          this.getClass().getName(),
          "GpsRecorderImpl: added fix: ("
              + location
              + ") to gpsBuffer, fixCounter = "
              + fixCounter);
    } else {
      Logger.log(Logger.INFO, this.getClass().getName(), "GpsRecorderImpl: no need to add the fix");
    }
  }
  public void start() {
    Logger.log(Logger.INFO, this.getClass().getName(), "start() enter");
    if (isStarted) {
      throw new IllegalStateException(
          "GpsRecorderImpl can not be restarted, create a new instance to use");
    }

    isRunning = true;
    new Thread(this).start();
    this.fixCounter = 0;
    this.startTime = System.currentTimeMillis();

    if (this.pauseUntilMillis < System.currentTimeMillis()) {
      startGps();
    } else {
      Logger.log(
          Logger.INFO,
          this.getClass().getName(),
          "1. need to pause GPS for " + ((pauseUntilMillis - System.currentTimeMillis()) / 1000));
    }

    isStarted = true;
  }
Example #11
0
  public void execute(int handlerID) {
    try {
      isRunning = true;

      retrieve();
    } catch (Exception e) {
      Logger.log(this.getClass().getName(), e);
    } finally {
      isRunning = false;
      if (null != listner) {
        listner.dimFinished();
      }
    }
  }
 public void setParameters(
     int sampleSize, int sampleInterval, int idleTimeBeforeStop, long pauseUntilMillis) {
   this.sampleSize = sampleSize;
   this.sampleIntervalInMillis = sampleInterval * 1000L;
   this.idleTimeBeforeStopInMillis = idleTimeBeforeStop * 1000L;
   this.pauseUntilMillis = pauseUntilMillis;
   Logger.log(
       Logger.INFO,
       this.getClass().getName(),
       "GpsRecorderImpl: setParameters() sampleSize = "
           + this.sampleSize
           + ", sampleInterval = "
           + sampleInterval
           + ", idleTimeBeforeStop = "
           + idleTimeBeforeStop);
 }
Example #13
0
  public void setStringAt(String str, int index) {
    synchronized (this) {
      int oldSize = getStringsSize();
      for (int i = oldSize; i < index + 1; i++) {
        addString(null);
      }

      try {
        if (str != null) {
          msgsBuff[index] = str.getBytes(UTF_8);
        } else {
          msgsBuff[index] = null;
        }

        if (msgs != null && index < msgs.length) {
          msgs[index] = str;
        }
      } catch (Throwable e) {
        Logger.log(this.getClass().getName(), e);
      }
    }
  }
Example #14
0
 private void writeLog(String logStr) {
   if (Logger.DEBUG) {
     Logger.log(Logger.INFO, this.getClass().getName(), logStr);
   }
 }
  public void run() {
    long waitTime = 1000;
    while (isRunning) {
      try {
        Logger.log(
            Logger.INFO, this.getClass().getName(), "GpsRecorderImpl: wait time = " + waitTime);
        synchronized (mutex) {
          mutex.wait(waitTime);
        }
        waitTime = 1000;

        if (!isRunning) break;

        if (startTime <= 0) {
          Logger.log(
              Logger.INFO, this.getClass().getName(), "startTime is zero, something wrong!!!");
          return;
        }

        if (pauseUntilMillis < System.currentTimeMillis()) {
          // find the nearest start time
          long nearestStartTime = getNearestStartTime(System.currentTimeMillis());

          if (Logger.DEBUG)
            Logger.log(
                Logger.INFO,
                this.getClass().getName(),
                "nearestStartTime = "
                    + nearestStartTime
                    + ", "
                    + (System.currentTimeMillis() - startTime));

          if (System.currentTimeMillis() - startTime >= this.sampleIntervalInMillis) {
            if (nearestStartTime == startTime) {
              // It should not happen
              startTime = nearestStartTime + this.sampleIntervalInMillis;
            } else {
              startTime = nearestStartTime;
            }

            // looks like there is no synchronization problem here
            fixCounter = 0;

            if (!isRunning) break;

            startGps();
          } else {
            if (fixCounter >= this.sampleSize) {
              long nextStartTime = nearestStartTime + this.sampleIntervalInMillis;
              if (nextStartTime - System.currentTimeMillis() >= this.idleTimeBeforeStopInMillis
                  && isGettingGps) {
                Logger.log(
                    Logger.INFO,
                    this.getClass().getName(),
                    "GpsRecorderImpl: stop gps for "
                        + ((nextStartTime - System.currentTimeMillis()) / 1000)
                        + " seconds");
                stopGps();
              }
              waitTime = Math.max(1000, nextStartTime - System.currentTimeMillis());
            }
          }
        } else {
          waitTime = Math.max(1000, pauseUntilMillis - System.currentTimeMillis());
          Logger.log(
              Logger.INFO,
              this.getClass().getName(),
              "2. need to pause GPS for "
                  + ((pauseUntilMillis - System.currentTimeMillis()) / 1000));
        }
      } catch (Throwable t) {
        Logger.log(this.getClass().getName(), t);
      }
    }

    isStopped = true;
  }
 public void setStatus(int status) {
   this.status = status;
   Logger.log(Logger.INFO, this.getClass().getName(), "MarketBilling: setStatus " + status);
 }
  public GpsRecorderImpl(String provider, LocationBuffer buffer) {
    this.provider = provider;
    this.gpsBuffer = buffer;

    Logger.log(Logger.INFO, this.getClass().getName(), "GpsRecorderImpl: timer started");
  }