Beispiel #1
1
  // ----This function getting search term and tweet id ----
  // ----the function adding the tweet id and the time of search to the collection search_results--
  public void SearchResultId(String searchword, String tweet_id) {
    log4j.info(
        "starting function SearchResultId with parameters: searchword = "
            + searchword
            + ", tweet_id"
            + tweet_id);
    try {
      DBObject searchobj = new BasicDBObject();
      searchobj.put("searchword", searchword);
      DBObject obj = this.collsr.findOne(searchobj); // get document if exists
      long min_time =
          System.currentTimeMillis() - this.frame_time; // minimum time to keep in document

      if (Long.parseLong(obj.get("last_update").toString()) < min_time) {
        // last updated before minimum time - checking each tweet
        String[] tweets = obj.get("tweets").toString().split(",");
        String new_string = "";
        for (int i = 1; i < tweets.length; i += 2) // going over all existing tweets in document
        {
          if (Long.parseLong(tweets[i]) >= min_time) {
            // tweet stays in document
            if (new_string == "") {
              // no leading comma
              new_string += tweets[i - 1] + "," + tweets[i];
            } else {
              // leading comma
              new_string += "," + tweets[i - 1] + "," + tweets[i];
            }
          }
        }
        obj.put("tweets", new_string + "," + tweet_id);
        obj.put("last_update", System.currentTimeMillis());
        // obj.put("in_process", 0);
        this.collsr.save(obj);
      } else {
        // last updated after minimum time - just adding tweet
        obj.put("tweets", obj.get("tweets").toString() + "," + tweet_id);
        this.collsr.save(obj);
      }

    } catch (NullPointerException e) {
      // there is no document yet, creating one
      DBObject searchobj = new BasicDBObject();
      searchobj.put("searchword", searchword);
      searchobj.put("tweets", tweet_id);
      searchobj.put("last_update", System.currentTimeMillis());
      this.collsr.save(searchobj);
    }
    log4j.info("ending function SearchResultId");
  }
Beispiel #2
1
 // ----This function gets as a parameter a list of terms----
 // ---------the function returns a list of tweet ids from collection search_results-----------
 // ----------------------------------------------------------------------------------------
 public LinkedList<String> get_tweets(LinkedList<String> search_terms) {
   log4j.info("starting function get_tweets");
   LinkedList<String> result = new LinkedList<String>();
   Iterator<String> terms = search_terms.iterator();
   long curr_time = System.currentTimeMillis();
   long min_time = curr_time - this.frame_time; // time below min_time will be ignored
   int count_all = 0; // tweets counter
   while (terms.hasNext()) {
     int count = 0;
     String term = terms.next();
     DBObject st = new BasicDBObject();
     try {
       st.put("searchword", term);
       DBObject obj = this.collsr.findOne(st); // look for the relevant document
       String[] tweets_plus_time =
           obj.get("tweets")
               .toString()
               .split(","); // make an array, even indexes are tweet_id's and odd indexes are their
       // time
       String new_string =
           ""; // the string to replace eventually the current field 'tweets' in the document
       for (int i = 0;
           i < tweets_plus_time.length - 1;
           i += 2) // go over the tweet ids from the document
       {
         if (Long.parseLong(tweets_plus_time[i + 1])
             >= min_time) // tweet time is within the time frame
         {
           result.add(tweets_plus_time[i]); // add tweet id to result
           count++;
           if (new_string == "") // add tweet information without leading comma
           {
             new_string += tweets_plus_time[i] + "," + tweets_plus_time[i + 1];
             // count++;
           } else // add tweet information with leading comma
           {
             new_string += "," + tweets_plus_time[i] + "," + tweets_plus_time[i + 1];
           }
         }
       }
       count_all += count;
       log4j.info(count + " tweets for term: " + term);
       obj.put("tweets", new_string); // replace 'tweets' field
       obj.put("last_update", System.currentTimeMillis()); // update time of update
       collsr.save(obj);
     } catch (NullPointerException e) {
       log4j.info("search_term: " + term + ", is not in collection search_results");
     }
   }
   log4j.info("over_all there are " + count_all + " tweets to compare!!!");
   log4j.info("ending function get_tweets");
   return result;
 }
  /**
   * Called before window creation, descendants should override to initialize the data, initialize
   * params.
   */
  void preInit(XCreateWindowParams params) {
    state_lock = new StateLock();
    initialising = InitialiseState.NOT_INITIALISED;
    embedded = Boolean.TRUE.equals(params.get(EMBEDDED));
    visible = Boolean.TRUE.equals(params.get(VISIBLE));

    Object parent = params.get(PARENT);
    if (parent instanceof XBaseWindow) {
      parentWindow = (XBaseWindow) parent;
    } else {
      Long parentWindowID = (Long) params.get(PARENT_WINDOW);
      if (parentWindowID != null) {
        parentWindow = XToolkit.windowToXWindow(parentWindowID);
      }
    }

    Long eventMask = (Long) params.get(EVENT_MASK);
    if (eventMask != null) {
      long mask = eventMask.longValue();
      mask |= SubstructureNotifyMask;
      params.put(EVENT_MASK, mask);
    }

    screen = -1;
  }
