All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.nadron.service.impl.SimpleUniqueIdGenerator Maven / Gradle / Ivy

Go to download

Nadron is a high speed socket based java game server written using Netty and Mike Rettig's Jetlang. It is specifically tuned for network based multiplayer games and supports TCP and UDP network protocols.

The newest version!
package io.nadron.service.impl;

import io.nadron.service.UniqueIDGeneratorService;
import io.nadron.util.NadronConfig;

import java.util.concurrent.atomic.AtomicLong;


/**
 * Uses an atomic long to increment and provide a unique id. This will not work
 * in case of clustered servers.
 * 
 * @author Abraham.Menacherry
 * 
 */
public class SimpleUniqueIdGenerator implements UniqueIDGeneratorService 
{
	public static final AtomicLong ID = new AtomicLong(0l);
	
	@Override
	public Object generate() 
	{
		String nodeName = System.getProperty(NadronConfig.NODE_NAME);
		if (null == nodeName || "".equals(nodeName)) 
		{
			return ID.incrementAndGet();
		} 
		else 
		{
			return nodeName + ID.incrementAndGet();
		}
	}

	@Override
	public Object generateFor(@SuppressWarnings("rawtypes") Class klass) 
	{
		return klass.getSimpleName() + ID.incrementAndGet();
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy