/* (non-Javadoc)
   * @see android.app.Activity#onCreate(android.os.Bundle)
   */
  @Override
  public void onCreate(Bundle savedState) {
    super.onCreate(savedState);
    Debug.print("onCreate()");
    try {
      MotionEventWrapper5.checkAvailable();
      Rokon.motionEvent5 = new MotionEventWrapper5();
    } catch (VerifyError e) {
    }

    try {
      MotionEventWrapper8.checkAvailable();
      Rokon.motionEvent8 = new MotionEventWrapper8();
    } catch (VerifyError e) {
    }
    if (engineCreated) {
      Debug.print("onCreate() when already started, creating new GLSurfaceView");
      // surfaceView = new RokonSurfaceView(this);
      // setContentView(surfaceView);
      return;
    }
    Debug.print("Engine Activity created");
    onCreate();
    if (!engineCreated) {
      Debug.error("The engine was not created");
      Debug.print("#################### FINISH ME HERE");
      finish();
      return;
    }
  }
Beispiel #2
0
  static {
    lmanager = (LogManager) LogManagerUtil.getLogManager();
    String voutClass = lmanager.getProperty(LogConstants.VERIFIER_ACTION_CLASS);
    try {

      Class c = Class.forName(voutClass);
      vout = (IVerifierOutput) c.newInstance();
    } catch (Exception e) {
      Debug.error("Authorizer : Exception : ", e);
    }
  }
Beispiel #3
0
 /**
  * Loads properties from a java resource. This will load the named resource identifier into the
  * given properties instance.
  *
  * @param properties the Properties instance to receive the properties.
  * @param propsIn an InputStream to read properties from
  * @return true if the properties file exists and was loaded.
  */
 public static boolean loadProperties(Properties properties, InputStream propsIn) {
   try {
     properties.load(propsIn);
     return true;
   } catch (java.io.IOException e) {
     if (Debug.debugging("properties")) {
       Debug.error("PropUtils: Caught IOException loading properties from InputStream.");
     }
     return false;
   }
 }
Beispiel #4
0
  /**
   * Load the named file from the named directory into the given <code>Properties</code> instance.
   * If the file is not found a warning is issued. If an IOException occurs, a fatal error is
   * printed.
   *
   * @param props the instance to receive the loaded properties
   * @param dir the directory where the properties file resides
   * @param file the name of the file
   * @return true if the properties file exists and was loaded.
   */
  public static boolean loadProperties(Properties props, String dir, String file) {
    File propsFile = new File(dir, file);

    try {
      InputStream propsStream = new FileInputStream(propsFile);
      props.load(propsStream);
      if (Debug.debugging("properties")) {
        Debug.output("PropUtils: Found " + propsFile);
      }
      return true;

    } catch (java.io.FileNotFoundException e) {
      if (Debug.debugging("properties")) {
        Debug.output("PropUtils: File not found -  \"" + propsFile + "\"");
      }
    } catch (java.io.IOException e) {
      Debug.error("PropUtils: Caught IO Exception reading \"" + propsFile + "\"");
      e.printStackTrace();
    } catch (java.security.AccessControlException ace) {
    }
    return false;
  }
  /**
   * Add the event to the end of queue.
   *
   * @param event The event to add to the queue.
   * @exception FrameworkException Thrown on errors.
   */
  public void add(Event event) throws FrameworkException {
    Debug.log(Debug.MSG_STATUS, "QUEUE OPERATION: Adding event to database queue ...");

    Connection dbConn = null;

    PreparedStatement ps = null;

    long startTime = -1;

    if (Debug.isLevelEnabled(Debug.BENCHMARK)) startTime = System.currentTimeMillis();

    try {
      event.id = PersistentSequence.getNextSequenceValue(SEQUENCE_NAME);

      dbConn = DBConnectionPool.getInstance().acquireConnection();

      event.arrivalTime = new java.sql.Timestamp(System.currentTimeMillis());

      if (Debug.isLevelEnabled(Debug.DB_DATA))
        Debug.log(Debug.DB_DATA, "\n" + LINE + "\nExecuting SQL:\n" + INSERT_EVENT_SQL);

      if (Debug.isLevelEnabled(Debug.DB_DATA))
        Debug.log(Debug.DB_DATA, "Event being inserted into database:\n" + event.describe());

      if (Debug.isLevelEnabled(Debug.MSG_DATA))
        Debug.log(Debug.MSG_DATA, "Event contents:\n" + event.message);

      ps = dbConn.prepareStatement(INSERT_EVENT_SQL);

      ps.setString(1, event.channelName);
      ps.setInt(2, event.id);

      DBLOBUtils.setCLOB(ps, 3, event.message);

      ps.setTimestamp(4, event.arrivalTime);

      int numRows = ps.executeUpdate();

      if (numRows != 1) {
        String errMsg =
            "Execution of SQL statement ["
                + INSERT_EVENT_SQL
                + "] affected ["
                + numRows
                + "] rows.";

        Debug.error(errMsg);

        throw new FrameworkException(errMsg);
      }

      DBConnectionPool.getInstance().commit(dbConn);

      if (Debug.isLevelEnabled(Debug.DB_DATA))
        Debug.log(Debug.DB_DATA, "Successfully committed SQL operation.\n" + LINE);

      // NOTE: We don't add the item just inserted into the database into the in-memory
      // queue, as we want it loaded by the separate dequeueing thread.
    } catch (SQLException sqle) {
      throw new DatabaseException(
          "ERROR: Could not execute SQL statement:\n" + DBInterface.getSQLErrorMessage(sqle));
    } catch (Exception e) {
      throw new DatabaseException("ERROR: Could not execute SQL statement:\n" + e.toString());
    } finally {
      releaseDatabaseResources(dbConn, ps);

      if (Debug.isLevelEnabled(Debug.BENCHMARK) && (startTime > 0)) {
        long stopTime = System.currentTimeMillis();

        Debug.log(
            Debug.BENCHMARK,
            "ELAPSED TIME ["
                + (stopTime - startTime)
                + "] msec:  "
                + "SQL: Time to insert event into PersistentEvent database table.");
      }
    }
  }
  /**
   * Update the given event as indicated.
   *
   * @param event The event to update.
   * @param eventStatus The event delivery status.
   * @exception FrameworkException Thrown on errors.
   */
  public void update(Event event, EventStatus eventStatus) throws FrameworkException {
    if (Debug.isLevelEnabled(Debug.MSG_STATUS))
      Debug.log(
          Debug.MSG_STATUS,
          "QUEUE OPERATION: Updating database queue using event status ["
              + eventStatus.name
              + "] ...");

    // If no consumers were available, the event delivery wasn't attempted so leave
    // the queue in its current state.
    if (eventStatus == EventStatus.NO_CONSUMERS_AVAILABLE) {
      Debug.log(
          Debug.MSG_STATUS, "Skipping queue update, as no consumers were available to process it.");

      return;
    }

    Connection dbConn = null;

    PreparedStatement ps = null;

    long startTime = -1;

    if (Debug.isLevelEnabled(Debug.BENCHMARK)) startTime = System.currentTimeMillis();

    try {
      dbConn = DBConnectionPool.getInstance().acquireConnection();

      if (eventStatus == EventStatus.DELIVERY_SUCCESSFUL) {
        // If the event was successfully delivered, update status in database to delivered.
        if (Debug.isLevelEnabled(Debug.DB_DATA))
          Debug.log(Debug.DB_DATA, "\n" + LINE + "\nExecuting SQL:\n" + UPDATE_EVENT_SUCCESS_SQL);

        ps = dbConn.prepareStatement(UPDATE_EVENT_SUCCESS_SQL);

        java.sql.Timestamp ts = new java.sql.Timestamp(System.currentTimeMillis());

        ps.setTimestamp(1, ts);
        ps.setString(2, event.channelName);
        ps.setInt(3, event.id);
      } else if (eventStatus == EventStatus.DELIVERY_FAILED) {
        // If the event delivery failed, we mark it as failed in the database.
        if (Debug.isLevelEnabled(Debug.DB_DATA))
          Debug.log(Debug.DB_DATA, "\n" + LINE + "\nExecuting SQL:\n" + UPDATE_EVENT_ERROR_SQL);

        // Truncate error message if it's larger than database column.
        if ((event.lastErrorMessage != null)
            && (event.lastErrorMessage.length() > MAX_ERROR_MESSAGE_LENGTH))
          event.lastErrorMessage = event.lastErrorMessage.substring(0, MAX_ERROR_MESSAGE_LENGTH);

        event.lastErrorTime = new java.sql.Timestamp(System.currentTimeMillis());

        ps = dbConn.prepareStatement(UPDATE_EVENT_ERROR_SQL);

        ps.setTimestamp(1, event.lastErrorTime);
        ps.setString(2, event.lastErrorMessage);
        ps.setString(3, event.channelName);
        ps.setInt(4, event.id);
      } else {
        throw new FrameworkException(
            "ERROR: Invalid event update type [" + eventStatus.name + "].");
      }

      if (Debug.isLevelEnabled(Debug.DB_DATA))
        Debug.log(Debug.DB_DATA, "Event being operated on in database:\n" + event.describe());

      int numRows = ps.executeUpdate();

      if (numRows > 1) {
        String errMsg = "Execution of update SQL statement affected [" + numRows + "] rows.";

        Debug.error(errMsg);

        throw new FrameworkException(errMsg);
      }

      DBConnectionPool.getInstance().commit(dbConn);

      if (Debug.isLevelEnabled(Debug.DB_DATA))
        Debug.log(Debug.DB_DATA, "Successfully committed SQL operation.\n" + LINE);

      // At this point, the event should be removed from the in-memory buffer of events as well,
      // irrespective of processing outcome.
      if (Debug.isLevelEnabled(Debug.MSG_STATUS))
        Debug.log(
            Debug.MSG_STATUS,
            "Removing event [" + event.describe() + "] from in-memory queue buffer.");

      boolean removed = queue.remove(event);

      if (Debug.isLevelEnabled(Debug.MSG_STATUS))
        Debug.log(
            Debug.MSG_STATUS,
            "Event removed? ["
                + removed
                + "].  In-memory queue buffer size ["
                + queue.size()
                + "].");
    } catch (SQLException sqle) {
      throw new DatabaseException(
          "ERROR: Could not execute SQL statement:\n" + DBInterface.getSQLErrorMessage(sqle));
    } catch (Exception e) {
      throw new DatabaseException("ERROR: Could not execute SQL statement:\n" + e.toString());
    } finally {
      releaseDatabaseResources(dbConn, ps);

      if (Debug.isLevelEnabled(Debug.BENCHMARK) && (startTime > 0)) {
        long stopTime = System.currentTimeMillis();

        Debug.log(
            Debug.BENCHMARK,
            "ELAPSED TIME ["
                + (stopTime - startTime)
                + "] msec:  "
                + "SQL: Time to update event in PersistentEvent database table.");
      }
    }
  }
  /**
   * Reads the next line from the process. This method will be used only if the supporting Java
   * Native Interface library could not be loaded.
   */
  private synchronized String pure_readLine() {
    String line;
    long current, timeout = ((new Date()).getTime()) + threshold;

    if (null == p || null == in || null == err) return null;
    // Debug.verbose("P4Process.readLine()");
    try {
      for (; ; ) {
        if (null == p || null == in || null == err) {
          Debug.error("P4Process.readLine(): Something went null");
          return null;
        }

        current = (new Date()).getTime();
        if (current >= timeout) {
          Debug.error("P4Process.readLine(): Timeout");
          // If this was generating a new object from stdin, return an
          // empty string. Otherwise, return null.
          for (int i = 0; i < new_cmd.length; i++) {
            if (new_cmd[i].equals("-i")) return "";
          }
          return null;
        }

        // Debug.verbose("P4Process.readLine().in: "+in);
        try {
          /**
           * If there's something coming in from stdin, return it. We assume that the p4 command was
           * called with -s which sends all messages to standard out pre-pended with a string that
           * indicates what kind of messsage it is error warning text info exit
           */
          // Some errors still come in on Standard error
          while (err.ready()) {
            line = err.readLine();
            if (null != line) {
              addP4Error(line + "\n");
            }
          }

          if (in.ready()) {
            line = in.readLine();
            Debug.verbose("From P4:" + line);
            if (line.startsWith("error")) {
              if (!line.trim().equals("")
                  && (-1 == line.indexOf("up-to-date"))
                  && (-1 == line.indexOf("no file(s) to resolve"))) {
                addP4Error(line);
              }
            } else if (line.startsWith("warning")) {
            } else if (line.startsWith("text")) {
            } else if (line.startsWith("info")) {
            } else if (line.startsWith("exit")) {
              int exit_code =
                  new Integer(line.substring(line.indexOf(" ") + 1, line.length())).intValue();
              if (0 == exit_code) {
                Debug.verbose("P4 Exec Complete.");
              } else {
                Debug.error("P4 exited with an Error!");
              }
              return null;
            }
            if (!raw) line = line.substring(line.indexOf(":") + 1).trim();
            Debug.verbose("P4Process.readLine(): " + line);
            return line;
          }
        } catch (NullPointerException ne) {
        }
        // If there's nothing on stdin or stderr, check to see if the
        // process has exited. If it has, return null.
        try {
          exit_code = p.exitValue();
          return null;
        } catch (IllegalThreadStateException ie) {
          Debug.verbose("P4Process: Thread is not done yet.");
        }
        // Sleep for a second, so this thread can't become a CPU hog.
        try {
          Debug.verbose("P4Process: Sleeping...");
          Thread.sleep(100); // Sleep for 1/10th of a second.
        } catch (InterruptedException ie) {
        }
      }
    } catch (IOException ex) {
      return null;
    }
  }
