Example #1
0
def registerType(type, pid):
    assert type.isType()

    cache_lock.acquire()
    try:
        id = "T"+generate()
        if isNodeId(pid):
            __cache[id] = [type, None, __getTypeReferences(type)]
        else:
            __cache[id] = [type, pid, __getTypeReferences(type)]

        return id
    finally:
        cache_lock.release()
Example #2
0
def registerType(type, pid):
    assert type.isType()

    cache_lock.acquire()
    try:
        id = "T" + generate()
        if isNodeId(pid):
            __cache[id] = [type, None, __getTypeReferences(type)]
        else:
            __cache[id] = [type, pid, __getTypeReferences(type)]

        return id
    finally:
        cache_lock.release()
Example #3
0
    def my_name_is(self, req, msgid, message, data):
        # when someone connects who already has an id they need to let us know who they are...
        name = str(data[0])
        assert utils.isNodeId(name)

        req.name = str(name)
        req.send(msgid, (done, ))
        if neighbours.has_key(name):
            return
        neighbours[name] = req
        req.type = "SERVER"
        sendMessageToNode(name, None, my_name_is, node_id)

        stats.inc_stat("server_con_current")
        stats.inc_stat("server_con_total")
Example #4
0
    def my_name_is(self, req, msgid, message, data):
        # when someone connects who already has an id they need to let us know who they are...
        name = str(data[0])
        assert utils.isNodeId(name)

        req.name = str(name)
        req.send(msgid, (done, ))
        if neighbours.has_key(name):
            return
        neighbours[name] = req
        req.type = "SERVER"
        sendMessageToNode(name, None, my_name_is, node_id)

        stats.inc_stat("server_con_current")
        stats.inc_stat("server_con_total")
Example #5
0
def main():
    """\internal
    \brief Parse command line options and start the server.
    """
    global server, domain_server, node_id, neighbours, local_ts, options

    options = getOptions()

    if not options.daemon:
        import subprocess
        subprocess.Popen("linda_monitor", shell=True)
        #pid = os.fork()
        #if pid != 0:
        #    from monitor import monitor
        #    return monitor.Thread(options.port).run()

    _linda_server.init()

    if options.peer:
        options.peer.append("127.0.0.1") # always allow local connections.

    def lookupname(addr):
        try:
            addr,r = addr.split("/")
        except ValueError:
            r = "32"

        addr = socket.gethostbyname(addr)
        if addr.count(".") != 3:
            print "%s is not in n.n.n.n[/r] format" % (addr+"/"+r)
            sys.exit(0)
        return addr+"/"+r

    node_id = "N"+guid.generate()
    _linda_server.setnodeid(node_id)

    if options.mdns and not options.disable_mdns:
        import mdns
        s = mdns.connect()
        if s:
            options.connect = s[0]
            options.connectport = s[1]

    if options.connect is not None and len(options.connect) > 0:
        if options.connectport:
            con = zip(options.connect, options.connectport) + [(x, 2102) for x in options.connect[len(options.connectport):]]
        else:
            con = zip(options.connect, [2102 for _ in options.connect])
        assert len(con) == len(options.connect)
        i = 0
        while True:
            svr, port = con[i]
            s = _linda_server.connect("%s:%s" % (svr, port));
            if s is None:
                if i < len(con)-1:
                    i += 1
                    continue
                else:
                    print "Unable to connect to server %s:%i." % (svr, port)
                    sys.exit(-1)

            s = Connection(s)
            s.type = None

            s.send(None, (get_node_id, ))
            node = s.recv()[2]
            assert utils.isNodeId(node), repr(node)

            s.send(None, (my_name_is, node_id))
            s.recv()
            s.type = "SERVER"

            s.name = node
            neighbours[node] = s
            connections.sockets.append(s)
            break

    local_ts.newTupleSpace("UTS")

    while True:
        try:
            socket_watcher()
        except KeyboardInterrupt:
            cleanShutdown()
            raise
        break
Example #6
0
def main():
    """\internal
    \brief Parse command line options and start the server.
    """
    global server, domain_server, node_id, neighbours, local_ts, options

    options = getOptions()

    if not options.daemon:
        import subprocess
        subprocess.Popen("linda_monitor", shell=True)
        #pid = os.fork()
        #if pid != 0:
        #    from monitor import monitor
        #    return monitor.Thread(options.port).run()

    _linda_server.init()

    if options.peer:
        options.peer.append("127.0.0.1")  # always allow local connections.

    def lookupname(addr):
        try:
            addr, r = addr.split("/")
        except ValueError:
            r = "32"

        addr = socket.gethostbyname(addr)
        if addr.count(".") != 3:
            print "%s is not in n.n.n.n[/r] format" % (addr + "/" + r)
            sys.exit(0)
        return addr + "/" + r

    node_id = "N" + guid.generate()
    _linda_server.setnodeid(node_id)

    if options.mdns and not options.disable_mdns:
        import mdns
        s = mdns.connect()
        if s:
            options.connect = s[0]
            options.connectport = s[1]

    if options.connect is not None and len(options.connect) > 0:
        if options.connectport:
            con = zip(options.connect, options.connectport) + [
                (x, 2102) for x in options.connect[len(options.connectport):]
            ]
        else:
            con = zip(options.connect, [2102 for _ in options.connect])
        assert len(con) == len(options.connect)
        i = 0
        while True:
            svr, port = con[i]
            s = _linda_server.connect("%s:%s" % (svr, port))
            if s is None:
                if i < len(con) - 1:
                    i += 1
                    continue
                else:
                    print "Unable to connect to server %s:%i." % (svr, port)
                    sys.exit(-1)

            s = Connection(s)
            s.type = None

            s.send(None, (get_node_id, ))
            node = s.recv()[2]
            assert utils.isNodeId(node), repr(node)

            s.send(None, (my_name_is, node_id))
            s.recv()
            s.type = "SERVER"

            s.name = node
            neighbours[node] = s
            connections.sockets.append(s)
            break

    local_ts.newTupleSpace("UTS")

    while True:
        try:
            socket_watcher()
        except KeyboardInterrupt:
            cleanShutdown()
            raise
        break