Exemplo n.º 1
0
  @Test
  public void testBackpressure() throws Exception {
    createAndRegisterStats();
    MockStatsSource.delay = 20;

    /*
     * Generate a bunch of requests, should get backpressure on some of them
     */
    for (int ii = 0; ii < 30; ii++) {
      m_mvoltdb
          .getStatsAgent()
          .performOpsAction(m_mockConnection, 32, OpsSelector.STATISTICS, subselect("DR", 0));
    }

    boolean hadBackpressure = false;
    for (int ii = 0; ii < 30; ii++) {
      ClientResponseImpl response = responses.take();

      if (response.getStatus() == ClientResponse.GRACEFUL_FAILURE) {
        assertTrue("Too many pending stat requests".equals(response.getStatusString()));
        hadBackpressure = true;
      }
    }
    assertTrue(hadBackpressure);

    /*
     * Now having recieved all responses, it should be possible to collect the stats
     */
    m_mvoltdb
        .getStatsAgent()
        .performOpsAction(m_mockConnection, 32, OpsSelector.STATISTICS, subselect("DR", 0));
    ClientResponseImpl response = responses.take();
    verifyResults(response);
  }
Exemplo n.º 2
0
  private boolean schedule() {
    try {
      /* hash com os workers em processamento. Indexado pela tarefa*/
      workingOn = new Hashtable();
      currentStatus = Phase.MAP;
      while (!currentStatus.equals(Phase.ERROR)) {

        Worker worker = (Worker) workerQueue.take();
        Task task = (Task) taskQueue.take();
        TaskStatus op = task.getStatus();

        /* termina escalonamento se encontra flag de fim*/
        if (op.value() == TaskStatus._END) {
          break;
        }
        workingOn.put(task, worker);
        worker.execute(channel, task);
      }

      if (currentStatus.equals(Phase.ERROR)) {
        return false;
      }

      return true;
    } catch (Exception e) {
      exception = LogError.getStackTrace(e);
      reporter.report(0, "MasterServant::schedule - Escalonamento interrompido. \n" + exception);
      return false;
    }
  }
Exemplo n.º 3
0
  public void run() {
    while (true) {
      try {
        if (locker.isEmpty()) {
          logger.debug(
              "Waiting(locked) for requests or data items, Number of total listeners: "
                  + listeners.size());
          locker.put(locker.take());
          logger.debug(
              "Lock released, trying to find interest listeners (total listeners:"
                  + listeners.size()
                  + ")");
        }
      } catch (InterruptedException e) {
        logger.error(e.getMessage(), e);
      }

      for (Entry<DistributionRequest, DataEnumerator> item : candidateListeners.entrySet()) {
        boolean success = flushStreamElement(item.getValue(), item.getKey());
        if (success == false) removeListener(item.getKey());
        else {
          if (!item.getValue().hasMoreElements()) {
            removeListenerFromCandidates(item.getKey());
            // As we are limiting the number of elements returned by the JDBC driver
            // we consume the eventual remaining items.
            consume(null, item.getKey().getVSensorConfig());
          }
        }
      }
    }
  }
Exemplo n.º 4
0
  @Override
  public ErisMessage receive(long timeout)
      throws org.eris.messaging.TransportException, org.eris.messaging.ReceiverException,
          org.eris.messaging.TimeoutException {
    checkClosed();
    if (_creditMode == CreditMode.EXPLICT && _capacity == 0) {
      throw new org.eris.messaging.ReceiverException(
          "Since CreditMode is EXPLICIT, you need to explicity set the capacity before calling receive");
    }
    issuePreReceiveCredit();
    ErisMessage msg = null;
    try {
      if (timeout == 0) {
        msg = _queue.take();
      } else {
        msg = _queue.poll(timeout, TimeUnit.MILLISECONDS);
      }
    } catch (InterruptedException e) {
      checkClosed();
    }

    if (msg != null) {
      issuePostReceiveCredit();
      return msg;
    } else {
      checkClosed();
      if (timeout == 0) {
        throw new org.eris.messaging.ReceiverException("Receive operation was interrupted");
      } else {
        throw new org.eris.messaging.TimeoutException(
            "Timeout waiting for message to be available");
      }
    }
  }
  @Override
  public void run() {
    Thread videoDecoder = new Thread(new VideoDecoder(this));
    videoDecoder.start();
    long lastFrameWrite = System.nanoTime() - NANOSECONDS_PER_FRAME;
    long timeNow = 0;

    try {
      while ((!videoDecoded || !imgBuffer.isEmpty()) && frame.isVisible()) {
        timeNow = System.nanoTime();
        if (timeNow - lastFrameWrite >= NANOSECONDS_PER_FRAME) {
          lastFrameWrite = timeNow;
          BufferedImage img = imgBuffer.take();
          g.drawImage(img, 0, 0, frame.getWidth(), frame.getHeight(), null);

          ByteArrayOutputStream bos = new ByteArrayOutputStream();
          ImageIO.write(img, "jpg", bos);
          proxy.receiveImage(ByteBuffer.wrap(bos.toByteArray()));
        }
      }
    } catch (IOException | InterruptedException e) {
      // other user has disconnected, stop sending video
    }

    imgBuffer.clear();
    frame.setVisible(false);
    try {
      proxy.setFrameVisible(true, false);
    } catch (IOException e) {
      System.err.println("The other user has disconnected, stopping video.");
    }
  }