Beispiel #4
0
  /**
   * Creates the tool context denoting the range of samples that should be analysed by a tool.
   *
   * @return a tool context, never <code>null</code>.
   */
  private ToolContext createToolContext() {
    int startOfDecode = -1;
    int endOfDecode = -1;

    final int dataLength = this.dataContainer.getValues().length;
    if (this.dataContainer.isCursorsEnabled()) {
      if (this.dataContainer.isCursorPositionSet(0)) {
        final Long cursor1 = this.dataContainer.getCursorPosition(0);
        startOfDecode = this.dataContainer.getSampleIndex(cursor1.longValue()) - 1;
      }
      if (this.dataContainer.isCursorPositionSet(1)) {
        final Long cursor2 = this.dataContainer.getCursorPosition(1);
        endOfDecode = this.dataContainer.getSampleIndex(cursor2.longValue()) + 1;
      }
    } else {
      startOfDecode = 0;
      endOfDecode = dataLength;
    }

    startOfDecode = Math.max(0, startOfDecode);
    if ((endOfDecode < 0) || (endOfDecode >= dataLength)) {
      endOfDecode = dataLength - 1;
    }

    return new DefaultToolContext(startOfDecode, endOfDecode);
  }
Beispiel #5
0
 public long GetRateTimeFrame(Long UserId, Long numofhours) {
   this.log4j.info("=================================================================");
   this.log4j.info(
       "getting rate for user id: " + UserId + " within the last " + numofhours + " hours");
   long diff = numofhours * 60 * 60 * 1000; // hours to millis
   BasicDBObject docline = new BasicDBObject();
   docline.put("user_id", UserId); // querying to find the right userId
   DBObject doc = this.collrate.findOne(docline);
   if (doc == null) // there is no document for the user
   {
     this.log4j.error("user id : " + UserId + " does not exist");
     return -1L;
   } else // document exists
   {
     long result = 0;
     long currstart = Long.parseLong(doc.get("current_slot_start_time_millis").toString());
     if (System.currentTimeMillis() - diff > currstart) {
       this.log4j.info("result is 0");
       return 0;
     } else {
       double backslots = diff / this.slot_time_millis;
       if (backslots > this.num_of_slots) {
         this.log4j.info(
             "you requested longer time than the time frame, the result will be only for the previous timeframe");
       }
       for (int i = 0; i < backslots || i < this.num_of_slots; i++) {
         int slot = (int) ((this.current_slot_index - i + this.num_of_slots) % this.num_of_slots);
         result += Long.parseLong(doc.get("slot" + slot).toString());
       }
       this.log4j.info("result is " + result);
       return result;
     }
   }
 }
Beispiel #6
0
 /**
  * Goes to the current cursor position of the cursor with the given index.
  *
  * @param aCursorIdx the index of the cursor to go to, >= 0 && < 10.
  */
 public void gotoCursorPosition(final int aCursorIdx) {
   if ((this.mainFrame != null) && this.dataContainer.isCursorsEnabled()) {
     final Long cursorPosition = this.dataContainer.getCursorPosition(aCursorIdx);
     if (cursorPosition != null) {
       this.mainFrame.gotoPosition(cursorPosition.longValue());
     }
   }
 }
