private void stepTimeout() {
    boolean updated = false;
    synchronized (channels) {
      Iterator<ChannelInfo> it = channels.values().iterator();
      while (it.hasNext()) {
        ChannelInfo channel = it.next();
        Iterator<UserInfo> removed = channel.stepTimeout(getTimeoutLimit());

        if (removed != null) {
          updated = true;
          String channelName = channel.getChannelName();
          while (removed.hasNext()) {
            UserInfo user = removed.next();
            ServerLogger.getInstance()
                .channelLeaved(channelName, user.getUserName(), user.getInetSocketAddress());
          }
          if (channel.isEmpty()) {
            it.remove();
            ServerLogger.getInstance().channelRemoved(channelName);
          }
        }
      }

      if (updated) {
        updateChannelsCache();
      }
    }
  }
Ejemplo n.º 2
0
  // Do an O(n^2) pass through updating all connectivity
  public void updateModel() {
    Iterator it1 = state.getMoteSimObjects().iterator();
    while (it1.hasNext()) {
      MoteSimObject moteSender = (MoteSimObject) it1.next();
      Iterator it2 = state.getMoteSimObjects().iterator();
      while (it2.hasNext()) {
        MoteSimObject moteReceiver = (MoteSimObject) it2.next();
        if (moteReceiver.getID() == moteSender.getID()) continue;

        updateLossRate(moteSender, moteReceiver);
      }
    }
  }
Ejemplo n.º 3
0
 public ListNode deleteDuplicates(ListNode a) {
   ListNode temp = a;
   LinkedHashMap<Integer, Integer> map = new LinkedHashMap<Integer, Integer>();
   int i = 0;
   while (temp != null) {
     if (map.get(temp.val) == null) {
       map.put(temp.val, 1);
     } else {
       map.put(temp.val, map.get(temp.val) + 1);
     }
     temp = temp.next;
   }
   System.out.println(map);
   Iterator<Integer> it = map.keySet().iterator();
   ListNode root = null;
   ListNode root1 = null;
   while (it.hasNext()) {
     int x = it.next();
     if (map.get(x) == 1) {
       if (root == null) {
         root = new ListNode(x);
         root1 = root;
       } else {
         ListNode node = new ListNode(x);
         root1.next = node;
         root1 = node;
       }
     }
   }
   return root;
 }
Ejemplo n.º 4
0
  /**
   * ** Returns an array of root DBFactoryTree nodes based on the specified top-level DBFactory.
   * ** @param initialFactories The root DBFactories which are traversed to create the
   * DBFactoryTree. If null ** all root DBFactories will be traversed. ** @return An array of rot
   * DBFactoryTree nodes.
   */
  public static DBFactoryTree[] getDBFactoryTree(DBFactory<? extends DBRecord> initialFactories[]) {
    Set<String> addedTables = new HashSet<String>();
    DBFactoryTree rootNode = new DBFactoryTree();

    /* start with initial factories */
    if (initialFactories != null) {
      for (int i = 0; i < initialFactories.length; i++) {
        DBFactory<? extends DBRecord> dbf = initialFactories[i];
        DBFactoryTree._traverseDBFactoryTree(0, dbf, rootNode, addedTables);
      }
    }

    /* traverse remaining DBFactories, if any */
    OrderedMap<String, DBFactory<? extends DBRecord>> dbFactMap =
        new OrderedMap<String, DBFactory<? extends DBRecord>>(DBAdmin.getTableFactoryMap());
    for (Iterator<String> i = dbFactMap.keyIterator(); i.hasNext(); ) {
      String tn = i.next();
      DBFactory<? extends DBRecord> dbFact = (DBFactory<? extends DBRecord>) dbFactMap.get(tn);
      DBFactoryTree._traverseDBFactoryTree(0, dbFact, rootNode, addedTables);
    }

    /* return list of root children */
    DBFactoryTree roots[] = rootNode.getChildren();
    if (roots != null) {
      // clear our temporary root node from the table factory roots
      for (int i = 0; i < roots.length; i++) {
        roots[i].setParentNode(null);
      }
    }
    return roots;
  }
Ejemplo n.º 5
0
  private static void connectCallbackHandler(String moduleName, boolean isConnect) {
    Iterator iter = (isConnect ? connectHandlers.iterator() : disconnectHandlers.iterator());

    while (iter.hasNext()) {
      CONNECT_HANDLE_TYPE handler = (CONNECT_HANDLE_TYPE) iter.next();
      handler.handle(moduleName);
    }
  }
Ejemplo n.º 6
0
 /**
  * ** Gets args as RTProperties instance ** @return A new RTProperties instance with this URIArg's
  * key value pairs
  */
 public RTProperties getArgProperties() {
   RTProperties rtp = new RTProperties();
   for (Iterator i = this.getKeyValList().iterator(); i.hasNext(); ) {
     KeyVal kv = (KeyVal) i.next();
     rtp.setString(kv.getKey(), this.decodeArg(kv.getValue()));
   }
   return rtp;
 }
Ejemplo n.º 7
0
  // Send the loss rate for all pairs of motes to the simulator
  public void publishModel() {
    debug.err.println("RADIOMODEL: Publishing model, current is " + curModel);
    Iterator it1 = state.getMoteSimObjects().iterator();
    while (it1.hasNext()) {
      MoteSimObject moteSender = (MoteSimObject) it1.next();
      MoteCoordinateAttribute moteSenderCoord = moteSender.getCoordinate();
      Iterator it2 = state.getMoteSimObjects().iterator();
      while (it2.hasNext()) {
        MoteSimObject moteReceiver = (MoteSimObject) it2.next();
        if (moteReceiver.getID() == moteSender.getID()) continue;

        String key = graphKey(moteSender, moteReceiver);
        double prob = ((Double) connectivityGraph.get(key)).doubleValue();
        publishLossRate(moteSender, moteReceiver, prob);
      }
    }
  }
Ejemplo n.º 8
0
 /** ** Removes all arguments which have blank values ** @return This URIArg */
 public URIArg removeBlankValues() {
   for (Iterator<KeyVal> i = this.getKeyValList().iterator(); i.hasNext(); ) {
     KeyVal kv = i.next();
     if (!kv.hasValue()) {
       i.remove();
     }
   }
   return this;
 }
Ejemplo n.º 9
0
 /**
  * ** Removes all occurances of the specified key from the URI ** @param key The key to remove
  * ** @return This URIArg, with the argument added
  */
 public URIArg removeArg(String key) {
   if (key != null) {
     for (Iterator<KeyVal> i = this.getKeyValList().iterator(); i.hasNext(); ) {
       KeyVal kv = i.next();
       if (kv.getKey().equals(key)) {
         i.remove();
       }
     }
   }
   return this;
 }
Ejemplo n.º 10
0
 /**
  * ** Returns a String representation of all key/values ** @param sbuff The StringBuffer to write
  * the key/values to, or null ** for a new one ** @return A String representation of all
  * key/values
  */
 public StringBuffer getArgString(StringBuffer sbuff) {
   StringBuffer sb = (sbuff != null) ? sbuff : new StringBuffer();
   for (Iterator i = this.getKeyValList().iterator(); i.hasNext(); ) {
     KeyVal kv = (KeyVal) i.next();
     sb.append(kv.toString());
     if (i.hasNext()) {
       sb.append("&");
     }
   }
   return sb;
 }
Ejemplo n.º 11
0
  private static boolean removeFromHandlerList(List list, Class handlerClass) {
    boolean found = false;
    Iterator iter = list.iterator();

    /* Do it this way because multiple handlers can be subscribed  */
    while (iter.hasNext() && !found) {
      found = (iter.next().getClass() == handlerClass);
      if (found) iter.remove();
    }
    return found;
  }
Ejemplo n.º 12
0
  public void count_account_stats(String hostname, Collection AccountStatisticReturnVal_objs) {
    Collection coll = AccountStatisticReturnVal_objs;
    AccountStatisticReturnVal acstat;
    Iterator tour;

    tour = coll.iterator();
    while (tour.hasNext()) {
      acstat = (AccountStatisticReturnVal) tour.next();
      count_account_stat(hostname, acstat);
    }
    return;
  }
Ejemplo n.º 13
0
  private static void changeCallbackHandler(String msgName, int numHandlers) {
    List handlerList = (List) handlerChangeHashTable.get(msgName);
    if (handlerList == null) {
      System.out.println("Ooops -- no change handlers for message " + msgName);
      return;
    }
    Iterator iter = handlerList.iterator();

    while (iter.hasNext()) {
      ((CHANGE_HANDLE_TYPE) iter.next()).handle(msgName, numHandlers);
    }
  }
Ejemplo n.º 14
0
 /**
  * ** Returns a String representation of all key/values ** @param sbuff The StringBuffer to write
  * the key/values to, or null for a new one ** @param includeBlankValues True to include keys for
  * blank values. ** @return A String representation of all key/values
  */
 public StringBuffer getArgString(StringBuffer sbuff, boolean includeBlankValues) {
   StringBuffer sb = (sbuff != null) ? sbuff : new StringBuffer();
   int argCnt = 0;
   for (Iterator i = this.getKeyValList().iterator(); i.hasNext(); ) {
     KeyVal kv = (KeyVal) i.next();
     if (includeBlankValues || kv.hasValue()) {
       if (argCnt > 0) {
         sb.append("&");
       }
       sb.append(kv.toString());
       argCnt++;
     }
   }
   return sb;
 }
Ejemplo n.º 15
0
  public void tally_accounts_bip_status(Collection accounts) {
    Account account;
    Iterator tour;

    BICServerLog.debugMsg(
        "BillRunTabulator("
            + billrun.get_billrunid()
            + ").tally_accounts_bip_status(): entered with accounts.size() = "
            + accounts.size());
    tour = accounts.iterator();
    while (tour.hasNext()) {
      account = (Account) tour.next();
      tally_account_bip_status(account);
    }
    return;
  }
Ejemplo n.º 16
0
  @RequestMapping(value = VIDEO_SEARCH_PATH, method = RequestMethod.GET)
  public @ResponseBody String[] searchVideo(
      @RequestParam(value = "username") String uName,
      @RequestParam(value = "video") String videoHash,
      HttpServletResponse response) {
    System.out.println("Search from:" + uName);
    if (!user_vidNameMap.containsKey(uName)) {
      response.setStatus(402); // client not connected
      return null;
    }

    Set<String> users = vidName_UserMap.get(videoHash);

    if (users == null) {
      System.out.println("Srearching main server\n");
      try {
        users = masterService.psSearch(hostAdder, videoHash);
      } catch (Exception e) {
        System.err.println(e.getMessage());
        return null;
      }
      if (users == null) return null;
      if (vidName_UserMap.containsKey(videoHash)) {
        vidName_UserMap.get(videoHash).addAll(users);
      } else {
        Set<String> s = new HashSet<String>();
        s.addAll(users);
        vidName_UserMap.put(videoHash, s);
      }
    } else {
      Iterator<String> it = users.iterator();
      while (it.hasNext()) {
        String temp = it.next();
        if (!activeUsers.contains(temp)) {
          it.remove();
        }
      }
    }
    System.out.println("Search result : " + Arrays.asList(users.toArray(new String[0])));
    // String [] a = new String[]
    return users.toArray(new String[0]);
  }
Ejemplo n.º 17
0
  private void removeUser(String user) {
    int count = 0;

    if (user_vidNameMap.containsKey(user)) {
      Set<String> vids = user_vidNameMap.get(user);
      Iterator<String> it = vids.iterator();
      while (it.hasNext()) {
        removeFromvidName_UserMap(user, it.next());
      }
      vids.clear();
      user_vidNameMap.remove(user);
    }
    activeUsers.remove(user);
    int ans = masterService.psDisConnectClient(hostAdder, user);
    while (ans != ACK) {
      if (count > 10) throw new RuntimeException("Time out in removing user from MS");
      reconnectToMS();
      ans = masterService.psDisConnectClient(hostAdder, user);
      count++;
    }
    System.out.println("User " + user + " removed.");
  }
Ejemplo n.º 18
0
 @Scheduled(fixedDelay = SCHEDULED_CHECK)
 public void checkActiveClients() {
   Set<String> users = user_vidNameMap.keySet();
   Iterator<String> it = users.iterator();
   long time = System.currentTimeMillis();
   int count = 0;
   while (it.hasNext()) {
     count++;
     String user = it.next();
     if (user == null) continue;
     if (userAliveMap.containsKey(user)) {
       if (userAliveMap.get(user).longValue() < time) {
         removeUser(user);
         userAliveMap.remove(user);
       }
     } else {
       throw new RuntimeException("user in user-vid map but not in user-alive map");
     }
   }
   // System.out.println("Debug: Scheduled Check count:"+count+" user
   // count:"+user_vidNameMap.size());
   System.gc();
 }
  public void run() {
    setAllColors(Color.GREEN);
    setTurnRadarRight(Double.POSITIVE_INFINITY);

    double robotX, robotY;
    double robotHeading, angleToGoal, angleToObs;
    double adjustment;
    double obsAngle, obsAdjustment;
    double angleDiff;
    double speedToGoal, speedFromObs;

    Enemy temp;
    obstacles = new HashMap<String, Enemy>(10);

    while (true) {
      if (foundGoal) {
        robotX = getX();
        robotY = getY();
        goalX = obstacles.get(GOAL_NAME).x;
        goalY = obstacles.get(GOAL_NAME).y;

        // Adjust robocode's returned heading so that 0 aligns with the positive x-axis instead of
        // the positive y-axis.
        // Also make it so that positive angle indicates a counter clockwise rotation instead of the
        // clockwise style
        // returned by robocode.
        robotHeading = 360 - (getHeading() - 90);
        angleToGoal = Math.toDegrees(Math.atan2(goalY - robotY, goalX - robotX));
        if (angleToGoal < 0) {
          angleToGoal += 360;
        }

        adjustment = angleToGoal - robotHeading;
        adjustment = normalizeAngle(adjustment);
        speedToGoal = calcRobotSpeedLinear(robotX, robotY, goalX, goalY);

        // Calculate how the robot's heading and speed should be affected by objects that it has
        // located
        // as it explores the world.
        Iterator it = obstacles.entrySet().iterator();
        while (it.hasNext()) {
          System.out.println("Iterating through objects.");

          Map.Entry pairs = (Map.Entry) it.next();

          // If the current item in the Iterator isn't the goal.
          if (!pairs.getKey().equals(GOAL_NAME)) {
            temp = (Enemy) pairs.getValue();
            speedFromObs = calcObjRepulseSpeed(robotX, robotY, temp.x, temp.y);

            // If the robot is in range of the object to be affected by it's repulsion.
            if (speedFromObs != 0) {
              obsAngle = Math.toDegrees(Math.atan2(robotY - temp.y, robotX - temp.x));
              if (obsAngle < 0) obsAngle += 360;

              angleDiff = obsAngle - angleToGoal;
              angleDiff = normalizeAngle(angleDiff);
              adjustment += (angleDiff * (speedFromObs / speedToGoal));
              speedToGoal -= speedFromObs;
            }
          }

          // Was getting a null pointer exception when using this. The internet lied about its
          // usefulness.
          // it.remove(); // avoids a ConcurrentModificationException
        }

        adjustment = normalizeAngle(adjustment);
        setTurnLeft(adjustment);
        // ahead(speedToGoal);
        setAhead(speedToGoal);
      }

      execute();
    }
  }