Java Code Examples for org.springframework.util.IdGenerator

The following examples show how to use org.springframework.util.IdGenerator. These examples are extracted from open source projects. 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 Project: spring-analysis-note   Source File: MessageHeaderAccessor.java    License: 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 2
Source Project: java-technology-stack   Source File: MessageHeaderAccessor.java    License: 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
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 4
@Override
public void initHeaders(MessageHeaderAccessor headerAccessor) {
	IdGenerator idGenerator = getIdGenerator();
	if (idGenerator != null) {
		headerAccessor.setIdGenerator(idGenerator);
	}
	headerAccessor.setEnableTimestamp(isEnableTimestamp());
}
 
Example 5
Source Project: spring-analysis-note   Source File: MessageBuilderTests.java    License: 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 6
@Override
public void initHeaders(MessageHeaderAccessor headerAccessor) {
	IdGenerator idGenerator = getIdGenerator();
	if (idGenerator != null) {
		headerAccessor.setIdGenerator(idGenerator);
	}
	headerAccessor.setEnableTimestamp(isEnableTimestamp());
}
 
Example 7
Source Project: java-technology-stack   Source File: MessageBuilderTests.java    License: 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 8
Source Project: spring4-understanding   Source File: MessageBuilderTests.java    License: 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 9
@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 10
@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 11
Source Project: spring-analysis-note   Source File: MessageHeaders.java    License: MIT License 4 votes vote down vote up
protected static IdGenerator getIdGenerator() {
	IdGenerator generator = idGenerator;
	return (generator != null ? generator : defaultIdGenerator);
}
 
Example 12
/**
 * Return the configured {@code IdGenerator}, if any.
 */
@Nullable
public IdGenerator getIdGenerator() {
	return this.idGenerator;
}
 
Example 13
Source Project: java-technology-stack   Source File: MessageHeaders.java    License: MIT License 4 votes vote down vote up
protected static IdGenerator getIdGenerator() {
	IdGenerator generator = idGenerator;
	return (generator != null ? generator : defaultIdGenerator);
}
 
Example 14
/**
 * Return the configured {@code IdGenerator}, if any.
 */
@Nullable
public IdGenerator getIdGenerator() {
	return this.idGenerator;
}
 
Example 15
Source Project: spring4-understanding   Source File: MessageHeaders.java    License: Apache License 2.0 4 votes vote down vote up
protected static IdGenerator getIdGenerator() {
	return (idGenerator != null ? idGenerator : defaultIdGenerator);
}
 
Example 16
/**
 * Return the configured {@code IdGenerator}, if any.
 */
public IdGenerator getIdGenerator() {
	return this.idGenerator;
}
 
Example 17
public CompositeRouteDefinitionLocator(Flux<RouteDefinitionLocator> delegates,
		IdGenerator idGenerator) {
	this.delegates = delegates;
	this.idGenerator = idGenerator;
}
 
Example 18
/**
 * 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 19
Source Project: spring-analysis-note   Source File: MessageHeaderAccessor.java    License: 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 20
/**
 * 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 21
Source Project: java-technology-stack   Source File: MessageHeaderAccessor.java    License: 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 22
/**
 * 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 23
/**
 * 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;
}