コード例 #1
0
  @Override
  public void processCalculations(final User u, final Entity point, final Value value)
      throws NimbitsException {

    final List<Entity> calculations =
        EntityServiceFactory.getInstance().getEntityByTrigger(u, point, EntityType.calculation);
    for (final Entity entity : calculations) {
      Calculation c = (Calculation) entity;
      try {

        final List<Entity> target =
            EntityServiceFactory.getInstance().getEntityByKey(u, c.getTarget(), EntityType.point);
        if (target.isEmpty()) {
          log.severe("Point target was null " + c.getTarget());
          log.severe(c.getFormula());
          log.severe("trigger: " + c.getTrigger());
          disableCalc(u, c);
        } else {
          log.info("Solving calc" + c.getFormula());
          final Value result = solveEquation(u, c);
          log.info("result" + result);
          ValueServiceFactory.getInstance().recordValue(u, target.get(0), result);
        }
      } catch (NimbitsException e1) {
        LogHelper.logException(this.getClass(), e1);
        disableCalc(u, c);
      }
    }
  }
コード例 #2
0
  /**
   * @param sourceFile File to read from
   * @return List of String objects with the shas
   */
  public static FileRequestFileContent readRequestFile(final File sourceFile) {
    if (!sourceFile.isFile() || !(sourceFile.length() > 0)) {
      return null;
    }
    Document d = null;
    try {
      d = XMLTools.parseXmlFile(sourceFile.getPath());
    } catch (final Throwable t) {
      logger.log(Level.SEVERE, "Exception in readRequestFile, during XML parsing", t);
      return null;
    }

    if (d == null) {
      logger.log(Level.SEVERE, "Could'nt parse the request file");
      return null;
    }

    final Element rootNode = d.getDocumentElement();

    if (rootNode.getTagName().equals(TAG_FrostFileRequestFile) == false) {
      logger.severe(
          "Error: xml request file does not contain the root tag '"
              + TAG_FrostFileRequestFile
              + "'");
      return null;
    }

    final String timeStampStr = XMLTools.getChildElementsTextValue(rootNode, TAG_timestamp);
    if (timeStampStr == null) {
      logger.severe("Error: xml file does not contain the tag '" + TAG_timestamp + "'");
      return null;
    }
    final long timestamp = Long.parseLong(timeStampStr);

    final List<Element> nodelist = XMLTools.getChildElementsByTagName(rootNode, TAG_shaList);
    if (nodelist.size() != 1) {
      logger.severe("Error: xml request files must contain only one element '" + TAG_shaList + "'");
      return null;
    }

    final Element rootShaNode = nodelist.get(0);

    final List<String> shaList = new LinkedList<String>();
    final List<Element> xmlKeys = XMLTools.getChildElementsByTagName(rootShaNode, TAG_sha);
    for (final Element el : xmlKeys) {

      final Text txtname = (Text) el.getFirstChild();
      if (txtname == null) {
        continue;
      }

      final String sha = txtname.getData();
      shaList.add(sha);
    }

    final FileRequestFileContent content = new FileRequestFileContent(timestamp, shaList);
    return content;
  }
コード例 #3
0
  void _pickInitial() throws MongoException {
    if (_curAddress != null) return;

    // we need to just get a server to query for ismaster
    _pickCurrent();

    try {
      _logger.info("current address beginning of _pickInitial: " + _curAddress);

      DBObject im = isMasterCmd();
      if (_isMaster(im)) return;

      synchronized (_allHosts) {
        Collections.shuffle(_allHosts);
        for (ServerAddress a : _allHosts) {
          if (_curAddress == a) continue;

          _logger.info("remote [" + _curAddress + "] -> [" + a + "]");
          _set(a);

          im = isMasterCmd();
          if (_isMaster(im)) return;

          _logger.severe("switched to: " + a + " but isn't master");
        }

        throw new MongoException("can't find master");
      }
    } catch (Exception e) {
      _logger.log(Level.SEVERE, "can't pick initial master, using random one", e);
    }
  }
コード例 #4
0
 private void remember(Object tv) { // remember where allocated
   synchronized (undisposed) {
     java.io.StringWriter sw = new java.io.StringWriter();
     java.io.PrintWriter pw = new java.io.PrintWriter(sw);
     new Exception("This vector was never disposed").printStackTrace(pw);
     pw.flush();
     undisposed.put(tv, sw.toString());
     // LOG.info("**********************************************");
     // LOG.info(sw.toString());
     max = Math.max(max, undisposed.size());
     total += 1;
     if (undisposed.size() > 12 && !printedUndisposed) {
       LOG.severe("**********************************************");
       LOG.severe(getTraces());
       LOG.severe("**********************************************");
       printedUndisposed = true;
     }
   }
 }
コード例 #5
0
  public void disconnected() {
    isConnected = false;

    MainFrame.getInstance().setDisconnected();

    SwingUtilities.invokeLater(
        new Runnable() {
          public void run() {
            uploadModel.removeExternalUploads();
            downloadModel.removeExternalDownloads();
          }
        });
    logger.severe("disconnected!");
  }