Beispiel #7
0
 /** Goes to the current cursor position of the last available cursor. */
 public void gotoLastAvailableCursor() {
   if ((this.mainFrame != null) && this.dataContainer.isCursorsEnabled()) {
     for (int c = CapturedData.MAX_CURSORS - 1; c >= 0; c--) {
       if (this.dataContainer.isCursorPositionSet(c)) {
         final Long cursorPosition = this.dataContainer.getCursorPosition(c);
         if (cursorPosition != null) {
           this.mainFrame.gotoPosition(cursorPosition.longValue());
         }
         break;
       }
     }
   }
 }
Beispiel #8
0
  /**
   * Set the access time for this Node
   *
   * @param timeStr the selected time
   */
  void setTimeStamp(String timeStr) {
    if (timeStr == null || timeStr.trim().length() == 0) {
      setTimeStamp();
      setTimeStampStr();
      return;
    }

    Date time = null;
    try {
      time = new Date(Long.parseLong(timeStr));
    } catch (NumberFormatException e) {
      Logger.getLogger(LoggerName).log(Level.SEVERE, "error parsing timeStamp", e);
      if (AUTHORABLE) {
        setParseError("error parsing timeStamp " + timeStr + " " + e.getMessage());
      } else {
        setParseError("syntax error");
      }
    }

    if (time == null) {
      setTimeStamp();
    } else {
      timeStamp = time;
    }
    setTimeStampStr();
  }
 String getWindow(long window) {
   XBaseWindow w = XToolkit.windowToXWindow(window);
   if (w == null) {
     return Long.toHexString(window);
   } else {
     return w.toString();
   }
 }
  /**
   * @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;
  }
 public void xRequestFocus() {
   XToolkit.awtLock();
   try {
     if (focusLog.isLoggable(Level.FINER))
       focusLog.finer("XSetInputFocus on " + Long.toHexString(getWindow()));
     XlibWrapper.XSetInputFocus(XToolkit.getDisplay(), getWindow());
   } finally {
     XToolkit.awtUnlock();
   }
 }
Beispiel #12
0
  // ----This function searching the data Base and finds the tweet with the same tweet_id----
  // ---------the function was given,and returns the text of the tweet as a string-----------
  // ----------------------------------------------------------------------------------------
  public String FromTweetIdToText(String TweetId) {
    // log4j.info("==================================================");
    // DBCollection coll=db.getCollection("all_tweets");
    BasicDBObject query5 = new BasicDBObject();
    query5.put("id", Long.parseLong(TweetId));
    DBObject cursor6 =
        this.collat.findOne(query5); // querying to find the document with the right tweet_id

    String str = cursor6.get("text").toString();
    return str;
  }
Beispiel #13
0
 /** Creates a map of the classes fields. */
 protected static Object getParamArg(Class cl) {
   if (!cl.isPrimitive()) return null;
   else if (boolean.class.equals(cl)) return Boolean.FALSE;
   else if (byte.class.equals(cl)) return new Byte((byte) 0);
   else if (short.class.equals(cl)) return new Short((short) 0);
   else if (char.class.equals(cl)) return new Character((char) 0);
   else if (int.class.equals(cl)) return Integer.valueOf(0);
   else if (long.class.equals(cl)) return Long.valueOf(0);
   else if (float.class.equals(cl)) return Float.valueOf(0);
   else if (double.class.equals(cl)) return Double.valueOf(0);
   else throw new UnsupportedOperationException();
 }
Beispiel #14
0
  /** Set the access time for this Node as Now() */
  private void setTimeStampStr() {
    if (timeStamp == null) {
      timeStampStr = "";
    }

    try {
      timeStampStr = Long.toString(timeStamp.getTime());
    } catch (NumberFormatException e) {
      Logger.getLogger(LoggerName).log(Level.SEVERE, "", e);
      timeStampStr = "";
    }
  }