Beispiel #8
0
  /**
   * Returns a URL that names either a resource, a local file, or an internet URL.
   *
   * @param askingClass the class asking for the URL. Can be null.
   * @param name name of the resource, file or URL.
   * @throws java.net.MalformedURLException
   * @return URL
   */
  public static URL getResourceOrFileOrURL(Class askingClass, String name)
      throws java.net.MalformedURLException {

    boolean DEBUG = Debug.debugging("proputils");

    if (name == null) {
      if (DEBUG) Debug.output("PropUtils.getROFOU(): null file name");
      return null;
    }

    URL retval = null;
    if (DEBUG) Debug.output("PropUtils.getROFOU(): looking for " + name);

    if (askingClass != null) {
      // First see if we have a resource by that name
      if (DEBUG) Debug.output("PropUtils.getROFOU(): checking as resource");

      retval = askingClass.getResource(name);
    }
    if (retval == null) {
      // Check the general classpath...
      if (DEBUG) Debug.output("PropUtils.getROFOU(): checking in general classpath");
      retval = Thread.currentThread().getContextClassLoader().getResource(name);
    }
    if (retval == null && !Environment.isApplet()) {
      // Check the classpath plus the share directory, which may
      // be in the openmap.jar file or in the development
      // environment.
      if (DEBUG) Debug.output("PropUtils.getROFOU(): checking with ClassLoader");
      retval = ClassLoader.getSystemResource("share/" + name);
    }

    if (retval == null && Environment.isApplet()) {
      if (DEBUG) Debug.output("PropUtils.getROFOU(): checking with URLClassLoader");
      URL[] cba = new URL[1];
      cba[0] = Environment.getApplet().getCodeBase();
      URLClassLoader ucl = URLClassLoader.newInstance(cba);
      retval = ucl.getResource(name);
    }

    // If there was no resource by that name available
    if (retval == null) {
      if (DEBUG) Debug.output("PropUtils.getROFOU(): not found as resource");

      try {
        java.io.File file = new java.io.File(name);
        if (file.exists()) {
          retval = file.toURL();
          if (DEBUG) Debug.output("PropUtils.getROFOU(): found as file :)");
        } else {
          // Otherwise treat it as a raw URL.
          if (DEBUG) Debug.output("PropUtils.getROFOU(): Not a file, checking as URL");
          retval = new URL(name);
          java.io.InputStream is = retval.openStream();
          is.close();
          if (DEBUG) Debug.output("PropUtils.getROFOU(): OK as URL :)");
        }
      } catch (java.io.IOException ioe) {
        retval = null;
      } catch (java.security.AccessControlException ace) {
        Debug.error("PropUtils: AccessControlException trying to access " + name);
        retval = null;
      } catch (Exception e) {
        Debug.error("PropUtils: caught exception " + e.getMessage());
        retval = null;
      }
    }

    if (DEBUG) {
      if (retval != null) {
        Debug.output("Resource " + name + "=" + retval.toString());
      } else {
        Debug.output("Resource " + name + " can't be found...");
      }
    }

    return retval;
  }
  /**
   * If NF_HEADER_LOCATION_PROP exists in context use as the header to forward to Gateway. If
   * IS_ASYNCHRONOUS_PROP exists in context then use that value to call either processAsync or
   * processSync
   *
   * @param input MessageObject containing the value to be processed *
   * @param mpcontext The context
   * @return Optional NVPair containing a Destination name and a MessageObject, or null if none.
   * @exception ProcessingException Thrown if processing fails.
   * @exception MessageException Thrown if bad message.
   */
  public NVPair[] process(MessageProcessorContext ctx, MessageObject input)
      throws MessageException, ProcessingException {
    if (input == null) return null;

    try {
      serverName = getRequiredProperty(ctx, input, SERVER_NAME_PROP);
    } catch (MessageException me) {
      throw new ProcessingException(me.getMessage());
    }

    if (StringUtils.hasValue(headerLocation)) {
      try {
        header = getString(headerLocation, ctx, input);
      } catch (MessageException me) {
        throw new ProcessingException(me.getMessage());
      }
    }

    if (StringUtils.hasValue(isAsyncLocation)) {
      try {
        isAsync = StringUtils.getBoolean(getString(isAsyncLocation, ctx, input));
      } catch (FrameworkException fe) {
        throw new ProcessingException(
            "Value of " + IS_ASYNCHRONOUS_LOCATION_PROP + " is not TRUE/FALSE. " + fe.getMessage());
      }
    }

    // Fetch the alternate Orb Address, if one exists at the specified context location
    if (StringUtils.hasValue(orbAgentAddrLocation)) {
      try {
        if (exists(orbAgentAddrLocation, ctx, input, true)) {
          orbAgentAddr = getString(orbAgentAddrLocation, ctx, input);
          if (Debug.isLevelEnabled(Debug.MSG_STATUS))
            Debug.log(
                Debug.MSG_STATUS,
                "RequestHandlerClient:: alternate orb exists with orb agent address ["
                    + orbAgentAddr
                    + "]");
        }
      } catch (MessageException me) {
        throw new ProcessingException(me.getMessage());
      }
    }

    // Fetch the alternate Orb Port, if one exists at the specified context location
    if (StringUtils.hasValue(orbAgentPortLocation)) {
      try {
        if (exists(orbAgentPortLocation, ctx, input, true)) {
          orbAgentPort = getString(orbAgentPortLocation, ctx, input);
          if (Debug.isLevelEnabled(Debug.MSG_STATUS))
            Debug.log(
                Debug.MSG_STATUS,
                "RequestHandlerClient:: alternate orb exists with orb agent port ["
                    + orbAgentPort
                    + "]");
        }
      } catch (MessageException me) {
        throw new ProcessingException(me.getMessage());
      }
    }

    String msg = input.getString();

    try {
      try {
        return (formatNVPair(makeClientCall(serverName, false, header, msg)));
      } catch (Exception e) {
        // Any of the following exceptions indicate that the failure might be due to
        // a CORBA communications issue (stale object reference) that should be retried.
        if ((e instanceof org.omg.CORBA.OBJECT_NOT_EXIST)
            || (e instanceof org.omg.CORBA.TRANSIENT)
            || (e instanceof org.omg.CORBA.COMM_FAILURE)
            || (e instanceof org.omg.CORBA.INV_OBJREF)
            || (e instanceof org.omg.CORBA.UNKNOWN)) {
          Debug.warning(
              "Caught the following CORBA communication error, so retrying:\n"
                  + e.toString()
                  + "\n"
                  + Debug.getStackTrace(e));

          return (formatNVPair(makeClientCall(serverName, true, header, msg)));
        } else {
          // It's not a communication exception indicating that retry is recommended,
          // so just re-throw it.
          throw e;
        }
      }
    } catch (Exception e) {
      if (e instanceof InvalidDataException) {
        Debug.error(e.toString() + "\n" + Debug.getStackTrace(e));

        throw new MessageException(((InvalidDataException) e).errorMessage);
      } else {
        Debug.error(e.toString() + "\n" + Debug.getStackTrace(e));

        throw new ProcessingException(e.toString());
      }
    }
  }