Exemplo n.º 6
0
 @Override
 public Boolean call() {
   synchronized (isStarted) {
     isStarted.set(true);
     isStarted.notify();
   }
   try {
     while (true) {
       flushPage = null;
       try {
         flushPage = flushQ.take();
         if (flushPage == POISON_PILL || terminateFlag.get()) {
           return true;
         }
       } catch (InterruptedException e) {
         if (flushPage == null) {
           continue;
         }
       }
       flushPage.flush();
       emptyQ.offer(flushPage);
     }
   } catch (Exception e) {
     if (LOGGER.isLoggable(Level.INFO)) {
       LOGGER.info("-------------------------------------------------------------------------");
       LOGGER.info("LogFlusher is terminating abnormally. System is in unusalbe state.");
       LOGGER.info("-------------------------------------------------------------------------");
     }
     e.printStackTrace();
     throw e;
   }
 }
Exemplo n.º 7
0
  public void run() {
    LOG.info("TopologyAssign thread has been started");
    runFlag = true;

    while (runFlag) {
      TopologyAssignEvent event;
      try {
        event = queue.take();
      } catch (InterruptedException e1) {
        continue;
      }
      if (event == null) {
        continue;
      }

      /** topology分配 */
      boolean isSuccess = doTopologyAssignment(event);

      if (isSuccess == false) {
      } else {
        try {
          cleanupDisappearedTopology();
        } catch (Exception e) {
          LOG.error("Failed to do cleanup disappear topology ", e);
          continue;
        }
      }
    }
  }
  @Override
  public void tempFileAnalysis(
      LinkedBlockingQueue<String> urlQ, LinkedBlockingQueue<DataModle> dmQ) {
    logger.info("now useful URL queue size:" + urlQ.size());

    DataModle dm = null;
    String url = "";
    try {
      url = urlQ.take();
    } catch (InterruptedException e2) {
      logger.warn("url queue is empty,can not take a dm");
      return;
    }

    try {
      dm = elementFilter(url);
    } catch (IOException e1) {
      logger.error("can not generate a dm");
      return;
    }

    try {
      dmQ.put(dm);
    } catch (InterruptedException e) {
      logger.warn("unfinishDmQ is full,can not put a dm");
    }
  }
Exemplo n.º 9
0
 public void run() {
   boolean closed = false;
   while (!closed) {
     try {
       Object o = queue.take();
       if (CMD_CLOSE.equals(o)) {
         transport.close();
         closed = true;
       } else if (CMD_FLUSH.equals(o)) {
         transport.flush();
       } else if (o instanceof byte[]) {
         transport.write((byte[]) o);
       } else if (o instanceof Integer) {
         transport.write((Integer) o);
       }
     } catch (IOException e) {
       Log.e(TAG, "Unable to send deferred data", e);
       try {
         transport.flush();
       } catch (IOException ioe) {
         Log.d(TAG, "transport was closed, dispatching disconnect event");
         bridge.dispatchDisconnect(false);
         closed = true;
       }
     } catch (InterruptedException e) {
       Log.e(TAG, "received an unexpected thread interrupt, exiting", e);
       transport.close();
       bridge.dispatchDisconnect(false);
       closed = true;
     }
   }
 }
Exemplo n.º 10
0
 /** {@inheritDoc} */
 public ScheduledTask getNextTask(boolean wait) throws InterruptedException {
   ScheduledTask task = queue.poll();
   if ((task != null) || (!wait)) {
     return task;
   }
   return queue.take();
 }
