Start an RPC to fetch a Value, handling short-cutting dup-fetches
499197
static RPC<TaskGetKey> start( H2ONode target, Key key ) {
    // Do we have an old TaskGetKey in-progress?
    RPC<TaskGetKey> old = TGKS.get(key);
    if( old != null ) return old;
    // Make a new TGK.
    RPC<TaskGetKey> rpc = new RPC(target,new TaskGetKey(key),1.0f);
    if( (old=TGKS.putIfMatchUnlocked(key,rpc,null)) != null )
      return old;               // Failed because an old exists
    rpc.setTaskNum().call();    // Start the op
    return rpc;                 // Successful install of a fresh RPC
  }
1011624
def _dispatch_rpc(self, address, rpc_id, arg_payload):
        """"""

        if self.emulator.is_tile_busy(address):
            self._track_change('device.rpc_busy_response', (address, rpc_id, arg_payload, None, None), formatter=format_rpc)
            raise BusyRPCResponse()

        try:
            # Send the RPC immediately and wait for the response
            resp = super(EmulatedDevice, self).call_rpc(address, rpc_id, arg_payload)
            self._track_change('device.rpc_sent', (address, rpc_id, arg_payload, resp, None), formatter=format_rpc)

            return resp
        except AsynchronousRPCResponse:
            self._track_change('device.rpc_started', (address, rpc_id, arg_payload, None, None), formatter=format_rpc)
            raise
        except Exception as exc:
            self._track_change('device.rpc_exception', (address, rpc_id, arg_payload, None, exc), formatter=format_rpc)
            raise
257932
function router(rpc, handlers, req, res) {
  var $       = rpc.$;
  var api     = rpc.api;
  var request = api.handle(req.method, req.url);
  var dom     = domain.create();

  // the request handler doesn't exit
  // TODO: hoist response logic
  if (!request) {
    res.statusCode = 404;
    res.end();
    return;
  }

  var context = new Context(); // TODO: hoist to own module
  var handle  = request.handle;
  var params  = {};

  // TODO: hoist logic to 'union' module
  var key;
  for(key in request.params) params[key] = request.params[key];
  for(key in request.query)  params[key] = request.query[key];

  var future = $.future();

  future.setWritable(res);
  future.setReadable(req);

  // TODO: extract request making logic
  res.setHeader('Transfer-Encoding' , 'chunked');
  res.setHeader('Content-Type'      , 'application/json');

  dom.on('error', function (err) {
    var statusCode = err.statusCode;

    // only catch known errors, re-throw unexpected errors
    if (!statusCode) throw err;

    // TODO: hoist response logic
    res.statusCode = statusCode;
    res.write(JSON.stringify(err));
    res.end();
  });

  // domain should handle all route errors
  dom.run(function () {
    handlers[handle](future, params, context);
  });
}
731484
def store(key, value, mode = nil, &dup_handler)
      if mode == :add and dup_handler.nil?
        super
      elsif dup_handler
        warn "block supersedes mode argument" unless mode.nil?
        k        = cast_key_in(key)
        callback = lambda { |old_value_pointer, old_size, returned_size, _|
          old_value         = cast_from_null_terminated_colums(
                                *old_value_pointer.get_bytes(0, old_size)
                              )
          replacement, size = cast_to_null_terminated_colums( yield( key,
                                                                     old_value,
                                                                     value ) )
          returned_size.put_int(0, size)
          pointer = Utilities.malloc(size)
          pointer.put_bytes(0, replacement) unless pointer.address.zero?
          pointer
        }
        try(:putproc, k, cast_to_null_terminated_colums(value), callback, nil)
        value
      else
        Utilities.temp_map do |map|
          map.update(value) { |string|
            cast_to_bytes_and_length(string)
          }
          result = super(key, map, mode, &dup_handler)
          result == map ? value : result
        end
      end
    end
588728
def param_fetch_one(self, name):
        ''''''
        try:
            idx = int(name)
            self.mav.param_request_read_send(self.target_system, self.target_component, "", idx)
        except Exception:
            self.mav.param_request_read_send(self.target_system, self.target_component, name, -1)
457230
def fetch_synchronous(self, endpoint_name, query_params=None):
        """"""

        endpoint_url = constants.URL_PREFIX + "/" + self._version + "/" + endpoint_name

        if query_params is None:
            query_params = {}

        return self._request_client.get(endpoint_url, query_params)
410982
def start(self):
        """"""
        self._useV2 = self.cf.platform.get_protocol_version() >= 4

        logger.debug('[%d]: Using V2 protocol: %d', self.port, self._useV2)

        logger.debug('[%d]: Start fetching...', self.port)
        # Register callback in this class for the port
        self.cf.add_port_callback(self.port, self._new_packet_cb)

        # Request the TOC CRC
        self.state = GET_TOC_INFO
        pk = CRTPPacket()
        pk.set_header(self.port, TOC_CHANNEL)
        if self._useV2:
            pk.data = (CMD_TOC_INFO_V2,)
            self.cf.send_packet(pk, expected_reply=(CMD_TOC_INFO_V2,))
        else:
            pk.data = (CMD_TOC_INFO,)
            self.cf.send_packet(pk, expected_reply=(CMD_TOC_INFO,))
1256100
def _prepare_fetch(self, request: Request, response: Response):
        '''
        '''
        self._request = request
        self._response = response

        yield from self._init_stream()

        connection_closed = self._control_connection.closed()

        if connection_closed:
            self._login_table.pop(self._control_connection, None)
            yield from self._control_stream.reconnect()

        request.address = self._control_connection.address

        connection_reused = not connection_closed
        self.event_dispatcher.notify(self.Event.begin_control, request, connection_reused=connection_reused)

        if connection_closed:
            yield from self._commander.read_welcome_message()

        yield from self._log_in()

        self._response.request = request
940922
function rpushx(key, value, req) {
  var val = this.getKey(key, req);
  if(val === undefined) {
    return 0;
  }
  return val.rpush([value]);
}
523389
def fetch(self):
        """"""
        start = datetime.now()
        r = requests.get(self._url(), auth=(self.key, ""))
        self._delay_for_ratelimits(start)

        if r.status_code not in self.TRUTHY_CODES:
            return self._handle_request_exception(r)

        response = r.json()
        if self.ENVELOPE:
            self.data = response.get(self.ENVELOPE, {})
        else:
            self.data = response

        # Move to separate function so it can be overrridden
        self._process_meta(response)
869516
def rpc(self, feature, cmd, *args, **kw):
        

        rpc_id = (feature << 8 | cmd)

        result_format = _create_resp_format(kw.get('result_type'), kw.get('result_format'))
        arg_format = kw.get('arg_format')
        if arg_format is None:
            arg_format = _create_arg_format(args)

        passed_kw = {}
        if 'timeout' in kw:
            passed_kw['timeout'] = kw['timeout']

        response = self.rpc_v2(rpc_id, arg_format, result_format, *args, **passed_kw)

        old_return = kw.get('result_type')
        if old_return is not None:
            return _create_old_return_value(response, *old_return)

        return response
577975
def rpc_start( working_dir, port, subdomain_index=None, thread=True ):
    
    rpc_srv = BlockstackdRPCServer( working_dir, port, subdomain_index=subdomain_index )
    log.debug("Starting RPC on port {}".format(port))

    if thread:
        rpc_srv.start()

    return rpc_srv
29689
async def startup(self, app):
        """"""
        if self.cfg.fake:
            if not FakeConnection:
                raise PluginException('Install fakeredis for fake connections.')

            self.conn = await FakeConnection.create()
            if self.cfg.pubsub:
                self.pubsub_conn = self.conn

        else:
            try:
                if self.cfg.poolsize <= 1:
                    self.conn = await asyncio.wait_for(
                        asyncio_redis.Connection.create(
                            host=self.cfg.host, port=self.cfg.port,
                            password=self.cfg.password, db=self.cfg.db,
                        ), self.cfg.timeout)
                else:
                    self.conn = await asyncio.wait_for(asyncio_redis.Pool.create(
                        host=self.cfg.host, port=self.cfg.port,
                        password=self.cfg.password, db=self.cfg.db,
                        poolsize=self.cfg.poolsize,
                    ), self.cfg.timeout)
                if self.cfg.pubsub:
                    self.pubsub_conn = await asyncio.wait_for(
                        asyncio_redis.Connection.create(
                            host=self.cfg.host, port=self.cfg.port,
                            password=self.cfg.password, db=self.cfg.db,
                        ), self.cfg.timeout
                    )
            except asyncio.TimeoutError:
                raise PluginException('Muffin-redis connection timeout.')

        if self.cfg.pubsub:
            self.pubsub_subscription = await self.pubsub_conn.start_subscribe()
            self.pubsub_reader = ensure_future(self._pubsub_reader_proc(), loop=self.app.loop)
53755
def on_recv_rsp(self, rsp_pb):
        """"""
        ret_code, msg, conn_info_map = InitConnect.unpack_rsp(rsp_pb)

        if self._notify_obj is not None:
            self._notify_obj.on_async_init_connect(ret_code, msg, conn_info_map)

        return ret_code, msg
890087
void startRemotePut() {
    assert !_key.home();
    int x = 0;
    // assert I am waiting on threads with higher priority?
    while( (x=_rwlock.get()) != -1 ) // Spin until rwlock==-1
      if( x == 1 || RW_CAS(0,1,"remote_need_notify") )
        try { ForkJoinPool.managedBlock(this); } catch( InterruptedException e ) { }
  }
478536
def CallFunction(self):
    """"""
    if self._xmlrpc_proxy is None:
      return None

    rpc_call = getattr(self._xmlrpc_proxy, self._RPC_FUNCTION_NAME, None)
    if rpc_call is None:
      return None

    try:
      return rpc_call()  # pylint: disable=not-callable
    except (
        expat.ExpatError, SocketServer.socket.error,
        xmlrpclib.Fault) as exception:
      logger.warning('Unable to make RPC call with error: {0!s}'.format(
          exception))
      return None
324717
def process_result_value(self, value, dialect):
        
        if value is not None:
            cmd = "value = {}".format(value)
            exec(cmd)
        return value