Beispiel #15
0
  @Override
  public void run() {
    this.subSocket = this.mqm.getSubscriber();

    this.subSocket.subscribe("EUR/USD".getBytes()); // @TODO: Enable other pairs!
    this.subSocket.subscribe("USD/CHF".getBytes());
    this.subSocket.subscribe("EUR/CHF".getBytes());

    int index = 0;
    EVENT event = null;

    while (true) {
      PAIR pair = this.getPair(new String(this.subSocket.recv(0)));
      assert (pair != null);

      UUID uuid = UUID.fromString(new String(this.subSocket.recv(0)));
      assert (uuid != null);

      StringTokenizer st = new StringTokenizer(new String(this.subSocket.recv(0)), "|");
      assert (st != null && st.hasMoreTokens());

      RATE_EVENT_INFO rei =
          new RATE_EVENT_INFO(
              pair,
              new TICK(
                  Long.parseLong(st.nextToken()),
                  Double.parseDouble(st.nextToken()),
                  Double.parseDouble(st.nextToken())));

      logger.log(Level.INFO, rei.toString());
      index = 0;
      while (true) {
        event = null;
        synchronized (this.events) {
          if (index < this.events.size()) {
            event = this.events.get(index++);
          } else {
            break;
          }
        }

        if (event != null) {
          if (event.match(rei)) {
            this.mqm.setUuid(uuid);
            event.handle(rei, this);
          }
        } else {
          throw new NullPointerException("event");
        }
      }
    }
  }
Beispiel #16
0
  /**
   * Sets the cursor position of the cursor with the given index.
   *
   * @param aCursorIdx the index of the cursor to set, >= 0 && < 10;
   * @param aLocation the mouse location on screen where the cursor should become, cannot be <code>
   *     null</code>.
   */
  public void setCursorPosition(final int aCursorIdx, final Point aLocation) {
    // Implicitly enable cursor mode, the user already had made its
    // intensions clear that he want to have this by opening up the
    // context menu anyway...
    setCursorMode(true);

    if (this.mainFrame != null) {
      // Convert the mouse-position to a sample index...
      final long sampleIdx = this.mainFrame.convertMousePositionToSampleIndex(aLocation);

      this.dataContainer.setCursorPosition(aCursorIdx, Long.valueOf(sampleIdx));

      fireCursorChangedEvent(aCursorIdx, aLocation.x);
    }

    updateActions();
  }
  /**
   * @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;
  }
  /**
   * Verifies that all required parameters are set. If not, sets them to default values. Verifies
   * values of critical parameters, adjust their values when needed.
   *
   * @throws IllegalArgumentException if params is null
   */
  protected void checkParams(XCreateWindowParams params) {
    if (params == null) {
      throw new IllegalArgumentException("Window creation parameters are null");
    }
    params.putIfNull(PARENT_WINDOW, Long.valueOf(XToolkit.getDefaultRootWindow()));
    params.putIfNull(BOUNDS, new Rectangle(DEF_LOCATION, DEF_LOCATION, MIN_SIZE, MIN_SIZE));
    params.putIfNull(DEPTH, Integer.valueOf((int) XlibWrapper.CopyFromParent));
    params.putIfNull(VISUAL, Long.valueOf(XlibWrapper.CopyFromParent));
    params.putIfNull(VISUAL_CLASS, Integer.valueOf((int) XlibWrapper.InputOnly));
    params.putIfNull(VALUE_MASK, Long.valueOf(XlibWrapper.CWEventMask));
    Rectangle bounds = (Rectangle) params.get(BOUNDS);
    bounds.width = Math.max(MIN_SIZE, bounds.width);
    bounds.height = Math.max(MIN_SIZE, bounds.height);

    Long eventMaskObj = (Long) params.get(EVENT_MASK);
    long eventMask = eventMaskObj != null ? eventMaskObj.longValue() : 0;
    // We use our own synthetic grab see XAwtState.getGrabWindow()
    // (see X vol. 1, 8.3.3.2)
    eventMask |= PropertyChangeMask | OwnerGrabButtonMask;
    params.put(EVENT_MASK, Long.valueOf(eventMask));
  }
    @Override
    public void readFrame(Buffer buffer) {
      // example data:
      // --ssBoundary8345
      // Content-Type: image/jpeg
      // Content-Length: 114587

      try {
        String line;
        // eat leading blank lines
        while (true) {
          line = readLine(MAX_LINE_LENGTH);
          if (line == null) {
            buffer.setEOM(true);
            buffer.setLength(0);
            return;
          }

          if (!line.trim().equals("")) break; // end of header
        }

        if (boundary == null) {
          boundary = line.trim(); // TODO: we should be able to get
          // this from the content type, but
          // the content type has this
          // stripped out. So we'll just take
          // the first nonblank line to be the
          // boundary.
          // System.out.println("boundary: " + boundary);
        } else {
          if (!line.trim().equals(boundary)) {
            // throw new IOException("Expected boundary: " +
            // toPrintable(line));
            // TODO: why do we seem to get these when playing back
            // mmr files recorded using FmjTranscode?
            logger.warning("Expected boundary (frame " + framesRead + "): " + toPrintable(line));

            // handle streams that are truncated in the middle of a
            // frame:
            final int eatResult = eatUntil(boundary); // TODO: no
            // need to
            // store the
            // data

            logger.info(
                "Ignored bytes (eom after="
                    + (eatResult < 0)
                    + "): "
                    + (eatResult < 0 ? (-1 * eatResult - 1) : eatResult));
            if (eatResult < 0) {
              buffer.setEOM(true);
              buffer.setLength(0);
              return;
            }

            // now read boundary
            line = readLine(MAX_LINE_LENGTH);
            if (!line.trim().equals(boundary)) {
              throw new RuntimeException("No boundary found after eatUntil(boundary)"); // should
              // never
              // happen
            }
          }
        }

        final Properties properties = new Properties();

        while (true) {
          line = readLine(MAX_LINE_LENGTH);
          if (line == null) {
            buffer.setEOM(true);
            buffer.setLength(0);
            return;
          }

          if (line.trim().equals("")) break; // end of header

          if (!parseProperty(line, properties))
            throw new IOException("Expected property: " + toPrintable(line));
        }

        final String contentType = properties.getProperty("Content-Type".toUpperCase());
        if (contentType == null) {
          logger.warning("Header properties: " + properties);
          throw new IOException("Expected Content-Type in header");
        }

        // check supported content types:
        if (!isSupportedFrameContentType(contentType)) {
          throw new IOException("Unsupported Content-Type: " + contentType);
        }

        if (frameContentType == null) {
          frameContentType = contentType;
        } else {
          if (!contentType.equals(frameContentType))
            throw new IOException(
                "Content type changed during stream from "
                    + frameContentType
                    + " to "
                    + contentType);
        }

        // TODO: check that size doesn't change throughout

        final byte[] data;

        final String contentLenStr = properties.getProperty("Content-Length".toUpperCase());
        if (contentLenStr != null) { // if we know the content length, use it
          final int contentLen;
          try {
            contentLen = Integer.parseInt(contentLenStr);
          } catch (NumberFormatException e) {
            throw new IOException("Invalid content length: " + contentLenStr);
          }

          // now, read the content-length bytes
          data = readFully(contentLen); // TODO: don't realloc each
          // time
        } else {
          // if we don't know the content length, just read until we
          // find the boundary.
          // Some IP cameras don't specify it, like
          // http://webcam-1.duesseldorf.it-on.net/cgi-bin/nph-update.cgi
          data = readUntil(boundary);
        }

        // ext
        final String timestampStr = properties.getProperty(TIMESTAMP_KEY.toUpperCase());
        if (timestampStr != null) {
          try {
            final long timestamp = Long.parseLong(timestampStr);
            buffer.setTimeStamp(timestamp);

          } catch (NumberFormatException e) {
            logger.log(Level.WARNING, "" + e, e);
          }
        }

        if (data == null) {
          buffer.setEOM(true);
          buffer.setLength(0);
          return;
        }

        buffer.setData(data);
        buffer.setOffset(0);
        buffer.setLength(data.length);
        ++framesRead;

      } catch (IOException e) {
        throw new RuntimeException(e);
      }
    }