コード例 #6
0
ファイル: PBVCPlugin.java プロジェクト: vohoaiviet/placecomm
  private long InstancesCount() {

    String sIname = ClassNameTF.getText().trim();
    long lNumberOfInstance = 0;
    if (sIname.length() > 0) {
      String sClassName = ClassNameTF.getText();
      try {
        Cls cls = kb.getCls(sClassName);
        Collection colInstances = kb.getInstances(cls);
        lNumberOfInstance = colInstances.size();
      } catch (Exception e) {
        theLogger.severe("Class not found");
      }

    } else {
      try {
        Collection colInstances = kb.getInstances();
        lNumberOfInstance = colInstances.size();
      } catch (Exception e) {
        theLogger.severe("Class not found");
      }
    }
    return lNumberOfInstance;
  }
コード例 #7
0
ファイル: ParseResult.java プロジェクト: ViktorShaban/metaos
  /**
   * Stores the value for the given field associated to given symbol. Be careful: If symbol has not
   * been previously inserted, object will become incoherent.
   */
  public void putValue(final String symbol, final Field field, final double val) {
    Map<Field, Double> vs = values.get(symbol);
    if (vs == null) vs = new HashMap<Field, Double>();
    vs.put(field, val);
    this.values.put(symbol, vs);

    // Consistency check.
    for (int i = 0; i < this.symbols.size(); i++) {
      if (this.symbols.get(i).equals(symbol)) return;
    }
    log.severe(
        "Danger: inconsistent usage of ParseResult object. "
            + "'putValue' function should be called AFTER 'addSymbol'. "
            + "Read documentation");
  }
コード例 #8
0
ファイル: Main.java プロジェクト: nagyistoce/jabberskype
 public void cancelUpdate(String window_name) {
   try {
     saveUpdateSettings();
     if (!cmd.getQuiet()) {
       if (window_name == null) {
         window = new MainWindow();
       } else {
         window = (AbstractWindow) newInstance(window_name);
       }
       addWindow(window);
       window.setVisible(window.getWindowSettings().getVisible());
       window.postLoad();
     }
   } catch (Exception ex) {
     ex.printStackTrace();
     logger.severe("Could not start application: " + ex.getMessage());
   }
 }
コード例 #9
0
  /**
   * @param chkKeys List of String objects with the shas
   * @param targetFile target file
   * @return true if write was successful
   */
  public static boolean writeRequestFile(
      final FileRequestFileContent content, final File targetFile) {

    final Document doc = XMLTools.createDomDocument();
    if (doc == null) {
      logger.severe("Error - writeRequestFile: factory could'nt create XML Document.");
      return false;
    }

    final Element rootElement = doc.createElement(TAG_FrostFileRequestFile);
    doc.appendChild(rootElement);

    final Element timeStampElement = doc.createElement(TAG_timestamp);
    final Text timeStampText = doc.createTextNode(Long.toString(content.getTimestamp()));
    timeStampElement.appendChild(timeStampText);
    rootElement.appendChild(timeStampElement);

    final Element rootChkElement = doc.createElement(TAG_shaList);
    rootElement.appendChild(rootChkElement);

    for (final String chkKey : content.getShaStrings()) {

      final Element nameElement = doc.createElement(TAG_sha);
      final Text text = doc.createTextNode(chkKey);
      nameElement.appendChild(text);

      rootChkElement.appendChild(nameElement);
    }

    boolean writeOK = false;
    try {
      writeOK = XMLTools.writeXmlFile(doc, targetFile);
    } catch (final Throwable t) {
      logger.log(Level.SEVERE, "Exception in writeRequestFile/writeXmlFile", t);
    }

    return writeOK;
  }
