-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
146 additions
and
6 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
23 changes: 23 additions & 0 deletions
23
quick-rpc-client/src/main/java/com/tvd12/quick/rpc/client/annotation/RpcResponseHandled.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,23 @@ | ||
package com.tvd12.quick.rpc.client.annotation; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Inherited; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
/** | ||
* | ||
* @author tavandung12 | ||
* | ||
*/ | ||
@Inherited | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target({ ElementType.TYPE }) | ||
public @interface RpcResponseHandled { | ||
|
||
String value() default ""; | ||
|
||
String command() default ""; | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
quick-rpc-client/src/main/java/com/tvd12/quick/rpc/client/handler/RpcResponseHandler.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,9 @@ | ||
package com.tvd12.quick.rpc.client.handler; | ||
|
||
import com.tvd12.quick.rpc.client.entity.RpcResponse; | ||
|
||
public interface RpcResponseHandler { | ||
|
||
void handle(RpcResponse response); | ||
|
||
} |
57 changes: 57 additions & 0 deletions
57
quick-rpc-client/src/main/java/com/tvd12/quick/rpc/client/handler/RpcResponseHandlers.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,57 @@ | ||
package com.tvd12.quick.rpc.client.handler; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import com.tvd12.ezyfox.builder.EzyBuilder; | ||
|
||
public class RpcResponseHandlers { | ||
|
||
protected final Map<String, RpcResponseHandler> handlers; | ||
|
||
protected RpcResponseHandlers(Builder builder) { | ||
this.handlers = new HashMap<>(builder.handlers); | ||
} | ||
|
||
public RpcResponseHandler getHandler(String command) { | ||
return handlers.get(command); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "RpcResponseHandlers(" + handlers + ")"; | ||
} | ||
|
||
public static Builder builder() { | ||
return new Builder(); | ||
} | ||
|
||
public static class Builder implements EzyBuilder<RpcResponseHandlers> { | ||
|
||
protected Map<String, RpcResponseHandler> handlers; | ||
|
||
public Builder() { | ||
this.handlers = new HashMap<>(); | ||
} | ||
|
||
public Builder addHandler(String cmd, RpcResponseHandler handler) { | ||
handlers.put(cmd, handler); | ||
return this; | ||
} | ||
|
||
public Builder addHandlers(Map<String, RpcResponseHandler> handlers) { | ||
for(String cmd : handlers.keySet()) { | ||
RpcResponseHandler handler = handlers.get(cmd); | ||
addHandler(cmd, handler); | ||
} | ||
return this; | ||
} | ||
|
||
@Override | ||
public RpcResponseHandlers build() { | ||
return new RpcResponseHandlers(this); | ||
} | ||
|
||
} | ||
|
||
} |
20 changes: 20 additions & 0 deletions
20
...c-client/src/main/java/com/tvd12/quick/rpc/client/util/RpcResponseHandledAnnotations.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,20 @@ | ||
package com.tvd12.quick.rpc.client.util; | ||
|
||
import com.tvd12.ezyfox.io.EzyStrings; | ||
import com.tvd12.quick.rpc.client.annotation.RpcResponseHandled; | ||
|
||
public final class RpcResponseHandledAnnotations { | ||
|
||
private RpcResponseHandledAnnotations() {} | ||
|
||
public static String getCommand(RpcResponseHandled annotation) { | ||
if(EzyStrings.isNoContent(annotation.value())) | ||
return annotation.command(); | ||
return annotation.value(); | ||
} | ||
|
||
public static String getCommand(Class<?> rpcHandlerClass) { | ||
return getCommand(rpcHandlerClass.getAnnotation(RpcResponseHandled.class)); | ||
} | ||
|
||
} |
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