Beispiel #20
0
  // ----This function gets the raw json from raw_data collection----
  // ---------the function separate the tweets and inserts it to all_tweets collection and calling
  // all other data processing methods-----------
  // ----------------------------------------------------------------------------------------
  public void update_all_tweets(final double num_of_slots, final double max_time_frame_hours)
      throws MongoException, ParseException {
    log4j.info("starting update_all_tweets function");
    String res = new String();
    Integer countelements = 0;
    while (true) {
      // DBCursor cursor = this.collrd.find();
      while (this.collrd.count() < 1) { // no documents to process
        try {
          log4j.info("there is no raw data at the moment, going to sleep for 10 seconds");
          Thread.currentThread();
          Thread.sleep(1000 * 10);
          log4j.info("woke up, continues");
          // cursor = this.collrd.find();
        } catch (InterruptedException e) {
          log4j.error("InterruptedException caught, at update_all_tweets");
          log4j.error(e);
        }
      }
      DBCursor cursor = this.collrd.find(); // get all documents from raw_data collection
      try {
        while (cursor.hasNext()) {
          DBObject currdoc = cursor.next();
          log4j.info("getting a document from the raw data db");
          Object results = currdoc.get("results"); // result - json array of tweets
          try {
            res = results.toString();
          } catch (NullPointerException e) {
            res = "";
          }
          Object obj = JSONValue.parse(res);
          log4j.info("making an array from the jsons tweets");
          JSONArray array = (JSONArray) obj; // make an array of tweets
          // JSONParser parser = new JSONParser();
          try {
            if (res != "") { // if there are tweets
              @SuppressWarnings("rawtypes")
              Iterator iterArray = array.iterator();
              log4j.info("iterating over array tweets");
              try {
                while (iterArray.hasNext()) {
                  Object current = iterArray.next();
                  final DBObject dbObject =
                      (DBObject) JSON.parse(current.toString()); // parse all tweet data to json
                  countelements++;
                  // System.out.println("element number" + countelements.toString());
                  dbObject.put("max_id", currdoc.get("max_id")); // add max_id to tweet data
                  dbObject.put("query", currdoc.get("query")); // add query word to tweet data
                  dbObject.put(
                      "query_time", currdoc.get("query_time")); // add query time to tweet data
                  dbObject.put("query_time_string", currdoc.get("query_time_string"));
                  dbObject.put(
                      "text",
                      "@"
                          + dbObject.get("from_user").toString()
                          + ": "
                          + dbObject.get("text").toString()); // add user_name to beginning of text
                  dbObject.put("count", 1L); // add appearance counter to tweet data
                  log4j.info("inserting tweet id: " + dbObject.get("id").toString());
                  try {
                    DBObject object = new BasicDBObject();
                    object.put(
                        "id", Long.parseLong(dbObject.get("id").toString())); // object to search
                    DBObject newobject = collat.findOne(object);
                    if (newobject != null) {
                      newobject.put(
                          "count",
                          Long.parseLong(newobject.get("count").toString())
                              + 1); // update counter if id already exists
                      collat.update(object, newobject);
                    }
                  } catch (NullPointerException e) {

                  }
                  collat.insert(dbObject);
                  // collrd.findAndRemove(currdoc);
                  // log4j.info("calling function update_search_terms");
                  // final String text = "@" + dbObject.get("from_user").toString() + ": " +
                  // dbObject.get("text").toString();

                  /*Thread t10=new Thread(new Runnable(){
                  	public void run(){
                  		UpdateTweetCounterId(Long.parseLong(dbObject.get("id").toString()));
                  	}
                  });*/

                  Thread t11 =
                      new Thread(
                          new Runnable() {
                            public void run() {
                              update_search_terms(
                                  dbObject.get("text").toString(),
                                  num_of_slots,
                                  max_time_frame_hours,
                                  dbObject.get("query").toString());
                            }
                          });

                  Thread t12 =
                      new Thread(
                          new Runnable() {
                            public void run() {
                              rate_user(
                                  Long.parseLong(dbObject.get("from_user_id").toString()),
                                  dbObject.get("from_user").toString(),
                                  max_time_frame_hours);
                              // UpdateUserRate((long)num_of_slots,slot_time_millis,Long.parseLong(dbObject.get("from_user_id").toString()) , dbObject.get("from_user").toString() ,(long)0);
                            }
                          });

                  Thread t13 =
                      new Thread(
                          new Runnable() {
                            public void run() {
                              String quer = dbObject.get("query").toString();
                              quer = quer.replaceAll("%40", "@");
                              quer = quer.replaceAll("%23", "#");
                              long id =
                                  (long)
                                      (Double.parseDouble(dbObject.get("query_time").toString())
                                          * 1000);
                              String idplus = dbObject.get("id").toString() + "," + id;
                              SearchResultId(quer, idplus);
                            }
                          });
                  // t10.start();
                  t11.start();
                  t12.start();
                  t13.start();
                  try {
                    log4j.info("Waiting for threads to finish.");
                    // t10.join();
                    t11.join();
                    t12.join();
                    t13.join();
                  } catch (InterruptedException e) {
                    log4j.error("Main thread (update_all_tweets) Interrupted");
                  }
                }
              } catch (Exception e) {
                log4j.error(e);
                e.printStackTrace();
              }
            }
          } catch (NullPointerException e) {
            log4j.error(e);
            log4j.info("NullPointerException caught, at update_all_tweets");
          }
          log4j.info("removing processed document from raw_data collection");
          try {
            this.collrd.remove(currdoc);
          } catch (Exception e) {
            log4j.debug(e);
          }
        }
      } catch (MongoException e) {
        log4j.error(e);
      }
    }
  }
