org.springframework.util.IdGenerator Java Examples

The following examples show how to use org.springframework.util.IdGenerator. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MessageHeaderAccessor.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
public void setIdAndTimestamp() {
	if (!isMutable()) {
		return;
	}
	if (getId() == null) {
		IdGenerator idGenerator = (MessageHeaderAccessor.this.idGenerator != null ?
				MessageHeaderAccessor.this.idGenerator : MessageHeaders.getIdGenerator());
		UUID id = idGenerator.generateId();
		if (id != null && id != MessageHeaders.ID_VALUE_NONE) {
			getRawHeaders().put(ID, id);
		}
	}
	if (getTimestamp() == null) {
		if (MessageHeaderAccessor.this.enableTimestamp) {
			getRawHeaders().put(TIMESTAMP, System.currentTimeMillis());
		}
	}
}
 
Example #2
Source File: MessageHeaderAccessor.java    From spring-analysis-note with MIT License 6 votes vote down vote up
public void setImmutable() {
	if (!this.mutable) {
		return;
	}

	if (getId() == null) {
		IdGenerator idGenerator = (MessageHeaderAccessor.this.idGenerator != null ?
				MessageHeaderAccessor.this.idGenerator : MessageHeaders.getIdGenerator());
		UUID id = idGenerator.generateId();
		if (id != MessageHeaders.ID_VALUE_NONE) {
			getRawHeaders().put(ID, id);
		}
	}

	if (getTimestamp() == null) {
		if (MessageHeaderAccessor.this.enableTimestamp) {
			getRawHeaders().put(TIMESTAMP, System.currentTimeMillis());
		}
	}

	this.mutable = false;
}
 
Example #3
Source File: MessageHeaderAccessor.java    From java-technology-stack with MIT License 6 votes vote down vote up
public void setImmutable() {
	if (!this.mutable) {
		return;
	}

	if (getId() == null) {
		IdGenerator idGenerator = (MessageHeaderAccessor.this.idGenerator != null ?
				MessageHeaderAccessor.this.idGenerator : MessageHeaders.getIdGenerator());
		UUID id = idGenerator.generateId();
		if (id != MessageHeaders.ID_VALUE_NONE) {
			getRawHeaders().put(ID, id);
		}
	}

	if (getTimestamp() == null) {
		if (MessageHeaderAccessor.this.enableTimestamp) {
			getRawHeaders().put(TIMESTAMP, System.currentTimeMillis());
		}
	}

	this.mutable = false;
}
 
Example #4
Source File: IdTimestampMessageHeaderInitializer.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
public void initHeaders(MessageHeaderAccessor headerAccessor) {
	IdGenerator idGenerator = getIdGenerator();
	if (idGenerator != null) {
		headerAccessor.setIdGenerator(idGenerator);
	}
	headerAccessor.setEnableTimestamp(isEnableTimestamp());
}
 
Example #5
Source File: MessageHeaderAccessorTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void idTimestampWithMutableHeaders() {
	MessageHeaderAccessor accessor = new MessageHeaderAccessor();
	accessor.setIdGenerator(new IdGenerator() {
		@Override
		public UUID generateId() {
			return MessageHeaders.ID_VALUE_NONE;
		}
	});
	accessor.setEnableTimestamp(false);
	accessor.setLeaveMutable(true);
	MessageHeaders headers = accessor.getMessageHeaders();

	assertNull(headers.getId());
	assertNull(headers.getTimestamp());

	final UUID id = new UUID(0L, 23L);
	accessor.setIdGenerator(new IdGenerator() {
		@Override
		public UUID generateId() {
			return id;
		}
	});
	accessor.setEnableTimestamp(true);
	accessor.setImmutable();

	assertSame(id, accessor.getMessageHeaders().getId());
	assertNotNull(headers.getTimestamp());
}
 
Example #6
Source File: MessageBuilderTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void testBuildMessageWithoutIdAndTimestamp() {
	MessageHeaderAccessor headerAccessor = new MessageHeaderAccessor();
	headerAccessor.setIdGenerator(new IdGenerator() {
		@Override
		public UUID generateId() {
			return MessageHeaders.ID_VALUE_NONE;
		}
	});
	Message<?> message = MessageBuilder.createMessage("foo", headerAccessor.getMessageHeaders());
	assertNull(message.getHeaders().getId());
	assertNull(message.getHeaders().getTimestamp());
}
 
Example #7
Source File: MessageBuilderTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void testBuildMessageWithoutIdAndTimestamp() {
	MessageHeaderAccessor headerAccessor = new MessageHeaderAccessor();
	headerAccessor.setIdGenerator(new IdGenerator() {
		@Override
		public UUID generateId() {
			return MessageHeaders.ID_VALUE_NONE;
		}
	});
	Message<?> message = MessageBuilder.createMessage("foo", headerAccessor.getMessageHeaders());
	assertNull(message.getHeaders().getId());
	assertNull(message.getHeaders().getTimestamp());
}
 
Example #8
Source File: MessageHeaderAccessorTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void idGeneratorCustom() {
	final UUID id = new UUID(0L, 23L);
	MessageHeaderAccessor accessor = new MessageHeaderAccessor();
	accessor.setIdGenerator(new IdGenerator() {
		@Override
		public UUID generateId() {
			return id;
		}
	});
	assertSame(id, accessor.getMessageHeaders().getId());
}
 
Example #9
Source File: IdTimestampMessageHeaderInitializer.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public void initHeaders(MessageHeaderAccessor headerAccessor) {
	IdGenerator idGenerator = getIdGenerator();
	if (idGenerator != null) {
		headerAccessor.setIdGenerator(idGenerator);
	}
	headerAccessor.setEnableTimestamp(isEnableTimestamp());
}
 
Example #10
Source File: MessageBuilderTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void testBuildMessageWithoutIdAndTimestamp() {
	MessageHeaderAccessor headerAccessor = new MessageHeaderAccessor();
	headerAccessor.setIdGenerator(new IdGenerator() {
		@Override
		public UUID generateId() {
			return MessageHeaders.ID_VALUE_NONE;
		}
	});
	Message<?> message = MessageBuilder.createMessage("foo", headerAccessor.getMessageHeaders());
	assertNull(message.getHeaders().getId());
	assertNull(message.getHeaders().getTimestamp());
}
 
Example #11
Source File: IdTimestampMessageHeaderInitializer.java    From java-technology-stack with MIT License 4 votes vote down vote up
/**
 * Return the configured {@code IdGenerator}, if any.
 */
@Nullable
public IdGenerator getIdGenerator() {
	return this.idGenerator;
}
 
Example #12
Source File: IdTimestampMessageHeaderInitializer.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
/**
 * Return the configured {@code IdGenerator}, if any.
 */
public IdGenerator getIdGenerator() {
	return this.idGenerator;
}
 
Example #13
Source File: MessageHeaders.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
protected static IdGenerator getIdGenerator() {
	return (idGenerator != null ? idGenerator : defaultIdGenerator);
}
 
Example #14
Source File: MessageHeaders.java    From spring-analysis-note with MIT License 4 votes vote down vote up
protected static IdGenerator getIdGenerator() {
	IdGenerator generator = idGenerator;
	return (generator != null ? generator : defaultIdGenerator);
}
 
Example #15
Source File: MessageHeaders.java    From java-technology-stack with MIT License 4 votes vote down vote up
protected static IdGenerator getIdGenerator() {
	IdGenerator generator = idGenerator;
	return (generator != null ? generator : defaultIdGenerator);
}
 
Example #16
Source File: IdTimestampMessageHeaderInitializer.java    From spring-analysis-note with MIT License 4 votes vote down vote up
/**
 * Return the configured {@code IdGenerator}, if any.
 */
@Nullable
public IdGenerator getIdGenerator() {
	return this.idGenerator;
}
 
Example #17
Source File: CompositeRouteDefinitionLocator.java    From spring-cloud-gateway with Apache License 2.0 4 votes vote down vote up
public CompositeRouteDefinitionLocator(Flux<RouteDefinitionLocator> delegates,
		IdGenerator idGenerator) {
	this.delegates = delegates;
	this.idGenerator = idGenerator;
}
 
Example #18
Source File: MessageHeaderAccessor.java    From java-technology-stack with MIT License 2 votes vote down vote up
/**
 * A package-private mechanism to configure the IdGenerator strategy to use.
 * <p>By default this property is not set in which case the default IdGenerator
 * in {@link org.springframework.messaging.MessageHeaders} is used.
 * @see IdTimestampMessageHeaderInitializer
 */
void setIdGenerator(IdGenerator idGenerator) {
	this.idGenerator = idGenerator;
}
 
Example #19
Source File: MessageHeaderAccessor.java    From spring4-understanding with Apache License 2.0 2 votes vote down vote up
/**
 * A package-private mechanism to configure the IdGenerator strategy to use.
 * <p>By default this property is not set in which case the default IdGenerator
 * in {@link org.springframework.messaging.MessageHeaders} is used.
 * @see IdTimestampMessageHeaderInitializer
 */
void setIdGenerator(IdGenerator idGenerator) {
	this.idGenerator = idGenerator;
}
 
Example #20
Source File: IdTimestampMessageHeaderInitializer.java    From spring4-understanding with Apache License 2.0 2 votes vote down vote up
/**
 * Configure the IdGenerator strategy to initialize {@code MessageHeaderAccessor}
 * instances with.
 * <p>By default this property is set to {@code null} in which case the default
 * IdGenerator of {@link org.springframework.messaging.MessageHeaders} is used.
 * <p>To have no id's generated at all, see {@link #setDisableIdGeneration()}.
 */
public void setIdGenerator(IdGenerator idGenerator) {
	this.idGenerator = idGenerator;
}
 
Example #21
Source File: IdTimestampMessageHeaderInitializer.java    From java-technology-stack with MIT License 2 votes vote down vote up
/**
 * Configure the IdGenerator strategy to initialize {@code MessageHeaderAccessor}
 * instances with.
 * <p>By default this property is set to {@code null} in which case the default
 * IdGenerator of {@link org.springframework.messaging.MessageHeaders} is used.
 * <p>To have no ids generated at all, see {@link #setDisableIdGeneration()}.
 */
public void setIdGenerator(@Nullable IdGenerator idGenerator) {
	this.idGenerator = idGenerator;
}
 
Example #22
Source File: MessageHeaderAccessor.java    From spring-analysis-note with MIT License 2 votes vote down vote up
/**
 * A package-private mechanism to configure the IdGenerator strategy to use.
 * <p>By default this property is not set in which case the default IdGenerator
 * in {@link org.springframework.messaging.MessageHeaders} is used.
 * @see IdTimestampMessageHeaderInitializer
 */
void setIdGenerator(IdGenerator idGenerator) {
	this.idGenerator = idGenerator;
}
 
Example #23
Source File: IdTimestampMessageHeaderInitializer.java    From spring-analysis-note with MIT License 2 votes vote down vote up
/**
 * Configure the IdGenerator strategy to initialize {@code MessageHeaderAccessor}
 * instances with.
 * <p>By default this property is set to {@code null} in which case the default
 * IdGenerator of {@link org.springframework.messaging.MessageHeaders} is used.
 * <p>To have no ids generated at all, see {@link #setDisableIdGeneration()}.
 */
public void setIdGenerator(@Nullable IdGenerator idGenerator) {
	this.idGenerator = idGenerator;
}