Class Channel
- All Implemented Interfaces:
VirtualChannel,Closeable,AutoCloseable
A Channel is a mechanism for two JVMs to communicate over
bi-directional InputStream/OutputStream pair.
Channel represents an endpoint of the stream, and thus
two Channels are always used in a pair.
Communication is established as soon as two Channel instances
are created at the end fo the stream pair
until the stream is terminated via close().
The basic unit of remoting is an executable Callable object.
An application can create a Callable object, and execute it remotely
by using the call(Callable) method or callAsync(Callable) method.
In this sense, Channel is a mechanism to delegate/offload computation
to other JVMs and somewhat like an agent system. This is bit different from
remoting technologies like CORBA or web services, where the server exposes a
certain functionality that clients invoke.
Callable object, as well as the return value / exceptions,
are transported by using Java serialization. All the necessary class files
are also shipped over Channel on-demand, so there's no need to
pre-deploy such classes on both JVMs.
Implementor's Note
Channel builds its features in a layered model. Its higher-layer
features are built on top of its lower-layer features, and they
are called layer-0, layer-1, etc.
- Author:
- Kohsuke Kawaguchi
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classCallback "interface" for changes in the state ofChannel.static enumCommunication mode used in conjunction withClassicCommandTransport. -
Field Summary
FieldsModifier and TypeFieldDescriptionfinal AtomicIntegerTotal counts of remote classloading activities.final AtomicIntegerPrefetch cache hits.final AtomicLongTotal number of nanoseconds spent for remote class loading.final ExecutorServicestatic final intDefault pipe window size.final CapabilityCapability of the remoteChannel.final AtomicIntegerTotal count of remote resource loading.final AtomicLongTotal number of nanoseconds spent for remote resource loading. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedChannel(ChannelBuilder settings, CommandTransport transport) Channel(String name, ExecutorService exec, Channel.Mode mode, InputStream is, OutputStream os) Deprecated.Channel(String name, ExecutorService exec, Channel.Mode mode, InputStream is, OutputStream os, OutputStream header) Deprecated.as of 2.24 UseChannelBuilderChannelBuilder(name, exec) .withMode(mode) .withHeaderStream(header) .withArbitraryCallableAllowed(true) .withRemoteClassLoadingAllowed(true) .build(is, os)Channel(String name, ExecutorService exec, Channel.Mode mode, InputStream is, OutputStream os, OutputStream header, boolean restricted) Deprecated.as of 2.24 UseChannelBuilderChannelBuilder(name, exec) .withMode(mode) .withHeaderStream(header) .withArbitraryCallableAllowed(!restricted) .withRemoteClassLoadingAllowed(!restricted) .withBaseLoader(base) .build(is, os)Channel(String name, ExecutorService exec, Channel.Mode mode, InputStream is, OutputStream os, OutputStream header, boolean restricted, ClassLoader base) Deprecated.as of 2.24 UseChannelBuilderChannelBuilder(name, exec) .withMode(mode) .withHeaderStream(header) .withArbitraryCallableAllowed(!restricted) .withRemoteClassLoadingAllowed(!restricted) .withBaseLoader(base) .build(is, os)Channel(String name, ExecutorService exec, CommandTransport transport, boolean restricted, ClassLoader base) Deprecated.as of 2.24 UseChannelBuilderChannelBuilder(name, exec) .withArbitraryCallableAllowed(!restricted) .withRemoteClassLoadingAllowed(!restricted) .withBaseLoader(base) .build(transport)Channel(String name, ExecutorService exec, CommandTransport transport, boolean restricted, ClassLoader base, JarCache jarCache) Deprecated.as of 2.38 UseChannelBuilderChannelBuilder(name, exec) .withArbitraryCallableAllowed(!restricted) .withRemoteClassLoadingAllowed(!restricted) .withBaseLoader(base) .withJarCache(jarCache) .build(transport)Channel(String name, ExecutorService exec, InputStream is, OutputStream os) Deprecated.as of 2.24 UseChannelBuilderChannelBuilder(name, exec) .withMode(Channel.Mode.BINARY) .build(is, os)Channel(String name, ExecutorService exec, InputStream is, OutputStream os, OutputStream header) Deprecated.as of 2.24 UseChannelBuilderChannelBuilder(name, exec) .withMode(Channel.Mode.BINARY) .withHeaderStream(header) .build(is, os) -
Method Summary
Modifier and TypeMethodDescriptionvoidRegisters a newChannel.Listener.voidDeprecated.voidaddLocalExecutionInterceptor(CallableDecorator decorator) Adds aCallableDecoratorthat gets a chance to decorate everyCallables that run locally sent by the other peer.<V,T extends Throwable>
VMakes a remote procedure call.Makes an asynchronous remote procedure call.voidclose()Performs an orderly shut down of this channel (and the remote peer.)voidCloses the channel.createLocalToRemotePortForwarding(int recvPort, String forwardHost, int forwardPort) Deprecated.as of 3.39createRemoteToLocalPortForwarding(int recvPort, String forwardHost, int forwardPort) Deprecated.as of 3.39static Channelcurrent()This method can be invoked during the serialization/deserialization of objects when they are transferred to the remoteChannel, as well as duringCallable.call()is invoked.static ChannelGets current channel or fails withIllegalStateException.voidPrint the diagnostic information.static voidCallsdumpDiagnostics(PrintWriter)across all the active channels in this system.voidDumps the list of exported objects and their allocation traces to the given output.voidPrint the performance counters.<T> TExports an object for remoting to the otherChannelby creating a remotable proxy.Gets cause of the close request.If this channel is built with jar file caching, return the object that manages this cache.longTODO: this is not safe against clock skew and is called from jenkins core (and potentially plugins)getName()<T> TgetProperty(ChannelProperty<T> key) getProperty(Object key) Gets the application specific property set bysetProperty(Object, Object).<T> TgetRemoteProperty(ChannelProperty<T> key) getRemoteProperty(Object key) Gets the property set on the remote peer.final ThrowableGet why the sender side of the channel has been closed.Deprecated.Future version of the remoting module may add other modes of creating channel that doesn't involve stream pair.booleanstatic booleanChecks whether an exception seems to be related to a closed channel.booleanReturnstrueif the channel is either in the process of closing down or has closed down.booleanIf the receiving end of the channel is closed (that is, if we are guaranteed to receive nothing further), this method returns true.booleanIs the sender side of the transport already closed?booleanbooleanDeprecated.Use methods likeisRemoteClassLoadingAllowed()andisArbitraryCallableAllowed()to test individual features.voidjoin()Waits for thisChannelto be closed down.voidjoin(long timeout) Waits for thisChannelto be closed down, but only up the given milliseconds.voidIncrease reference count so much to effectively prevent de-allocation.voidPin down the exported classloader.booleanpreloadJar(Callable<?, ?> classLoaderRef, Class<?>... classesInJar) Preloads jar files on the remote side.booleanpreloadJar(ClassLoader local, Class<?>... classesInJar) booleanpreloadJar(ClassLoader local, URL... jars) booleanRemoves a listener.voidDeprecated.voidremoveLocalExecutionInterceptor(CallableDecorator decorator) Removes the filter introduced byaddLocalExecutionInterceptor(CallableDecorator).voidResets all the performance counters.voidsetArbitraryCallableAllowed(boolean b) voidsetJarCache(JarCache jarCache) You can change theJarCachewhile the channel is in operation, but doing so doesn't impactRemoteClassLoaders that are already created.voidsetMaximumBytecodeLevel(short level) Sets the maximum bytecode version (~ JDK) that we expect this channel to be able to load.<T> TsetProperty(ChannelProperty<T> key, T value) setProperty(Object key, Object value) Sets the property value on this side of the channel.voidsetRemoteClassLoadingAllowed(boolean b) Controls whether or not this channel is willing to load classes from the other side.voidsetRestricted(boolean b) Deprecated.Use methods likesetRemoteClassLoadingAllowed(boolean)andsetArbitraryCallableAllowed(boolean)to control individual features.hudson.remoting.ExportTable.ExportListvoidsyncIO()Blocks until all the I/O packets sent before this gets fully executed by the remote side, then return.voidBlocks until all the I/O packets sent from remote is fully locally executed, then return.voidAborts the connection in response to an error.toString()<T> TwaitForProperty(ChannelProperty<T> key) waitForProperty(Object key) Works likegetProperty(Object)but wait until some value is set by someone.<T> TwaitForRemoteProperty(ChannelProperty<T> key) Deprecated.BecauseChannelPropertyis identity-equality, this method would never work.Gets the property set on the remote peer.
-
Field Details
-
executor
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public final ExecutorService executor -
classLoadingTime
Total number of nanoseconds spent for remote class loading.Remote code execution often results in classloading activity (more precisely, when the remote peer requests some computation on this channel, this channel often has to load necessary classes from the remote peer.)
This counter represents the total amount of time this channel had to spend loading classes from the remote peer. The time measurement doesn't include the time locally spent to actually define the class (as the local classloading would have incurred the same cost.)
-
classLoadingCount
Total counts of remote classloading activities. Used in a pair withclassLoadingTime. -
classLoadingPrefetchCacheCount
Prefetch cache hits. Out of all the counts inclassLoadingCount, how many times were we able to resolve them by ourselves, saving a remote roundtrip call?- Since:
- 2.24
-
resourceLoadingTime
Total number of nanoseconds spent for remote resource loading.- See Also:
-
resourceLoadingCount
Total count of remote resource loading.- See Also:
-
remoteCapability
Capability of the remoteChannel. -
PIPE_WINDOW_SIZE
public static final int PIPE_WINDOW_SIZEDefault pipe window size.This controls the amount of bytes that can be in flight. Value too small would fail to efficiently utilize a high-latency/large-bandwidth network, but a value too large would cause the risk of a large memory consumption when a pipe clogs (that is, the receiver isn't consuming bytes we are sending fast enough.)
If we have a gigabit ethernet (with effective transfer rate of 100M bps) and 20ms latency, the pipe will hold (100M bits/sec * 0.02sec / 8 bits/byte = 0.25MB. So 1MB or so is big enough for most network, and hopefully this is an acceptable enough memory consumption in case of clogging.
- See Also:
-
PipeWindow
-
-
Constructor Details
-
Channel
@Deprecated public Channel(String name, ExecutorService exec, InputStream is, OutputStream os) throws IOException Deprecated.as of 2.24 UseChannelBuilderChannelBuilder(name, exec) .withMode(Channel.Mode.BINARY) .build(is, os)- Throws:
IOException
-
Channel
@Deprecated public Channel(String name, ExecutorService exec, Channel.Mode mode, InputStream is, OutputStream os) throws IOException Deprecated.as of 2.24 UseChannelBuilderChannelBuilder(name, exec) .withMode(mode) .build(is, os)- Throws:
IOException
-
Channel
@Deprecated public Channel(String name, ExecutorService exec, InputStream is, OutputStream os, OutputStream header) throws IOException Deprecated.as of 2.24 UseChannelBuilderChannelBuilder(name, exec) .withMode(Channel.Mode.BINARY) .withHeaderStream(header) .build(is, os)- Throws:
IOException
-
Channel
@Deprecated public Channel(String name, ExecutorService exec, Channel.Mode mode, InputStream is, OutputStream os, OutputStream header) throws IOException Deprecated.as of 2.24 UseChannelBuilderChannelBuilder(name, exec) .withMode(mode) .withHeaderStream(header) .withArbitraryCallableAllowed(true) .withRemoteClassLoadingAllowed(true) .build(is, os)- Throws:
IOException
-
Channel
@Deprecated public Channel(String name, ExecutorService exec, Channel.Mode mode, InputStream is, OutputStream os, OutputStream header, boolean restricted) throws IOException Deprecated.as of 2.24 UseChannelBuilderChannelBuilder(name, exec) .withMode(mode) .withHeaderStream(header) .withArbitraryCallableAllowed(!restricted) .withRemoteClassLoadingAllowed(!restricted) .withBaseLoader(base) .build(is, os)- Throws:
IOException
-
Channel
@Deprecated public Channel(String name, ExecutorService exec, Channel.Mode mode, InputStream is, OutputStream os, OutputStream header, boolean restricted, ClassLoader base) throws IOException Deprecated.as of 2.24 UseChannelBuilderChannelBuilder(name, exec) .withMode(mode) .withHeaderStream(header) .withArbitraryCallableAllowed(!restricted) .withRemoteClassLoadingAllowed(!restricted) .withBaseLoader(base) .build(is, os)Creates a new channel.- Parameters:
restricted- SeeChannel(String, ExecutorService, Mode, InputStream, OutputStream, OutputStream, boolean, ClassLoader)- Throws:
IOException
-
Channel
@Deprecated public Channel(String name, ExecutorService exec, CommandTransport transport, boolean restricted, ClassLoader base) throws IOException Deprecated.as of 2.24 UseChannelBuilderChannelBuilder(name, exec) .withArbitraryCallableAllowed(!restricted) .withRemoteClassLoadingAllowed(!restricted) .withBaseLoader(base) .build(transport)- Throws:
IOException- Since:
- 2.13
-
Channel
@Deprecated public Channel(String name, ExecutorService exec, CommandTransport transport, boolean restricted, ClassLoader base, JarCache jarCache) throws IOException Deprecated.as of 2.38 UseChannelBuilderChannelBuilder(name, exec) .withArbitraryCallableAllowed(!restricted) .withRemoteClassLoadingAllowed(!restricted) .withBaseLoader(base) .withJarCache(jarCache) .build(transport)Creates a new channel.- Parameters:
name- SeeChannel(String, ExecutorService, Mode, InputStream, OutputStream, OutputStream, boolean, ClassLoader)exec- SeeChannel(String, ExecutorService, Mode, InputStream, OutputStream, OutputStream, boolean, ClassLoader)transport- The transport that we runChannelon top of.base- SeeChannel(String, ExecutorService, Mode, InputStream, OutputStream, OutputStream, boolean, ClassLoader)restricted- SeeChannel(String, ExecutorService, Mode, InputStream, OutputStream, OutputStream, boolean, ClassLoader)- Throws:
IOException- Since:
- 2.24
-
Channel
protected Channel(@NonNull ChannelBuilder settings, @NonNull CommandTransport transport) throws IOException - Throws:
IOException- Since:
- 2.38
-
-
Method Details
-
isOutClosed
public boolean isOutClosed()Is the sender side of the transport already closed? -
getSenderCloseCause
Get why the sender side of the channel has been closed.- Returns:
- Close cause or
nullif the sender side is active.nullresult does not guarantee that the channel is actually operational. - Since:
- 3.11
-
isClosingOrClosed
public boolean isClosingOrClosed()Returnstrueif the channel is either in the process of closing down or has closed down. If the result istrue, it means that the channel will be closed at some point by Remoting, and that it makes no sense to send any newUserRequests to the remote side. Invocations likecall(Callable)andcallAsync(Callable)will just fail as well.- Since:
- 2.33
-
getCloseRequestCause
Gets cause of the close request.- Returns:
outClosedif notnull, value of the transient cachecloseRequestCauseotherwise. The latter one may show random cause in the case of race conditions.- Since:
- 3.11
-
export
Exports an object for remoting to the otherChannelby creating a remotable proxy. The returned reference must be kept if there is ongoing operation on the remote side. Once it is released, the exported object will be deallocated as well. Please keep in mind that the object may be also released earlier than expected by JVM (e.g. see JENKINS-23271).- Specified by:
exportin interfaceVirtualChannel- Type Parameters:
T- Type- Parameters:
type- Interface to be remoted.instance- Instance to be exported.nullinstances won't be exported to the remote instance.All the parameters and return values must be serializable.
- Returns:
- the proxy object that implements
T. This object can be transferred to the otherChannel, and calling methods on it from the remote side will invoke the same method on the given localinstanceobject.nullif the input instance isnull.
-
pin
Increase reference count so much to effectively prevent de-allocation.- Parameters:
instance- Instance to be pinned
-
pinClassLoader
Pin down the exported classloader. -
preloadJar
public boolean preloadJar(Callable<?, ?> classLoaderRef, Class<?>... classesInJar) throws IOException, InterruptedExceptionPreloads jar files on the remote side.This is a performance improvement method that can be safely ignored if your goal is just to make things working.
Normally, classes are transferred over the network one at a time, on-demand. This design is mainly driven by how Java classloading works — we can't predict what classes will be necessarily upfront very easily.
Classes are loaded only once, so for long-running
Channel, this is normally an acceptable overhead. But sometimes, for example when a channel is short-lived, or when you know that you'll need a majority of classes in certain jar files, then it is more efficient to send a whole jar file over the network upfront and thereby avoiding individual class transfer over the network.That is what this method does. It ensures that a series of jar files are copied to the remote side (AKA "preloading.") Classloading will consult the preloaded jars before performing network transfer of class files.
Beware that this method is not useful in all configurations. If a
RemoteClassLoaderhas anotherRemoteClassLoaderas a parent, which would be typical, then preloading a JAR in it will not reduce network round-trips: each class load still has to callloadClasson the parent, which will wind up checking the remote side just to get a negative answer.- Parameters:
classLoaderRef- This parameter is used to identify the remote classloader that will prefetch the specified jar files. That is, prefetching will ensure that prefetched jars will kick in when thisCallableobject is actually executed remote side.RemoteClassLoaders are created wisely, one per localClassLoader, so this parameter doesn't have to be exactly the sameCallableto be executed later — it just has to be of the same class.classesInJar-Classobjects that identify jar files to be preloaded. Jar files that contain the specified classes will be preloaded into the remote peer. You just need to specify one class per one jar.- Returns:
- true if the preloading actually happened. false if all the jars are already preloaded. This method is implemented in such a way that unnecessary jar file transfer will be avoided, and the return value will tell you if this optimization kicked in. Under normal circumstances your program shouldn't depend on this return value. It's just a hint.
- Throws:
IOException- if the preloading fails.InterruptedException
-
preloadJar
public boolean preloadJar(ClassLoader local, Class<?>... classesInJar) throws IOException, InterruptedException - Throws:
IOExceptionInterruptedException
-
preloadJar
- Throws:
IOExceptionInterruptedException
-
getJarCache
If this channel is built with jar file caching, return the object that manages this cache.- Returns:
- JAR Cache object.
nullif JAR caching is disabled - Since:
- 2.24, 3.10 JAR Cache is Nonnull, 3.12 JAR Cache made nullable again due to JENKINS-45755
-
setJarCache
You can change theJarCachewhile the channel is in operation, but doing so doesn't impactRemoteClassLoaders that are already created. So to best avoid performance loss due to race condition, please set a JarCache in the constructor, unless your call sequence guarantees that you call this method before remote classes are loaded.- Parameters:
jarCache- New JAR Cache to be used. Cannot benull, JAR Cache disabling on a running channel is not supported.- Since:
- 2.24
-
call
public <V,T extends Throwable> V call(Callable<V, T> callable) throws IOException, T, InterruptedExceptionMakes a remote procedure call.Sends
Callableto the remote system, executes it, and returns its result. Such calls will be considered as user-space requests. If the channel cannot execute the requests (e.g. when it is being closed), the operations may be rejected even if the channel is still active.- Specified by:
callin interfaceVirtualChannel- Parameters:
callable- Callable to be executed- Throws:
IOException- If there's any error in the communication betweenChannels.T- User exception defined by the callableInterruptedException- If the current thread is interrupted while waiting for the completion.
-
callAsync
Makes an asynchronous remote procedure call.Similar to
VirtualChannel.call(Callable)but returns immediately. The result of theCallablecan be obtained through theFutureobject. Such calls will be considered as user-space requests. If the channel cannot execute the requests (e.g. when it is being closed), the operations may be rejected even if the channel is still active.- Specified by:
callAsyncin interfaceVirtualChannel- Returns:
- The
Futureobject that can be used to wait for the completion. - Throws:
IOException- If there's an error during the communication.
-
terminate
Aborts the connection in response to an error. This is an SPI forCommandTransportimplementation to notifyChannelwhen the underlying connection is severed. Once the call is calledcloseRequestedwill be set immediately to prevent further executions ofUserRequests.- Parameters:
e- The error that caused the connection to be aborted. Never null.
-
addListener
Registers a newChannel.Listener.- See Also:
-
removeListener
Removes a listener.- Returns:
- false if the given listener has not been registered to begin with.
-
addLocalExecutionInterceptor
Adds aCallableDecoratorthat gets a chance to decorate everyCallables that run locally sent by the other peer. This is useful to tweak the environment those closures are run, such as setting up the thread context environment. -
removeLocalExecutionInterceptor
Removes the filter introduced byaddLocalExecutionInterceptor(CallableDecorator). -
addLocalExecutionInterceptor
Deprecated. -
removeLocalExecutionInterceptor
Deprecated. -
join
Waits for thisChannelto be closed down. The close-down of aChannelmight be initiated locally or remotely.- Specified by:
joinin interfaceVirtualChannel- Throws:
InterruptedException- If the current thread is interrupted while waiting for the completion.
-
isInClosed
public boolean isInClosed()If the receiving end of the channel is closed (that is, if we are guaranteed to receive nothing further), this method returns true. -
isRestricted
Deprecated.Use methods likeisRemoteClassLoadingAllowed()andisArbitraryCallableAllowed()to test individual features.Returns true if this channel has any of the security restrictions enabled. -
setRestricted
Deprecated.Use methods likesetRemoteClassLoadingAllowed(boolean)andsetArbitraryCallableAllowed(boolean)to control individual features.Activates/disables all the security restriction mode. -
isRemoteClassLoadingAllowed
public boolean isRemoteClassLoadingAllowed()- Since:
- 2.47
-
setRemoteClassLoadingAllowed
public void setRemoteClassLoadingAllowed(boolean b) Controls whether or not this channel is willing to load classes from the other side. The default is on.- Since:
- 2.47
-
isArbitraryCallableAllowed
public boolean isArbitraryCallableAllowed()- Since:
- 2.47
-
setArbitraryCallableAllowed
public void setArbitraryCallableAllowed(boolean b) - Since:
- 2.47
- See Also:
-
setMaximumBytecodeLevel
Sets the maximum bytecode version (~ JDK) that we expect this channel to be able to load. If attempts are made to load remote classes using newer bytecode, they are immediately rejected, even if the remote JVM is actually new enough to load it. This helps maintain compatibility by making tests fail immediately without the need for an old JDK installation. By default, the remote class loader will try to load any bytecode version.- Parameters:
level- e.g. 5 for JDK 5 (the minimum sensible value)- Throws:
IOExceptionInterruptedException- Since:
- 2.29
-
join
Waits for thisChannelto be closed down, but only up the given milliseconds.- Specified by:
joinin interfaceVirtualChannel- Parameters:
timeout- TImeout in milliseconds- Throws:
InterruptedException- If the current thread is interrupted while waiting for the completion.- Since:
- 1.299
-
resetPerformanceCounters
public void resetPerformanceCounters()Resets all the performance counters. -
dumpPerformanceCounters
Print the performance counters.- Parameters:
w- Output writer- Throws:
IOException- Since:
- 2.24
-
dumpDiagnostics
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public void dumpDiagnostics(@NonNull PrintWriter w) throws IOException Print the diagnostic information.Here's how you interpret these metrics:
- Created
- When the channel was created, which is more or less the same thing as when the channel is connected.
- Commands sent
-
Number of
Commandobjects sent to the other side. More specifically, number of commands successfully passed totransport, which means data was written to socket withClassicCommandTransportbut just buffered for write withNioChannelHub. If you have access to the remoting diagnostics of the other side of the channel, then you can compare this with "commandsReceived" metrics of the other side to see how many commands are in transit in transport. IfcommandsSent==commandsReceived, then no command is in transit. - Commands received
-
Number of
Commandobjects received from the other side. More precisely, number of commands reported fromtransport. So for example, if data is still buffered somewhere in the networking stack, it won't be counted here. - Last command sent
-
The timestamp in which the last command was sent to the other side. The timestamp in which
lastCommandSentAtwas updated. - Last command received
-
The timestamp in which the last command was sent to the other side. The timestamp in which
lastCommandReceivedAtwas updated. - Pending outgoing calls
- Number of RPC calls (e.g., method call through a proxy) that are made but not returned yet. If you have the remoting diagnostics of the other side, you can compare this number with "pending incoming calls" on the other side to see how many RPC calls are executing vs in flight. "one side's incoming calls" < "the other side's outgoing calls" indicates some RPC requests or responses are passing through the network layer, and mismatch between "# of commands sent" vs "# of commands received" can give some indication of whether it is request or response that's in flight.
- Pending incoming calls
- The reverse of "pending outgoing calls". Number of RPC calls (e.g., method call through a proxy) that the other side has made to us but not yet returned yet.
- Parameters:
w- Output destination- Throws:
IOException- Error while creating or writing the channel information- Since:
- 2.62.3 - stable 2.x (restricted), 3.1
-
close
Performs an orderly shut down of this channel (and the remote peer.)- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceVirtualChannel- Throws:
IOException- if the orderly shut-down failed.
-
close
Closes the channel. Once the call is calledcloseRequestedwill be set immediately to prevent further executions ofUserRequests.- Parameters:
diagnosis- If someone (either this side or the other side) tries to use a channel that's already closed, they'll get a stack trace indicating that the channel has already been closed. This diagnosis, if provided, will further chained to that exception, providing more contextual information about why the channel was closed.- Throws:
IOException- Since:
- 2.8
-
getProperty
Gets the application specific property set bysetProperty(Object, Object). These properties are also accessible from the remote channel viagetRemoteProperty(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 remoteChannel.- Parameters:
key- Key- Returns:
- The property or
nullif there is no property for the specified key
-
getProperty
-
waitForProperty
Works likegetProperty(Object)but wait until some value is set by someone.- Parameters:
key- Property key- Throws:
IllegalStateException- if the channel is closed. The idea is that channel properties are expected to be the coordination mechanism between two sides of the channel, and this method in particular is a way of one side to wait for the set by the other side of the channel (viawaitForRemoteProperty(Object). If we don't abort after the channel shutdown, this method will block forever.InterruptedException
-
waitForProperty
- Throws:
InterruptedException
-
setProperty
Sets the property value on this side of the channel.- Parameters:
key- Property keyvalue- Value to set.nullremoves the existing entry without adding a new one.- Returns:
- Old property value or
nullif it was not set - See Also:
-
setProperty
-
getRemoteProperty
Gets the property set on the remote peer.- Returns:
nullif the property of the said key isn't set.
-
getRemoteProperty
-
waitForRemoteProperty
Gets the property set on the remote peer. This method blocks until the property is set by the remote peer.- Throws:
InterruptedException
-
waitForRemoteProperty
Deprecated.BecauseChannelPropertyis identity-equality, this method would never work. This is a design error.- Throws:
InterruptedException
-
getUnderlyingOutput
Deprecated.Future version of the remoting module may add other modes of creating channel that doesn't involve stream pair. Therefore, we aren't committing to this method. This method isn't a part of the committed API of the channel class.Obtain the output stream passed to the constructor.- Returns:
- While the current version always return a non-null value, the caller must not
make that assumption for the above reason. This method may return null in the future version
to indicate that the
Channelis not sitting on top of a stream pair.
-
createLocalToRemotePortForwarding
@Deprecated public ListeningPort createLocalToRemotePortForwarding(int recvPort, String forwardHost, int forwardPort) throws IOException, InterruptedException Deprecated.as of 3.39Starts a local to remote port forwarding (the equivalent of "ssh -L").- Parameters:
recvPort- The port on this local machine that we'll listen to. 0 to let OS pick a random available port. If you specify 0, useListeningPort.getPort()to figure out the actual assigned port.forwardHost- The remote host that the connection will be forwarded to. Connection to this host will be made from the other JVM that thisChannelrepresents.forwardPort- The remote port that the connection will be forwarded to.- Returns:
- Created
PortForwarder - Throws:
IOExceptionInterruptedException
-
createRemoteToLocalPortForwarding
@Deprecated public ListeningPort createRemoteToLocalPortForwarding(int recvPort, String forwardHost, int forwardPort) throws IOException, InterruptedException Deprecated.as of 3.39Starts a remote to local port forwarding (the equivalent of "ssh -R").- Parameters:
recvPort- The port on the remote JVM (represented by thisChannel) that we'll listen to. 0 to let OS pick a random available port. If you specify 0, useListeningPort.getPort()to figure out the actual assigned port.forwardHost- The remote host that the connection will be forwarded to. Connection to this host will be made from this JVM.forwardPort- The remote port that the connection will be forwarded to.- Returns:
- Created
PortForwarder. - Throws:
IOExceptionInterruptedException
-
syncIO
Blocks until all the I/O packets sent before this gets fully executed by the remote side, then return.- Throws:
IOException- If the remote doesn't support this operation, or if sync fails for other reasons.InterruptedException
-
syncLocalIO
Description copied from interface:VirtualChannelBlocks until all the I/O packets sent from remote is fully locally executed, then return.- Specified by:
syncLocalIOin interfaceVirtualChannel- Throws:
InterruptedException
-
getName
-
toString
-
dumpExportTable
Dumps the list of exported objects and their allocation traces to the given output.- Throws:
IOException
-
startExportRecording
public hudson.remoting.ExportTable.ExportList startExportRecording() -
getLastHeard
public long getLastHeard()TODO: this is not safe against clock skew and is called from jenkins core (and potentially plugins)- See Also:
-
lastCommandReceivedAt
-
current
This method can be invoked during the serialization/deserialization of objects when they are transferred to the remoteChannel, as well as duringCallable.call()is invoked.- Returns:
nullif the calling thread is not performing serialization.
-
currentOrFail
Gets current channel or fails withIllegalStateException.- Returns:
- Current channel
- Throws:
IllegalStateException- the calling thread has no associated channel.- Since:
- 3.14
- See Also:
-
dumpDiagnosticsForAll
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public static void dumpDiagnosticsForAll(@NonNull PrintWriter w) CallsdumpDiagnostics(PrintWriter)across all the active channels in this system. Used for diagnostics.- Parameters:
w- Output destination- Since:
- 2.62.3 - stable 2.x (restricted), 3.1
-
isClosedChannelException
Checks whether an exception seems to be related to a closed channel. DetectsChannelClosedException,ClosedChannelException, andEOFExceptionanywhere in the exception or suppressed exception chain.
-
ChannelBuilderChannelBuilder(name, exec) .withMode(mode) .build(is, os)