- Notifications
You must be signed in to change notification settings - Fork 45
add transport interface #20
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
Changes from all commits
Commits
Show all changes
6 commits Select commit Hold shift + click to select a range
afd1a8d add transport interface
houzhizhen 95e8976 rename BufferHandler to MessageHandler
houzhizhen 94fdc96 improve comments
houzhizhen 55ffac9 improve comments
houzhizhen e74cb42 improve comments
houzhizhen 4caf851 improve comments
houzhizhen 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
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
33 changes: 33 additions & 0 deletions 33 computer-core/src/main/java/com/baidu/hugegraph/computer/core/network/MessageHandler.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,33 @@ | ||
| /* | ||
| * Copyright 2017 HugeGraph Authors | ||
| * | ||
| * 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 com.baidu.hugegraph.computer.core.network; | ||
| | ||
| import java.nio.ByteBuffer; | ||
| | ||
| public interface MessageHandler { | ||
| | ||
| /** | ||
| * Handle the buffer received. There are two buffer list for a partition, | ||
| * one for sorting and one for receiving new buffers. It may block the | ||
| * caller if the receiving list reached threshold and the sorting list is | ||
| * sorting in process. | ||
| */ | ||
| void handle(byte messageType, int partition, ByteBuffer buffer); | ||
| } |
61 changes: 61 additions & 0 deletions 61 computer-core/src/main/java/com/baidu/hugegraph/computer/core/network/Transport4Client.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,61 @@ | ||
| /* | ||
| * Copyright 2017 HugeGraph Authors | ||
| * | ||
| * 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 com.baidu.hugegraph.computer.core.network; | ||
| | ||
| import java.io.IOException; | ||
| | ||
| import com.baidu.hugegraph.computer.core.config.Config; | ||
| | ||
| import io.netty.buffer.ByteBuf; | ||
| | ||
| /** | ||
| * This is used for worker to send buffer to other worker. The whole process | ||
| * contains several iteration. In one iteration {@link #startSession} is | ||
| * called only once. {@link #send} is called zero or more times. | ||
| * {@link #finishSession()} is called only once. | ||
| */ | ||
| public interface Transport4Client { | ||
| | ||
| /** | ||
| * Init the connection from client to server. This method is called only | ||
| * once. MAX_PENDING_REQUESTS is set in config | ||
| * @throws IOException if can't create connection. | ||
| */ | ||
| void init(Config config, String hostname, int port) throws IOException; | ||
| | ||
| /** | ||
| * This method is called before an iteration of sending buffers. | ||
| */ | ||
| void startSession(); | ||
| | ||
| /** | ||
| * Send the buffer to the server. Block the caller if busy. | ||
| * This method is called zero or many times in iteration. | ||
| * @throws IOException if failed, the job will fail. | ||
| */ | ||
| void send(byte messageType, int partition, ByteBuf buffer) | ||
| throws IOException; | ||
| | ||
| /** | ||
| * This method is called after an iteration. It will block the caller to | ||
| * make sure the buffers sent be received by target workers. | ||
| */ | ||
| void finishSession() throws IOException; | ||
| } |
40 changes: 40 additions & 0 deletions 40 computer-core/src/main/java/com/baidu/hugegraph/computer/core/network/Transport4Server.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,40 @@ | ||
| /* | ||
| * Copyright 2017 HugeGraph Authors | ||
| * | ||
| * 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 com.baidu.hugegraph.computer.core.network; | ||
| | ||
| import com.baidu.hugegraph.computer.core.config.Config; | ||
| | ||
| /** | ||
| * This is used for worker that receives data. | ||
| */ | ||
| public interface Transport4Server { | ||
| | ||
| /** | ||
| * Startup server, return the port listened. The port range in config is | ||
| * [{@link @ComputerOptions.WORKER_DATA_PORT_START #STATIC_FIELD}, | ||
| * {@link @ComputerOptions.WORKER_DATA_PORT_END #STATIC_FIELD}]. | ||
| */ | ||
| int listen(Config config, MessageHandler handler); | ||
| | ||
| /** | ||
| * Stop the server | ||
| */ | ||
| void stop(); | ||
| } | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add pauseReceive() and resumeReceive()
if the pending_messages feature can control flow rate, we can delete ignore-resume
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
listen, set the port range in config.