forked from apache/kafka
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
KAFKA-16730: Initial version of share group consumer client code (apa…
…che#16461) This is the initial version of the share group consumer client code. It implements the complete ShareConsumer interface. There are unit tests, but not integration tests yet since those would depend upon complete broker code, which is not available at this point. Reviewers: Apoorv Mittal <[email protected]>, Manikumar Reddy <[email protected]>, Lianet Magrans <[email protected]>
- Loading branch information
1 parent
3790a50
commit cf3d5d6
Showing
54 changed files
with
12,932 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
clients/src/main/java/org/apache/kafka/clients/consumer/internals/AcknowledgementBatch.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
/* | ||
* 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 org.apache.kafka.clients.consumer.internals; | ||
|
||
import org.apache.kafka.common.message.ShareAcknowledgeRequestData; | ||
import org.apache.kafka.common.message.ShareFetchRequestData; | ||
import org.apache.kafka.common.protocol.MessageUtil; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class AcknowledgementBatch { | ||
private long firstOffset; | ||
private long lastOffset; | ||
private List<Byte> acknowledgeTypes; | ||
|
||
public AcknowledgementBatch() { | ||
this.firstOffset = 0L; | ||
this.lastOffset = 0L; | ||
this.acknowledgeTypes = new ArrayList<>(0); | ||
} | ||
|
||
public long firstOffset() { | ||
return this.firstOffset; | ||
} | ||
|
||
public long lastOffset() { | ||
return this.lastOffset; | ||
} | ||
|
||
public List<Byte> acknowledgeTypes() { | ||
return this.acknowledgeTypes; | ||
} | ||
|
||
public AcknowledgementBatch setFirstOffset(long v) { | ||
this.firstOffset = v; | ||
return this; | ||
} | ||
|
||
public AcknowledgementBatch setLastOffset(long v) { | ||
this.lastOffset = v; | ||
return this; | ||
} | ||
|
||
public AcknowledgementBatch setAcknowledgeTypes(List<Byte> v) { | ||
this.acknowledgeTypes = v; | ||
return this; | ||
} | ||
|
||
public ShareAcknowledgeRequestData.AcknowledgementBatch toShareAcknowledgeRequest() { | ||
return new ShareAcknowledgeRequestData.AcknowledgementBatch() | ||
.setFirstOffset(firstOffset) | ||
.setLastOffset(lastOffset) | ||
.setAcknowledgeTypes(acknowledgeTypes); | ||
} | ||
|
||
public ShareFetchRequestData.AcknowledgementBatch toShareFetchRequest() { | ||
return new ShareFetchRequestData.AcknowledgementBatch() | ||
.setFirstOffset(firstOffset) | ||
.setLastOffset(lastOffset) | ||
.setAcknowledgeTypes(acknowledgeTypes); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (!(obj instanceof AcknowledgementBatch)) return false; | ||
AcknowledgementBatch other = (AcknowledgementBatch) obj; | ||
if (firstOffset != other.firstOffset) return false; | ||
if (lastOffset != other.lastOffset) return false; | ||
if (this.acknowledgeTypes == null) { | ||
return other.acknowledgeTypes == null; | ||
} else { | ||
return this.acknowledgeTypes.equals(other.acknowledgeTypes); | ||
} | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
int hashCode = 0; | ||
hashCode = 31 * hashCode + ((int) (firstOffset >> 32) ^ (int) firstOffset); | ||
hashCode = 31 * hashCode + ((int) (lastOffset >> 32) ^ (int) lastOffset); | ||
hashCode = 31 * hashCode + (acknowledgeTypes == null ? 0 : acknowledgeTypes.hashCode()); | ||
return hashCode; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "AcknowledgementBatch(" | ||
+ "firstOffset=" + firstOffset | ||
+ ", lastOffset=" + lastOffset | ||
+ ", acknowledgeTypes=" + MessageUtil.deepToString(acknowledgeTypes.iterator()) | ||
+ ")"; | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
...ava/org/apache/kafka/clients/consumer/internals/AcknowledgementCommitCallbackHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* 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 org.apache.kafka.clients.consumer.internals; | ||
|
||
import org.apache.kafka.clients.consumer.AcknowledgementCommitCallback; | ||
import org.apache.kafka.common.TopicIdPartition; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
public class AcknowledgementCommitCallbackHandler { | ||
|
||
private static final Logger LOG = LoggerFactory.getLogger(AcknowledgementCommitCallbackHandler.class); | ||
private final AcknowledgementCommitCallback acknowledgementCommitCallback; | ||
private boolean enteredCallback = false; | ||
|
||
AcknowledgementCommitCallbackHandler(AcknowledgementCommitCallback acknowledgementCommitCallback) { | ||
this.acknowledgementCommitCallback = acknowledgementCommitCallback; | ||
} | ||
|
||
public boolean hasEnteredCallback() { | ||
return enteredCallback; | ||
} | ||
|
||
void onComplete(List<Map<TopicIdPartition, Acknowledgements>> acknowledgementsMapList) { | ||
final ArrayList<Throwable> exceptions = new ArrayList<>(); | ||
acknowledgementsMapList.forEach(acknowledgementsMap -> acknowledgementsMap.forEach((partition, acknowledgements) -> { | ||
Exception exception = null; | ||
if (acknowledgements.getAcknowledgeErrorCode() != null) { | ||
exception = acknowledgements.getAcknowledgeErrorCode().exception(); | ||
} | ||
Set<Long> offsets = acknowledgements.getAcknowledgementsTypeMap().keySet(); | ||
Set<Long> offsetsCopy = Collections.unmodifiableSet(offsets); | ||
enteredCallback = true; | ||
try { | ||
acknowledgementCommitCallback.onComplete(Collections.singletonMap(partition, offsetsCopy), exception); | ||
} catch (Throwable e) { | ||
LOG.error("Exception thrown by acknowledgement commit callback", e); | ||
exceptions.add(e); | ||
} finally { | ||
enteredCallback = false; | ||
} | ||
})); | ||
if (!exceptions.isEmpty()) { | ||
throw ConsumerUtils.maybeWrapAsKafkaException(exceptions.get(0), "Exception thrown by acknowledgement commit callback"); | ||
} | ||
} | ||
} |
Oops, something went wrong.