Ejemplo n.º 1
0
    private void initialize(Map<HRegionLocation, FlushWorker> serverToFlushWorkerMap) {
      if (serverToFlushWorkerMap == null) {
        return;
      }

      long averageCalcSum = 0;
      int averageCalcCount = 0;
      for (Map.Entry<HRegionLocation, FlushWorker> entry : serverToFlushWorkerMap.entrySet()) {
        HRegionLocation addr = entry.getKey();
        FlushWorker worker = entry.getValue();

        long bufferedCounter = worker.getTotalBufferedCount();
        long failedCounter = worker.getTotalFailedCount();
        long serverMaxLatency = worker.getMaxLatency();
        AtomicAverageCounter averageCounter = worker.getAverageLatencyCounter();
        // Get sum and count pieces separately to compute overall average
        SimpleEntry<Long, Integer> averageComponents = averageCounter.getComponents();
        long serverAvgLatency = averageCounter.getAndReset();

        this.totalBufferedPutCounter += bufferedCounter;
        this.totalFailedPutCounter += failedCounter;
        if (serverMaxLatency > this.maxLatency) {
          this.maxLatency = serverMaxLatency;
        }
        averageCalcSum += averageComponents.getKey();
        averageCalcCount += averageComponents.getValue();

        this.serverToBufferedCounterMap.put(addr.getHostnamePort(), bufferedCounter);
        this.serverToFailedCounterMap.put(addr.getHostnamePort(), failedCounter);
        this.serverToAverageLatencyMap.put(addr.getHostnamePort(), serverAvgLatency);
        this.serverToMaxLatencyMap.put(addr.getHostnamePort(), serverMaxLatency);
      }
      this.overallAverageLatency = averageCalcCount != 0 ? averageCalcSum / averageCalcCount : 0;
    }
Ejemplo n.º 2
0
  @Override
  public String remove(Object k) {
    int rowToRemove = -1;
    String removedValue = null;

    for (int i = 0; i < data.size(); i++) {
      SimpleEntry<String, String> row = data.get(i);

      if (caseSensitive) {
        if (row.getKey().equals(k)) {
          removedValue = row.getValue();
          rowToRemove = i;
        }
      } else {
        if (row.getKey().equalsIgnoreCase(k.toString())) {
          removedValue = row.getValue();
          rowToRemove = i;
        }
      }
    }

    if (rowToRemove >= 0) {
      data.remove(rowToRemove);
      fireDataChangeNotification();
      return removedValue;
    } else return null;
  }
Ejemplo n.º 3
0
 @Override
 public void streamTo(OutputStream out) throws IOException {
   Streamable.Helper.intToStream(data.size(), out);
   for (SimpleEntry<String, String> entry : data) {
     Streamable.Helper.stringToStream(entry.getKey(), out);
     Streamable.Helper.stringToStream(entry.getValue(), out);
   }
 }
Ejemplo n.º 4
0
 public SimpleEntry<String, Integer> solveBoard(int id) {
   // Anem a buscar el tauler a la bd, el resolem i el retornem
   SimpleEntry<String, Integer> board = dataController.getBoard(id);
   SudokuGame sudokuGame = new SudokuGame(board.getKey(), board.getValue());
   int time = sudokuGame.sudokuSolve();
   SimpleEntry<String, Integer> result =
       new SimpleEntry<String, Integer>(sudokuGame.boardToString(), time);
   return result;
 }
  private ArrayList<SimpleEntry<String, MethodEnvironment>> getMethodEnvironmentsFor(
      String methodName) {
    ArrayList<SimpleEntry<String, MethodEnvironment>> sameNameMethodEnvironments =
        new ArrayList<SimpleEntry<String, MethodEnvironment>>();

    for (SimpleEntry<String, MethodEnvironment> methodEnvironment : _allMethods)
      if (methodEnvironment.getKey().equals(methodName))
        sameNameMethodEnvironments.add(methodEnvironment);

    return sameNameMethodEnvironments;
  }
Ejemplo n.º 6
0
  @Override
  public String get(Object o) {
    for (SimpleEntry<String, String> row : data) {
      if (caseSensitive) {
        if (row.getKey().equals(o)) return row.getValue();
      } else {
        if (row.getKey().equalsIgnoreCase(o.toString())) return row.getValue();
      }
    }

    return null;
  }
Ejemplo n.º 7
0
  @Override
  public String put(String k, String v) {
    for (SimpleEntry<String, String> row : data) {
      if (caseSensitive) {
        if (row.getKey().equals(k)) {
          String oldValue = row.getValue();
          row.setValue(v);
          for (TableModelListener listener : listeners)
            listener.tableChanged(new TableModelEvent(this));
          return oldValue;
        }
      } else {
        if (row.getKey().equalsIgnoreCase(k)) {
          String oldValue = row.getValue();
          row.setValue(v);
          for (TableModelListener listener : listeners)
            listener.tableChanged(new TableModelEvent(this));
          return oldValue;
        }
      }
    }

    data.add(new SimpleEntry<String, String>(k, v));
    fireDataChangeNotification();
    return null;
  }
