storm transaction源码解读transactional类

/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package backtype.storm.transactional;

import backtype.storm.coordination.BatchOutputCollector;
import backtype.storm.task.TopologyContext;
import backtype.storm.topology.IComponent;
import java.math.BigInteger;
import java.util.Map;

public interface ITransactionalSpout<T> extends IComponent {
public interface Coordinator<X> {
/**
*为从未创建的此特定事务ID创建元数据
  以前被发射过。 元数据应包含任何必要的内容
  能够在以后重播事务的确切批次。
元数据存储在Zookeeper中。
  Storm使用组件配置中配置的Kryo序列化
这个spout序列化和反序列化元数据。
* 
* @param txid The id of the transaction.
* @param prevMetadata The metadata of the previous transaction
* @return the metadata for this new transaction
*/
X initializeTransaction(BigInteger txid, X prevMetadata);

/**
*如果它可以发出一个新的事务,则返回true,否则返回false(将跳过此事务)。如果你想要在下一个事务之间有一个延迟,你应该睡在这里(这将被调用
反复循环)。
*/
boolean isReady();

/**
* 从此协调器中释放所有资源。
*/
void close();
}

public interface Emitter<X> {
/**
*发出指定事务尝试的批处理和事务的元数据。 元数据由协调器在initializeTranaction方法中创建。
此方法必须始终在同一事务ID的所有任务中发出相同批次的元组。 所有发出的元组的第一个字段必须包含提供的TransactionAttempt
* 
*/
void emitBatch(TransactionAttempt tx, X coordinatorMeta, BatchOutputCollector collector);

/**
*可以安全地清除提供的事务id之前的任何事务状态,因此此方法应该清除该状态。
*/
void cleanupBefore(BigInteger txid);

/**
*释放此发射器持有的所有资源
*/
void close();
}

/**
*TransactionalSpout的协调器在单个线程中运行,并指示何时应该发出批量的元组以及何时应该提交事务。
您在TransactionalSpout中提供的协调器为每个事务提供元数据,以便可以重放事务。
*/
Coordinator<T> getCoordinator(Map conf, TopologyContext context);

/**
* TransactionalSpout的发射器在群集中运行任意数量的任务。 发射器负责为事务发出批量元组,
并且必须确保始终为同一事务ID发出相同批次的元组。
*/ 
Emitter<T> getEmitter(Map conf, TopologyContext context);
}

  

posted @ 2018-07-06 12:58  uuhh  阅读(93)  评论(0编辑  收藏  举报