Tabnine Logo
net.sergeych.farcall
Code IndexAdd Tabnine to your IDE (free)

How to use net.sergeych.farcall

Best Java code snippets using net.sergeych.farcall (Showing top 20 results out of 315)

origin: UniversaBlockchain/universa

/**
 * Start the protocol in one-way mode: this instance only issues commands. Any commands from remote will return
 * error 'unknown_command'
 */
public void start() {
  start(new Target() {
    @Override
    public Object onCommand(Command command) throws Exception {
      throw new RemoteException("unknown_command", "command is not known");
    }
  });
}
origin: UniversaBlockchain/universa

  @Override
  public Object onCommand(Command command) throws Exception {
    throw new RemoteException("unknown_command", "command is not known");
  }
});
origin: UniversaBlockchain/universa

/**
 * Send command without parameters
 *
 * @param name of the command
 * @return deferred result
 */
public CommandResult send(String name) {
  return send(name, null, null);
}
origin: UniversaBlockchain/universa

/**
 * Create instance but does not start handshake.
 *
 * @param myKey
 * @param input
 * @param output
 *
 * @throws IOException
 */
public BitrustedConnector(PrivateKey myKey,
             InputStream input,
             OutputStream output)
    throws IOException {
  this.myKey = myKey;
  connection = new Farcall(new BossConnector(input, output));
  connection.asyncCommands(Executors.newSingleThreadExecutor());
}
origin: UniversaBlockchain/universa

@Test(timeout = 200)
public void testBasicRPC() throws Exception {
  Interconnection ic = new Interconnection(5);
  Farcall a = new Farcall(ic.getConnectorA());
  Farcall b = new Farcall(ic.getConnectorB());
  basicTest(ic, a, b);
}
origin: UniversaBlockchain/universa

private void doCall(Map<String, Object> input, int serial) {
  try {
    Object result = target.onCommand(new Command(input));
    sendToRemote("ref", serial, "result", result);
  } catch (RemoteException e) {
    sendErrorNoExceptions(serial, e.getRemoteErrorClass(), e.getRemoteErrorText());
  } catch (Exception e) {
    sendErrorNoExceptions(serial, e.getClass().getSimpleName(), e.getMessage());
  }
}
origin: UniversaBlockchain/universa

  @Override
  public Object onCommand(Command command) throws Exception {
    if (command.is("ping")) {
      return "pong";
    } else if (command.is("echoargs")) {
      HashMap<String, Object> res = new HashMap<>();
      res.put("simple", command.getParams());
      res.put("key", command.getKeyParams());
      return res;
    }
    throw new IllegalArgumentException("unknown command: " + command.getName());
  }
});
origin: UniversaBlockchain/universa

@Test(timeout = 200)
public void bossConnector() throws Exception {
  StreamConnector sa = new StreamConnector();
  StreamConnector sb = new StreamConnector();
  BossConnector connA = new BossConnector(sa.getInputStream(), sb.getOutputStream());
  BossConnector connB = new BossConnector(sb.getInputStream(), sa.getOutputStream());
  Farcall a = new Farcall(connA);
  Farcall b = new Farcall(connB);
  basicTest(null, a, b);
}
origin: UniversaBlockchain/universa

@Test(timeout = 200)
public void jsonConnector() throws Exception {
  StreamConnector sa = new StreamConnector();
  StreamConnector sb = new StreamConnector();
  JsonConnector connA = new JsonConnector(sa.getInputStream(), sb.getOutputStream());
  JsonConnector connB = new JsonConnector(sb.getInputStream(), sa.getOutputStream());
  Farcall a = new Farcall(connA);
  Farcall b = new Farcall(connB);
  basicTest(null, a, b);
}
origin: UniversaBlockchain/universa

  private void processReply(Map<String, Object> input, Integer ref) {
    CommandResult dr;
//        synchronized (resultQueue) {
    dr = resultQueue.remove(ref);
//        }
    if (dr != null) {
      Object error = input.get("error");
      if (error != null) {
        dr.sendFailure(RemoteException.makeException(error));
      } else {
        Object result = input.get("result");
        dr.sendSuccess(result);
      }
    }
  }

origin: UniversaBlockchain/universa

@Override
public void close() {
  connected = false;
  connection.close();
}
origin: UniversaBlockchain/universa

/**
 * Send remote command with all kind of parameters
 *
 * @param name      of the command
 * @param params    array parameters or null
 * @param keyParams map parameters or null
 * @return deferred result
 */
public CommandResult send(String name, ArrayList<Object> params, HashMap<String, Object>
    keyParams) {
  if (worker == null)
    throw new IllegalStateException("farcall instance must be started");
  return sendToRemote("cmd", name, "args", params, "kwargs", keyParams);
}
origin: UniversaBlockchain/universa

public void close() {
  connectorA.close();
  connectorB.close();
}
origin: UniversaBlockchain/universa

private void processCommand(Map<String, Object> input, int serial) throws IOException {
  if (executor != null)
    executor.submit(() -> {
      doCall(input, serial);
    });
  else
    doCall(input, serial);
}
origin: UniversaBlockchain/universa

public Interconnection(int capacity) {
  qa = new ArrayBlockingQueue<Object>(capacity);
  qb = new ArrayBlockingQueue<Object>(capacity);
  connectorA = new QueueConnector(qa, qb);
  connectorB = new QueueConnector(qb, qa);
}
origin: UniversaBlockchain/universa

private void sendErrorNoExceptions(int serial, String remoteErrorClass, String remoteErrorText) {
  try {
    sendError(serial, remoteErrorClass, remoteErrorText);
  } catch (IOException e) {
    log.wtf("failed to send asynchronous answer: " + remoteErrorText, e);
  }
}
origin: UniversaBlockchain/universa

/**
 * Send Farcall command to the remote with only array parameters. To read remote answer, use returned {@link
 * DeferredResult} instance.
 *
 * @param name   command name
 * @param params array parameters
 * @return deferred result
 */
public CommandResult sendParams(String name, Object... params) {
  return send(name, Ut.arrayToList(params), null);
}
origin: UniversaBlockchain/universa

@SuppressWarnings("unchecked")
static Exception makeException(Object error) {
  if (error instanceof Map) {
    return new RemoteException((Map<String, Object>) error);
  }
  return new ProtocolException("bad remote exception record: " + error);
}
origin: UniversaBlockchain/universa

private void sendError(int serial, String remoteErrorClass, String remoteErrorText) throws
    IOException {
  sendToRemote("ref", serial,
      "error", Ut.mapFromArray(
          "class", remoteErrorClass,
          "text", remoteErrorText));
}
origin: UniversaBlockchain/universa

/**
 * Send remote command with only keyed parameters. The arguments shoul be sequence of key, value pairs, where keys
 * must be String. For example:
 * <code><pre>
 *     farcall.sendKeyParams("foo", "param1", 10, "param2", 20, "bar", "baz")
 * </pre></code>
 * The return value being passed via {@link DeferredResult} is either data returned by the remote party, e.g. {@link
 * java.util.List}, {@link Map}, simple types, strings, or whatever else {@link Connector} allows, or, in the case
 * the remote throws and error, instance of the {@link RemoteException} class.
 *
 * @param name
 * @param keysAndValues key1, value1, key2, value2... sequence
 * @return deferred result
 */
public CommandResult sendKeyParams(String name, Object... keysAndValues) {
  return send(name, null, Ut.mapFromArray(keysAndValues));
}
net.sergeych.farcall

Most used classes

  • Command
    Farcall command representation. Each farcall command consist of name and optional parameters array a
  • Farcall$CommandResult
    Deferred result of the Farcall command execution, to be used inside the farcall package. Provides se
  • Farcall
    The Farcall protocol general implementation. Cross-platform fast, simple and elegant RPC protocol. S
  • BossConnector
    Created by sergeych on 13.04.16.
  • Interconnection$QueueConnector
  • Connector,
  • Farcall$RemoteException,
  • Farcall$Target,
  • FarcallTest,
  • Interconnection
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now