本文整理汇总了Java中hudson.remoting.Channel类的典型用法代码示例。如果您正苦于以下问题:Java Channel类的具体用法?Java Channel怎么用?Java Channel使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Channel类属于hudson.remoting包,在下文中一共展示了Channel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: openChannel
import hudson.remoting.Channel; //导入依赖的package包/类
public static Channel openChannel ( InetSocketAddress isa ) throws IOException, SocketException {
System.err.println("* Opening socket " + isa);
Socket s = SocketFactory.getDefault().createSocket(isa.getAddress(), isa.getPort());
s.setKeepAlive(true);
s.setTcpNoDelay(true);
System.err.println("* Opening channel");
OutputStream outputStream = s.getOutputStream();
DataOutputStream dos = new DataOutputStream(outputStream);
dos.writeUTF("Protocol:CLI-connect");
ExecutorService cp = Executors.newCachedThreadPool(new ThreadFactory() {
public Thread newThread ( Runnable r ) {
Thread t = new Thread(r, "Channel");
t.setDaemon(true);
return t;
}
});
Channel c = new ChannelBuilder("EXPLOIT", cp).withMode(Mode.BINARY).build(s.getInputStream(), outputStream);
System.err.println("* Channel open");
return c;
}
示例2: initPython
import hudson.remoting.Channel; //导入依赖的package包/类
private void initPython() {
if (pexec == null) {
pexec = new PythonExecutor(this);
String[] jMethods = new String[2];
jMethods[0] = "supportsProtocol";
jMethods[1] = "authenticate";
String[] pFuncs = new String[2];
pFuncs[0] = "supports_protocol";
pFuncs[1] = "authenticate";
Class[][] argTypes = new Class[2][];
argTypes[0] = new Class[1];
argTypes[0][0] = String.class;
argTypes[1] = new Class[3];
argTypes[1][0] = String.class;
argTypes[1][1] = Channel.class;
argTypes[1][2] = Connection.class;
pexec.checkAbstrMethods(jMethods, pFuncs, argTypes);
String[] functions = new String[0];
int[] argsCount = new int[0];
pexec.registerFunctions(functions, argsCount);
}
}
示例3: forceGetChannel
import hudson.remoting.Channel; //导入依赖的package包/类
public Channel forceGetChannel() throws InterruptedException, ExecutionException
{
Channel channel = getChannel();
if (channel == null)
{
connect(true).get();
channel = getChannel();
}
return channel;
}
示例4: getCloudForChannel
import hudson.remoting.Channel; //导入依赖的package包/类
/**
* If the build was workflow, get the ID of that channel.
*/
public static Optional<DockerCloud> getCloudForChannel(VirtualChannel channel) {
if( channel instanceof Channel) {
Channel c = (Channel)channel;
Node node = Jenkins.getInstance().getNode( c.getName() );
if (node instanceof DockerTransientNode) {
return Optional.of(((DockerTransientNode) node).getCloud());
}
}
return Optional.empty();
}
示例5: checkChannel
import hudson.remoting.Channel; //导入依赖的package包/类
@Override
public Channel checkChannel() throws AbortException {
initPython();
if (pexec.isImplemented(2)) {
return (Channel) pexec.execPython("check_channel");
} else {
return super.checkChannel();
}
}
示例6: preOnline
import hudson.remoting.Channel; //导入依赖的package包/类
@Override
public void preOnline(Computer c, Channel channel, FilePath root, TaskListener listener) throws IOException, InterruptedException {
initPython();
if (pexec.isImplemented(2)) {
pexec.execPythonVoid("pre_online", c, channel, root, listener);
} else {
super.preOnline(c, channel, root, listener);
}
}
示例7: addContents
import hudson.remoting.Channel; //导入依赖的package包/类
@Override
public void addContents(@NonNull Container container) {
container.add(new PrintedContent("channel-diagnostics.md") {
@Override
protected void printTo(PrintWriter out) throws IOException {
// this method is new in remoting. see JENKINS-39150 change in remoting
try {
Method m = Channel.class.getMethod("dumpDiagnosticsForAll", PrintWriter.class);
m.invoke(null,out);
} catch (Exception e) {
SupportLogFormatter.printStackTrace(e, out);
}
}
});
}
示例8: writeReplace
import hudson.remoting.Channel; //导入依赖的package包/类
/** {@inheritDoc} */
@Override
protected Object writeReplace() throws java.io.ObjectStreamException {
Channel currentChannel = Channel.current();
if (currentChannel == null)
throw new java.io.WriteAbortedException("No current channel", new java.lang.NullPointerException());
return remoteProxyFor(currentChannel.export(IGitAPI.class, this));
}
示例9: writeReplace
import hudson.remoting.Channel; //导入依赖的package包/类
/**
* When sent to remote, switch to the proxy.
*
* @return a {@link java.lang.Object} object.
* @throws java.io.ObjectStreamException if current channel is null
*/
protected Object writeReplace() throws java.io.ObjectStreamException {
Channel currentChannel = Channel.current();
if (currentChannel == null)
throw new java.io.WriteAbortedException("No current channel", new java.lang.NullPointerException());
return remoteProxyFor(currentChannel.export(GitClient.class, this));
}
示例10: launchChannel
import hudson.remoting.Channel; //导入依赖的package包/类
@Override
public Channel launchChannel(String[] cmd, OutputStream out, FilePath workDir, Map<String, String> envVars) throws IOException, InterruptedException {
String lastArg = cmd[cmd.length - 1];
if(lastArg.startsWith(toolsDir) && lastArg.endsWith(".sh")) {
logger.info(lastArg + " is a tools script, skipping cov-build");
decorated.launchChannel(cmd, out, workDir, envVars);
}
return decorated.launchChannel(prefix(cmd), out, workDir, envVars);
}
示例11: launchChannel
import hudson.remoting.Channel; //导入依赖的package包/类
@Override
public Channel launchChannel(String[] cmd, OutputStream out, FilePath workDir, Map<String, String> envVars) throws IOException, InterruptedException {
return null;
}
示例12: connectViaCliPort
import hudson.remoting.Channel; //导入依赖的package包/类
private Channel connectViaCliPort(URL jenkins, CliPort cliPort) throws IOException {
LOG.debug("Trying to connect directly via TCP/IP to {}", cliPort.endpoint);
final Socket s = new Socket();
// this prevents a connection from silently terminated by the router in between or the other peer
// and that goes without unnoticed. However, the time out is often very long (for example 2 hours
// by default in Linux) that this alone is enough to prevent that.
s.setKeepAlive(true);
// we take care of buffering on our own
s.setTcpNoDelay(true);
s.connect(cliPort.endpoint, 3000);
OutputStream out = SocketChannelStream.out(s);
closables.add(s::close);
Connection c = new Connection(SocketChannelStream.in(s), out);
DataInputStream dis = new DataInputStream(s.getInputStream());
DataOutputStream dos = new DataOutputStream(s.getOutputStream());
dos.writeUTF("Protocol:CLI2-connect");
String greeting = dis.readUTF();
if (!greeting.equals("Welcome")) {
throw new IOException("Handshaking failed: " + greeting);
}
try {
byte[] secret = c.diffieHellman(false).generateSecret();
SecretKey sessionKey = new SecretKeySpec(Connection.fold(secret, 128 / 8), "AES");
c = c.encryptConnection(sessionKey, "AES/CFB8/NoPadding");
// validate the instance identity, so that we can be sure that we are talking to the same server
// and there's no one in the middle.
byte[] signature = c.readByteArray();
if (cliPort.identity != null) {
Signature verifier = Signature.getInstance("SHA1withRSA");
verifier.initVerify(cliPort.getIdentity());
verifier.update(secret);
if (!verifier.verify(signature))
throw new IOException("Server identity signature validation failed.");
}
} catch (GeneralSecurityException e) {
throw (IOException) new IOException("Failed to negotiate transport security").initCause(e);
}
final Channel channel = new ChannelBuilder("CLI connection to " + jenkins, pool)
.withMode(Channel.Mode.BINARY)
.withBaseLoader(null)
.withArbitraryCallableAllowed(true)
.withRemoteClassLoadingAllowed(true)
.build(new BufferedInputStream(c.in), new BufferedOutputStream(c.out));
LOG.trace("Returning channel: {}.", channel);
return channel;
// return new Channel(
// "CLI connection to " + jenkins, // name
// pool, //exec
// Channel.Mode.BINARY,
// new BufferedInputStream(c.in),
// new BufferedOutputStream(c.out),
// null,
// false,
// null
// );
}
示例13: getChannel
import hudson.remoting.Channel; //导入依赖的package包/类
public Channel getChannel() {
return channel;
}
示例14: setChannel
import hudson.remoting.Channel; //导入依赖的package包/类
@Override
public void setChannel(Channel channel, OutputStream launchLog, Channel.Listener listener)
throws IOException, InterruptedException {
super.setChannel(channel, launchLog, listener);
}
示例15: launch
import hudson.remoting.Channel; //导入依赖的package包/类
@Override
public void launch(SlaveComputer computer, TaskListener listener)
throws IOException, InterruptedException {
final PrintStream llog = listener.getLogger();
DockerComputer dockerComputer;
if (computer instanceof DockerComputer) {
dockerComputer = (DockerComputer) computer;
} else {
listener.error("Docker JNLP Launcher accepts only DockerComputer.class");
throw new IllegalArgumentException("Docker JNLP Launcher accepts only DockerComputer.class");
}
Objects.requireNonNull(dockerComputer);
final String containerId = dockerComputer.getContainerId();
final DockerCloud dockerCloud = dockerComputer.getCloud();
// Objects.requireNonNull(dockerCloud, "Cloud not found for computer " + computer.getName());
if (isNull(dockerCloud)) {
listener.error("Cloud not found for computer " + computer.getName());
throw new NullPointerException("Cloud not found for computer " + computer.getName());
}
final DockerClient client = dockerCloud.getClient();
final DockerSlave node = dockerComputer.getNode();
if (isNull(node)) {
throw new NullPointerException("Node can't be null");
}
InspectContainerResponse inspect = client.inspectContainerCmd(containerId).exec();
if (nonNull(inspect) && nonNull(inspect.getState().getRunning()) &&
!inspect.getState().getRunning()) {
throw new IllegalStateException("Container is not running!");
}
PipedOutputStream out = new PipedOutputStream();
PipedInputStream inputStream = new PipedInputStream(out, 4096);
IOCallback callback = new IOCallback(listener, out);
PipedInputStream pipedInputStream = new PipedInputStream(4096);
PipedOutputStream outputStream = new PipedOutputStream(pipedInputStream);
llog.println("Attaching to container...");
ExecCreateCmdResponse cmdResponse = client.execCreateCmd(containerId)
.withAttachStderr(true)
.withAttachStdin(true)
.withAttachStdout(true)
.withTty(false)
.withCmd("/bin/bash", "-c", "java -Dfile.encoding=UTF-8 -jar /tmp/slave.jar")
.withUser("root")
.exec();
client.execStartCmd(cmdResponse.getId())
.withStdIn(pipedInputStream)
.exec(callback);
// client.attachContainerCmd(containerId)
// .withStdErr(true)
// .withStdOut(true)
// .withFollowStream(true)
// .withStdIn(pipedInputStream)
// .exec(callback);
// container stdout is InputStream ... in.read()
// container stdin is out.write()
computer.setChannel(inputStream, outputStream, listener.getLogger(), new Channel.Listener() {
@Override
public void onClosed(Channel channel, IOException cause) {
try {
callback.close();
} catch (IOException e) {
Throwables.propagate(e);
}
}
});
}