コード例 #10
0
ファイル: MsgFormatter.java プロジェクト: printmiles/JavaNews
  /**
   * Takes the provided array of objects and stores the contents in the back-end database. The array
   * is expected to contain the following objects:
   *
   * <ul>
   *   <li>0 - Severity (String)
   *   <li>1 - PSE node name (String)
   *   <li>2 - Link ID (String)
   *   <li>3 - Received Error Message (String)
   *   <li>4 - Date received from the PSE (String)
   *   <li>5 - The universally unique identifier of the message (String)
   * </ul>
   *
   * @param dataToStore An object array in the format mentioned above.
   */
  public void storeDataInDb(Object[] dataToStore) {
    final int WORKED_OK = 1;
    final int DISCOVERED_NEW_LINK = 2;
    final int DISCOVERED_DUPLICATES = 3;
    final int ERROR_ENCOUNTERED = 4;
    final int NO_ENTRIES_FOUND = 5;
    final int DISCOVERED_LINK_MESSAGE = 6;

    DbInterface dbI = new DbInterface(originatingPort);
    int x = dbI.storeMessage(formattedMessage);
    switch (x) {
      case WORKED_OK:
        {
          // storeMessage worked without any problems.
          log.finest("Message saved in the database with a UUID of: " + formattedMessage[5]);
          String msg = (String) formattedMessage[3];
          Object[] linkState = new Object[3];
          linkState[0] = formattedMessage[1];
          linkState[1] = formattedMessage[2];
          linkState[2] = new Integer(LINK_STATE_UNKNOWN);
          if (msg.equals("LINK DOWN")) {
            linkState[2] = new Integer(LINK_STATE_DOWN);
            parent.setLinkData(linkState);
          }
          if (msg.equals("LINK UP")) {
            linkState[2] = new Integer(LINK_STATE_UP);
            parent.setLinkData(linkState);
          }
          break;
        }
      case DISCOVERED_NEW_LINK:
        {
          // storeMessage detected that this link was from a new link not in the database.
          String msg = (String) formattedMessage[3];
          if (msg.equals("LINK DOWN")) {
            parent.addNewLink(
                (String) formattedMessage[1], (String) formattedMessage[2], LINK_STATE_DOWN);
          } else if (msg.equals("LINK UP")) {
            parent.addNewLink(
                (String) formattedMessage[1], (String) formattedMessage[2], LINK_STATE_UP);
          } else {
            parent.addNewLink(
                (String) formattedMessage[1], (String) formattedMessage[2], LINK_STATE_UNKNOWN);
          }
          break;
        }
      case DISCOVERED_DUPLICATES:
        {
          // storeMessage detected duplicates in the database. Generate a warning to the user.
          log.severe(
              "Duplicates in the index of tblCodexLinks were detected while trying to save the received message.");
          System.err.println(
              "Duplicates were detected in the index of tblCodexLinks. Your database may be corrupt.");
          break;
        }
      case ERROR_ENCOUNTERED:
        {
          // storeMessage encountered an exception
          log.warning(
              "storeMessage() encountered an exception. The message it was trying to save may not have been entered into the database.");
          System.err.println(
              "An exception was detected while trying to save the message in the database. The data may not have been saved, please check the logs for more information.");
          break;
        }
      case DISCOVERED_LINK_MESSAGE:
        {
          String msg = (String) formattedMessage[3];
          if (msg.equals("LINK DOWN")) {
            parent.addNewLink(
                (String) formattedMessage[1], (String) formattedMessage[2], LINK_STATE_DOWN);
          } else if (msg.equals("LINK UP")) {
            parent.addNewLink(
                (String) formattedMessage[1], (String) formattedMessage[2], LINK_STATE_UP);
          } else {
            parent.addNewLink(
                (String) formattedMessage[1], (String) formattedMessage[2], LINK_STATE_UNKNOWN);
          }
          break;
        }
      default:
        {
          // storeMessage returned a value that wasn't recognised
          log.warning("storeMessage returned an unexpected value: " + x);
          break;
        }
    }
  }
コード例 #11
0
 public void connected() {
   isConnected = true;
   MainFrame.getInstance().setConnected();
   logger.severe("now connected");
 }
コード例 #12
0
  @Override
  public Value solveEquation(final User user, final Calculation calculation)
      throws NimbitsException {

    final MathEvaluator m = new MathEvaluatorImpl(calculation.getFormula());
    log.info(calculation.getFormula());

    if (!Utils.isEmptyString(calculation.getX()) && calculation.getFormula().contains("x")) {
      //  Point p = PointServiceFactory.getInstance().getPointByKey(calculation.getX());
      final Entity p =
          EntityServiceFactory.getInstance()
              .getEntityByKey(user, calculation.getX(), EntityType.point)
              .get(0);

      if (p != null) {
        log.info("calc has an x car and i found " + p.getName());
        final List<Value> val = ValueServiceFactory.getInstance().getCurrentValue(p);

        final double d = val.isEmpty() ? 0.0 : val.get(0).getDoubleValue();

        m.addVariable("x", d);
      } else {
        log.severe("calc has an x car and x not found");
      }
    }
    if (!Utils.isEmptyString(calculation.getY()) && calculation.getFormula().contains("y")) {
      final Entity p =
          EntityServiceFactory.getInstance()
              .getEntityByKey(user, calculation.getY(), EntityType.point)
              .get(0);

      // Point p = PointServiceFactory.getInstance().getPointByKey(calculation.getY());
      if (p != null) {
        final List<Value> val = ValueServiceFactory.getInstance().getCurrentValue(p);
        final double d = val.isEmpty() ? 0.0 : val.get(0).getDoubleValue();
        m.addVariable("y", d);
      }
    }
    if (!Utils.isEmptyString(calculation.getZ()) && calculation.getFormula().contains("z")) {
      final Entity p =
          EntityServiceFactory.getInstance()
              .getEntityByKey(user, calculation.getZ(), EntityType.point)
              .get(0);

      //  Point p = PointServiceFactory.getInstance().getPointByKey(calculation.getZ());
      if (p != null) {
        final List<Value> val = ValueServiceFactory.getInstance().getCurrentValue(p);
        final double d = val.isEmpty() ? 0.0 : val.get(0).getDoubleValue();
        m.addVariable("z", d);
      }
    }

    final Double retVal = m.getValue();

    if (retVal == null) {

      throw new NimbitsException("Formula returned a null value: " + calculation.getFormula());
    }

    return ValueFactory.createValueModel(retVal, "CV");
  }