-
Notifications
You must be signed in to change notification settings - Fork 15.4k
KAFKA-14247: Define event handler interface and events #12663
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
hachikuji
merged 25 commits into
apache:trunk
from
philipnee:consumer-refactor-event-handler-definition
Oct 3, 2022
Merged
Changes from 5 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
6ce7fef
Basic event handler definition
1597d31
Define EventHandler interface
f60d2e2
lint error
a1cd844
moving packages
fbcef3b
reduce the scope
3ced858
PR comments for naming and documentation
ccb5f14
Documentation on the beahvior
b04d33d
Add isEmpty and remove excessive public
8489337
Remove unused import
6629e27
Handle capacity limitation
6d97d2a
clean up a comment
816b285
A stubbed event handler to demonstrate the usage.
625b16c
typo
078ab7f
Revert "typo"
3213e57
Revert "A stubbed event handler to demonstrate the usage."
c6d67e2
Prototyping
f5b25e6
clean up and documentation
43f798c
fetches should happen on the background thread.
ffe6432
fix a lint error
bf73d8f
clarify poll loop
d77e1e3
improve documentation
d3d3d54
more documentation
9cb4682
clarification
e0949e9
documentation
e63f1ee
typo: 'prototype
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
clients/src/main/java/org/apache/kafka/clients/consumer/internals/DefaultEventHandler.java
This file contains hidden or 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,44 @@ | ||
| /* | ||
| * 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.internals.events.ConsumerRequestEvent; | ||
| import org.apache.kafka.clients.consumer.internals.events.ConsumerResponseEvent; | ||
|
|
||
| import java.util.concurrent.BlockingQueue; | ||
| import java.util.concurrent.LinkedBlockingQueue; | ||
|
|
||
| public class DefaultEventHandler implements EventHandler<ConsumerRequestEvent, ConsumerResponseEvent> { | ||
| private BlockingQueue<ConsumerRequestEvent> consumerRequestEvents; | ||
| private BlockingQueue<ConsumerResponseEvent> consumerResponseEvents; | ||
|
|
||
| public DefaultEventHandler() { | ||
| this.consumerRequestEvents = new LinkedBlockingQueue<>(); | ||
| this.consumerResponseEvents = new LinkedBlockingQueue<>(); | ||
| // TODO: a concreted implementation of how requests are being consumed, and how responses are being produced. | ||
| } | ||
|
|
||
| @Override | ||
| public ConsumerResponseEvent poll() { | ||
| return consumerResponseEvents.poll(); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean add(ConsumerRequestEvent event) { | ||
| return consumerRequestEvents.add(event); | ||
| } | ||
| } |
29 changes: 29 additions & 0 deletions
29
clients/src/main/java/org/apache/kafka/clients/consumer/internals/EventHandler.java
This file contains hidden or 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,29 @@ | ||
| /* | ||
| * 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; | ||
|
|
||
| /** | ||
| * The EventHandler interfaces the client and handler implementation. The client should add an event for consumption, | ||
| * and try to poll for the responses. Here, one could poll a response with type K, and add a request with type T. | ||
| * @param <T> Event request type | ||
| * @param <K> Event response type | ||
| */ | ||
| public interface EventHandler<T, K> { | ||
|
philipnee marked this conversation as resolved.
Outdated
|
||
| public K poll(); | ||
| public boolean add(T event); | ||
|
philipnee marked this conversation as resolved.
Outdated
|
||
| } | ||
20 changes: 20 additions & 0 deletions
20
...rc/main/java/org/apache/kafka/clients/consumer/internals/events/ConsumerRequestEvent.java
This file contains hidden or 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,20 @@ | ||
| /* | ||
| * 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.events; | ||
|
|
||
| abstract public class ConsumerRequestEvent { | ||
|
philipnee marked this conversation as resolved.
Outdated
|
||
| } | ||
20 changes: 20 additions & 0 deletions
20
...c/main/java/org/apache/kafka/clients/consumer/internals/events/ConsumerResponseEvent.java
This file contains hidden or 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,20 @@ | ||
| /* | ||
| * 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.events; | ||
|
|
||
| abstract public class ConsumerResponseEvent { | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.