
org.subethamail.smtp.server.TimeBasedSessionIdFactory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of subethasmtp Show documentation
Show all versions of subethasmtp Show documentation
A fork of a fork (!) of SubEtha, an easy-to-use server-side SMTP library for Java.
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