Beispiel #21
0
 private void CountInstancesBtnMouseClicked(
     java.awt.event.MouseEvent evt) { // GEN-FIRST:event_CountInstancesBtnMouseClicked
   // TODO add your handling code here:
   LoggingAreaTA.append("Total: " + Long.toString(InstancesCount()) + " instances");
 } // GEN-LAST:event_CountInstancesBtnMouseClicked
 /** Creates normal child window */
 XBaseWindow(long parentWindow, Rectangle bounds) {
   this(
       new XCreateWindowParams(
           new Object[] {BOUNDS, bounds, PARENT_WINDOW, Long.valueOf(parentWindow)}));
 }
 /* This create is used by the XEmbeddedFramePeer since it has to create the window
 as a child of the netscape window. This netscape window is passed in as wid */
 XBaseWindow(long parentWindow) {
   this(
       new XCreateWindowParams(
           new Object[] {PARENT_WINDOW, Long.valueOf(parentWindow), EMBEDDED, Boolean.TRUE}));
 }
  /**
   * Creates window with parameters specified by <code>params</code>
   *
   * @see #init
   */
  private final void create(XCreateWindowParams params) {
    XToolkit.awtLock();
    try {
      XSetWindowAttributes xattr = new XSetWindowAttributes();
      try {
        checkParams(params);

        long value_mask = ((Long) params.get(VALUE_MASK)).longValue();

        Long eventMask = (Long) params.get(EVENT_MASK);
        xattr.set_event_mask(eventMask.longValue());
        value_mask |= XlibWrapper.CWEventMask;

        Long border_pixel = (Long) params.get(BORDER_PIXEL);
        if (border_pixel != null) {
          xattr.set_border_pixel(border_pixel.longValue());
          value_mask |= XlibWrapper.CWBorderPixel;
        }

        Long colormap = (Long) params.get(COLORMAP);
        if (colormap != null) {
          xattr.set_colormap(colormap.longValue());
          value_mask |= XlibWrapper.CWColormap;
        }
        Long background_pixmap = (Long) params.get(BACKGROUND_PIXMAP);
        if (background_pixmap != null) {
          xattr.set_background_pixmap(background_pixmap.longValue());
          value_mask |= XlibWrapper.CWBackPixmap;
        }

        Long parentWindow = (Long) params.get(PARENT_WINDOW);
        Rectangle bounds = (Rectangle) params.get(BOUNDS);
        Integer depth = (Integer) params.get(DEPTH);
        Integer visual_class = (Integer) params.get(VISUAL_CLASS);
        Long visual = (Long) params.get(VISUAL);
        Boolean overrideRedirect = (Boolean) params.get(OVERRIDE_REDIRECT);
        if (overrideRedirect != null) {
          xattr.set_override_redirect(overrideRedirect.booleanValue());
          value_mask |= XlibWrapper.CWOverrideRedirect;
        }

        Boolean saveUnder = (Boolean) params.get(SAVE_UNDER);
        if (saveUnder != null) {
          xattr.set_save_under(saveUnder.booleanValue());
          value_mask |= XlibWrapper.CWSaveUnder;
        }

        Integer backingStore = (Integer) params.get(BACKING_STORE);
        if (backingStore != null) {
          xattr.set_backing_store(backingStore.intValue());
          value_mask |= XlibWrapper.CWBackingStore;
        }

        Integer bitGravity = (Integer) params.get(BIT_GRAVITY);
        if (bitGravity != null) {
          xattr.set_bit_gravity(bitGravity.intValue());
          value_mask |= XlibWrapper.CWBitGravity;
        }

        if (log.isLoggable(Level.FINE)) {
          log.fine("Creating window for " + this + " with the following attributes: \n" + params);
        }
        window =
            XlibWrapper.XCreateWindow(
                XToolkit.getDisplay(),
                parentWindow.longValue(),
                bounds.x,
                bounds.y, // location
                bounds.width,
                bounds.height, // size
                0, // border
                depth.intValue(), // depth
                visual_class.intValue(), // class
                visual.longValue(), // visual
                value_mask, // value mask
                xattr.pData); // attributes

        if (window == 0) {
          throw new IllegalStateException(
              "Couldn't create window because of wrong parameters. Run with NOISY_AWT to see details");
        }
        XToolkit.addToWinMap(window, this);
      } finally {
        xattr.dispose();
      }
    } finally {
      XToolkit.awtUnlock();
    }
  }
 public String toString() {
   return super.toString() + "(" + Long.toString(getWindow(), 16) + ")";
 }