Exemplo n.º 11
0
  /** Method description */
  @Override
  public void run() {
    QueueItem item = null;

    while (!stopped) {
      try {
        item = queue.take();

        long start = System.currentTimeMillis();

        process(item);

        long end = System.currentTimeMillis() - start;

        if (end > 0) {
          averageProcessingTime = (averageProcessingTime + end) / 2;
        }
      } catch (Exception e) {
        log.log(
            Level.SEVERE,
            this.getClass().getName()
                + ",("
                + getName()
                + ") Exception during packet processing: "
                + item.getPacket(),
            e);
      }

      ++runsCnt;
    }
  }
Exemplo n.º 12
0
  @Override
  public void run() {
    while (running) {
      try {
        User user = userFIFO.take();
        try {
          register(user);
          user.isCreated = true;
          user.message = "Användaren skapades";
          user.significantChange();
          edit(user);
          edit2(user);
          logout();
          user.isDone = true;
          user.message = "Användaren är klar!";
          user.significantChange();
        } catch (TimeoutException q) {
          user.isAlive = false;
          user.message = "Registrering misslyckades";
          user.significantChange();
        }

      } catch (InterruptedException e) {
        terminate();
      }
    }
  }
Exemplo n.º 13
0
 /** Get an event from the queue. */
 synchronized AppletEvent getNextEvent() throws InterruptedException {
   while (queue == null || queue.isEmpty()) {
     wait();
   }
   int eventId = queue.take();
   return new AppletEvent(this, eventId, null);
 }
 @Override
 public void run() {
   try {
     while (true) {
       Request request = submittedRequests.take();
       long traceMask = ZooTrace.CLIENT_REQUEST_TRACE_MASK;
       if (request.type == OpCode.ping) {
         traceMask = ZooTrace.CLIENT_PING_TRACE_MASK;
       }
       if (LOG.isTraceEnabled()) {
         ZooTrace.logRequest(LOG, traceMask, 'P', request, "");
       }
       if (Request.requestOfDeath == request) {
         break;
       }
       pRequest(request);
     }
   } catch (InterruptedException e) {
     LOG.error("Unexpected interruption", e);
   } catch (RequestProcessorException e) {
     if (e.getCause() instanceof XidRolloverException) {
       LOG.info(e.getCause().getMessage());
     }
     LOG.error("Unexpected exception", e);
   } catch (Exception e) {
     LOG.error("Unexpected exception", e);
   }
   LOG.info("PrepRequestProcessor exited loop!");
 }
Exemplo n.º 15
0
 @Override
 protected Packet read() throws IOException {
   try {
     return input.take();
   } catch (final InterruptedException e) {
     throw new IOException(e);
   }
 }
Exemplo n.º 16
0
 public OutputLine nextBlocking() {
   try {
     return m_output.take();
   } catch (InterruptedException e) {
     e.printStackTrace();
   }
   return null;
 }
 @Override
 public Message take() {
   try {
     return queue.take();
   } catch (InterruptedException e) {
     return null;
   }
 }
 public Emage next() {
   try {
     return queue.take();
   } catch (InterruptedException e) {
     log.error(e.getMessage());
   }
   return null;
 }
 private byte readByteFromSerialBuffer() throws InterruptedException, ShieldFrameNotComplete {
   if (ShieldFrameTimeout != null && ShieldFrameTimeout.isTimeout())
     throw new ShieldFrameNotComplete();
   isSerialBufferWaiting = true;
   byte temp = serialBuffer.take();
   if (ShieldFrameTimeout != null) ShieldFrameTimeout.resetTimer();
   return temp;
 }
Exemplo n.º 20
0
 public Message getNextMessageToSend() throws InterruptedException {
   try {
     return blockDataQ.take();
   } catch (InterruptedException e) {
     if (!stopped) {
       e.printStackTrace();
     }
     throw e;
   }
 }
Exemplo n.º 21
0
  /** @see stream.io.AbstractStream#readNext() */
  @Override
  public Data readNext() throws Exception {

    try {
      Data item = queue.take();
      return item;
    } catch (Exception e) {
      throw e;
    }
  }
Exemplo n.º 22
0
 @Override
 public void run() {
   while (!queue.isEmpty()) {
     try {
       Task t = queue.take();
       t.run();
     } catch (InterruptedException e) {
       e.printStackTrace();
     }
   }
 }
Exemplo n.º 23
0
  @Override
  public void run() {
    while (true) {
      try {
        Future f = futures.take();

        f.get();
      } catch (Throwable ex) {
        Logger.getLogger(FutureHelper.class.getName()).log(Level.SEVERE, null, ex);
      }
    }
  }
