public final void uninstallFrom(Channel ch) { synchronized (ch) { FilePathFilterAggregator filters = ch.getProperty(FilePathFilterAggregator.KEY); if (filters!=null) { filters.remove(this); } } }
/** * 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); }
/** * 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; }
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; }
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; }
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); } } } }
if (ch != null) { String cookie = event.getProperty(JnlpConnectionState.COOKIE_KEY); if (cookie != null && cookie.equals(ch.getProperty(COOKIE_NAME))) {
public <T> T getProperty(ChannelProperty<T> key) { return key.type.cast(getProperty((Object) key)); }
public final void uninstallFrom(Channel ch) { synchronized (ch) { FilePathFilterAggregator filters = ch.getProperty(FilePathFilterAggregator.KEY); if (filters!=null) { filters.remove(this); } } }
/** * 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); }
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; }
/** * 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; }
/** * 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; } }
/** * 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; } }
/** * 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; } }
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)); } }
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; }
@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); }
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)); }
@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)); }