当前位置: 首页>>代码示例>>Java>>正文


Java IdGenerator类代码示例

本文整理汇总了Java中org.springframework.util.IdGenerator的典型用法代码示例。如果您正苦于以下问题:Java IdGenerator类的具体用法?Java IdGenerator怎么用?Java IdGenerator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


IdGenerator类属于org.springframework.util包,在下文中一共展示了IdGenerator类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setIdAndTimestamp

import org.springframework.util.IdGenerator; //导入依赖的package包/类
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());
		}
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:19,代码来源:MessageHeaderAccessor.java

示例2: testBuildMessageWithoutIdAndTimestamp

import org.springframework.util.IdGenerator; //导入依赖的package包/类
@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());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:14,代码来源:MessageBuilderTests.java

示例3: idGeneratorCustom

import org.springframework.util.IdGenerator; //导入依赖的package包/类
@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());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:13,代码来源:MessageHeaderAccessorTests.java

示例4: idTimestampWithMutableHeaders

import org.springframework.util.IdGenerator; //导入依赖的package包/类
@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());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:30,代码来源:MessageHeaderAccessorTests.java

示例5: getIdGenerator

import org.springframework.util.IdGenerator; //导入依赖的package包/类
protected static IdGenerator getIdGenerator() {
	return (idGenerator != null ? idGenerator : defaultIdGenerator);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:4,代码来源:MessageHeaders.java

示例6: getIdGenerator

import org.springframework.util.IdGenerator; //导入依赖的package包/类
/**
 * Return the configured {@code IdGenerator}, if any.
 */
public IdGenerator getIdGenerator() {
	return this.idGenerator;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:7,代码来源:IdTimestampMessageHeaderInitializer.java

示例7: setIdGenerator

import org.springframework.util.IdGenerator; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:11,代码来源:IdTimestampMessageHeaderInitializer.java

示例8: setIdGenerator

import org.springframework.util.IdGenerator; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:10,代码来源:MessageHeaderAccessor.java


注:本文中的org.springframework.util.IdGenerator类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。