예제 #1
0
  private static void fdCallbackHandler(int fd) {
    FD_HANDLER_TYPE handler = (FD_HANDLER_TYPE) fdHashTable.get(Integer.toString(fd));

    if (handler != null) {
      handler.handle(fd);
    } else System.out.println("Ooops -- no handler for fd");
  }
예제 #2
0
 public static ZigBee findRemote(long address64) {
   ZigBee zb;
   synchronized (knownNodes) {
     zb = knownNodes.get(new Long(address64));
   }
   return zb;
 }
예제 #3
0
  private static void timerCallbackHandler(int handlerNum, long currentTime, long scheduledTime) {
    TIMER_HANDLER_TYPE handler =
        (TIMER_HANDLER_TYPE) timerHashTable.get(Integer.toString(handlerNum));

    if (handler != null) {
      handler.handle(currentTime, scheduledTime);
    } else System.out.println("Ooops -- no handler for timer");
  }
예제 #4
0
  /** ** Gets the SMSoutboubdGateway for the specified name */
  public static SMSOutboundGateway GetSMSGateway(String name) {

    /* get handler */
    if (StringTools.isBlank(name)) {
      return null;
    } else {
      return SmsGatewayHandlerMap.get(name.toLowerCase());
    }
  }
예제 #5
0
  public void count_bip_exits(String hostname) {
    int[] pos;

    pos = (int[]) mbips.get(hostname);
    if (pos == null) {
      pos = make_int_array(MBIPS_NUM_POS);
      mbips.put(hostname, pos);
    }

    ++pos[MBIPS_BIPS_EXITTED_POS];
    return;
  }
예제 #6
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);
    }
  }
예제 #7
0
  public void count_account_stat(String hostname, AccountStatisticReturnVal acstat) {
    double[] pos;

    pos = (double[]) mtimes.get(hostname);
    if (pos == null) {
      pos = make_double_array(MTIMES_NUM_POS);
      mtimes.put(hostname, pos);
    }

    pos[MTIMES_CPU_TIME_POS] += acstat.get_cpu_time();
    pos[MTIMES_WALL_TIME_POS] += acstat.get_wall_time();
    return;
  }
예제 #8
0
  static ZigBee findOrCreateRemote(long address64, short address16) {
    ZigBee zb;
    synchronized (knownNodes) {
      zb = knownNodes.get(new Long(address64));

      if (zb == null) {
        zb = new ZigBee();
        zb.updateAddress64(address64);
      }
    }
    zb.updateAddress16(address16);
    return zb;
  }
예제 #9
0
  private static void msgCallbackHandler(int handlerNum, int msgInstance, int byteArray) {
    handlerHashData handlerData = (handlerHashData) msgHashTable.get(Integer.toString(handlerNum));

    if (handlerData != null) {
      Object object;
      try {
        int formatter = IPC_msgInstanceFormatter(msgInstance);
        object = unmarshallMsgData(formatter, byteArray, handlerData.dataClass);
        handlerData.handler.handle(new MSG_INSTANCE(msgInstance), object);
      } catch (Exception e) {
        handleException("msgCallbackHandler", IPC_msgInstanceName(msgInstance), e);
      }
    } else System.out.println("Ooops -- no handler for " + IPC_msgInstanceName(msgInstance));
  }
예제 #10
0
  private static void queryNotifyCallbackHandler(int handlerNum, int msgInstance, int byteArray) {
    String hashKey = Integer.toString(handlerNum);
    handlerHashData handlerData = (handlerHashData) msgHashTable.get(hashKey);

    msgHashTable.remove(hashKey);
    if (handlerData != null) {
      Object object;
      try {
        object =
            unmarshallMsgData(
                IPC_msgInstanceFormatter(msgInstance), byteArray, handlerData.dataClass);
        handlerData.handler.handle(new MSG_INSTANCE(msgInstance), object);
      } catch (Exception e) {
        handleException("queryNotifyCallbackHandler", IPC_msgInstanceName(msgInstance), e);
      }
    } else
      System.out.println(
          "Ooops -- no query notification handler for " + IPC_msgInstanceName(msgInstance));
  }
 @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();
    }
  }
예제 #13
0
 public static String[] lookUp(String key) {
   Map<String, String[]> intervals = fillMap();
   return intervals.get(key);
 }
예제 #14
0
  void processCommandResponse(byte[] packet, int offset) throws ZigBeeException, SerialException {
    String command = new String(packet, offset, 2); // commands are all 2 characters.
    Command c;
    synchronized (outstandingCommands) {
      c = outstandingCommands.get(packet[4]);
    }
    if (c == null) {
      System.err.println("Command " + command + " command already timed out or not issued.");
    } else {
      if (c.command != ZigBeeCommands.ND || packet.length == 9) {
        c.status = new Byte(packet[offset + 2]);
        synchronized (outstandingCommands) {
          outstandingCommands.values().remove(c);
        }
      } else {
        c = null;
      }
    }

    if (packet[offset + 2] != 0) {
      // Need to get the message to the user.
      if (c != null && packet[offset + 2] == 4) {
        if (c.retransmits++ < c.maxRetransmits) {
          executeCommand(c, 0);
          return;
        }
      }
      if (c != null) {
        synchronized (c) {
          c.notifyAll();
        }
      }
      return;
    }

    // Did we get some data back as well?
    if (packet.length > offset + 4) {
      command = command.toUpperCase();
      ZigBeeCommands zbc;
      try {
        zbc = ZigBeeCommands.valueOf(command);
        if (c != null) {
          if (zbc.responseString) {
            c.response = bytesToString(packet, offset + 3, packet.length - offset - 1);
          } else {
            c.response = new Long(bytesToNum(packet, offset + 3, 8, packet.length - 1));
          }
        }
        zbc.process(this, packet, offset + 3);
      } catch (IllegalArgumentException iae) {
        if (c != null) {
          c.response = new Long(bytesToNum(packet, offset + 3, 8, packet.length - 1));
        }
        // unhandled message, just ignore it.
      }
    }

    // let any waiters know we are done.
    if (c != null) {
      synchronized (c) {
        c.notifyAll();
      }
    }
  }