Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
O
opcua-asyncio
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Nikola Balog
opcua-asyncio
Commits
6b3dc593
Commit
6b3dc593
authored
May 14, 2016
by
ORD
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #181 from stanti/lazyloading
Perform lazy loading when restoring a cached address space
parents
5f20c92f
2fcbbf85
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
4 deletions
+34
-4
opcua/server/address_space.py
opcua/server/address_space.py
+34
-4
No files found.
opcua/server/address_space.py
View file @
6b3dc593
from
threading
import
RLock
import
logging
from
datetime
import
datetime
import
collections
import
shelve
try
:
import
cPickle
as
pickle
except
:
...
...
@@ -466,15 +468,43 @@ class AddressSpace(object):
"""
dump address space as binary to file
"""
with
open
(
path
,
'wb'
)
as
f
:
pickle
.
dump
(
self
.
_nodes
,
f
,
pickle
.
HIGHEST_PROTOCOL
)
s
=
shelve
.
open
(
path
,
"n"
,
protocol
=
pickle
.
HIGHEST_PROTOCOL
)
for
nodeid
in
self
.
_nodes
.
keys
():
s
[
nodeid
.
to_string
()]
=
self
.
_nodes
[
nodeid
]
s
.
close
()
def
load
(
self
,
path
):
"""
load address space from file, overwritting everything current address space
"""
with
open
(
path
,
'rb'
)
as
f
:
self
.
_nodes
=
pickle
.
load
(
f
)
class
LazyLoadingDict
(
collections
.
MutableMapping
):
def
__init__
(
self
,
source
):
self
.
source
=
source
self
.
cache
=
{}
def
__getitem__
(
self
,
key
):
try
:
return
self
.
cache
[
key
]
except
KeyError
:
node
=
self
.
cache
[
key
]
=
self
.
source
[
key
.
to_string
()]
return
node
def
__setitem__
(
self
,
key
,
value
):
self
.
cache
[
key
]
=
value
def
__contains__
(
self
,
key
):
return
key
in
self
.
cache
or
key
.
to_string
()
in
self
.
source
def
__delitem__
(
self
,
key
):
raise
NotImplementedError
def
__iter__
(
self
):
raise
NotImplementedError
def
__len__
(
self
):
raise
NotImplementedError
self
.
_nodes
=
LazyLoader
(
shelve
.
open
(
path
,
"r"
))
def
get_attribute_value
(
self
,
nodeid
,
attr
):
with
self
.
_lock
:
...
...
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