File: BankServer.py

package info (click to toggle)
pyro 1%3A3.14-5
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 2,048 kB
  • ctags: 1,988
  • sloc: python: 11,194; xml: 128; sh: 52; makefile: 28
file content (56 lines) | stat: -rw-r--r-- 1,171 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env python

#
#	The banks server
#

import sys
import Pyro.naming
import Pyro.core
from Pyro.errors import PyroError,NamingError
import banks

group = ':banks1'   # the namespace group for all test servers

# avoid network port trouble with the VSB bank server
Pyro.config.PYRO_PORT=Pyro.config.PYRO_PORT+1

# initialize the server and set the default namespace group
Pyro.core.initServer()
Pyro.config.PYRO_NS_DEFAULTGROUP=group


# locate the NS
print 'Searching Naming Service...'
daemon = Pyro.core.Daemon()
locator = Pyro.naming.NameServerLocator()
ns = locator.getNS()


# make sure our namespace group exists
try:
	ns.createGroup(group)
except NamingError:
	pass

daemon.useNameServer(ns)

# connect a new object implementation (first unregister previous one)
try:
	ns.unregister('Rabobank')
	ns.unregister('VSB')
except NamingError:
	pass

# use Delegation approach for object implementation
obj1=Pyro.core.ObjBase()
obj1.delegateTo(banks.Rabobank())
daemon.connect(obj1,'Rabobank')
obj2=Pyro.core.ObjBase()
obj2.delegateTo(banks.VSB())
daemon.connect(obj2,'VSB')

# enter the service loop.
print 'Banks are ready for customers.'
daemon.requestLoop()