github.com/adnan-c/fabric_e2e_couchdb@v0.6.1-preview.0.20170228180935-21ce6b23cf91/orderer/kafka/chain_partition.go (about)

     1  /*
     2  Copyright IBM Corp. 2016 All Rights Reserved.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8                   http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package kafka
    18  
    19  import "fmt"
    20  
    21  const rawPartition = 0
    22  
    23  // ChainPartition identifies the Kafka partition the orderer interacts with.
    24  type ChainPartition interface {
    25  	Topic() string
    26  	Partition() int32
    27  	fmt.Stringer
    28  }
    29  
    30  type chainPartitionImpl struct {
    31  	tpc string
    32  	prt int32
    33  }
    34  
    35  // Returns a new chain partition for a given chain ID and partition.
    36  func newChainPartition(chainID string, partition int32) ChainPartition {
    37  	return &chainPartitionImpl{
    38  		// TODO https://github.com/apache/kafka/blob/trunk/core/src/main/scala/kafka/common/Topic.scala#L29
    39  		tpc: fmt.Sprintf("%x", chainID),
    40  		prt: partition,
    41  	}
    42  }
    43  
    44  // Topic returns the Kafka topic of this chain partition.
    45  func (cp *chainPartitionImpl) Topic() string {
    46  	return cp.tpc
    47  }
    48  
    49  // Partition returns the Kafka partition of this chain partition.
    50  func (cp *chainPartitionImpl) Partition() int32 {
    51  	return cp.prt
    52  }
    53  
    54  // String returns a string identifying the chain partition.
    55  func (cp *chainPartitionImpl) String() string {
    56  	return fmt.Sprintf("%s/%d", cp.tpc, cp.prt)
    57  }