Commits

Adam Lindsay committed e6e9569

Swapped 'destination' and 'method' in the signature for (generic_)remote_call(): with introduction of partials, it's now easier to have dedicated client commands as functions.

Comments (0)

Files changed (6)

     comp = location.rsplit(':', 1)
     return Location(comp[0], int(comp[1]))
 
-def generic_remote_call(clientclass, destination, method, *args):
+def generic_remote_call(clientclass, method, destination, *args):
     transport = TSocket.TSocket(destination.address, destination.port)
     transport = TTransport.TBufferedTransport(transport)
     protocol = TBinaryProtocol.TBinaryProtocol(transport)
     return out
 
 remote_call = partial(generic_remote_call, Locator.Client)
+ping = partial(generic_remote_call, Base.Client, 'ping')
 
 def select_peers(in_set):
     lst = sorted(in_set)
     loc = Location(location.address, location.port)
     for a in range(maximum):
         try:
-            if service == remote_call(loc, 'service_type'):
+            if service == remote_call('service_type', loc):
                 return loc
         except NodeNotFound:
             pass
     loc = Location(location.address, location.port)
     for a in range(maximum):
         try:
-            remote_call(loc, 'ping')
+            ping(loc)
             return loc
         except NodeNotFound:
             loc.port += 1
     loc = Location(location.address, location.port)
     for a in range(maximum):
         try:
-            remote_call(loc, 'ping')
+            ping(loc)
             loc.port += 1
         except NodeNotFound:
             return loc
     wait = WAITPERIOD
     for a in range(maximum):
         try:
-            remote_call(loc, 'ping')
+            ping(loc)
             return
         except NodeNotFound:
             sleep(wait)
         self.peer = peer
         self.ring = HashRing()
         try:
-            remote_call(self.location, 'ping')
+            ping(self.location)
             print 'Uh-oh. Our location responded to a ping!'
             raise socket.error(43, 'Address already in use')
         except NodeNotFound:
         destinations = select_peers(self.ring.nodes.difference(map(loc2str,authorities)))
         for destination in destinations:
             try:
-                remote_call(str2loc(destination), 'remove', location, authorities)
+                remote_call('remove', str2loc(destination), location, authorities)
                 break
             except NodeNotFound, tx:
                 # enter all nodes as authorities to avoid race conditions
         destinations = select_peers(self.ring.nodes.difference(map(loc2str,authorities)))
         for destination in destinations:
             try:
-                remote_call(str2loc(destination), 'add', location, authorities)
+                remote_call('add', str2loc(destination), location, authorities)
                 break
             except NodeNotFound, tx:
                 # enter all nodes as authorities to avoid race conditions
         self.ring.remove(self.here)
         for node in select_peers(self.ring.nodes):
             try:
-                remote_call(str2loc(node), 'remove', self.location, [self.location])
+                remote_call('remove', str2loc(node), self.location, [self.location])
                 break
             except NodeNotFound, tx:
                 pass
     def local_join(self):
         self.ring.append(self.here)
         if self.peer:
-            self.ring.extend(map(loc2str, remote_call(self.peer, 'get_all')))
-            remote_call(self.peer, 'join', self.location)
+            self.ring.extend(map(loc2str, remote_call('get_all', self.peer)))
+            remote_call('join', self.peer, self.location)
             print 'Joining the network...'
         else:
             print 'Initiating the network...'
         loc = str2loc(options.peer)
     else:
         loc = find_matching_service(Location('localhost', DEFAULTPORT), SERVICENAME) or sys.exit()
-    print remote_call(loc, 'get', key)
+    print remote_call('get', loc, key)
     else:
         loc = find_matching_service(Location('localhost', DEFAULTPORT), SERVICENAME) or sys.exit()
     for key, value in DICTIONARY.items():
-        remote_call(loc, 'put', key, value)
+        remote_call('put', loc, key, value)
         loc = str2loc(options.peer)
     else:
         loc = find_matching_service(Location('localhost', DEFAULTPORT), SERVICENAME) or sys.exit()
-    remote_call(loc, 'put', key, value)
+    remote_call('put', loc, key, value)
             return self.store[key]
         else:
             try:
-                return remote_call(dest, 'get', key)
+                return remote_call('get', dest, key)
             except location.NodeNotFound, tx:
                 self.remove(tx.location, map(location.str2loc, self.ring.nodes))
                 return ''
             return
         else:
             try:
-                remote_call(dest, 'put', key, value)
+                remote_call('put', dest, key, value)
             except location.NodeNotFound, tx:
                 self.remove(tx.location, map(location.str2loc, self.ring.nodes))
                 return
         destinations = location.select_peers(self.ring.nodes.difference(map(location.loc2str,authorities)))
         for destination in destinations:
             try:
-                remote_call(location.str2loc(destination), 'add', loc, authorities)
+                remote_call('add', location.str2loc(destination), loc, authorities)
                 break
             except location.NodeNotFound, tx:
                 self.remove(tx.location, map(location.str2loc, self.ring.nodes))
         sleep(WAITPERIOD)
         for key, value in self.store.items():
             if location.loc2str(self.get_node(key)) == locstr:
-                remote_call(loc, 'put', key, value)
+                remote_call('put', loc, key, value)
                 del self.store[key] 
                 print 'dropped %s' % key
         print "added %s:%d" % (loc.address, loc.port)
                 dest = self.get_node(key)
                 try:
                     if location.loc2str(dest) not in informed:
-                        remote_call(dest, 'remove', self.location, [self.location])
-                    remote_call(dest, 'ping')
+                        remote_call('remove', dest, self.location, [self.location])
+                    remote_call('ping', dest)
                     informed.add(location.loc2str(dest))
-                    remote_call(dest, 'put', key, value)
+                    remote_call('put', dest, key, value)
                 except location.NodeNotFound, tx:
                     print "not found"
                     pass
             if not informed:
                 for dest in location.select_peers(self.ring.nodes):
                     try:
-                        remote_call(location.str2loc(dest), 'remove', self.location, [self.location])
+                        remote_call('remove', location.str2loc(dest), self.location, [self.location])
                         informed.add(dest)
                         break
                     except location.NodeNotFound, tx:
     else:
         loc = find_matching_service(Location('localhost', DEFAULTPORT), SERVICENAME) or sys.exit()
     for key in KEYS:
-        value = remote_call(loc, 'get', key)
+        value = remote_call('get', loc, key)
         if value:
             print value
         else:
-            print "None received from expected %s" % remote_call(loc, 'get_node', key)
+            print "None received from expected %s" % remote_call('get_node', loc, key)