Esempio n. 1
0
  private void postTasks(String strFileName)
      throws NumberFormatException, FileNotFoundException, InterruptedException {
    stageLock.acquire();
    Thread.currentThread().setPriority(8);
    Semaphore objSemaphore = new Semaphore(0);

    Set<Task> objects = null;
    url = getUrl();
    qu = new QueueDetails(REQUESTQ, RESPONSEQ, clientName, url);
    PrintManager.PrintMessage("creating tasks");
    objects = readFileAndMakeTasks(strFileName, clientName);
    PrintManager.PrintProdMessage("Posting tasks started " + System.nanoTime());
    TaskQueueFactory.getQueue().postTask(objSemaphore, objects, REQUESTQ, url, clientName);

    String time = String.valueOf(System.nanoTime());
    // check the mode of operation

    // Get the already running workers
    long numOfWorkers = WorkerMonitor.getNumOfWorkerThreads(hazelClinetObj);
    PrintManager.PrintProdMessage("numOfWorkers " + numOfWorkers);
    if (numOfWorkers == 0) {
      numOfWorkers = 1;
    }
    long loopCount = objects.size() / (numberofWorkerThreads);
    loopCount = loopCount == 0 ? 1 : loopCount;
    PrintManager.PrintProdMessage("Number of Cleint Q Advertizements " + loopCount);
    DistributedQueue queue = QueueFactory.getQueue();
    objSemaphore.acquire();
    for (int loopIndex = 0; loopIndex < loopCount; loopIndex++) {
      queue.pushToQueue(qu);
    }
    PrintManager.PrintProdMessage("Cleint Q Advertizements done");
    mapClientStatus.putIfAbsent(this.clientName + "," + STARTED, time);
    // Start monitoring the Submitted Queue length for completion
    new Thread(this).start();
    // Start monitoring the Submitted Queue length for reporting
    if (monitoringEnabled) {
      PrintManager.PrintProdMessage("monitoringEnabled starting Clinet monitor");
      new Thread(objClientMonior).start();
    }
  }
Esempio n. 2
0
  @Override
  public void run() {
    long startTime = System.currentTimeMillis();
    long startMeasureTime = System.currentTimeMillis();
    long currtime = startMeasureTime;
    int counter = 0;
    while (!submittedTasks.isEmpty()) {
      currtime = System.currentTimeMillis();
      if (currtime - startMeasureTime >= throughputpolltime) {
        startMeasureTime = currtime;
        PrintManager.PrintProdMessage("Recording throughput " + System.nanoTime() + " " + counter);
        mapThroughPutStatus.putIfAbsent(
            clientName + "," + System.nanoTime(), String.valueOf(counter));
        counter = 0;
      }
      Task task = TaskQueueFactory.getQueue().retrieveTask(RESPONSEQ, url, clientName);
      if (task != null) {
        if (task.isMultiTask()) {
          for (Task tasks : task.getTasks()) {
            PrintManager.PrintMessage("Task[" + tasks.getTaskId() + "]completed");
            submittedTasks.remove(tasks.getTaskId());
            counter++;
          }
        } else {
          PrintManager.PrintMessage("Task[" + task.getTaskId() + "]completed");
          submittedTasks.remove(task.getTaskId());
          counter++;
        }
      }
      // Advertise tasks again after some time
      if (System.currentTimeMillis() - startTime > pollTime) {
        PrintManager.PrintProdMessage(
            "PANIC !!! Queue Resubmistions by Client at " + System.nanoTime());
        startTime = System.currentTimeMillis();
        DistributedQueue queue = QueueFactory.getQueue();
        queue.pushToQueue(qu);
      }
    }
    if (monitoringEnabled) {
      // Shutdown monitor
      objClientMonior.setClientShutoff(true);
    }
    String time = String.valueOf(System.nanoTime());
    String[] valFin = {clientName, String.valueOf(System.nanoTime()), FINISHED};
    mapClientStatus.putIfAbsent(this.clientName + "," + FINISHED, time);
    if (monitoringEnabled) {
      cassandraClient.insertClientStatus(valFin);
      try {
        Thread.sleep(6000);
      } catch (InterruptedException e) {
        PrintManager.PrintException(e);
      }
    }

    PrintManager.PrintProdMessage("Shutting down Client " + this.clientName + " at " + time);
    // Shutdown hazel
    hazelClinetObj.shutdown();
    if (monitoringEnabled) {
      cassandraClient.close();
    }
    PrintManager.PrintProdMessage("Lock status" + this.stageLock.hasQueuedThreads());
    this.stageLock.release();
  }