hudson.remoting.Channel.current()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(7.3k)|赞(0)|评价(0)|浏览(215)

本文整理了Java中hudson.remoting.Channel.current()方法的一些代码示例,展示了Channel.current()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Channel.current()方法的具体详情如下:
包路径:hudson.remoting.Channel
类名称:Channel
方法名:current

Channel.current介绍

[英]This method can be invoked during the serialization/deserialization of objects when they are transferred to the remote Channel, as well as during Callable#call() is invoked.
[中]当对象传输到远程通道时,可以在对象的序列化/反序列化过程中调用此方法,也可以在调用可调用的#call()过程中调用此方法。

代码示例

代码示例来源:origin: jenkinsci/jenkins

@Override public Integer call() {
    Channel c = Channel.current();
    if (c == null) {
      return -1;
    }
    return c.classLoadingPrefetchCacheCount.get();
  }
}

代码示例来源:origin: jenkinsci/jenkins

public int main(List<String> args, Locale locale, InputStream stdin, OutputStream stdout, OutputStream stderr) {
  // remoting sets the context classloader to the RemoteClassLoader,
  // which slows down the classloading. we don't load anything from CLI,
  // so counter that effect.
  Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
  PrintStream out = new PrintStream(stdout);
  PrintStream err = new PrintStream(stderr);
  String subCmd = args.get(0);
  CLICommand cmd = CLICommand.clone(subCmd);
  if(cmd!=null) {
    cmd.channel = Channel.current();
    final CLICommand old = CLICommand.setCurrent(cmd);
    try {
      transportAuth = Channel.currentOrFail().getProperty(CLICommand.TRANSPORT_AUTHENTICATION);
      cmd.setTransportAuth(transportAuth);
      return cmd.main(args.subList(1,args.size()),locale, stdin, out, err);
    } finally {
      CLICommand.setCurrent(old);
    }
  }
  err.println("No such command: "+subCmd);
  new HelpCommand().main(Collections.emptyList(), locale, stdin, out, err);
  return -1;
}

代码示例来源:origin: jenkinsci/jenkins

@Override public Integer call() {
    Channel c = Channel.current();
    if (c == null) {
      return -1;
    }
    return resource ? c.resourceLoadingCount.get() : c.classLoadingCount.get();
  }
}

代码示例来源:origin: jenkinsci/jenkins

@Override public Long call() {
    Channel c = Channel.current();
    if (c == null) {
      return -1L;
    }
    return resource ? c.resourceLoadingTime.get() : c.classLoadingTime.get();
  }
}

代码示例来源:origin: jenkinsci/jenkins

private void writeObject(ObjectOutputStream oos) throws IOException {
  Channel target = Channel.current();
  if(channel!=null && channel!=target)
    throw new IllegalStateException("Can't send a remote FilePath to a different remote channel");
  oos.defaultWriteObject();
  oos.writeBoolean(channel==null);
}

代码示例来源:origin: jenkinsci/jenkins

@Override
public Channel getChannelOrFail() throws ChannelClosedException {
  final Channel ch = Channel.current();
  if (ch == null) {
    throw new ChannelClosedException(new IllegalStateException("No channel associated with the thread"));
  }
  return ch;
}

代码示例来源:origin: jenkinsci/jenkins

/**
 * Returns an {@link FilePathFilter} object that represents all the in-scope filters,
 * or {@code null} if none is needed.
 */
public static @CheckForNull FilePathFilter current() {
  Channel ch = Channel.current();
  if (ch==null)   return null;
  return ch.getProperty(FilePathFilterAggregator.KEY);
}

代码示例来源:origin: jenkinsci/jenkins

/**
 * Use {@link Remote} as the serialized form.
 */
/*package*/ Object writeReplace() {
  return new Remote(this,Channel.current());
}

代码示例来源:origin: jenkinsci/jenkins

private Object writeReplace() {
  return Channel.current().export(CliEntryPoint.class,this);
}

代码示例来源:origin: jenkinsci/jenkins

public T call() throws IOException {
  try {
    return callable.invoke(new File(remote), Channel.current());
  } catch (InterruptedException e) {
    throw new TunneledInterruptedException(e);
  }
}

代码示例来源:origin: jenkinsci/jenkins

