Skip to content

Commit

Permalink
add a method argument to decide cacheable
Browse files Browse the repository at this point in the history
  • Loading branch information
guyinyou committed Oct 16, 2023
1 parent 7e5d88a commit 0a4b73b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ public RemotingCommand processRequest(final ChannelHandlerContext ctx, RemotingC
RemotingCommand response = RemotingCommand.createResponseCommand(PopMessageResponseHeader.class);
final PopMessageResponseHeader responseHeader = (PopMessageResponseHeader) response.readCustomHeader();
final PopMessageRequestHeader requestHeader =
(PopMessageRequestHeader) request.decodeCommandCustomHeader(PopMessageRequestHeader.class);
(PopMessageRequestHeader) request.decodeCommandCustomHeader(PopMessageRequestHeader.class, true);
StringBuilder startOffsetInfo = new StringBuilder(64);
StringBuilder msgOffsetInfo = new StringBuilder(64);
StringBuilder orderCountInfo = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,14 +261,19 @@ public void writeCustomHeader(CommandCustomHeader customHeader) {

public CommandCustomHeader decodeCommandCustomHeader(
Class<? extends CommandCustomHeader> classHeader) throws RemotingCommandException {
if (cachedHeader != null) {
return decodeCommandCustomHeader(classHeader, false);
}

public CommandCustomHeader decodeCommandCustomHeader(
Class<? extends CommandCustomHeader> classHeader, boolean cacheAble) throws RemotingCommandException {
if (cacheAble && cachedHeader != null) {
return cachedHeader;
}
cachedHeader = decodeCommandCustomHeader(classHeader, true);
cachedHeader = decodeCommandCustomHeaderDirectly(classHeader, true);
return cachedHeader;
}

public CommandCustomHeader decodeCommandCustomHeader(Class<? extends CommandCustomHeader> classHeader,
public CommandCustomHeader decodeCommandCustomHeaderDirectly(Class<? extends CommandCustomHeader> classHeader,
boolean useFastEncode) throws RemotingCommandException {
CommandCustomHeader objectHeader;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ private HashMap<String, String> buildExtFields(List<Field> fields) {

private void check(RemotingCommand command, List<Field> fields,
Class<? extends CommandCustomHeader> classHeader) throws Exception {
CommandCustomHeader o1 = command.decodeCommandCustomHeader(classHeader, false);
CommandCustomHeader o1 = command.decodeCommandCustomHeaderDirectly(classHeader, false);
CommandCustomHeader o2 = classHeader.getDeclaredConstructor().newInstance();
((FastCodesHeader)o2).decode(command.getExtFields());
for (Field f : fields) {
Expand Down

0 comments on commit 0a4b73b

Please sign in to comment.