本文整理了Java中hudson.remoting.Channel.getProperty()
方法的一些代码示例,展示了Channel.getProperty()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Channel.getProperty()
方法的具体详情如下:
包路径:hudson.remoting.Channel
类名称:Channel
方法名:getProperty
[英]Gets the application specific property set by #setProperty(Object,Object). These properties are also accessible from the remote channel via #getRemoteProperty(Object).
This mechanism can be used for one side to discover contextual objects created by the other JVM (as opposed to executing Callable, which cannot have any reference to the context of the remote Channel.
[中]获取由#setProperty(对象,对象)设置的特定于应用程序的属性。还可以通过#getRemoteProperty(对象)从远程通道访问这些属性。
此机制可用于一方发现由另一JVM创建的上下文对象(与执行Callable相反,后者不能引用远程通道的上下文)。
代码示例来源:origin: jenkinsci/jenkins
public final void uninstallFrom(Channel ch) {
synchronized (ch) {
FilePathFilterAggregator filters = ch.getProperty(FilePathFilterAggregator.KEY);
if (filters!=null) {
filters.remove(this);
}
}
}
代码示例来源: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
/**
* 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 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
public Boolean call() throws Exception {
if (File.pathSeparatorChar==';') return false; // Windows
Channel c = getOpenChannelOrFail();
StandardOutputStream sos = (StandardOutputStream) c.getProperty(StandardOutputStream.class);
if (sos!=null) {
swap(sos);
return true;
}
OutputStream o = c.getUnderlyingOutput();
if (o instanceof StandardOutputStream) {
swap((StandardOutputStream) o);
return true;
}
return false;
}
代码示例来源:origin: jenkinsci/jenkins
protected void execute(TaskListener listener) throws IOException, InterruptedException {
if (!enabled) return;
long now = System.currentTimeMillis();
for (Computer c: Jenkins.get().getComputers()) {
VirtualChannel ch = c.getChannel();
if (ch instanceof Channel) {
Channel channel = (Channel) ch;
if (now-channel.getLastHeard() > TIME_TILL_PING) {
// haven't heard from this agent for a while.
Long lastPing = (Long)channel.getProperty(ConnectionActivityMonitor.class);
if (lastPing!=null && now-lastPing > TIMEOUT) {
LOGGER.info("Repeated ping attempts failed on "+c.getName()+". Disconnecting");
c.disconnect(OfflineCause.create(Messages._ConnectionActivityMonitor_OfflineCause()));
} else {
// send a ping. if we receive a reply, it will be reflected in the next getLastHeard() call.
channel.callAsync(PING_COMMAND);
if (lastPing==null)
channel.setProperty(ConnectionActivityMonitor.class,now);
}
} else {
// we are receiving data nicely
channel.setProperty(ConnectionActivityMonitor.class,null);
}
}
}
}
代码示例来源:origin: jenkinsci/jenkins
if (ch != null) {
String cookie = event.getProperty(JnlpConnectionState.COOKIE_KEY);
if (cookie != null && cookie.equals(ch.getProperty(COOKIE_NAME))) {
代码示例来源:origin: jenkinsci/remoting
public <T> T getProperty(ChannelProperty<T> key) {
return key.type.cast(getProperty((Object) key));
}
代码示例来源:origin: org.jenkins-ci.main/jenkins-core
public final void uninstallFrom(Channel ch) {
synchronized (ch) {
FilePathFilterAggregator filters = ch.getProperty(FilePathFilterAggregator.KEY);
if (filters!=null) {
filters.remove(this);
}
}
}
代码示例来源:origin: org.jenkins-ci.main/jenkins-core
/**
* Returns an {@link FilePathFilter} object that represents all the in-scope filters,
* or 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/remoting
protected JarLoader getJarLoader(Channel channel) throws InterruptedException {
JarLoader jl = channel.getProperty(JarLoader.THEIRS);
if (jl==null) {// even if two threads run this simultaneously, it is harmless
jl = (JarLoader) channel.waitForRemoteProperty(JarLoader.OURS);
channel.setProperty(JarLoader.THEIRS,jl);
}
return jl;
}
代码示例来源:origin: org.jenkins-ci.main/jenkins-core
/**
* 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: org.eclipse.hudson.main/hudson-core
/**
* 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 slave (more precisely,
* it only works from the remoting request-handling thread in slaves, which means if you've started
* separate thread on slaves, 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 (Hudson.getInstance()!=null)
return MasterComputer.localChannel;
// if this method is called from within the slave computation thread, this should work
Channel c = Channel.current();
if (c!=null && c.getProperty("slave")==Boolean.TRUE)
return c;
return null;
}
}
代码示例来源:origin: org.jvnet.hudson.main/hudson-core
/**
* 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 slave (more precisely,
* it only works from the remoting request-handling thread in slaves, which means if you've started
* separate thread on slaves, 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 (Hudson.getInstance()!=null)
return MasterComputer.localChannel;
// if this method is called from within the slave computation thread, this should work
Channel c = Channel.current();
if (c!=null && c.getProperty("slave")==Boolean.TRUE)
return c;
return null;
}
}
代码示例来源:origin: hudson/hudson-2.x
/**
* 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 slave (more precisely,
* it only works from the remoting request-handling thread in slaves, which means if you've started
* separate thread on slaves, 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 (Hudson.getInstance()!=null)
return MasterComputer.localChannel;
// if this method is called from within the slave computation thread, this should work
Channel c = Channel.current();
if (c!=null && c.getProperty("slave")==Boolean.TRUE)
return c;
return null;
}
}
代码示例来源:origin: jenkinsci/remoting
private void mockCorrectLoad() throws IOException, InterruptedException {
when(mockChannel.getProperty(JarLoader.THEIRS)).thenReturn(mockJarLoader);
doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocationOnMock) throws Throwable {
RemoteOutputStream o = (RemoteOutputStream) invocationOnMock.getArguments()[2];
o.write(CONTENTS.getBytes(StandardCharsets.UTF_8));
return null;
}
}).when(mockJarLoader).writeJarTo(
eq(expectedChecksum.sum1),
eq(expectedChecksum.sum2),
any(RemoteOutputStream.class));
}
}
代码示例来源:origin: org.jenkins-ci.main/jenkins-core
public Boolean call() throws Exception {
if (File.pathSeparatorChar==';') return false; // Windows
Channel c = Channel.current();
StandardOutputStream sos = (StandardOutputStream) c.getProperty(StandardOutputStream.class);
if (sos!=null) {
swap(sos);
return true;
}
OutputStream o = c.getUnderlyingOutput();
if (o instanceof StandardOutputStream) {
swap((StandardOutputStream) o);
return true;
}
return false;
}
代码示例来源:origin: jenkinsci/remoting
@Test
public void testRetrieveChecksumDifferent() throws Exception {
when(mockChannel.getProperty(JarLoader.THEIRS)).thenReturn(mockJarLoader);
doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocationOnMock) throws Throwable {
RemoteOutputStream o = (RemoteOutputStream) invocationOnMock.getArguments()[2];
o.write("Some other contents".getBytes(StandardCharsets.UTF_8));
return null;
}
}).when(mockJarLoader).writeJarTo(
eq(expectedChecksum.sum1),
eq(expectedChecksum.sum2),
any(RemoteOutputStream.class));
expectedEx.expect(IOException.class);
expectedEx.expectCause(hasMessage(StringContains.containsString(
"Incorrect checksum of retrieved jar")));
fileSystemJarCache.retrieve(
mockChannel, expectedChecksum.sum1, expectedChecksum.sum2);
}
代码示例来源:origin: jenkinsci/remoting
public void testGetSetProperty() throws Exception {
channel.setProperty("foo","bar");
assertEquals("bar", channel.getProperty("foo"));
assertEquals("bar",channel.waitForProperty("foo"));
ChannelProperty<Class> typedProp = new ChannelProperty<Class>(Class.class,"a type-safe property");
channel.setProperty(typedProp, Void.class);
assertEquals(Void.class, channel.getProperty(typedProp));
assertEquals(Void.class, channel.waitForProperty(typedProp));
}
代码示例来源:origin: jenkinsci/remoting
@Test
@Bug(39547)
public void retrieveInvalidChecksum() throws Exception {
when(mockChannel.getProperty(JarLoader.THEIRS)).thenReturn(mockJarLoader);
File expected = fileSystemJarCache.map(expectedChecksum.sum1, expectedChecksum.sum2);
writeToFile(expected, "This is no going to match the checksum");
mockCorrectLoad();
URL url = fileSystemJarCache.retrieve(mockChannel, expectedChecksum.sum1, expectedChecksum.sum2);
assertEquals(expectedChecksum, Checksum.forURL(url));
}
内容来源于网络,如有侵权,请联系作者删除!