Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Renamed CommandResponseMessage to CommandResultMessage.
- asCommandResultMessage now checks whether the result is a Message already.
- Loading branch information
1 parent
d36edbf
commit 480449e
Showing
43 changed files
with
362 additions
and
357 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
98 changes: 0 additions & 98 deletions
98
core/src/main/java/org/axonframework/commandhandling/GenericCommandResponseMessage.java
This file was deleted.
Oops, something went wrong.
103 changes: 103 additions & 0 deletions
103
core/src/main/java/org/axonframework/commandhandling/GenericCommandResultMessage.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,103 @@ | ||
/* | ||
* Copyright (c) 2010-2018. Axon Framework | ||
* | ||
* Licensed 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.axonframework.commandhandling; | ||
|
||
import org.axonframework.messaging.GenericMessage; | ||
import org.axonframework.messaging.Message; | ||
import org.axonframework.messaging.MessageDecorator; | ||
import org.axonframework.messaging.MetaData; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* Generic implementation of {@link CommandResultMessage}. | ||
* | ||
* @param <R> The type of the payload contained in this Message | ||
* @author Milan Savic | ||
* @since 4.0 | ||
*/ | ||
public class GenericCommandResultMessage<R> extends MessageDecorator<R> implements CommandResultMessage<R> { | ||
|
||
private static final long serialVersionUID = 9013948836930094183L; | ||
|
||
/** | ||
* Returns the given {@code commandResult} as a {@link CommandResultMessage} instance. If {@code commandResult} | ||
* already implements {@link CommandResultMessage}, it is returned as-is. If {@code commandResult} implements {@link | ||
* Message}, payload and meta data will be used to construct new {@link GenericCommandResultMessage}. Otherwise, the | ||
* given {@code commandResult} is wrapped into a {@link GenericCommandResultMessage} as its payload. | ||
* | ||
* @param commandResult the command result to be wrapped as {@link CommandResultMessage} | ||
* @param <T> The type of the payload contained in returned Message | ||
* @return a Message containing given {@code commandResult} as payload, or {@code commandResult} if already | ||
* implements {@link CommandResultMessage} | ||
*/ | ||
@SuppressWarnings("unchecked") | ||
public static <T> CommandResultMessage<T> asCommandResultMessage(Object commandResult) { | ||
if (CommandResultMessage.class.isInstance(commandResult)) { | ||
return (CommandResultMessage<T>) commandResult; | ||
} else if (Message.class.isInstance(commandResult)) { | ||
Message<?> commandResultMessage = (Message<?>) commandResult; | ||
return new GenericCommandResultMessage<>((T) commandResultMessage.getPayload(), | ||
commandResultMessage.getMetaData()); | ||
} | ||
return new GenericCommandResultMessage<>((T) commandResult); | ||
} | ||
|
||
/** | ||
* Creates a Command Result Message with the given {@code commandResult} as the payload. | ||
* | ||
* @param commandResult the payload for the Message | ||
*/ | ||
public GenericCommandResultMessage(R commandResult) { | ||
this(commandResult, MetaData.emptyInstance()); | ||
} | ||
|
||
/** | ||
* Creates a Command Result Message with the given {@code commandResult} as the payload and {@code metaData} as | ||
* the meta data. | ||
* | ||
* @param commandResult the payload for the Message | ||
* @param metaData the meta data for the Message | ||
*/ | ||
public GenericCommandResultMessage(R commandResult, Map<String, ?> metaData) { | ||
this(new GenericMessage<>(commandResult, metaData)); | ||
} | ||
|
||
/** | ||
* Creates a new Command Result Message with given {@code delegate} message. | ||
* | ||
* @param delegate the message delegate | ||
*/ | ||
public GenericCommandResultMessage(Message<R> delegate) { | ||
super(delegate); | ||
} | ||
|
||
@Override | ||
public GenericCommandResultMessage<R> withMetaData(Map<String, ?> metaData) { | ||
return new GenericCommandResultMessage<>(getDelegate().withMetaData(metaData)); | ||
} | ||
|
||
@Override | ||
public GenericCommandResultMessage<R> andMetaData(Map<String, ?> metaData) { | ||
return new GenericCommandResultMessage<>(getDelegate().andMetaData(metaData)); | ||
} | ||
|
||
@Override | ||
protected String describeType() { | ||
return "GenericCommandResultMessage"; | ||
} | ||
} |
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
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
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
Oops, something went wrong.