Beispiel #26
0
  private TypedValues guessUntypedValue(String name, String value) {
    TypedValues list = new TypedValues(name);

    if (value.startsWith("java:")) { // possible java static reference
      int dot;
      if (value.equals("java:null")) {
        list.add(new TypedValue(Object.class, null));
      } else if (value.charAt(5) == '$') { // reference to a local object (assemble @id)
        ElementInfo element = _local.get(value.substring(6));
        if (element != null) {
          list.add(new TypedValue(element.type, element.data));
        }
      } else if ((dot = value.lastIndexOf('.')) > 5) {
        try {
          // public static refernce? (don't override access control)
          _logger.fine("public static refernce? " + value);
          Object object =
              Class.forName(value.substring(5, dot)).getField(value.substring(dot + 1)).get(null);
          Class<?> type = object.getClass();
          list.add(new TypedValue(type, object));
          // automatic upscaling to larger types
          if (type == Byte.class) {
            object = new Short(((Byte) object).byteValue());
            list.add(new TypedValue(Short.class, object));
            type = Short.class;
          }
          if (type == Short.class) {
            object = new Integer(((Short) object).shortValue());
            list.add(new TypedValue(Integer.class, object));
            type = Integer.class;
          }
          if (type == Integer.class) {
            object = new Long(((Integer) object).intValue());
            list.add(new TypedValue(Long.class, object));
            type = Long.class;
          }
          if (type == Long.class) {
            object = new Float(((Long) object).longValue());
            list.add(new TypedValue(Float.class, object));
            type = Float.class;
          }
          if (type == Float.class) {
            object = new Double(((Float) object).floatValue());
            list.add(new TypedValue(Double.class, object));
          }
        } catch (Exception x) {
          _logger.fine(value + " looked like a static reference but is not: " + x.getMessage());
          // class reference?
          guessClassReference(list, value.substring(5));
        }
      } else { // no '.' at all
        // class reference?
        guessClassReference(list, value.substring(5));
      }
    } else if (value.equals("true")) {
      list.add(new TypedValue(Boolean.class, Boolean.TRUE));
    } else if (value.equals("false")) {
      list.add(new TypedValue(Boolean.class, Boolean.FALSE));
    } else {
      // numbers? multiple possibilities
      try {
        list.add(new TypedValue(Integer.class, Integer.valueOf(value)));
      } catch (Exception x) {
      }
      try {
        list.add(new TypedValue(Long.class, Long.valueOf(value)));
      } catch (Exception x) {
      }
      try {
        list.add(new TypedValue(Float.class, Float.valueOf(value)));
      } catch (Exception x) {
      }
      try {
        list.add(new TypedValue(Double.class, Double.valueOf(value)));
      } catch (Exception x) {
      }
    }

    // always try String as the last resort
    list.add(new TypedValue(String.class, value));

    return list;
  }