public void write(Collection<SinkRecord> records) {
    for (SinkRecord sinkRecord : records) {
      final String indexOverride = topicToIndexMap.get(sinkRecord.topic());
      final String index = indexOverride != null ? indexOverride : sinkRecord.topic();
      final boolean ignoreKey = ignoreKeyTopics.contains(sinkRecord.topic()) || this.ignoreKey;
      final boolean ignoreSchema =
          ignoreSchemaTopics.contains(sinkRecord.topic()) || this.ignoreSchema;

      if (!ignoreSchema && !existingMappings.contains(index)) {
        try {
          if (Mapping.getMapping(client, index, type) == null) {
            Mapping.createMapping(client, index, type, sinkRecord.valueSchema());
          }
        } catch (IOException e) {
          // FIXME: concurrent tasks could attempt to create the mapping and one of the requests may
          // fail
          throw new ConnectException("Failed to initialize mapping for index: " + index, e);
        }
        existingMappings.add(index);
      }

      final IndexableRecord indexableRecord =
          DataConverter.convertRecord(sinkRecord, index, type, ignoreKey, ignoreSchema);

      bulkProcessor.add(indexableRecord, flushTimeoutMs);
    }
  }
Ejemplo n.º 2
0
  /**
   * Creates the given number of axes, and then the sticks, triggers and d-pad based on the mapping
   * configuration.
   *
   * @param numberOfAxes The number of axes.
   */
  public void createAxes(int numberOfAxes) {
    if (Log.debugEnabled) {
      Log.logger.debug("Process " + numberOfAxes + " analog axes...");
      Log.logger.debug("Number of triggers: " + Mapping.getNumberOfTriggers(this));
      Log.logger.debug("Number of sticks: " + Mapping.getNumberOfSticks(this));
    }

    // -----------------------  TODO: Use pooling for these ------
    this.axes = new BaseAxis[numberOfAxes];
    this.triggers = new BaseTrigger[Mapping.getNumberOfTriggers(this)];
    this.sticks = new BaseStick[Mapping.getNumberOfSticks(this)];

    int triggerNo = 0;
    for (int axisNo = 0; axisNo < axes.length; axisNo++) {
      String mapping = Mapping.getMapping(this, Mapping.MappingType.TRIGGER_AXIS, axisNo);
      if (mapping != null) {
        if (Log.debugEnabled) {
          Log.logger.debug("Process trigger axis...");
        }
        processTriggerAxis(mapping, axisNo, triggerNo++);
      }
      mapping = Mapping.getMapping(this, Mapping.MappingType.STICK_AXIS, axisNo);
      if (mapping != null) {
        if (Log.debugEnabled) {
          Log.logger.debug("Process stick axis...");
        }
        processStickAxis(mapping, axisNo);
      }
      mapping = Mapping.getMapping(this, Mapping.MappingType.DPAD_AXIS, axisNo);
      Log.logger.debug("D-pad mapping for axis " + axisNo + ": " + mapping);
      if (mapping != null) {
        if (Log.debugEnabled) {
          Log.logger.debug("Process d-pad axis...");
        }
        processDpadAxis(mapping, axisNo);
      }
    }
  }
Ejemplo n.º 3
0
  /**
   * Creates the given number of buttons, based on the mapping configuration.
   *
   * @param numberOfButtons The number of buttons.
   */
  public void createButtons(int numberOfButtons) {
    if (Log.debugEnabled) {
      Log.logger.debug("Create " + numberOfButtons + " buttons for pad...");
    }

    // -----------------------  TODO: Use pooling for button instances ------
    this.buttons = new BaseButton[numberOfButtons];
    for (int buttonNo = 0; buttonNo < numberOfButtons; buttonNo++) {
      this.buttons[buttonNo] = new BaseButton(this, buttonNo, "", "");
    }
    // -----------------------------------------------------------------------

    for (int buttonNo = 0; buttonNo < numberOfButtons; buttonNo++) {
      String mapping = Mapping.getMapping(this, MappingType.BUTTON, buttonNo);
      if (mapping != null) {
        ButtonID buttonID = ButtonID.getButtonIDfromString(mapping);
        if (Log.debugEnabled) {
          Log.logger.debug(
              "Map button no. "
                  + buttonNo
                  + " from mapping "
                  + mapping
                  + " to button ID "
                  + buttonID);
        }
        this.buttons[buttonNo].setID(buttonID);
        this.buttonMap.put(buttonID, this.buttons[buttonNo]);
        String label = Mapping.getButtonLabel(this, buttonID);
        if (label == null) {
          label = Mapping.getDefaultButtonLabel(buttonID);
        }
        if (label != null) {
          this.buttons[buttonNo].setDefaultLabel(label);
        }
        String labelKey = Mapping.getButtonLabelKey(this, buttonID);
        if (labelKey != null) {
          this.buttons[buttonNo].setLabelKey(labelKey);
        }
      }
    }
  }