private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException {
  Channel channel = Channel.current();
  assert channel!=null;
  ois.defaultReadObject();
  if(ois.readBoolean()) {
    this.channel = channel;
    this.filter = null;
  } else {
    this.channel = null;
    // If the remote channel wants us to create a FilePath that points to a local file,
    // we need to make sure the access control takes place.
    // This covers the immediate case of FileCallables taking FilePath into reference closure implicitly,
    // but it also covers more general case of FilePath sent as a return value or argument.
    this.filter = SoloFilePathFilter.wrap(FilePathFilter.current());
  }
}

代码示例来源:origin: jenkinsci/jenkins

/**
 * Obtains a {@link VirtualChannel} that allows some computation to be performed on the master.
 * This method can be called from any thread on the master, or from agent (more precisely,
 * it only works from the remoting request-handling thread in agents, which means if you've started
 * separate thread on agents, that'll fail.)
 *
 * @return null if the calling thread doesn't have any trace of where its master is.
 * @since 1.362
 */
public static VirtualChannel getChannelToMaster() {
  if (Jenkins.getInstanceOrNull()!=null) // check if calling thread is on master or on slave
    return FilePath.localChannel;
  // if this method is called from within the agent computation thread, this should work
  Channel c = Channel.current();
  if (c!=null && Boolean.TRUE.equals(c.getProperty("slave")))
    return c;
  return null;
}

代码示例来源:origin: jenkinsci/jenkins

public int join() throws InterruptedException, IOException {
  try {
    return p.join();
  } finally {
    // make sure I/O is delivered to the remote before we return
    Channel taskChannel = null;
    try {
      // Sync IO will fail automatically if the channel is being closed, no need to use getOpenChannelOrFail()
      // TODOL Replace by Channel#currentOrFail() when Remoting version allows
      taskChannel = Channel.current();
      if (taskChannel == null) {
        throw new IOException("No Remoting channel associated with this thread");
      }
      taskChannel.syncIO();
    } catch (Throwable t) {
      // this includes a failure to sync, agent.jar too old, etc
      LOGGER.log(Level.INFO, "Failed to synchronize IO streams on the channel " + taskChannel, t);
    }
  }
}

代码示例来源:origin: jenkinsci/jenkins

public static void applyConfiguration(SAXReader reader, Object context) throws IOException, InterruptedException {
  Collection<ParserConfigurator> all = Collections.emptyList();
  if (Jenkins.getInstanceOrNull()==null) {
    Channel ch = Channel.current();
    if (ch!=null)
      all = ch.call(new GetParserConfigurators());
  } else
    all = all();
  for (ParserConfigurator pc : all)
    pc.configure(reader,context);
}
private static class GetParserConfigurators extends SlaveToMasterCallable<Collection<ParserConfigurator>, IOException> {

代码示例来源:origin: org.jenkins-ci.main/jenkins-core

@Override public Integer call() {
    Channel c = Channel.current();
    if (c == null) {
      return -1;
    }
    return resource ? c.resourceLoadingCount.get() : c.classLoadingCount.get();
  }
}

代码示例来源:origin: org.jvnet.hudson.main/hudson-core

private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException {
  Channel channel = Channel.current();
  assert channel!=null;
  ois.defaultReadObject();
  if(ois.readBoolean()) {
    this.channel = channel;
  } else {
    this.channel = null;
  }
}

代码示例来源:origin: org.jenkins-ci.main/jenkins-core

@Override public Long call() {
    Channel c = Channel.current();
    if (c == null) {
      return Long.valueOf(-1);
    }
    return resource ? c.resourceLoadingTime.get() : c.classLoadingTime.get();
  }
}

代码示例来源:origin: org.jenkins-ci.main/jenkins-core

private void writeObject(ObjectOutputStream oos) throws IOException {
  Channel target = Channel.current();
  if(channel!=null && channel!=target)
    throw new IllegalStateException("Can't send a remote FilePath to a different remote channel");
  oos.defaultWriteObject();
  oos.writeBoolean(channel==null);
}

代码示例来源:origin: org.jvnet.hudson.main/hudson-core

private void writeObject(ObjectOutputStream oos) throws IOException {
  Channel target = Channel.current();
  if(channel!=null && channel!=target)
    throw new IllegalStateException("Can't send a remote FilePath to a different remote channel");
  oos.defaultWriteObject();
  oos.writeBoolean(channel==null);
}

代码示例来源:origin: org.eclipse.hudson/hudson-core

public T call() throws IOException {
  try {
    return callable.invoke(new File(remote), Channel.current());
  } catch (InterruptedException e) {
    throw new TunneledInterruptedException(e);
  }
}

相关文章