github.com/tenywen/fabric@v1.0.0-beta.0.20170620030522-a5b1ed380643/orderer/kafka/channel.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 defaultPartition = 0
    22  
    23  // channel identifies the Kafka partition the Kafka-based orderer interacts
    24  // with.
    25  type channel interface {
    26  	topic() string
    27  	partition() int32
    28  	fmt.Stringer
    29  }
    30  
    31  type channelImpl struct {
    32  	tpc string
    33  	prt int32
    34  }
    35  
    36  // Returns a new channel for a given topic name and partition number.
    37  func newChannel(topic string, partition int32) channel {
    38  	return &channelImpl{
    39  		tpc: fmt.Sprintf("%s", topic),
    40  		prt: partition,
    41  	}
    42  }
    43  
    44  // topic returns the Kafka topic this channel belongs to.
    45  func (chn *channelImpl) topic() string {
    46  	return chn.tpc
    47  }
    48  
    49  // partition returns the Kafka partition where this channel resides.
    50  func (chn *channelImpl) partition() int32 {
    51  	return chn.prt
    52  }
    53  
    54  // String returns a string identifying the Kafka topic/partition corresponding
    55  // to this channel.
    56  func (chn *channelImpl) String() string {
    57  	return fmt.Sprintf("%s/%d", chn.tpc, chn.prt)
    58  }