コード例 #1
0
  @Override
  public void open(Map conf, TopologyContext context, SpoutOutputCollector collector) {
    _collector = collector;
    Map stateConf = new HashMap(conf);

    List<String> zkServers = _spoutConfig.zkServers;
    if (zkServers == null) zkServers = (List<String>) conf.get(Config.STORM_ZOOKEEPER_SERVERS);

    Integer zkPort = _spoutConfig.zkPort;
    if (zkPort == null) zkPort = ((Number) conf.get(Config.STORM_ZOOKEEPER_PORT)).intValue();

    String zkRoot = _spoutConfig.zkRoot;

    stateConf.put(Config.TRANSACTIONAL_ZOOKEEPER_SERVERS, zkServers);
    stateConf.put(Config.TRANSACTIONAL_ZOOKEEPER_PORT, zkPort);
    stateConf.put(Config.TRANSACTIONAL_ZOOKEEPER_ROOT, zkRoot);

    Config componentConf = new Config();
    componentConf.registerSerialization(ZooMeta.class);

    // using TransactionalState like this is a hack
    _state = TransactionalState.newUserState(stateConf, _spoutConfig.id, componentConf);
    _partitions = new KafkaPartitionConnections(_spoutConfig);

    int totalPartitions = _spoutConfig.partitionsPerHost * _spoutConfig.hosts.size();
    int numTasks = context.getComponentTasks(context.getThisComponentId()).size();
    for (int p = context.getThisTaskIndex(); p < totalPartitions; p += numTasks) {
      _managedPartitions.add(p);
      _managers.put(p, new PartitionManager(p));
    }
  }
コード例 #2
0
 @Override
 public void ack(Object msgId) {
   TransactionAttempt tx = (TransactionAttempt) msgId;
   TransactionStatus status = _activeTx.get(tx.getTransactionId());
   if (status != null && tx.equals(status.attempt)) {
     if (status.status == AttemptStatus.PROCESSING) {
       status.status = AttemptStatus.PROCESSED;
     } else if (status.status == AttemptStatus.COMMITTING) {
       _activeTx.remove(tx.getTransactionId());
       _coordinatorState.cleanupBefore(tx.getTransactionId());
       _currTransaction = nextTransactionId(tx.getTransactionId());
       _state.setData(CURRENT_TX, _currTransaction);
     }
     sync();
   }
 }
コード例 #3
0
 @Override
 public void open(Map conf, TopologyContext context, SpoutOutputCollector collector) {
   _rand = new Random(Utils.secureRandomLong());
   _state =
       TransactionalState.newCoordinatorState(
           conf,
           (String) conf.get(Config.TOPOLOGY_TRANSACTIONAL_ID),
           _spout.getComponentConfiguration());
   _coordinatorState = new RotatingTransactionalState(_state, META_DIR, true);
   _collector = collector;
   _coordinator = _spout.getCoordinator(conf, context);
   _currTransaction = getStoredCurrTransaction(_state);
   Object active = conf.get(Config.TOPOLOGY_MAX_SPOUT_PENDING);
   if (active == null) {
     _maxTransactionActive = 1;
   } else {
     _maxTransactionActive = Utils.getInt(active);
   }
   _initializer = new StateInitializer();
 }
コード例 #4
0
 @Override
 public void close() {
   _state.close();
 }
コード例 #5
0
 private BigInteger getStoredCurrTransaction(TransactionalState state) {
   BigInteger ret = (BigInteger) state.getData(CURRENT_TX);
   if (ret == null) return INIT_TXID;
   else return ret;
 }