nameserver.py
Go to the documentation of this file.
1 # -*- Python -*-
2 # -*- coding: utf-8 -*-
3 
4 '''rtctree
5 
6 Copyright (C) 2009-2014
7  Geoffrey Biggs
8  RT-Synthesis Research Group
9  Intelligent Systems Research Institute,
10  National Institute of Advanced Industrial Science and Technology (AIST),
11  Japan
12  All rights reserved.
13 Licensed under the Eclipse Public License -v 1.0 (EPL)
14 http://www.opensource.org/licenses/eclipse-1.0.txt
15 
16 Object representing a name server node in the tree.
17 
18 '''
19 
20 
21 import CosNaming
22 from omniORB import CORBA, TRANSIENT_ConnectFailed
23 
24 from rtctree.exceptions import *
25 from rtctree.directory import Directory
26 
27 
28 ##############################################################################
29 ## Name server node object
30 
32  '''Node representing a name server.
33 
34  Name server nodes should only be present in the first level of the tree.
35  They can contain directories, managers and components as children.
36 
37  This class is a specialisation of the Directory class. It adds the
38  functionality necessary for connecting to a name server and getting the
39  root context.
40 
41  '''
42  def __init__(self, orb=None, address=None, parent=None, filter=[],
43  *args, **kwargs):
44  '''Constructor.
45 
46  @param orb An orb object to use to connect to the name server.
47  @param address The address of the name server. Used as the node name.
48  @param parent The parent node of this node, if any.
49  @param filter A list of paths to filter by.
50 
51  '''
52  super(NameServer, self).__init__(name=address, parent=parent,
53  filter=filter, *args, **kwargs)
54  self._parse_server(address, orb, filter)
55 
56  @property
57  def is_nameserver(self):
58  '''Is this node a name server (specialisation of directory nodes)?'''
59  return True
60 
61  @property
62  def orb(self):
63  '''The ORB used to access this name server.'''
64  with self._mutex:
65  return self._orb
66 
67  @property
68  def ns_object(self):
69  '''The object representing this name server.'''
70  with self._mutex:
71  return self._ns_obj
72 
73  def _parse_server(self, address, orb, filter=[]):
74  # Parse the name server.
75  with self._mutex:
76  self._address = address
77  self._orb = orb
78  root_context = self._connect_to_naming_service(address)
79  self._parse_context(root_context, orb, filter)
80 
81  def _connect_to_naming_service(self, address):
82  # Try to connect to a name server and get the root naming context.
83  with self._mutex:
84  self._full_address = 'corbaloc::{0}/NameService'.format(address)
85  try:
86  self._ns_obj = self._orb.string_to_object(self._full_address)
87  except CORBA.ORB.InvalidName:
88  raise InvalidServiceError(address)
89  try:
90  root_context = self._ns_obj._narrow(CosNaming.NamingContext)
91  except CORBA.TRANSIENT, e:
92  if e.args[0] == TRANSIENT_ConnectFailed:
93  raise InvalidServiceError(address)
94  else:
95  raise
96  if CORBA.is_nil(root_context):
97  raise FailedToNarrowRootNamingError(address)
98  return root_context
99 
100 
101 # vim: tw=79
102 
Name server node object.
Definition: nameserver.py:31
def _connect_to_naming_service(self, address)
Definition: nameserver.py:81
Directory node object.
Definition: directory.py:41
def _parse_server(self, address, orb, filter=[])
Definition: nameserver.py:73
def _parse_context(self, context, orb, filter=[])
Definition: directory.py:102
def __init__(self, orb=None, address=None, parent=None, filter=[], args, kwargs)
Definition: nameserver.py:43


rtctree
Author(s): Geoffrey Biggs
autogenerated on Fri Jun 7 2019 21:56:24