nameserver.py
Go to the documentation of this file.
00001 # -*- Python -*-
00002 # -*- coding: utf-8 -*-
00003 
00004 '''rtctree
00005 
00006 Copyright (C) 2009-2014
00007     Geoffrey Biggs
00008     RT-Synthesis Research Group
00009     Intelligent Systems Research Institute,
00010     National Institute of Advanced Industrial Science and Technology (AIST),
00011     Japan
00012     All rights reserved.
00013 Licensed under the Eclipse Public License -v 1.0 (EPL)
00014 http://www.opensource.org/licenses/eclipse-1.0.txt
00015 
00016 Object representing a name server node in the tree.
00017 
00018 '''
00019 
00020 
00021 import CosNaming
00022 from omniORB import CORBA, TRANSIENT_ConnectFailed
00023 
00024 from rtctree.exceptions import *
00025 from rtctree.directory import Directory
00026 
00027 
00028 ##############################################################################
00029 ## Name server node object
00030 
00031 class NameServer(Directory):
00032     '''Node representing a name server.
00033 
00034     Name server nodes should only be present in the first level of the tree.
00035     They can contain directories, managers and components as children.
00036 
00037     This class is a specialisation of the Directory class. It adds the
00038     functionality necessary for connecting to a name server and getting the
00039     root context.
00040 
00041     '''
00042     def __init__(self, orb=None, address=None, parent=None, filter=[],
00043                  *args, **kwargs):
00044         '''Constructor.
00045 
00046         @param orb An orb object to use to connect to the name server.
00047         @param address The address of the name server. Used as the node name.
00048         @param parent The parent node of this node, if any.
00049         @param filter A list of paths to filter by.
00050 
00051         '''
00052         super(NameServer, self).__init__(name=address, parent=parent,
00053                 filter=filter, *args, **kwargs)
00054         self._parse_server(address, orb, filter)
00055 
00056     @property
00057     def is_nameserver(self):
00058         '''Is this node a name server (specialisation of directory nodes)?'''
00059         return True
00060 
00061     @property
00062     def orb(self):
00063         '''The ORB used to access this name server.'''
00064         with self._mutex:
00065             return self._orb
00066 
00067     @property
00068     def ns_object(self):
00069         '''The object representing this name server.'''
00070         with self._mutex:
00071             return self._ns_obj
00072 
00073     def _parse_server(self, address, orb, filter=[]):
00074         # Parse the name server.
00075         with self._mutex:
00076             self._address = address
00077             self._orb = orb
00078             root_context = self._connect_to_naming_service(address)
00079             self._parse_context(root_context, orb, filter)
00080 
00081     def _connect_to_naming_service(self, address):
00082         # Try to connect to a name server and get the root naming context.
00083         with self._mutex:
00084             self._full_address = 'corbaloc::{0}/NameService'.format(address)
00085             try:
00086                 self._ns_obj = self._orb.string_to_object(self._full_address)
00087             except CORBA.ORB.InvalidName:
00088                 raise InvalidServiceError(address)
00089             try:
00090                 root_context = self._ns_obj._narrow(CosNaming.NamingContext)
00091             except CORBA.TRANSIENT, e:
00092                 if e.args[0] == TRANSIENT_ConnectFailed:
00093                     raise InvalidServiceError(address)
00094                 else:
00095                     raise
00096             if CORBA.is_nil(root_context):
00097                 raise FailedToNarrowRootNamingError(address)
00098             return root_context
00099 
00100 
00101 # vim: tw=79
00102 


rtctree
Author(s): Geoffrey Biggs
autogenerated on Wed Aug 26 2015 16:13:08