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

org.subethamail.smtp.server.TimeBasedSessionIdFactory Maven / Gradle / Ivy

Go to download

A fork of a fork (!) of SubEtha, an easy-to-use server-side SMTP library for Java.

There is a newer version: 7.1.3
Show newest version
package org.subethamail.smtp.server;

import java.util.Locale;

import javax.annotation.concurrent.GuardedBy;
import javax.annotation.concurrent.ThreadSafe;

/**
 * TimeBasedSessionIdFactory is a very simple {@link SessionIdFactory}, which
 * assigns numeric identifiers based on the current milliseconds time, amending
 * it as necessary to make it unique.
 */
@ThreadSafe
public final class TimeBasedSessionIdFactory implements SessionIdFactory {
	@GuardedBy("this")
	private long lastAllocatedId = 0;

	@Override
	public String create() {
		long id = System.currentTimeMillis();
		synchronized (this) {
			if (id <= lastAllocatedId)
				id = lastAllocatedId + 1;
			lastAllocatedId = id;
		}
		return Long.toString(id, 36).toUpperCase(Locale.ENGLISH);
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy