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
tom
2014-09-04 15:28:04 -0700
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
249829af3f69e0ce581b9539c576805f53dadd33
249829af
1 parent
e5ec3fd8
Cleaned-up some names and added a missing sync-block
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
7 deletions
net/core/trivial/src/main/java/org/onlab/onos/net/trivial/impl/SimpleDeviceStore.java
net/core/trivial/src/main/java/org/onlab/onos/net/trivial/impl/SimpleDeviceStore.java
View file @
249829a
...
...
@@ -13,7 +13,6 @@ import org.onlab.onos.net.provider.ProviderId;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.HashMap
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.Map
;
...
...
@@ -32,8 +31,8 @@ import static org.onlab.onos.net.device.DeviceEvent.Type.DEVICE_REMOVED;
class
SimpleDeviceStore
{
private
final
Map
<
DeviceId
,
DefaultDevice
>
devices
=
new
ConcurrentHashMap
<>();
private
final
Set
<
DeviceId
>
available
=
new
HashSet
<>();
private
final
Map
<
DeviceId
,
MastershipRole
>
roles
=
new
HashMap
<>();
private
final
Map
<
DeviceId
,
MastershipRole
>
roles
=
new
ConcurrentHashMap
<>();
private
final
Set
<
DeviceId
>
availableDevices
=
new
HashSet
<>();
/**
* Returns an iterable collection of all devices known to the system.
...
...
@@ -81,7 +80,7 @@ class SimpleDeviceStore {
desc
.
serialNumber
());
synchronized
(
this
)
{
devices
.
put
(
deviceId
,
device
);
available
.
add
(
deviceId
);
available
Devices
.
add
(
deviceId
);
}
return
new
DeviceEvent
(
DeviceEvent
.
Type
.
DEVICE_ADDED
,
device
);
}
...
...
@@ -100,14 +99,14 @@ class SimpleDeviceStore {
desc
.
serialNumber
());
synchronized
(
this
)
{
devices
.
put
(
device
.
id
(),
updated
);
available
.
add
(
device
.
id
());
available
Devices
.
add
(
device
.
id
());
}
return
new
DeviceEvent
(
DeviceEvent
.
Type
.
DEVICE_UPDATED
,
device
);
}
// Otherwise merely attempt to change availability
synchronized
(
this
)
{
boolean
added
=
available
.
add
(
device
.
id
());
boolean
added
=
available
Devices
.
add
(
device
.
id
());
return
added
?
new
DeviceEvent
(
DEVICE_AVAILABILITY_CHANGED
,
device
)
:
null
;
}
}
...
...
@@ -122,7 +121,7 @@ class SimpleDeviceStore {
synchronized
(
this
)
{
Device
device
=
devices
.
get
(
deviceId
);
checkArgument
(
device
!=
null
,
"Device with ID %s is not found"
,
deviceId
);
boolean
removed
=
available
.
remove
(
deviceId
);
boolean
removed
=
available
Devices
.
remove
(
deviceId
);
return
removed
?
new
DeviceEvent
(
DEVICE_AVAILABILITY_CHANGED
,
device
)
:
null
;
}
}
...
...
@@ -193,11 +192,13 @@ class SimpleDeviceStore {
* @return mastership role change event or null if no change
*/
DeviceEvent
setRole
(
DeviceId
deviceId
,
MastershipRole
role
)
{
synchronized
(
this
)
{
Device
device
=
getDevice
(
deviceId
);
checkArgument
(
device
!=
null
,
"Device with ID %s not found"
);
MastershipRole
oldRole
=
roles
.
put
(
deviceId
,
role
);
return
oldRole
==
role
?
null
:
new
DeviceEvent
(
DEVICE_MASTERSHIP_CHANGED
,
device
);
}
}
/**
* Administratively removes the specified device from the store.
...
...
Please
register
or
login
to post a comment