Class Pipe
- java.lang.Object
-
- hudson.remoting.Pipe
-
- All Implemented Interfaces:
ErrorPropagatingOutputStream
,Serializable
,SerializableOnlyOverRemoting
public final class Pipe extends Object implements SerializableOnlyOverRemoting, ErrorPropagatingOutputStream
Pipe for the remoteCallable
and the local program to talk to each other.There are two kinds of pipes. One is for having a local system write to a remote system, and the other is for having a remote system write to a local system. Use the different versions of the
create
method to create the appropriate kind of pipes.Once created,
Pipe
can be sent to the remote system as a part of a serialization ofCallable
betweenChannel
s. Once re-instantiated on the remoteChannel
, pipe automatically connects back to the local instance and perform necessary set up.The local and remote system can then call
getIn()
andgetOut()
to read/write bytes.Pipe can be only written by one system and read by the other system. It is an error to send one
Pipe
to two remoteChannel
s, or send onePipe
to the sameChannel
twice.Usage
final Pipe p = Pipe.createLocalToRemote(); channel.callAsync(new Callable() { public Object call() { InputStream in = p.getIn(); ... read from in ... } }); OutputStream out = p.getOut(); ... write to out ...
Similarly, for remote to local pipe,final Pipe p = Pipe.createRemoteToLocal(); channel.callAsync(new Callable() { public Object call() { OutputStream out = p.getOut(); ... write to out ... } }); InputStream in = p.getIn(); ... read from in ...
Implementation Note
For better performance,
Pipe
uses lower-levelCommand
abstraction to send data, instead of typed proxy object. This allows the writer to send data without blocking until the arrival of the data is confirmed.- Author:
- Kohsuke Kawaguchi
- See Also:
- Serialized Form
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static Pipe
createLocalToRemote()
Creates aPipe
that allows local system to write and remote system to read.static Pipe
createRemoteToLocal()
Creates aPipe
that allows remote system to write and local system to read.void
error(Throwable t)
Writes an error togetOut()
, which results inIOException
from the reading end.InputStream
getIn()
Gets the reading end of the pipe.OutputStream
getOut()
Gets the writing end of the pipe.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.jenkinsci.remoting.SerializableOnlyOverRemoting
getChannelForSerialization
-
-
-
-
Method Detail
-
getIn
public InputStream getIn()
Gets the reading end of the pipe.
-
getOut
public OutputStream getOut()
Gets the writing end of the pipe.
-
error
public void error(Throwable t) throws IOException
Writes an error togetOut()
, which results inIOException
from the reading end.- Specified by:
error
in interfaceErrorPropagatingOutputStream
- Parameters:
t
- if null, this method behaves exactly likeOutputStream.close()
- Throws:
IOException
- See Also:
ErrorPropagatingOutputStream.error(Throwable)
-
createRemoteToLocal
public static Pipe createRemoteToLocal()
Creates aPipe
that allows remote system to write and local system to read.
-
-