Exemplo n.º 24
0
 private void getAndInitNewPage() {
   appendPage = null;
   while (appendPage == null) {
     try {
       appendPage = emptyQ.take();
     } catch (InterruptedException e) {
       // ignore
     }
   }
   appendPage.reset();
   appendPage.setFileChannel(appendChannel);
   flushQ.offer(appendPage);
 }
Exemplo n.º 25
0
  public void dispatch() {
    while (true) {
      Runnable methodRequest;
      try {
        methodRequest = activationQueue.take();

        // 防止个别任务执行失败导致线程终止的代码在run方法中
        methodRequest.run();
      } catch (InterruptedException e) {
        // 处理该异常
      }
    }
  }
Exemplo n.º 26
0
 @Test
 public void testInvalidStatisticsSubselector() throws Exception {
   createAndRegisterStats();
   m_mvoltdb
       .getStatsAgent()
       .performOpsAction(m_mockConnection, 32, OpsSelector.STATISTICS, subselect("CRAZY", 0));
   ClientResponseImpl response = responses.take();
   assertEquals(ClientResponse.GRACEFUL_FAILURE, response.getStatus());
   assertEquals(
       "First argument to @Statistics must be a valid STRING selector, instead was CRAZY",
       response.getStatusString());
   System.out.println(response.toJSONString());
 }
  @Test
  public void testOffer() throws Exception {
    RpcStub handler1 = makeHandler(2);
    RpcStub handler2 = makeHandler(0);

    MultiplexPoolHandler han = new MultiplexPoolHandler(Collections.singleton(handler1), 2, 2);
    han.offer(handler1);
    han.offer(handler2);
    LinkedBlockingQueue<RpcStub> readyQueue = FieldUtil.getValue(han, "readyQueue");
    assertEquals(2, readyQueue.size());
    assertEquals(handler1, readyQueue.take());
    assertEquals(handler1, readyQueue.take());
  }
  @Override
  public void run() {
    try {
      while (!finished) {
        Request request = queuedRequests.take();
        if (LOG.isTraceEnabled()) {
          ZooTrace.logRequest(LOG, ZooTrace.CLIENT_REQUEST_TRACE_MASK, 'F', request, "");
        }
        if (request == Request.requestOfDeath) {
          break;
        }
        // We want to queue the request to be processed before we submit
        // the request to the leader so that we are ready to receive
        // the response
        nextProcessor.processRequest(request);

        // We now ship the request to the leader. As with all
        // other quorum operations, sync also follows this code
        // path, but different from others, we need to keep track
        // of the sync operations this Observer has pending, so we
        // add it to pendingSyncs.
        switch (request.type) {
          case OpCode.sync:
            zks.pendingSyncs.add(request);
            zks.getObserver().request(request);
            break;
          case OpCode.create:
          case OpCode.create2:
          case OpCode.delete:
          case OpCode.setData:
          case OpCode.reconfig:
          case OpCode.setACL:
          case OpCode.multi:
          case OpCode.check:
            zks.getObserver().request(request);
            break;
          case OpCode.createSession:
          case OpCode.closeSession:
            // Don't forward local sessions to the leader.
            if (!request.isLocalSession()) {
              zks.getObserver().request(request);
            }
            break;
        }
      }
    } catch (Exception e) {
      LOG.error("Unexpected exception causing exit", e);
    }
    LOG.info("ObserverRequestProcessor exited loop!");
  }
Exemplo n.º 29
0
  @Test
  public void testCollectDRStats() throws Exception {
    createAndRegisterStats();
    m_mvoltdb
        .getStatsAgent()
        .performOpsAction(m_mockConnection, 32, OpsSelector.STATISTICS, subselect("DR", 0));
    ClientResponseImpl response = responses.take();

    assertEquals(ClientResponse.SUCCESS, response.getStatus());
    VoltTable results[] = response.getResults();
    System.out.println(results[0]);
    System.out.println(results[1]);
    verifyResults(response);
  }
Exemplo n.º 30
0
  public void run() {
    while (true) {
      try {
        Job job = deleteJobQueue.take();
        job = jobDao.getById(job.getId());
        jobDao.delete(job);
        log.info(String.format("delete job id '%s' at %s", job.getId(), new Date()));

      } catch (InterruptedException e) {
        e
            .printStackTrace(); // To change body of catch statement use File | Settings | File
                                // Templates.
      }
    }
  }