Exemplo n.º 1
0
 private String getUrl() {
   InetAddress addr;
   String ipAddress = null;
   try {
     addr = InetAddress.getLocalHost();
     ipAddress = addr.getHostAddress();
   } catch (UnknownHostException e) {
     PrintManager.PrintException(e);
   }
   return "tcp://" + ipAddress + ":" + mqPortnumber;
 }
 @Override
 public Boolean call() throws Exception {
   try {
     PrintManager.PrintMessage(
         this.getTaskId() + " Inserting Data of  [" + fileSize + "] Bytes in Cassandra");
     // cassandraClient.insertData(new ByteArray((int) fileSize));
     return true;
   } catch (Exception e) {
     PrintManager.PrintException(e);
   }
   return false;
 }
Exemplo n.º 3
0
  public StagedClient(Semaphore stageLock) {
    super();
    try (FileReader reader = new FileReader("CloudKon.properties")) {
      clientName = genUniQID();
      submittedTasks = new ConcurrentHashMap<>();
      Properties properties = new Properties();
      properties.load(reader);
      // hazelClient
      hazelClinetObj = new QueueHazelcastUtil().getClient();
      mapClientStatus = hazelClinetObj.getMap(CLIENT_STATUS);
      mapQLengthStatus = hazelClinetObj.getMap(QUEUELENGTH);
      mapThroughPutStatus = hazelClinetObj.getMap(THROUGHPUT_STATUS);

      numberofWorkerThreads = Long.parseLong(properties.getProperty("numberofWorkerThreads"));
      pollTime = Long.parseLong(properties.getProperty("clientPollTime"));
      fileName = properties.getProperty("taskFilePath");
      mqPortnumber = properties.getProperty("mqPortnumber");
      taskType = properties.getProperty("taskType");
      taskCount = properties.getProperty("taskCount");
      tastLength = properties.getProperty("tastLength");
      fileSize = properties.getProperty("fileSize");
      filePath = properties.getProperty("filePath");
      monitoringEnabled = properties.getProperty("monitoringEnabled").equals("true");
      throughputpolltime = Long.parseLong(properties.getProperty("monPolltime"));
      this.stageLock = stageLock;
      if (monitoringEnabled) {
        String cassServerlist = properties.getProperty("cassServerlist");
        cassandraClient = new SimpleClient();
        cassandraClient.connect(cassServerlist);
        // Create monitor
        objClientMonior =
            new ClientMonior(
                clientName,
                cassandraClient,
                submittedTasks,
                mapQLengthStatus,
                hazelClinetObj,
                throughputpolltime);
      }

    } catch (IOException e) {
      PrintManager.PrintException(e);
    }
  }
Exemplo n.º 4
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();
  }