From 8f056afbb6ad09398c983403af07b6e9b5cc9098 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Sat, 28 Dec 2013 12:58:57 +0100 Subject: [PATCH] [New] added a semi unique id generation to StrolchAgent --- .../runtime/agent/api/StrolchAgent.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/main/java/li/strolch/runtime/agent/api/StrolchAgent.java b/src/main/java/li/strolch/runtime/agent/api/StrolchAgent.java index 2040bd65c..16b216a40 100644 --- a/src/main/java/li/strolch/runtime/agent/api/StrolchAgent.java +++ b/src/main/java/li/strolch/runtime/agent/api/StrolchAgent.java @@ -40,6 +40,11 @@ public class StrolchAgent { public static final String PROP_REALMS = "realms"; //$NON-NLS-1$ private static final Logger logger = LoggerFactory.getLogger(StrolchAgent.class); + /** + * the semi-unique id which is incremented on every {@link #getUniqueId()}-method call + */ + private static long uniqueId = System.currentTimeMillis() - 1119953500000l; + private ComponentContainerImpl container; private StrolchConfiguration strolchConfiguration; @@ -107,4 +112,18 @@ public class StrolchAgent { throw new IllegalStateException(msg); } } + + /** + * @return Returns the pseudo unique Id to be used during object creation from external services. + */ + public static synchronized String getUniqueId() { + + if (uniqueId == Long.MAX_VALUE - 1) { + uniqueId = 0; + } + + uniqueId += 1; + return Long.toString(uniqueId); + } + }