protected void checkExceptionHandling(
      final LinkedBlockingQueue<Throwable> unexpectedExceptions,
      ExecutorTaskAgent agent,
      Future<?> future,
      Class<? extends Exception> expectedKlass,
      boolean isExpected)
      throws InterruptedException {

    try {
      future.get();
    } catch (ExecutionException ce) {
      assertTrue(expectedKlass.isInstance(ce.getCause()));
      // ok
    }
    agent.awaitPendingTasks();

    if (expectedKlass == null || isExpected) {
      assertTrue(unexpectedExceptions.size() == 0);
      return;
    } else {
      assertTrue(unexpectedExceptions.size() == 1);
      Throwable removed = unexpectedExceptions.remove();
      assertTrue(expectedKlass.isInstance(removed));
    }
  }
Esempio n. 2
0
 @Override
 public void run() {
   while (true) {
     for (SocketProcessor socket : queue) {
       if (socket.isRequestTextLoader) {
         socket.isRequestTextLoader = false;
         // TODO
         Handler handler = new FileHandler(new ErrorHandler());
         // @SuppressWarnings("unused")
         RequestBuilder rb = new RequestBuilder(socket.requestText);
         Request request = rb.getRequest();
         Response response = handler.handle(request);
         socket.sendResponse(response);
         queue.remove(socket);
         socket.close();
         // socket.sendTestResponse(socket.requestText);
         /*
          * try { socket.sendResponse( "<html><body><h1>Hello
          * World!!!</h1></body></html>");
          * socket.bufferWritter.flush(); System.out.print("Response
          * sent!"); } catch (IOException e) { // TODO Auto-generated
          * catch block e.printStackTrace(); }
          */
       }
     }
   }
 }
 /** @since 3.0 */
 public void terminateJob(String jobId) throws CoreException {
   DebugUtil.trace(
       DebugUtil.JOB_TRACING,
       "RTS {0}: terminate job #{1}",
       getResourceManager().getConfiguration().getName(),
       jobId); //$NON-NLS-1$
   Job job = jobs.get(jobId);
   pendingJobQueue.remove(job);
   job.cancel();
 }
Esempio n. 4
0
 private void removeListenerFromCandidates(DistributionRequest listener) {
   /** Locker variable should be modified EXACTLY like candidateListeners variable. */
   logger.debug("Updating the candidate list [" + listener.toString() + " (removed)].");
   if (candidatesForNextRound.contains(listener)) {
     candidateListeners.put(listener, makeDataEnum(listener));
     candidatesForNextRound.remove(listener);
   } else {
     locker.remove(listener);
     candidateListeners.remove(listener);
   }
 }
 @Override
 public E remove() {
   return queue.remove();
 }
 @Override
 public boolean remove(Object o) {
   return queue.remove(o);
 }
Esempio n. 7
0
  /**
   * @param args
   * @throws Exception
   */
  public static void main(String[] args) throws Exception {
    //		nextMonitor = new Object();
    monitor = new Object();

    try {
      myIP = InetAddress.getLocalHost().getHostAddress();
    } catch (UnknownHostException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    ss = new ServerSocket(serverPort);

    if (args.length == 0) {
      next = new Socket(myIP, serverPort);
    } else if (args.length == 1) {
      next = new Socket(InetAddress.getByName(args[0]), serverPort);
    } else {
      System.out.println("Usage: peer [ip address]");
      System.exit(0);
    }

    prev = ss.accept();
    nextIn = new BufferedReader(new InputStreamReader(next.getInputStream()));
    nextOut = new PrintStream(next.getOutputStream(), true);
    prevIn = new BufferedReader(new InputStreamReader(prev.getInputStream()));
    prevOut = new PrintStream(prev.getOutputStream(), true);

    nextInput = new Thread(new NextInput());
    nextInput.start();
    nextOutput = new Thread(new NextOutput());
    nextOutput.start();
    prevOutput = new Thread(new PrevOutput());
    prevOutput.start();
    connectionHandler = new Thread(new ConnectionHandler());
    connectionHandler.start();
    prevInput = new Thread(new PrevInput());
    prevInput.start();

    BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in));
    String userInput;
    try {

      mainloop:
      while (!quit) {
        if ((userInput = stdIn.readLine()) != null) {
          if (userInput.toLowerCase().equals("quit")) {
            quit = true;
            break mainloop;
          } else if (Peer.debug && userInput.toLowerCase().equals("debug")) {
            System.out.println("PREV: " + prev.toString());
            System.out.println("NEXT: " + next.toString());
            System.out.println("SocketQueue empty? " + socketQueue.isEmpty());
            System.out.println("ChatQueue empty? " + chatQueue.isEmpty());
            System.out.println("reconnectQueue empty? " + reconnectQueue.isEmpty());
            System.out.println("Hold = " + hold + ", prevDone = " + prevDone + ", quit = " + quit);
          } else if (Peer.debug && userInput.toLowerCase().equals("test")) {
            Peer.prevOut.println("test");
          } else {
            Peer.chatQueue.add(Peer.myIP + ": " + userInput);
          }
        }
      }
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    while (!socketQueue.isEmpty()) {
      Socket s = socketQueue.remove();
      PrevOutput.sendReconnect(s);
    }

    try {
      prevOut.println("Hold");
      Thread.sleep(2000);
    } catch (InterruptedException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    while (!chatQueue.isEmpty()) {
      nextOut.println(chatQueue.remove());
    }

    prevOut.println(next.getInetAddress().getHostAddress());

    prevOut.close();
    prevIn.close();
    prev.close();

    nextOut.close();
    nextIn.close();
    next.close();

    ss.close();
  }
 /**
  * Removes selected IChangesListener from list
  *
  * @param listener Listener to be removed from list
  */
 public void removeWorldChangesListener(IChangesListener listener) {
   listeners.remove(listener);
 }
Esempio n. 9
0
 public void removeMessage() {
   Term message = mailbox.remove();
   setX(0, message);
   // TODO: remove timer
 }
Esempio n. 10
0
 public void loop_rec_end() {
   // TODO: this is technically not correct
   // TODO: we need to advance the message index instead
   mailbox.remove();
 }