Toggle navigation
Toggle navigation
This project
Loading...
Sign in
홍길동
/
onos
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
Brian O'Connor
2015-02-19 11:40:05 -0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
4e6c17d2b9d29c6f515113bb08b580f54a3a3d94
4e6c17d2
1 parent
2872628e
Fixing hash for Intent keys
Change-Id: Ie7807d95b3e58f2e79c6127251ef355b77ba05ff
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
13 deletions
core/api/src/main/java/org/onosproject/net/intent/Key.java
core/store/serializers/src/main/java/org/onosproject/store/serializers/KryoNamespaces.java
core/api/src/main/java/org/onosproject/net/intent/Key.java
View file @
4e6c17d
...
...
@@ -26,9 +26,9 @@ import java.util.Objects;
* Key class for Intents.
*/
// TODO maybe pull this up to utils
// TODO need to make this classes kryo serializable
public
class
Key
{
public
abstract
class
Key
{
//TODO consider making this a HashCode object (worry about performance)
private
final
long
hash
;
private
static
final
HashFunction
HASH_FN
=
Hashing
.
md5
();
...
...
@@ -40,15 +40,44 @@ public class Key {
return
hash
;
}
@Override
public
int
hashCode
()
{
return
(
int
)
(
hash
()
^
(
hash
()
>>>
32
));
}
@Override
public
abstract
boolean
equals
(
Object
obj
);
/**
* Creates a key based on the provided string.
* <p>
* Note: Two keys with equal value, but different appId, are not equal.
* </p>
*
* @param key the provided string
* @param appId application id to associate with this key
* @return the key for the string
*/
public
static
Key
of
(
String
key
,
ApplicationId
appId
)
{
return
new
StringKey
(
key
,
appId
);
}
/**
* Creates a key based on the provided long.
* <p>
* Note: Two keys with equal value, but different appId, are not equal.
* Also, "10" and 10L are different.
* </p>
*
* @param key the provided long
* @param appId application id to associate with this key
* @return the key for the long
*/
public
static
Key
of
(
long
key
,
ApplicationId
appId
)
{
return
new
LongKey
(
key
,
appId
);
}
p
ublic
static
final
class
StringKey
extends
Key
{
p
rivate
static
final
class
StringKey
extends
Key
{
private
final
ApplicationId
appId
;
private
final
String
key
;
...
...
@@ -67,9 +96,10 @@ public class Key {
return
key
;
}
// checkstyle requires this
@Override
public
int
hashCode
()
{
return
key
.
hashCode
();
return
super
.
hashCode
();
}
@Override
...
...
@@ -87,7 +117,7 @@ public class Key {
}
}
p
ublic
static
final
class
LongKey
extends
Key
{
p
rivate
static
final
class
LongKey
extends
Key
{
private
final
ApplicationId
appId
;
private
final
long
key
;
...
...
@@ -106,9 +136,10 @@ public class Key {
return
"0x"
+
Long
.
toHexString
(
key
);
}
// checkstyle requires this
@Override
public
int
hashCode
()
{
return
(
int
)
(
key
^
(
key
>>>
32
)
);
return
super
.
hashCode
(
);
}
@Override
...
...
@@ -120,10 +151,10 @@ public class Key {
return
false
;
}
final
LongKey
other
=
(
LongKey
)
obj
;
return
Objects
.
equals
(
this
.
appId
,
other
.
appId
)
&&
this
.
key
==
other
.
key
;
return
this
.
hash
()
==
other
.
hash
()
&&
this
.
key
==
other
.
key
&&
Objects
.
equals
(
this
.
appId
,
other
.
appId
);
}
}
}
...
...
core/store/serializers/src/main/java/org/onosproject/store/serializers/KryoNamespaces.java
View file @
4e6c17d
...
...
@@ -18,7 +18,6 @@ package org.onosproject.store.serializers;
import
com.google.common.collect.ImmutableList
;
import
com.google.common.collect.ImmutableMap
;
import
com.google.common.collect.ImmutableSet
;
import
org.onlab.packet.ChassisId
;
import
org.onlab.packet.Ip4Address
;
import
org.onlab.packet.Ip4Prefix
;
...
...
@@ -284,9 +283,9 @@ public final class KryoNamespaces {
FlowRuleBatchEntry
.
FlowRuleOperation
.
class
,
IntentId
.
class
,
IntentState
.
class
,
Key
.
class
,
Key
.
LongKey
.
class
,
Key
.
StringKey
.
class
,
//Key.class, is abstract
Key
.
of
(
1L
,
new
DefaultApplicationId
(
0
,
"bar"
)).
getClass
(),
//LongKey.class
Key
.
of
(
"foo"
,
new
DefaultApplicationId
(
0
,
"bar"
)).
getClass
(),
//StringKey.class
Intent
.
class
,
ConnectivityIntent
.
class
,
PathIntent
.
class
,
...
...
Please
register
or
login
to post a comment