*/
private UUID participantId;
+ private UUID replicaId;
+
/**
* Participant State, or {@code null} for messages from participants.
*/
this.stateChangeResult = source.stateChangeResult;
this.message = source.message;
this.messageType = source.messageType;
+ this.compositionId = source.compositionId;
this.participantId = source.participantId;
+ this.replicaId = source.replicaId;
this.state = source.state;
}
* Determines if this message applies to this participant type.
*
* @param participantId id of the participant to match against
+ * @param replicaId id of the participant to match against
* @return {@code true} if this message applies to this participant, {@code false} otherwise
*/
- public boolean appliesTo(@NonNull final UUID participantId) {
+ public boolean appliesTo(@NonNull final UUID participantId, @NonNull final UUID replicaId) {
// Broadcast message to all participants
- if (this.participantId == null) {
+ if ((this.participantId == null)
+ || (participantId.equals(this.participantId) && this.replicaId == null)) {
return true;
}
// Targeted message at this specific participant
- return participantId.equals(this.participantId);
+ return replicaId.equals(this.replicaId);
}
}
*/
private UUID participantId;
+ private UUID replicaId;
+
/**
* Automation Composition ID, or {@code null} for messages to participants.
*/
public ParticipantMessage(final ParticipantMessage source) {
this.messageType = source.messageType;
this.participantId = source.participantId;
+ this.replicaId = source.replicaId;
this.automationCompositionId = source.automationCompositionId;
this.compositionId = source.compositionId;
}
* Determines if this message applies to this participant type.
*
* @param participantId id of the participant to match against
+ * @param replicaId id of the participant to match against
* @return {@code true} if this message applies to this participant, {@code false} otherwise
*/
- public boolean appliesTo(@NonNull final UUID participantId) {
+ public boolean appliesTo(@NonNull final UUID participantId, @NonNull final UUID replicaId) {
// Broadcast message to all participants
- if (this.participantId == null) {
+ if ((this.participantId == null)
+ || (participantId.equals(this.participantId) && this.replicaId == null)) {
return true;
}
// Targeted message at this specific participant
- return participantId.equals(this.participantId);
+ return replicaId.equals(this.replicaId);
}
}
@Test
void testAppliesTo_NullParticipantId() {
message = makeMessage();
- assertThatThrownBy(() -> message.appliesTo(null)).isInstanceOf(NullPointerException.class);
+ assertThatThrownBy(() -> message.appliesTo(UUID.randomUUID(), null)).isInstanceOf(NullPointerException.class);
+ assertThatThrownBy(() -> message.appliesTo(null, UUID.randomUUID())).isInstanceOf(NullPointerException.class);
}
@Test
message = makeMessage();
// ParticipantId matches
- assertTrue(message.appliesTo(CommonTestData.getParticipantId()));
- assertFalse(message.appliesTo(CommonTestData.getRndParticipantId()));
+ assertTrue(message.appliesTo(CommonTestData.getParticipantId(), CommonTestData.getReplicaId()));
+ assertFalse(message.appliesTo(CommonTestData.getRndParticipantId(), CommonTestData.getReplicaId()));
}
@Test
message = makeMessage();
// ParticipantId does not match
- assertFalse(message.appliesTo(CommonTestData.getRndParticipantId()));
- assertTrue(message.appliesTo(CommonTestData.getParticipantId()));
+ assertFalse(message.appliesTo(CommonTestData.getRndParticipantId(), CommonTestData.getReplicaId()));
+ assertTrue(message.appliesTo(CommonTestData.getParticipantId(), CommonTestData.getReplicaId()));
}
private ParticipantAckMessage makeMessage() {
void testAppliesTo_NullParticipantId() {
message = makeMessage();
- assertThatThrownBy(() -> message.appliesTo(null)).isInstanceOf(NullPointerException.class);
+ assertThatThrownBy(() -> message.appliesTo(UUID.randomUUID(), null)).isInstanceOf(NullPointerException.class);
+ assertThatThrownBy(() -> message.appliesTo(null, UUID.randomUUID())).isInstanceOf(NullPointerException.class);
}
@Test
message = makeMessage();
// ParticipantId matches
- assertTrue(message.appliesTo(CommonTestData.getParticipantId()));
- assertFalse(message.appliesTo(CommonTestData.getRndParticipantId()));
+ assertTrue(message.appliesTo(CommonTestData.getParticipantId(), CommonTestData.getReplicaId()));
+ assertFalse(message.appliesTo(CommonTestData.getRndParticipantId(), CommonTestData.getReplicaId()));
}
@Test
void testAppliesTo_ParticipantIdNoMatch() {
message = makeMessage();
- assertFalse(message.appliesTo(CommonTestData.getRndParticipantId()));
- assertTrue(message.appliesTo(CommonTestData.getParticipantId()));
+ assertFalse(message.appliesTo(CommonTestData.getRndParticipantId(), CommonTestData.getReplicaId()));
+ assertTrue(message.appliesTo(CommonTestData.getParticipantId(), CommonTestData.getReplicaId()));
}
private ParticipantMessage makeMessage() {
public class CommonTestData {
public static final UUID PARTCICIPANT_ID = UUID.randomUUID();
+ public static final UUID REPLICA_ID = UUID.randomUUID();
private static final StandardYamlCoder YAML_TRANSLATOR = new StandardYamlCoder();
-
/**
* Returns participantId for test cases.
*
return PARTCICIPANT_ID;
}
+ /**
+ * Returns participantId for test cases.
+ *
+ * @return participant Id
+ */
+ public static UUID getReplicaId() {
+ return REPLICA_ID;
+ }
+
/**
* Returns participantId for test Jpa cases.
*
participantPrimeAck.setCompositionState(AcTypeState.COMMISSIONED);
participantPrimeAck.setStateChangeResult(StateChangeResult.NO_ERROR);
participantPrimeAck.setParticipantId(cacheProvider.getParticipantId());
+ participantPrimeAck.setReplicaId(cacheProvider.getReplicaId());
participantPrimeAck.setState(ParticipantState.ON_LINE);
publisher.sendParticipantPrimeAck(participantPrimeAck);
return;
var automationCompositionAck = new AutomationCompositionDeployAck(
ParticipantMessageType.AUTOMATION_COMPOSITION_STATECHANGE_ACK);
automationCompositionAck.setParticipantId(cacheProvider.getParticipantId());
+ automationCompositionAck.setReplicaId(cacheProvider.getReplicaId());
automationCompositionAck.setMessage("Already deleted or never used");
automationCompositionAck.setResult(true);
automationCompositionAck.setStateChangeResult(StateChangeResult.NO_ERROR);
var automationCompositionStateChangeAck =
new AutomationCompositionDeployAck(ParticipantMessageType.AUTOMATION_COMPOSITION_STATECHANGE_ACK);
automationCompositionStateChangeAck.setParticipantId(cacheProvider.getParticipantId());
+ automationCompositionStateChangeAck.setReplicaId(cacheProvider.getReplicaId());
automationCompositionStateChangeAck.setMessage(message);
automationCompositionStateChangeAck.setResponseTo(cacheProvider.getMsgIdentification().get(element.getId()));
automationCompositionStateChangeAck.setStateChangeResult(stateChangeResult);
participantPrimeAck.setCompositionState(state);
participantPrimeAck.setStateChangeResult(stateChangeResult);
participantPrimeAck.setParticipantId(cacheProvider.getParticipantId());
+ participantPrimeAck.setReplicaId(cacheProvider.getReplicaId());
participantPrimeAck.setState(ParticipantState.ON_LINE);
publisher.sendParticipantPrimeAck(participantPrimeAck);
cacheProvider.getMsgIdentification().remove(compositionId);
private ParticipantStatus createParticipantStatus() {
var statusMsg = new ParticipantStatus();
statusMsg.setParticipantId(cacheProvider.getParticipantId());
+ statusMsg.setReplicaId(cacheProvider.getReplicaId());
statusMsg.setState(ParticipantState.ON_LINE);
statusMsg.setParticipantSupportedElementType(cacheProvider.getSupportedAcElementTypes());
return statusMsg;
@Setter
private boolean registered = false;
+ @Getter
+ private final UUID replicaId;
+
private final List<ParticipantSupportedElementType> supportedAcElementTypes;
@Getter
public CacheProvider(ParticipantParameters parameters) {
this.participantId = parameters.getIntermediaryParameters().getParticipantId();
this.supportedAcElementTypes = parameters.getIntermediaryParameters().getParticipantSupportedElementTypes();
+ this.replicaId = UUID.randomUUID();
}
public List<ParticipantSupportedElementType> getSupportedAcElementTypes() {
* @return true if it applies, false otherwise
*/
public boolean appliesTo(ParticipantMessage participantMsg) {
- return participantMsg.appliesTo(cacheProvider.getParticipantId());
+ return participantMsg.appliesTo(cacheProvider.getParticipantId(), cacheProvider.getReplicaId());
}
/**
* @return true if it applies, false otherwise
*/
public boolean appliesTo(ParticipantAckMessage participantMsg) {
- return participantMsg.appliesTo(cacheProvider.getParticipantId());
+ return participantMsg.appliesTo(cacheProvider.getParticipantId(), cacheProvider.getReplicaId());
}
/**
public void sendParticipantRegister() {
var participantRegister = new ParticipantRegister();
participantRegister.setParticipantId(cacheProvider.getParticipantId());
+ participantRegister.setReplicaId(cacheProvider.getReplicaId());
participantRegister.setParticipantSupportedElementType(cacheProvider.getSupportedAcElementTypes());
publisher.sendParticipantRegister(participantRegister);
public void sendParticipantDeregister() {
var participantDeregister = new ParticipantDeregister();
participantDeregister.setParticipantId(cacheProvider.getParticipantId());
+ participantDeregister.setReplicaId(cacheProvider.getReplicaId());
publisher.sendParticipantDeregister(participantDeregister);
}
private ParticipantStatus makeHeartbeat() {
var heartbeat = new ParticipantStatus();
heartbeat.setParticipantId(cacheProvider.getParticipantId());
+ heartbeat.setReplicaId(cacheProvider.getReplicaId());
heartbeat.setState(ParticipantState.ON_LINE);
heartbeat.setParticipantSupportedElementType(cacheProvider.getSupportedAcElementTypes());
void appliesToTest() {
var cacheProvider = mock(CacheProvider.class);
when(cacheProvider.getParticipantId()).thenReturn(CommonTestData.getParticipantId());
+ when(cacheProvider.getReplicaId()).thenReturn(CommonTestData.getReplicaId());
var participantHandler = new ParticipantHandler(mock(AutomationCompositionHandler.class),
mock(AcLockHandler.class), mock(AcDefinitionHandler.class), mock(ParticipantMessagePublisher.class),
cacheProvider);
public static final UUID AC_ID_0 = UUID.randomUUID();
public static final UUID AC_ID_1 = UUID.randomUUID();
public static final UUID PARTCICIPANT_ID = UUID.randomUUID();
+ public static final UUID REPLICA_ID = UUID.randomUUID();
/**
* Get ParticipantIntermediaryParameters.
return PARTCICIPANT_ID;
}
+ public static UUID getReplicaId() {
+ return REPLICA_ID;
+ }
+
public static UUID getRndParticipantId() {
return UUID.randomUUID();
}