Re: [Orbit-python-list] NameService howto?
- From: Christian Robottom Reis <kiko async com br>
- To: <frehberg cs tu-berlin de>
- Cc: <orbit-python-list lists sourceforge net>, <orbit-list gnome org>
- Subject: Re: [Orbit-python-list] NameService howto?
- Date: Thu, 17 May 2001 15:20:46 -0300 (BRT)
On Thu, 17 May 2001, Frank Rehberger wrote:
> I dont understand how to connect to the nameservice of orbit.
> The following shows my code:
I assume here that you are running orbit-name-server, included in the
ORBit distro, yes?
> orb = CORBA.ORB_init(sys.argv, CORBA.ORB_ID)
> poa = orb.resolve_initial_references("RootPOA")
> service = orb.resolve_initial_references("NameService")
Ah, your error lies here, and I'd like Tack to comment if he may.
Look, every CORBA-ized object publishes an object reference for itself. If
you have noticed, when you run o-n-s, it prints to stdout it's own IOR.
Now I think the standard facility for retrieving this is from etc/orbitrc
or ~/.orbitrc. Which means AFAICS that if you run the NameService, you
have to paste the IOR into that file. I know of no other way to do it, but
perhaps Eliott or somebody from orbit can help.
This is a definite problem, since you'll be running the nameservice with
interruptions, possible, which means you'll have to update the file in
realtime. I avoid doing that completely by going an orthogonal way: I
catch the nameserver reference from o-n-s and:
a) store it in a file in an nfs-shared directory, where clients can catch
it.
b) publish the reference through a webserver or whatever other means. I
personally created a tiny socket server and client that just spits the IOR
over.
Now my personal opinion is that's just plain annoying. But CORBA -- not
ORBit, I think, put perhaps it lacks a service (from what I grasp of it)
provides no standard mechanism to bootstrap the IOR, and that's evil. And
since GNOME publishes IOR in another fashion (using xprops, I think) it
doesn't bother them enough to implement some standard workaround :-)
> I would like to list the nameservice content.
> Who can help me?
I used to have some clients but I seem to have lost them. I'm attaching
the evil solution I use, so you can check it out. Please comment out the
part referring to the configfile as I don't really want to hack this right
now :-)
Take care,
--
/\/\ Christian Reis, Senior Engineer, Async Open Source, Brazil
~\/~ http://async.com.br/~kiko/ | [+55 16] 274 4311
#!/usr/bin/env python
import socket, ConfigParser,sys
# FIXME: comes from ConfigFile
DEFAULT_HOST='localhost'
DEFAULT_PORT=3733
RCFILE="/usr/local/stoq/serverrc"
cp=ConfigParser.ConfigParser()
cp.read(RCFILE)
if cp.has_section("NameService"):
PORT=int(cp.get("NameService","NS_PORT"))
HOST=cp.get("NameService","NS_HOST")
print "From rcfile read port %d on host %s" % (PORT, HOST)
else:
print "Using default port %d" % DEFAULT_PORT
PORT=DEFAULT_PORT
HOST=DEFAULT_HOST
try:
s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.connect((HOST,PORT))
except:
print "Server not running on port %d of host %s" % (PORT,HOST)
sys.exit()
iorstring=s.recv(4096)
s.close()
#print "The Nameserver's IOR is: \n\n"+iorstring
print "IOR: %s" % iorstring,
#!/usr/local/bin/python
import socket, signal, sys, os, getopt, string
# Stoq nameserver IOR spitter v0.0
# Born 22 Nov 2K kiko async com br
# The DEFAULT_PORT is only used if the rcfile can't be read
# DEFAULT_HOST is useless, IMO
DEFAULT_PORT=3733
DEFAULT_HOST=""
DEBUG=0
def appkill(signum, frame):
print "%s: shutting down" % sys.argv[0]
sys.exit()
signal.signal(signal.SIGTERM,appkill)
signal.signal(signal.SIGINT,appkill)
PORT=DEFAULT_PORT
HOST=DEFAULT_HOST
try:
opt, args = getopt.getopt(sys.argv[1:],'p:h', ['help','port='] )
except getopt.error, s:
print "%s: %s" % (sys.argv[0] , s)
sys.exit(1)
for o in opt:
if o[0] == "-d" or o[0] == "--debug":
DEBUG=1
if o[0] == "-p" or o[0] == "--port":
try:
PORT=int(o[1])
except ValueError:
print "%s: port number must be integer" % sys.argv[0]
sys.exit(1)
if o[0] == "-h" or o[0] == "--help":
print "%s: CORBA Nameserver Wrapper (with TCP-spit IOR)" % sys.argv[0]
print "%s: usage: %s [-p port]" % ( sys.argv[0] , sys.argv[0] )
sys.exit(1)
try:
s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
# to avoid being stuck with sockets in TIME_WAIT
s.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1)
s.bind(HOST,PORT)
s.listen(1)
except:
s.close()
print 'Problem with socket creation and bind'
print sys.exc_type,sys.exc_value
sys.exit(1)
# inverted exception handling here - found is good, default is bad
try:
for f in string.split(os.environ["PATH"],":"):
if os.access( "%s/orbit-name-server" % f,os.X_OK):
raise "Found"
print "%s: orbit-name-server not found in path" % sys.argv[0]
sys.exit(1)
except "Found":
pass
# This is a bit of black magic but it works for me: we popen
# orbit-name-server, read the ior and f.close() it. Now, since this
# child process is mine, it dies when I sys.exit(), and we're all happy.
# Looks unlikely to work on Win32, but os.popen doesn't work anyway :-)
f=os.popen("orbit-name-server &","r")
iorstring=f.readline()
f.close()
if DEBUG:
print "IOR is %s" % iorstring
if DEBUG:
print "%s: started up with port to %s" % ( sys.argv[0] , PORT )
try:
while 1:
conn,addr=s.accept()
if DEBUG:
print 'Peer is',addr
conn.send(iorstring)
conn.close()
except SystemExit:
sys.exit(0)
except:
conn.close()
s.close()
print 'Foobared'
print sys.exc_type,sys.exc_value
sys.exit(1)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]