- bodies=AMF.getint(req) # Read number of bodies
- bodies.times do # Read each body
- message=AMF.getstring(req) # | get message name
- index=AMF.getstring(req) # | get index in response sequence
- bytes=AMF.getlong(req) # | get total size in bytes
- args=AMF.getvalue(req) # | get response (probably an array)
-
- case message
- when 'putway'; r=putway(renumberednodes,*args)
- renumberednodes=r[3]
- if r[1] != r[2] then renumberedways[r[1]] = r[2] end
- results[index]=AMF.putdata(index,r)
- when 'putrelation'; results[index]=AMF.putdata(index,putrelation(renumberednodes, renumberedways, *args))
- when 'deleteway'; results[index]=AMF.putdata(index,deleteway(*args))
- when 'putpoi'; r=putpoi(*args)
- if r[1] != r[2] then renumberednodes[r[1]] = r[2] end
- results[index]=AMF.putdata(index,r)
- when 'startchangeset'; results[index]=AMF.putdata(index,startchangeset(*args))
+ bodies=AMF.getint(req) # Read number of bodies
+ bodies.times do # Read each body
+ message=AMF.getstring(req) # | get message name
+ index=AMF.getstring(req) # | get index in response sequence
+ bytes=AMF.getlong(req) # | get total size in bytes
+ args=AMF.getvalue(req) # | get response (probably an array)
+ err=false # Abort batch on error
+
+ logger.info("Executing AMF #{message}:#{index}")
+ if err
+ results[index]=[-5,nil]
+ else
+ case message
+ when 'putway'; orn=renumberednodes.dup
+ r=putway(renumberednodes,*args)
+ renumberednodes=r[4].dup
+ r[4].delete_if { |k,v| orn.has_key?(k) }
+ if r[2] != r[3] then renumberedways[r[2]] = r[3] end
+ results[index]=AMF.putdata(index,r)
+ when 'putrelation'; results[index]=AMF.putdata(index,putrelation(renumberednodes, renumberedways, *args))
+ when 'deleteway'; results[index]=AMF.putdata(index,deleteway(*args))
+ when 'putpoi'; r=putpoi(*args)
+ if r[2] != r[3] then renumberednodes[r[2]] = r[3] end
+ results[index]=AMF.putdata(index,r)
+ when 'startchangeset';results[index]=AMF.putdata(index,startchangeset(*args))
+ end
+ if results[index][0]==-3 then err=true end # If a conflict is detected, don't execute any more writes
+ end