Ejemplo n.º 8
0
  public final void addItem(
      Material material,
      int amnt,
      String name,
      String[] lore,
      SimpleEntry<Enchantment, Integer>... enchantments) {
    ItemStack item = new ItemStack(material, amnt);
    for (SimpleEntry<Enchantment, Integer> entry : enchantments) {
      item.addEnchantment(entry.getKey(), entry.getValue());
    }

    ItemMeta meta = item.getItemMeta();
    meta.setDisplayName(name);
    meta.setLore(Arrays.asList(lore));
    item.setItemMeta(meta);

    items.add(item);
  }
Ejemplo n.º 9
0
 public void startMatch(int id) {
   // Inicia una partida a partir d'un tauler de la bd
   SimpleEntry<String, Integer> board = dataController.getBoard(id);
   match = new Match();
   match.setIdBoard(id);
   match.setBoardSolved(new SudokuBoard(board.getKey(), board.getValue()));
   match.setGame(new SudokuGame(board.getKey(), board.getValue()));
   match.setInitialState(new SudokuBoard(board.getKey(), board.getValue()));
 }
  private boolean containsMethodEnvironment(String methodName) {
    for (SimpleEntry<String, MethodEnvironment> methodEnvironment : _allMethods)
      if (methodEnvironment.getKey().equals(methodName)) return true;

    return false;
  }
Ejemplo n.º 11
0
  @Override
  public CreateResourceReport createResource(CreateResourceReport report) {
    report.setStatus(CreateResourceStatus.INVALID_CONFIGURATION);
    Address createAddress = new Address(this.address);

    String path = report.getPluginConfiguration().getSimpleValue("path", "");
    String resourceName;
    if (!path.contains("=")) {
      // this is not a singleton subsystem
      // resources like  example=test1 and example=test2 can be created
      resourceName = report.getUserSpecifiedResourceName();
    } else {
      // this is a request to create a true singleton subsystem
      // both the path and the name are set at resource level configuration
      resourceName = path.substring(path.indexOf('=') + 1);
      path = path.substring(0, path.indexOf('='));
    }

    createAddress.add(path, resourceName);

    Operation op = new Operation("add", createAddress);
    for (Property prop : report.getResourceConfiguration().getProperties()) {
      SimpleEntry<String, ?> entry = null;

      boolean isEntryEligible = true;
      if (prop instanceof PropertySimple) {
        PropertySimple propertySimple = (PropertySimple) prop;
        PropertyDefinitionSimple propertyDefinition =
            this.configurationDefinition.getPropertyDefinitionSimple(propertySimple.getName());

        if (propertyDefinition == null
            || (!propertyDefinition.isRequired() && propertySimple.getStringValue() == null)) {
          isEntryEligible = false;
        } else {
          entry = preparePropertySimple(propertySimple, propertyDefinition);
        }
      } else if (prop instanceof PropertyList) {
        PropertyList propertyList = (PropertyList) prop;
        PropertyDefinitionList propertyDefinition =
            this.configurationDefinition.getPropertyDefinitionList(propertyList.getName());

        if (!propertyDefinition.isRequired() && propertyList.getList().size() == 0) {
          isEntryEligible = false;
        } else {
          entry = preparePropertyList(propertyList, propertyDefinition);
        }
      } else if (prop instanceof PropertyMap) {
        PropertyMap propertyMap = (PropertyMap) prop;
        PropertyDefinitionMap propertyDefinition =
            this.configurationDefinition.getPropertyDefinitionMap(propertyMap.getName());

        if (!propertyDefinition.isRequired() && propertyMap.getMap().size() == 0) {
          isEntryEligible = false;
        } else {
          entry = preparePropertyMap(propertyMap, propertyDefinition);
        }
      }

      if (isEntryEligible) {
        op.addAdditionalProperty(entry.getKey(), entry.getValue());
      }
    }

    Result result = this.connection.execute(op);
    if (result.isSuccess()) {
      report.setStatus(CreateResourceStatus.SUCCESS);
      report.setResourceKey(createAddress.getPath());
      report.setResourceName(report.getUserSpecifiedResourceName());
    } else {
      report.setStatus(CreateResourceStatus.FAILURE);
      report.setErrorMessage(result.getFailureDescription());
    }

    return report;
  }
Ejemplo n.º 12
0
 public String generateBoard(int numCells, int diff) {
   SimpleEntry<String, String> boardGen = dataController.getSysBoard(diff);
   SudokuBoard board = new SudokuBoard(boardGen.getKey(), 3);
   SudokuFactory.generate(board, new SudokuBoard(boardGen.getValue(), 3), numCells);
   return board.boardToString();
 }