Ejemplo n.º 1
0
 private void fillCommandServiceInfo(String hostName, int port, TXTRecord txtRecord) {
   info.setId(new Identifier(domainId, serviceName));
   info.setAddress(new SocketAddress(hostName, port));
   byte[] nameBytes = txtRecord.getValue(DNSSDDiscoveryServiceAdapter.NAME);
   if (nameBytes != null) info.setName(Util.decode(nameBytes));
   restoreMetadata(info, txtRecord, ICommandServiceInfo.VERSION);
   restoreMetadata(info, txtRecord, ICommandServiceInfo.CLIENT_NAME);
   restoreMetadata(info, txtRecord, ICommandServiceInfo.CLIENT_SYMBOLIC_NAME);
   restoreMetadata(info, txtRecord, ICommandServiceInfo.CLIENT_VERSION);
   restoreMetadata(info, txtRecord, ICommandServiceInfo.CLIENT_BUILD_ID);
 }
Ejemplo n.º 2
0
  public IStatus execute(
      IProgressMonitor monitor,
      ICommand command,
      IReturnValueConsumer returnValueConsumer,
      Options options) {
    monitor.beginTask(null, 100);

    monitor.subTask(Messages.DNSSDRemoteCommandService_ResolveRemoteCommandService);

    boolean doResolve = false;
    synchronized (info) {
      if (!resolving) {
        resolving = true;
        doResolve = true;
      }
    }

    DNSSDService resolver = null;
    if (doResolve) {
      try {
        resolver = DNSSD.resolve(flags, ifIndex, serviceName, regType, domain, this);
      } catch (DNSSDException e) {
        return new Status(
            IStatus.ERROR,
            LANRemoteCommandPlugin.ID,
            Messages.DNSSDRemoteCommandService_FailedResolveRemoteCommand,
            e);
      }
    }
    try {
      while (resolving) {
        if (monitor.isCanceled()) return Status.CANCEL_STATUS;
        Thread.sleep(0);
      }
    } catch (InterruptedException e) {
      return Status.CANCEL_STATUS;
    } finally {
      if (resolver != null) {
        resolver.stop();
      }
    }

    if (monitor.isCanceled()) return Status.CANCEL_STATUS;
    monitor.worked(10);

    monitor.subTask(Messages.DNSSDRemoteCommandService_SendCommand);
    IProgressMonitor handleMonitor = new SubProgressMonitor(monitor, 90);
    OutgoingSocketCommandHandler handler = new OutgoingSocketCommandHandler(info.getAddress());
    handler.setPluginId(LANRemoteCommandPlugin.ID);
    handler.setSocketPool(socketPool);
    IStatus handled =
        handler.handleOutgoingCommand(
            handleMonitor, command, returnValueConsumer, options.timeout());
    if (!handleMonitor.isCanceled()) handleMonitor.done();
    return handled;
  }
Ejemplo n.º 3
0
 private static void restoreMetadata(
     SocketCommandServiceInfo info, TXTRecord txtRecord, String key) {
   byte[] bytes = txtRecord.getValue(key);
   info.setMetadata(key, bytes == null ? null : Util.decode(bytes));
 }