-
Notifications
You must be signed in to change notification settings - Fork 785
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace ForwardingMode enum for ForwardingMode interface
-Replace ForwardingMode enum for ForwardingMode interface -Introduce a ForwardAll ForwardingMode implementation -Introduce a ForwardNone ForwardingMode implementation -Introduce a ForwardMatchingInstances ForwardingMode implementation -Adjust AggregateMember annotation to take in a ForwardingMode class instead of an enum -Instantiate the right ForwardingMode in the AbstractChildEntityDefinition based on the class type in the AggregateMember -Filter the event targets based on the eventForwardingMode in the AbstractChildEntityDefinition implementations -Fix AggregateMember usages in tests [#388]
- Loading branch information
Showing
10 changed files
with
221 additions
and
88 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
40 changes: 40 additions & 0 deletions
40
core/src/main/java/org/axonframework/commandhandling/model/ForwardAll.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,40 @@ | ||
/* | ||
* Copyright (c) 2010-2017. 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.model; | ||
|
||
import org.axonframework.messaging.Message; | ||
|
||
import java.util.function.Supplier; | ||
|
||
/** | ||
* Forward all messages {@code T} regardless of their set up. | ||
* | ||
* @param <T> the implementation {@code T} of the {@link org.axonframework.messaging.Message} being forwarded. | ||
*/ | ||
public class ForwardAll<T extends Message<?>> implements ForwardingMode<T> { | ||
|
||
public static final ForwardAll INSTANCE = new ForwardAll(); | ||
|
||
@Override | ||
public ForwardingMode getInstance(Supplier<ForwardingMode> forwardingModeConstructor) { | ||
return forwardingModeConstructor.get(); | ||
} | ||
|
||
@Override | ||
public <E> boolean forwardMessage(T message, E target) { | ||
return true; | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
core/src/main/java/org/axonframework/commandhandling/model/ForwardMatchingInstances.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,64 @@ | ||
/* | ||
* Copyright (c) 2010-2017. 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.model; | ||
|
||
import org.axonframework.commandhandling.model.inspection.EntityModel; | ||
import org.axonframework.common.property.Property; | ||
import org.axonframework.messaging.Message; | ||
|
||
import java.util.Objects; | ||
import java.util.function.Supplier; | ||
|
||
import static org.axonframework.common.property.PropertyAccessStrategy.getProperty; | ||
|
||
/** | ||
* Only forward messages of type {@code T} if the routing key of the message matches the identifier of the entity. | ||
* | ||
* @param <T> the implementation {@code T} of the {@link org.axonframework.messaging.Message} being forwarded. | ||
*/ | ||
public class ForwardMatchingInstances<T extends Message<?>> implements ForwardingMode<T> { | ||
|
||
private static final String EMPTY_STRING = ""; | ||
|
||
private final String routingKey; | ||
private final EntityModel childEntity; | ||
|
||
public ForwardMatchingInstances(String routingKey, | ||
EntityModel childEntity) { | ||
this.routingKey = routingKey; | ||
this.childEntity = childEntity; | ||
} | ||
|
||
@Override | ||
public ForwardingMode getInstance(Supplier<ForwardingMode> forwardingModeConstructor) { | ||
return forwardingModeConstructor.get(); | ||
} | ||
|
||
@Override | ||
@SuppressWarnings("unchecked") | ||
public <E> boolean forwardMessage(T message, E target) { | ||
Property routingProperty = getProperty(message.getPayloadType(), routingKey()); | ||
|
||
Object routingValue = routingProperty.getValue(message.getPayload()); | ||
Object identifier = childEntity.getIdentifier(target); | ||
|
||
return Objects.equals(routingValue, identifier); | ||
} | ||
|
||
private String routingKey() { | ||
return Objects.equals(routingKey, EMPTY_STRING) ? childEntity.routingKey() : routingKey; | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
core/src/main/java/org/axonframework/commandhandling/model/ForwardNone.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,40 @@ | ||
/* | ||
* Copyright (c) 2010-2017. 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.model; | ||
|
||
import org.axonframework.messaging.Message; | ||
|
||
import java.util.function.Supplier; | ||
|
||
/** | ||
* Forward no messages {@code T} regardless of their set up. | ||
* | ||
* @param <T> the implementation {@code T} of the {@link org.axonframework.messaging.Message} being forwarded. | ||
*/ | ||
public class ForwardNone<T extends Message<?>> implements ForwardingMode<T> { | ||
|
||
public static final ForwardNone INSTANCE = new ForwardNone(); | ||
|
||
@Override | ||
public ForwardingMode getInstance(Supplier<ForwardingMode> forwardingModeConstructor) { | ||
return forwardingModeConstructor.get(); | ||
} | ||
|
||
@Override | ||
public <E> boolean forwardMessage(T message, E target) { | ||
return false; | ||
} | ||
} |
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.