Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
commons
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
3
Merge Requests
3
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DevOps
commons
Commits
43762b4d
Commit
43762b4d
authored
Apr 12, 2018
by
zhiguo.liu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
# 新 ID 生成器支持 data.center.id 为 0 时的反序列化
parent
1947c464
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
3 deletions
+8
-3
DefaultUidGenerator.java
.../java/cn/quantgroup/tech/util/id/DefaultUidGenerator.java
+8
-3
No files found.
commons-spring/src/main/java/cn/quantgroup/tech/util/id/DefaultUidGenerator.java
View file @
43762b4d
...
@@ -123,7 +123,6 @@ public class DefaultUidGenerator implements UidGenerator, InitializingBean {
...
@@ -123,7 +123,6 @@ public class DefaultUidGenerator implements UidGenerator, InitializingBean {
}
}
}
}
// TODO: 2018/3/5 反序列化 uid
@Override
@Override
public
String
parseUID
(
String
uidStr
)
{
public
String
parseUID
(
String
uidStr
)
{
BigInteger
bigInteger
=
new
BigInteger
(
uidStr
);
BigInteger
bigInteger
=
new
BigInteger
(
uidStr
);
...
@@ -138,6 +137,9 @@ public class DefaultUidGenerator implements UidGenerator, InitializingBean {
...
@@ -138,6 +137,9 @@ public class DefaultUidGenerator implements UidGenerator, InitializingBean {
long
sequence
=
(
uid
<<
(
totalBits
-
sequenceBits
))
>>>
(
totalBits
-
sequenceBits
);
long
sequence
=
(
uid
<<
(
totalBits
-
sequenceBits
))
>>>
(
totalBits
-
sequenceBits
);
long
workerId
=
(
uid
<<
(
totalBits
-
workerIdBits
-
sequenceBits
))
>>>
(
totalBits
-
workerIdBits
);
long
workerId
=
(
uid
<<
(
totalBits
-
workerIdBits
-
sequenceBits
))
>>>
(
totalBits
-
workerIdBits
);
long
dataCenterId
=
(
uid
<<
(
totalBits
-
dataCenterIdBits
-
workerIdBits
-
sequenceBits
))
>>>
(
totalBits
-
dataCenterIdBits
);
long
dataCenterId
=
(
uid
<<
(
totalBits
-
dataCenterIdBits
-
workerIdBits
-
sequenceBits
))
>>>
(
totalBits
-
dataCenterIdBits
);
if
(
dataCenterIdBits
==
0
)
{
dataCenterId
=
0
;
}
long
deltaSeconds
=
uid
>>>
(
dataCenterIdBits
+
workerIdBits
+
sequenceBits
);
long
deltaSeconds
=
uid
>>>
(
dataCenterIdBits
+
workerIdBits
+
sequenceBits
);
Date
thatTime
=
new
Date
(
TimeUnit
.
SECONDS
.
toMillis
(
epochSeconds
+
deltaSeconds
));
Date
thatTime
=
new
Date
(
TimeUnit
.
SECONDS
.
toMillis
(
epochSeconds
+
deltaSeconds
));
String
thatTimeStr
=
DateFormatUtils
.
format
(
thatTime
,
DATETIME_PATTERN
);
String
thatTimeStr
=
DateFormatUtils
.
format
(
thatTime
,
DATETIME_PATTERN
);
...
@@ -147,8 +149,11 @@ public class DefaultUidGenerator implements UidGenerator, InitializingBean {
...
@@ -147,8 +149,11 @@ public class DefaultUidGenerator implements UidGenerator, InitializingBean {
BigInteger
workerBig
=
getBigIntegerFromLength
(
workerIdBits
).
shiftLeft
((
int
)
sequenceBits
).
and
(
bigInteger
);
BigInteger
workerBig
=
getBigIntegerFromLength
(
workerIdBits
).
shiftLeft
((
int
)
sequenceBits
).
and
(
bigInteger
);
System
.
out
.
println
(
workerBig
);
System
.
out
.
println
(
workerBig
);
long
sequence
=
getBigIntegerFromLength
(
sequenceBits
).
and
(
bigInteger
).
longValue
();
long
sequence
=
getBigIntegerFromLength
(
sequenceBits
).
and
(
bigInteger
).
longValue
();
long
workerId
=
getBigIntegerFromLength
(
workerIdBits
).
and
(
bigInteger
.
shiftRight
((
int
)
sequenceBits
)).
longValue
();
long
workerId
=
getBigIntegerFromLength
(
workerIdBits
).
and
(
bigInteger
.
shiftRight
((
int
)
sequenceBits
)).
longValue
();
long
dataCenterId
=
getBigIntegerFromLength
(
dataCenterIdBits
).
and
(
bigInteger
.
shiftRight
((
int
)
sequenceBits
+(
int
)
workerIdBits
)).
longValue
();
long
dataCenterId
=
getBigIntegerFromLength
(
dataCenterIdBits
).
and
(
bigInteger
.
shiftRight
((
int
)
sequenceBits
+
(
int
)
workerIdBits
)).
longValue
();
if
(
dataCenterIdBits
==
0
)
{
dataCenterId
=
0
;
}
long
deltaSeconds
=
bigInteger
.
shiftRight
((
int
)
dataCenterIdBits
+
(
int
)
workerIdBits
+
(
int
)
sequenceBits
).
longValue
();
long
deltaSeconds
=
bigInteger
.
shiftRight
((
int
)
dataCenterIdBits
+
(
int
)
workerIdBits
+
(
int
)
sequenceBits
).
longValue
();
Date
thatTime
=
new
Date
(
TimeUnit
.
SECONDS
.
toMillis
(
epochSeconds
+
deltaSeconds
));
Date
thatTime
=
new
Date
(
TimeUnit
.
SECONDS
.
toMillis
(
epochSeconds
+
deltaSeconds
));
String
thatTimeStr
=
DateFormatUtils
.
format
(
thatTime
,
DATETIME_PATTERN
);
String
thatTimeStr
=
DateFormatUtils
.
format
(
thatTime
,
DATETIME_PATTERN
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment