Пример #1
0
 /**
  * Retrieves the last scenario used by the user
  *
  * @param userId
  * @return
  */
 public int lastUsedScenario(int userId) {
   try {
     // verifies the last scenario used by the user
     int lastScenarioId = 1;
     DBCollection usersCollection = getCollection("paprika", "users");
     BasicDBObject userQuery = new BasicDBObject();
     userQuery.put("userId", userId);
     logger.logp(Level.INFO, TAG, "lastUsedScenario", " userQuery:" + userQuery.toString());
     List<DBObject> userLastScenario = (List<DBObject>) usersCollection.find(userQuery).toArray();
     if (userLastScenario.size() > 0) {
       try {
         lastScenarioId = (Integer) userLastScenario.get(0).get("scenarioId");
       } catch (NullPointerException e) {
         logger.logp(
             Level.SEVERE, TAG, "verifiesLastScenario", e.getMessage() + " user id" + userId);
         e.printStackTrace();
         lastScenarioId = 0;
       }
     }
     ;
     return lastScenarioId;
   } catch (Exception e) {
     logger.logp(Level.SEVERE, TAG, "verifiesLastScenario", e.getMessage() + " user id" + userId);
     e.printStackTrace();
   }
   return 1; // if no last scenario is returned, uses scenarioId = 1 (paprika)
 }
Пример #2
0
  /**
   * For testing. Requires the <code>LEDremoteControl.ino</code> Arduino sketch on a USB connected
   * UNO.
   *
   * @param args
   * @throws Exception
   */
  public static void main(String[] args) throws Exception {
    final String mn = "main";

    st = new SerialTransport(SerialPort.BAUDRATE_115200);
    logger.logp(Level.INFO, "SerialTransport", mn, ">");

    lastRun = System.currentTimeMillis();
    blink(0, 0);
    blink(1, 0);
    blink(0, 0);
    blink(3, 500);
    blink(0, 500);
    blink(5, 500);
    blink(0, 500);
    blink(7, 500);
    blink(0, 500);

    for (int i = 0; i < 1000; i++) {
      System.out.print(i + ": ");
      blink(1, 500);
      blink(0, 500);
    }

    st.close();
    logger.logp(Level.INFO, "SerialTransport", mn, "<");
  }
Пример #3
0
 protected StoreConfig() {
   final String METHOD_NAME = "StoreConfig";
   initialise();
   if (logger.isLoggable(Level.FINER)) {
     logger.logp(Level.FINER, CLASS_NAME, METHOD_NAME, getAllGeneralProperties().toString());
     logger.logp(Level.FINER, CLASS_NAME, METHOD_NAME, getAllEnvironmentProperties().toString());
   }
 }
Пример #4
0
 /**
  * return a collection list.
  *
  * @param database
  * @return collection (the list of collections)
  */
 public List<String> getDatabaseNames() {
   try {
     // get the database
     List<String> dbNames = mongo.getDatabaseNames();
     logger.logp(Level.INFO, TAG, "getCollectionNames", " databases:" + dbNames);
     return dbNames;
   } catch (Exception e) {
     logger.logp(Level.SEVERE, TAG, "getCollectionNames", e.getMessage());
     e.printStackTrace();
   }
   return null;
 }
Пример #5
0
 /**
  * return a collection list.
  *
  * @param database
  * @return collection (the list of collections)
  */
 public Set<String> getCollectionNames(String database) {
   try {
     // get the database
     DB db = getDB(database);
     Set<String> collections = db.getCollectionNames();
     logger.logp(Level.INFO, TAG, "getCollectionNames", " database:" + database);
     return collections;
   } catch (Exception e) {
     logger.logp(
         Level.SEVERE, TAG, "getCollectionNames", e.getMessage() + " database:" + database);
     e.printStackTrace();
   }
   return null;
 }
Пример #6
0
  /**
   * Method logs {@code exception}'s message at the logging level specified by the {@code level}
   * argument.
   *
   * <p>If {@code cause} parameter is not {@code null}, it is logged as well and {@code exception}
   * original cause is initialized with instance referenced by {@code cause} parameter.
   *
   * @param exception exception whose message should be logged. Must not be {@code null}.
   * @param cause initial cause of the exception that should be logged as well and set as {@code
   *     exception}'s original cause. May be {@code null}.
   * @param level loging level which should be used for logging
   * @return the same exception instance that was passed in as the {@code exception} parameter.
   */
  public <T extends Throwable> T logException(
      final T exception, final Throwable cause, final Level level) {
    if (this.logger.isLoggable(level)) {
      if (cause == null) {
        logger.logp(level, componentClassName, getCallerMethodName(), exception.getMessage());
      } else {
        exception.initCause(cause);
        logger.logp(
            level, componentClassName, getCallerMethodName(), exception.getMessage(), cause);
      }
    }

    return exception;
  }
Пример #7
0
 /**
  * compress the database
  *
  * @return
  */
 @SuppressWarnings("unused")
 public String compressDB(String database) {
   try {
     int counter = 0;
     StringBuilder result = new StringBuilder();
     BasicDBObject cmd = new BasicDBObject();
     Set<String> listCollection = getCollectionNames(database);
     DB db = getDB(database);
     for (String collection : listCollection) {
       cmd.put("collStats", collection);
       CommandResult beforeCompact = db.command(cmd);
       cmd.put("compact", collection);
       CommandResult duringCompact = db.command(cmd);
       cmd.put("collStats", collection);
       CommandResult afterCompact = db.command(cmd);
       counter = counter + 1;
       result.append("Collection: " + collection + "\n");
       result.append("Before compact: " + beforeCompact + "\n");
       result.append("After  compact: " + afterCompact + "\n");
       result.append("---------------------------------------------- \n");
     }
     result.append("Returned number of documents: " + counter);
     return result.toString();
   } catch (Exception e) {
     logger.logp(Level.SEVERE, TAG, "compressDB", e.getMessage() + " database:" + database);
     e.printStackTrace();
   }
   return null;
 }
Пример #8
0
 private JDBCDriverManager() {
   logger.logp(
       java.util.logging.Level.FINE,
       OdaJdbcDriver.class.getName(),
       "JDBCDriverManager",
       "JDBCDriverManager starts up");
 }
  private void render(
      final List<? extends Spatial> toDrawA,
      final Spatial toDrawB,
      final Scene toDrawC,
      final List<Texture> texs,
      final int clear) {
    try {
      if (_pbuffer == null || _pbuffer.isBufferLost()) {
        if (_pbuffer != null && _pbuffer.isBufferLost()) {
          logger.warning("PBuffer contents lost - will recreate the buffer");
          deactivate();
          _pbuffer.destroy();
        }
        initPbuffer();
      }

      if (texs.size() == 1
          && _useDirectRender
          && !texs.get(0).getTextureStoreFormat().isDepthFormat()) {
        // setup and render directly to a 2d texture.
        LwjglTextureStateUtil.doTextureBind(texs.get(0), 0, true);
        activate();
        switchCameraIn(clear);
        _pbuffer.releaseTexImage(Pbuffer.FRONT_LEFT_BUFFER);

        if (toDrawA != null) {
          doDraw(toDrawA);
        } else {
          doDraw(toDrawB);
        }

        switchCameraOut();

        deactivate();
        _pbuffer.bindTexImage(Pbuffer.FRONT_LEFT_BUFFER);
      } else {
        // render and copy to a texture
        activate();
        switchCameraIn(clear);

        if (toDrawA != null) {
          doDraw(toDrawA);
        } else {
          doDraw(toDrawB);
        }

        switchCameraOut();

        for (int i = 0; i < texs.size(); i++) {
          copyToTexture(texs.get(i), 0, 0, _width, _height, 0, 0);
        }

        deactivate();
      }

    } catch (final Exception e) {
      logger.logp(
          Level.SEVERE, this.getClass().toString(), "render(Spatial, Texture)", "Exception", e);
    }
  }
Пример #10
0
  public void saveRules() {
    try {
      OutputHandler.SOP("Saving rules");

      if (!rulesFile.exists()) rulesFile.createNewFile();

      // create streams
      FileOutputStream stream = new FileOutputStream(rulesFile);
      OutputStreamWriter streamWriter = new OutputStreamWriter(stream);
      BufferedWriter writer = new BufferedWriter(streamWriter);

      writer.write("# " + rulesFile.getName() + " | numbers are automatically added");
      writer.newLine();

      for (String rule : rules) {
        writer.write(rule);
        writer.newLine();
      }

      writer.close();
      streamWriter.close();
      stream.close();

      OutputHandler.SOP("Completed saving rules file.");
    } catch (Exception e) {
      Logger lof = OutputHandler.felog;
      lof.logp(
          Level.SEVERE,
          "FEConfig",
          "Saving Rules",
          "Error writing the Rules file: " + rulesFile.getName(),
          e);
    }
  }
Пример #11
0
  /**
   * @param subElems
   * @throws DataException
   */
  private void populateDeprecatedAggregations(IConfigurationElement[] subElems)
      throws DataException {
    if (subElems == null) return;
    for (int j = 0; j < subElems.length; j++) {
      try {
        IAggregation aggrFunc =
            (IAggregation) subElems[j].createExecutableExtension(ATTRIBUTE_AGGREGATION_CLASS);
        String name = aggrFunc.getName().toUpperCase();

        AggrFunctionWrapper aggrWrapper = new AggrFunctionWrapper(aggrFunc);
        populateExtendedAggrInfo(name, aggrFunc, subElems[j], aggrWrapper);

        if (aggrMap.put(name, aggrWrapper) != null)
          throw new DataException(ResourceConstants.DUPLICATE_AGGREGATION_NAME, name);
        allAggrNames.add(name);
      } catch (Exception e) {
        logger.logp(
            Level.WARNING,
            AggrFunctionWrapper.class.getName(),
            "populateDeprecatedAggregations",
            "Exception in aggregation extension loading.",
            e);
      }
    }
  }
Пример #12
0
 public void log(Level level, String message, Throwable thrown) {
   if (isLoggable(level)) {
     String[] source = getSource();
     logger.logp(
         level, source[0], source[1], Thread.currentThread().getName() + ": " + message, thrown);
   }
 }
  private void activate() {
    if (_active == 0) {
      try {
        _oldContext = ContextManager.getCurrentContext();
        _pbuffer.makeCurrent();

        ContextManager.switchContext(_pbuffer);

        ContextManager.getCurrentContext().clearEnforcedStates();
        ContextManager.getCurrentContext().enforceStates(_enforcedStates);

        if (_bgColorDirty) {
          GL11.glClearColor(
              _backgroundColor.getRed(),
              _backgroundColor.getGreen(),
              _backgroundColor.getBlue(),
              _backgroundColor.getAlpha());
          _bgColorDirty = false;
        }
      } catch (final LWJGLException e) {
        logger.logp(Level.SEVERE, this.getClass().toString(), "activate()", "Exception", e);
        throw new Ardor3dException();
      }
    }
    _active++;
  }
  @Override
  protected void doPost(HttpServletRequest req, HttpServletResponse resp)
      throws ServletException, IOException {

    // get the tickerStr
    UserService userService = UserServiceFactory.getUserService();
    User user = userService.getCurrentUser();

    // get the user and check for non null
    if (user != null) {
      PersistenceManager pm = PMF.get().getPersistenceManager();
      Collection<UserComparisonTickers> comparisonTickersCollection = null;
      try {
        comparisonTickersCollection =
            getComparisonTickersService().getComparisonTickers(user.getEmail());
      } catch (Exception e) {
        log.logp(
            Level.SEVERE,
            GetComparisonTickersServlet.class.getName(),
            "method",
            "UserComparisonTickers could not be fetched from persistence storage",
            e);
      } finally {
        pm.close();
      }
      if (comparisonTickersCollection != null) {
        resp.getWriter().write(getComparisonTickersService().getJson(comparisonTickersCollection));
      }
    }
  }
 @BenchmarkMode(Mode.Throughput)
 @OutputTimeUnit(TimeUnit.SECONDS)
 @Benchmark
 public void param1JulFile() {
   // must specify sourceClass or JUL will look it up by walking the stack trace!
   julLogger.logp(
       Level.INFO, getClass().getName(), "param1JulFile", "This is a debug [{}] message", ++j);
 }
Пример #16
0
  /**
   * Method logs {@code exception}'s message at the logging level specified by the {@code level}
   * argument.
   *
   * <p>If {@code logCause} parameter is {@code true}, {@code exception}'s original cause is logged
   * as well (if exists). This may be used in cases when {@code exception}'s class provides
   * constructor to initialize the original cause. In such case you do not need to use {@link
   * #logException(Throwable, Throwable, Level) logException(exception, cause, level)} method
   * version but you might still want to log the original cause as well.
   *
   * @param exception exception whose message should be logged. Must not be {@code null}.
   * @param logCause deterimnes whether initial cause of the exception should be logged as well
   * @param level loging level which should be used for logging
   * @return the same exception instance that was passed in as the {@code exception} parameter.
   */
  public <T extends Throwable> T logException(
      final T exception, final boolean logCause, final Level level) {
    if (this.logger.isLoggable(level)) {
      if (logCause && exception.getCause() != null) {
        logger.logp(
            level,
            componentClassName,
            getCallerMethodName(),
            exception.getMessage(),
            exception.getCause());
      } else {
        logger.logp(level, componentClassName, getCallerMethodName(), exception.getMessage());
      }
    }

    return exception;
  }
Пример #17
0
  /**
   * Same as {@link #logSevereException(Throwable, boolean) logSevereException(exception, true)}.
   */
  public <T extends Throwable> T logSevereException(final T exception) {
    if (this.logger.isLoggable(Level.SEVERE)) {
      if (exception.getCause() == null) {
        logger.logp(
            Level.SEVERE, componentClassName, getCallerMethodName(), exception.getMessage());
      } else {
        logger.logp(
            Level.SEVERE,
            componentClassName,
            getCallerMethodName(),
            exception.getMessage(),
            exception.getCause());
      }
    }

    return exception;
  }
 @Test
 public void testLogParamMarkers() {
   final Logger flowLogger = Logger.getLogger("TestFlow");
   flowLogger.logp(
       java.util.logging.Level.FINER, "sourceClass", "sourceMethod", "ENTRY {0}", "params");
   final List<LogEvent> events = flowAppender.getEvents();
   assertEquals("ENTRY params", events.get(0).getMessage().getFormattedMessage());
 }
Пример #19
0
 /**
  * Writes a single byte to the serial transport. Checks if the byte could be written.
  *
  * @param b
  * @throws SerialPortException
  * @throws DisplayException if the operation was not successfully completed
  */
 public void writeByte(byte b) throws SerialPortException, DisplayException {
   final String mn = "writeByte";
   boolean result = serialPort.writeByte(b);
   if (!result) {
     String msg = "Write error";
     logger.logp(Level.WARNING, this.getClass().getName(), mn, msg);
     throw new DisplayException(msg);
   }
 }
Пример #20
0
  public final void trace(
      RuntimeContext context,
      String sourceClass,
      String sourceMethod,
      String message,
      Level level) {

    logger.logp(level, sourceClass, sourceMethod, message);
  }
Пример #21
0
  /**
   * For testing
   *
   * @param value
   * @param time
   * @throws DisplayException
   * @throws SerialPortException
   * @throws InterruptedException
   */
  private static void blink(int value, int time)
      throws DisplayException, SerialPortException, InterruptedException {
    final String mn = "blink";
    logger.logp(
        Level.INFO, "SerialTransport", mn, "> Sending " + value + ", waiting for " + time + "ms: ");

    st.writeByte((byte) value);
    String msg = st.getMessage();
    Thread.sleep(time);

    logger.logp(
        Level.INFO,
        "SerialTransport",
        mn,
        "< '" + msg + "' time total = " + (System.currentTimeMillis() - lastRun) + "ms");

    lastRun = System.currentTimeMillis();
  }
Пример #22
0
  public void close() throws SerialPortException, DisplayException {
    final String mn = "close";
    if (!serialPort.removeEventListener()) {
      String msg = "Could not remove event listener";
      logger.logp(Level.WARNING, this.getClass().getName(), mn, msg);
      throw new DisplayException(msg);
    }

    serialPort.closePort();
  }
Пример #23
0
 @Override
 public void read(final InputCapsule capsule) throws IOException {
   super.read(capsule);
   try {
     setRadius(capsule.readDouble("radius", 0));
   } catch (final IOException ex) {
     logger.logp(
         Level.SEVERE, this.getClass().toString(), "read(Ardor3DImporter)", "Exception", ex);
   }
 }
