Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
c85ac09e
D
dragonwell8_jdk
项目概览
openanolis
/
dragonwell8_jdk
通知
4
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
dragonwell8_jdk
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
c85ac09e
编写于
3月 13, 2013
作者:
D
dmocek
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
8001033: Refactor network address handling in virtual machine identifiers
Reviewed-by: smarks, hawtin, mchung
上级
3114becf
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
13 addition
and
56 deletion
+13
-56
src/share/classes/java/rmi/dgc/VMID.java
src/share/classes/java/rmi/dgc/VMID.java
+13
-56
未找到文件。
src/share/classes/java/rmi/dgc/VMID.java
浏览文件 @
c85ac09e
/*
* Copyright (c) 1996, 201
1
, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1996, 201
3
, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
...
...
@@ -25,10 +25,8 @@
package
java.rmi.dgc
;
import
java.io.*
;
import
java.net.*
;
import
java.rmi.server.UID
;
import
java.security.
*
;
import
java.security.
SecureRandom
;
/**
* A VMID is a identifier that is unique across all Java virtual
...
...
@@ -39,9 +37,8 @@ import java.security.*;
* @author Peter Jones
*/
public
final
class
VMID
implements
java
.
io
.
Serializable
{
/** array of bytes uniquely identifying this host */
private
static
byte
[]
localAddr
=
computeAddressHash
();
/** Array of bytes uniquely identifying this host */
private
static
final
byte
[]
randomBytes
;
/**
* @serial array of bytes uniquely identifying host created on
...
...
@@ -56,6 +53,14 @@ public final class VMID implements java.io.Serializable {
/** indicate compatibility with JDK 1.1.x version of class */
private
static
final
long
serialVersionUID
=
-
538642295484486218L
;
static
{
// Generate 8 bytes of random data.
SecureRandom
secureRandom
=
new
SecureRandom
();
byte
bytes
[]
=
new
byte
[
8
];
secureRandom
.
nextBytes
(
bytes
);
randomBytes
=
bytes
;
}
/**
* Create a new VMID. Each new VMID returned from this constructor
* is unique for all Java virtual machines under the following
...
...
@@ -65,7 +70,7 @@ public final class VMID implements java.io.Serializable {
* for the lifetime of this object. <p>
*/
public
VMID
()
{
addr
=
localAddr
;
addr
=
randomBytes
;
uid
=
new
UID
();
}
...
...
@@ -126,52 +131,4 @@ public final class VMID implements java.io.Serializable {
result
.
append
(
uid
.
toString
());
return
result
.
toString
();
}
/**
* Compute the hash an IP address. The hash is the first 8 bytes
* of the SHA digest of the IP address.
*/
private
static
byte
[]
computeAddressHash
()
{
/*
* Get the local host's IP address.
*/
byte
[]
addr
=
java
.
security
.
AccessController
.
doPrivileged
(
new
PrivilegedAction
<
byte
[]>()
{
public
byte
[]
run
()
{
try
{
return
InetAddress
.
getLocalHost
().
getAddress
();
}
catch
(
Exception
e
)
{
}
return
new
byte
[]
{
0
,
0
,
0
,
0
};
}
});
byte
[]
addrHash
;
final
int
ADDR_HASH_LENGTH
=
8
;
try
{
/*
* Calculate message digest of IP address using SHA.
*/
MessageDigest
md
=
MessageDigest
.
getInstance
(
"SHA"
);
ByteArrayOutputStream
sink
=
new
ByteArrayOutputStream
(
64
);
DataOutputStream
out
=
new
DataOutputStream
(
new
DigestOutputStream
(
sink
,
md
));
out
.
write
(
addr
,
0
,
addr
.
length
);
out
.
flush
();
byte
digest
[]
=
md
.
digest
();
int
hashlength
=
Math
.
min
(
ADDR_HASH_LENGTH
,
digest
.
length
);
addrHash
=
new
byte
[
hashlength
];
System
.
arraycopy
(
digest
,
0
,
addrHash
,
0
,
hashlength
);
}
catch
(
IOException
ignore
)
{
/* can't happen, but be deterministic anyway. */
addrHash
=
new
byte
[
0
];
}
catch
(
NoSuchAlgorithmException
complain
)
{
throw
new
InternalError
(
complain
.
toString
(),
complain
);
}
return
addrHash
;
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录