@Override public String toString() { return toParticipantAddress(); } }
/** * Constructs a new {@link EventGenerator} for the robot with the given name. * * @param robotName the name of the robot. * @param conversationUtil used to create conversations. */ public EventGenerator(RobotName robotName, ConversationUtil conversationUtil) { this.robotName = robotName; this.conversationUtil = conversationUtil; this.robotId = ParticipantId.ofUnsafe(robotName.toParticipantAddress()); }
/** * Appends proxyFor to the participant address. * * @param proxyFor the proxyFor. * @param participant the participant to apply the proxyFor. * @return new participant instance in the format * somebody+proxyFor@example.com. If proxyFor is null then just * returns unmodified participant. * @throws InvalidParticipantAddress if participant address and/or proxy are * invalid. */ public static ParticipantId toProxyParticipant(ParticipantId participant, String proxyFor) throws InvalidParticipantAddress { if (!Strings.isNullOrEmpty(proxyFor)) { RobotName robotName = RobotName.fromAddress(participant.getAddress()); robotName.setProxyFor(proxyFor); String robotAddress = robotName.toParticipantAddress(); if (!RobotName.isWellFormedAddress(robotAddress)) { throw new InvalidParticipantAddress(robotAddress, "is not a valid robot name, the proxy is likely to be wrong"); } return ParticipantId.of(robotName.toParticipantAddress()); } else { return participant; } }
/** * Checks whether the event should be filtered out. It can happen * if the robot received several deltas where in some delta it is added to * the wavelet but it didn't receive the WAVELET_SELF_ADDED event yet. * Or if robot already received WAVELET_SELF_REMOVED * event - then it should not receive events after that. * * @param event the event to filter. * @return true if the event should be filtered out */ protected boolean isEventFilteredOut(Event event) { boolean isEventSuspensionOveriden = false; if (event.getType().equals(EventType.WAVELET_SELF_REMOVED)) { // Stop processing events. isEventProcessingSuspended = true; // Allow robot receive WAVELET_SELF_REMOVED event, but suspend after that. isEventSuspensionOveriden = true; } if (event.getType().equals(EventType.WAVELET_SELF_ADDED)) { // Start processing events. isEventProcessingSuspended = false; } if ((isEventProcessingSuspended && !isEventSuspensionOveriden) || event.getModifiedBy().equals(robotName.toParticipantAddress())) { // Robot was removed from wave or this is self generated event. return true; } return false; }
public void testToAddress() { assertEquals("robot@appspot.com", RobotName.fromAddress("robot@appspot.com").toParticipantAddress()); assertEquals("robot+id@appspot.com", RobotName.fromAddress("robot+id@appspot.com").toParticipantAddress()); assertEquals("robot+id#1@appspot.com", RobotName.fromAddress("robot+id#1@appspot.com").toParticipantAddress()); assertEquals("robot@appspot.com", RobotName.fromAddress("robot#1@appspot.com").toEmailAddress()); assertEquals("robot#1@appspot.com", RobotName.fromAddress("robot#1@appspot.com").toEmailAddressWithVersion()); assertEquals("robot@appspot.com", RobotName.fromAddress("robot+proxy#1@appspot.com").toEmailAddress()); assertEquals("robot#1@appspot.com", RobotName.fromAddress("robot+proxy#1@appspot.com").toEmailAddressWithVersion()); }
public void testToAddress() { assertEquals("robot@appspot.com", RobotName.fromAddress("robot@appspot.com").toParticipantAddress()); assertEquals("robot+id@appspot.com", RobotName.fromAddress("robot+id@appspot.com").toParticipantAddress()); assertEquals("robot+id#1@appspot.com", RobotName.fromAddress("robot+id#1@appspot.com").toParticipantAddress()); assertEquals("robot@appspot.com", RobotName.fromAddress("robot#1@appspot.com").toEmailAddress()); assertEquals("robot#1@appspot.com", RobotName.fromAddress("robot#1@appspot.com").toEmailAddressWithVersion()); assertEquals("robot@appspot.com", RobotName.fromAddress("robot+proxy#1@appspot.com").toEmailAddress()); assertEquals("robot#1@appspot.com", RobotName.fromAddress("robot+proxy#1@appspot.com").toEmailAddressWithVersion()); }