Пример #1
0
 public void establishServerConnection() {
   try {
     ServerSocket server = new ServerSocket(5000);
   } catch (IOException e) {
     System.out.println("Could not listen on port: 5000");
     System.exit(-1);
   }
 }
Пример #2
0
  private void coordinator() throws InterruptedException {
    List<ActiveEvent> activeEvents = new ArrayList<>();
    long curTime = System.currentTimeMillis();
    for (User user : users) {
      if (user.isActive()) {
        for (Event event : user.getEvents()) {
          if (event.getDate().getTime() >= curTime) {
            activeEvents.add(new ActiveEvent(user.getName(), event.getDate(), event.getText()));
          }
        }
      }
    }
    Collections.sort(activeEvents);

    for (int i = 0; i < activeEvents.size(); i++) {
      if (i == 0) {
        Thread.sleep(activeEvents.get(i).getTime() - System.currentTimeMillis());
      } else {
        Thread.sleep(activeEvents.get(i).getTime() - activeEvents.get(i - 1).getTime());
      }
      activeEvents.get(i).print();
    }
  }
Пример #3
0
  /**
   * Concat arrays in one.
   *
   * @param arrays Arrays.
   * @return Summary array.
   */
  public static int[] concat(int[]... arrays) {
    assert arrays != null;
    assert arrays.length > 1;

    int len = 0;

    for (int[] a : arrays) len += a.length;

    int[] r = Arrays.copyOf(arrays[0], len);

    for (int i = 1, shift = 0; i < arrays.length; i++) {
      shift += arrays[i - 1].length;
      System.arraycopy(arrays[i], 0, r, shift, arrays[i].length);
    }

    return r;
  }
 public File getJavaHome() {
     String javaHome = getenv("JENKINS_JAVA_HOME");
     File home = StringUtils.isBlank(javaHome) ? null : new File(javaHome);
     if (home != null && home.isDirectory()) {
         return home;
     }
     javaHome = getenv("JAVA_HOME");
     home = StringUtils.isBlank(javaHome) ? null : new File(javaHome);
     if (home != null && home.isDirectory()) {
         return home;
     }
     javaHome = System.getProperty("java.home");
     home = StringUtils.isBlank(javaHome) ? null : new File(javaHome);
     if (home != null && home.isDirectory()) {
         return home;
     }
     return null;
 }
Пример #5
0
  @Test
  public void bindingTest() throws Exception {

    // String nativesPath = testOutput + "/build/natives";
    // System.load(nativesPath + "/librofl.so");
    System.loadLibrary("rofl");

    Class<?> clazz = Class.forName("test.BindingTest");

    assertEquals((long) 0xFFFFFFFF, clazz.getDeclaredField("GL_INVALID_INDEX").get(null));
    assertEquals(-0.5f, clazz.getDeclaredField("AL_FLANGER_DEFAULT_FEEDBACK").get(null));

    // TODO fix Exception: ...Caused by: java.lang.UnsatisfiedLinkError:
    // test.BindingTest.arrayTest0(JLjava/lang/Object;I)I
    /*
    // test values
    ByteBuffer dbb = Buffers.newDirectByteBuffer(32);
    ByteBuffer bb  = ByteBuffer.allocate(32).order(ByteOrder.nativeOrder());

    PointerBuffer dpb = PointerBuffer.allocateDirect(32);
    PointerBuffer pb  = PointerBuffer.allocate(32);

    long[] array = new long[] {1,2,3,4,5,6,7,8,9};
    int offset = 0;
    long id = 42;


    // invoke everything public
    Object bindingTest = clazz.newInstance();
    Method[] methods = clazz.getDeclaredMethods();

    for (Method method : methods) {

        // prepare method parameters
        Class<?>[] paramTypes = method.getParameterTypes();
        Object[] paramInstances = new Object[paramTypes.length];

        for (int i = 0; i < paramTypes.length; i++) {
            Class<?> paramType = paramTypes[i];
            if(paramType.isInstance(dbb)) {
                paramInstances[i] = dbb;
            }else if(paramType.isInstance(bb)) {
                paramInstances[i] = bb;
            }else if(paramType.isInstance(dpb)) {
                paramInstances[i] = dpb;
            }else if(paramType.isInstance(pb)) {
                paramInstances[i] = pb;
            }else if(paramType.isPrimitive()) { // TODO primitive types
                paramInstances[i] = offset;
            }else if(paramType.isArray()) {     // TODO array types
                paramInstances[i] = array;
            }
        }

        out.println("invoking: "+method);
        out.println("with params: ");
        for (Object param : paramInstances)
            out.print(param+", ");
        out.println();

        Object result = method.invoke(bindingTest, paramInstances);
        out.println("result: "+result);
        out.println("success");
    }
    */
  }
Пример #6
0
  public static void main(String[] args) throws IOException {

    BufferedReader in = new BufferedReader(new FileReader(args[0]));
    BufferedReader readIn = new BufferedReader(new InputStreamReader(System.in));

    int lineCount = 0;
    while (in.readLine() != null) {
      lineCount++;
    }

    // array of lines from file read-in
    String[] unsorted = new String[lineCount];
    int i = 0;

    // string we are cutting into substrings
    String sep = "";

    String roomName = "";
    int r = 0;
    String desc = "";
    String temp = "";

    List adventure = new List();

    while (i < lineCount) {
      sep = unsorted[i];
      temp = sep.substring(0, 1);
      String[][] cmds = new String[30][2];

      if (temp.equals("r")) {
        if (roomName != "") {
          adventure.insertRoom(roomName, desc, cmds);
          r = 0;
        }
        roomName = sep.substring(2, sep.length());
      }

      if (temp.equals("d")) {
        desc = desc.concat(sep.substring(2, sep.length()));
      }

      if (temp.equals("o")) {
        cmds[r][0] = sep.substring(2, sep.length());
      }

      if (temp.equals("t")) {
        cmds[r][1] = sep.substring(2, sep.length());
      }

      i++;
    }

    String room = adventure.firstRoom();

    String option = "";
    char input = 's';
    Stack history = new Stack();
    history.push(room);

    // Input from user
    while (!option.equals("q")) {
      option = readIn.readLine();

      if (option.length() > 1) {
        System.out.println("Invalid choice! Try again");
      } else {
        input = option.charAt(0);
        if (option != "") {
          // checks if its in range of valid options
          if (((int) input) - 97 < 13) {
            room = adventure.choice(room, input);
            history.push(room);
            adventure.options(room);
          } else {
            if ((int) input - 97 == 16) {
              System.out.println("Exit status: 0");
              System.exit(0);
            } else if ((int) input - 97 == 17) {
              history.restart(adventure.firstRoom());
            }
          }
        }
      }
    }
  }
Пример #7
0
  /**
   * Grabs local events and detects if events was lost since last poll.
   *
   * @param ignite Target grid.
   * @param evtOrderKey Unique key to take last order key from node local map.
   * @param evtThrottleCntrKey Unique key to take throttle count from node local map.
   * @param evtTypes Event types to collect.
   * @param evtMapper Closure to map grid events to Visor data transfer objects.
   * @return Collections of node events
   */
  public static Collection<VisorGridEvent> collectEvents(
      Ignite ignite,
      String evtOrderKey,
      String evtThrottleCntrKey,
      final int[] evtTypes,
      IgniteClosure<Event, VisorGridEvent> evtMapper) {
    assert ignite != null;
    assert evtTypes != null && evtTypes.length > 0;

    ConcurrentMap<String, Long> nl = ignite.cluster().nodeLocalMap();

    final long lastOrder = getOrElse(nl, evtOrderKey, -1L);
    final long throttle = getOrElse(nl, evtThrottleCntrKey, 0L);

    // When we first time arrive onto a node to get its local events,
    // we'll grab only last those events that not older than given period to make sure we are
    // not grabbing GBs of data accidentally.
    final long notOlderThan = System.currentTimeMillis() - EVENTS_COLLECT_TIME_WINDOW;

    // Flag for detecting gaps between events.
    final AtomicBoolean lastFound = new AtomicBoolean(lastOrder < 0);

    IgnitePredicate<Event> p =
        new IgnitePredicate<Event>() {
          /** */
          private static final long serialVersionUID = 0L;

          @Override
          public boolean apply(Event e) {
            // Detects that events were lost.
            if (!lastFound.get() && (lastOrder == e.localOrder())) lastFound.set(true);

            // Retains events by lastOrder, period and type.
            return e.localOrder() > lastOrder
                && e.timestamp() > notOlderThan
                && F.contains(evtTypes, e.type());
          }
        };

    Collection<Event> evts = ignite.events().localQuery(p);

    // Update latest order in node local, if not empty.
    if (!evts.isEmpty()) {
      Event maxEvt = Collections.max(evts, EVTS_ORDER_COMPARATOR);

      nl.put(evtOrderKey, maxEvt.localOrder());
    }

    // Update throttle counter.
    if (!lastFound.get())
      nl.put(evtThrottleCntrKey, throttle == 0 ? EVENTS_LOST_THROTTLE : throttle - 1);

    boolean lost = !lastFound.get() && throttle == 0;

    Collection<VisorGridEvent> res = new ArrayList<>(evts.size() + (lost ? 1 : 0));

    if (lost) res.add(new VisorGridEventsLost(ignite.cluster().localNode().id()));

    for (Event e : evts) {
      VisorGridEvent visorEvt = evtMapper.apply(e);

      if (visorEvt != null) res.add(visorEvt);
    }

    return res;
  }