Пример #24
0
 @Override
 public void write(final OutputCapsule capsule) throws IOException {
   super.write(capsule);
   try {
     capsule.write(getRadius(), "radius", 0);
   } catch (final IOException ex) {
     logger.logp(
         Level.SEVERE, this.getClass().toString(), "write(Ardor3DExporter)", "Exception", ex);
   }
 }
Пример #25
0
    @Override
    public synchronized void flush() throws IOException {
      super.flush();
      String record = this.toString();
      super.reset();

      if (record.length() > 0 && !record.equals(separator)) {
        logger.logp(level, "LoggerOutputStream", "log" + level, record);
      }
    }
  private void initPbuffer() {

    try {
      if (_pbuffer != null) {
        giveBackContext();
        ContextManager.removeContext(_pbuffer);
      }
      final PixelFormat format =
          new PixelFormat(
                  _settings.getAlphaBits(), _settings.getDepthBits(), _settings.getStencilBits())
              .withSamples(_settings.getSamples())
              .withBitsPerPixel(_settings.getColorDepth())
              .withStereo(_settings.isStereo());
      _pbuffer = new Pbuffer(_width, _height, format, _texture, null);
      final Object contextKey = _pbuffer;
      try {
        _pbuffer.makeCurrent();
      } catch (final LWJGLException e) {
        throw new RuntimeException(e);
      }

      final LwjglContextCapabilities caps =
          new LwjglContextCapabilities(GLContext.getCapabilities());
      ContextManager.addContext(
          contextKey, new RenderContext(contextKey, caps, ContextManager.getCurrentContext()));

    } catch (final Exception e) {
      logger.logp(Level.SEVERE, this.getClass().toString(), "initPbuffer()", "Exception", e);

      if (_texture != null && _useDirectRender) {
        logger.warning(
            "Your card claims to support Render to Texture but fails to enact it.  Updating your driver might solve this problem.");
        logger.warning("Attempting to fall back to Copy Texture.");
        _texture = null;
        _useDirectRender = false;
        initPbuffer();
        return;
      }

      logger.log(Level.WARNING, "Failed to create Pbuffer.", e);
      return;
    }

    try {
      activate();

      _width = _pbuffer.getWidth();
      _height = _pbuffer.getHeight();

      deactivate();
    } catch (final Exception e) {
      logger.log(Level.WARNING, "Failed to initialize created Pbuffer.", e);
      return;
    }
  }
Пример #27
0
 // TODO: set as private
 public DB getDB(String database) {
   try {
     DB db;
     // check if we already have this database in the Map
     if (dbMap.containsKey(database)) {
       db = dbMap.get(database);
     } else {
       db = mongo.getDB(database);
       // add the database to the Map
       dbMap.put(database, db);
     }
     logger.logp(Level.INFO, TAG, "getDB", " database:" + database);
     // return the database
     return db;
   } catch (Exception e) {
     logger.logp(Level.SEVERE, TAG, "getDB", e.getMessage() + " database:" + database);
     e.printStackTrace();
   }
   return null;
 }
 private void deactivate() {
   if (_active == 1) {
     try {
       giveBackContext();
     } catch (final LWJGLException e) {
       logger.logp(Level.SEVERE, this.getClass().toString(), "deactivate()", "Exception", e);
       throw new Ardor3dException();
     }
   }
   _active--;
 }
Пример #29
0
 /** Returns null and logs a warning as this is not supported. */
 @Override
 public ResourceSource getRelativeSource(final String name) {
   if (logger.isLoggable(Level.WARNING)) {
     logger.logp(
         Level.WARNING,
         getClass().getName(),
         "getRelativeSource(String)",
         "StringResourceSource does not support this method.");
   }
   return null;
 }
 @BenchmarkMode(Mode.Throughput)
 @OutputTimeUnit(TimeUnit.SECONDS)
 @Benchmark
 public void param3JulFile() {
   // must specify sourceClass or JUL will look it up by walking the stack trace!
   julLogger.logp(
       Level.INFO,
       getClass().getName(),
       "param3JulFile",
       "Val1={}, val2={}, val3={}",
       new Object[] {++j, ++k, ++m});
 }