try { topPipe.source().configureBlocking(false); topPipe.sink().configureBlocking(false); final Pipe bottomPipe = Pipe.open(); try { bottomPipe.source().configureBlocking(false); bottomPipe.sink().configureBlocking(false); final WorkerThread peerThread = getPeerThread(peer); final SelectionKey topSourceKey = registerChannel(topPipe.source()); final SelectionKey topSinkKey = peerThread.registerChannel(topPipe.sink()); final SelectionKey bottomSourceKey = peerThread.registerChannel(bottomPipe.source()); final SelectionKey bottomSinkKey = registerChannel(bottomPipe.sink()); final NioPipeStreamConnection leftConnection = new NioPipeStreamConnection(this, bottomSourceKey, topSinkKey); final NioPipeStreamConnection rightConnection = new NioPipeStreamConnection(this, topSourceKey, bottomSinkKey); } finally { if (! ok) { safeClose(bottomPipe.sink()); safeClose(bottomPipe.source()); safeClose(topPipe.sink()); safeClose(topPipe.source());
public ChannelPipe<StreamSourceChannel, StreamSinkChannel> createHalfDuplexPipe(final XnioIoFactory peer) throws IOException { getWorker().checkShutdown(); final Pipe pipe = Pipe.open(); boolean ok = false; try { pipe.source().configureBlocking(false); pipe.sink().configureBlocking(false); final WorkerThread peerThread = getPeerThread(peer); final SelectionKey readKey = registerChannel(pipe.source()); final SelectionKey writeKey = peerThread.registerChannel(pipe.sink()); final NioPipeStreamConnection leftConnection = new NioPipeStreamConnection(this, readKey, null); final NioPipeStreamConnection rightConnection = new NioPipeStreamConnection(this, null, writeKey); leftConnection.writeClosed(); rightConnection.readClosed(); final ChannelPipe<StreamSourceChannel,StreamSinkChannel> result = new ChannelPipe<StreamSourceChannel, StreamSinkChannel>(leftConnection.getSourceChannel(), rightConnection.getSinkChannel()); ok = true; return result; } finally { if (! ok) { safeClose(pipe.sink()); safeClose(pipe.source()); } } }
/** * write the segment (denoted by its offset and length) into an output file * stream */ public void writeToPipe(Pipe pipe, long os, long len) throws java.io.IOException { SinkChannel sinkChannel = pipe.sink(); fc.transferTo(os, len, sinkChannel); }
public Object call() throws Exception { try { selector.select(); } finally { ByteBuffer buf = ByteBuffer.allocate(1); buf.put((byte) 0); buf.flip(); pipe.sink().write(buf); } return null; } }
public Object call() throws Exception { try { selector.select(); } finally { ByteBuffer buf = ByteBuffer.allocate(1); buf.put((byte) 0); buf.flip(); pipe.sink().write(buf); } return null; }
public Object call() throws Exception { try { selector.select(); } finally { ByteBuffer buf = ByteBuffer.allocate(1); buf.put((byte) 0); buf.flip(); pipe.sink().write(buf); } return null; }
public Object call() throws Exception { try { selector.select(); } finally { ByteBuffer buf = ByteBuffer.allocate(1); buf.put((byte) 0); buf.flip(); pipe.sink().write(buf); } return null; } }
public Object call() throws Exception { try { selector.select(); } finally { ByteBuffer buf = ByteBuffer.allocate(1); buf.put((byte) 0); buf.flip(); pipe.sink().write(buf); } return null; } }
void pipeWrite() throws IOException { if (_pipeWriteCount.incrementAndGet() == 1) _pipe.sink().write(ByteBuffer.wrap(_pipeWriteByte)); }
public void run() { try { final WritableByteChannel wbc = pipe.sink(); representation.write(wbc); wbc.close(); } catch (IOException ioe) { Context.getCurrentLogger().log(Level.FINE, "Error while writing to the piped channel.", ioe); } } });
@Override public void wakeup() { try { wakeup.sink().write(ByteBuffer.allocate(1)); } catch(ClosedChannelException channelClosedException) { // Ignore - pipe already closed by reactor being shutdown. } catch(IOException ioException) { throw new ReactorInternalException(ioException); } }
public void run() { try { SinkChannel sinkChannel = pipe.sink(); writeTo(sinkChannel); sinkChannel.close(); } catch (IOException e) { throw new RuntimeException(e); } } }.start();
/** * Write to the pipe */ public int write(ByteBuffer src) throws IOException { checkFlipped(); return pipe.sink().write(src); }
/** * Get a writer that can write to this pipe. The pipe must be writable */ public Writer getWriter() { checkFlipped(); return new PipeChannelWriter(this, Channels.newWriter(pipe.sink(), charset)); }
/** * True if the pipe is open */ public boolean isOpen() { return pipe.sink().isOpen() || pipe.source().isOpen(); }
public void cleanup() throws IOException { pipe.sink().close(); pipe.source().close(); } }
public void cleanup() throws IOException { pipe.sink().close(); pipe.source().close(); } }
/** * Get an outputstream that can write to this pipe. The Pipe must be writable */ public OutputStream getOutputStream() { checkFlipped(); return new PipeChannelOutputStream(this, Channels.newOutputStream(pipe.sink())); }
@JRubyMethod(name = "pipe", meta = true) public static IRubyObject pipe(ThreadContext context, IRubyObject recv) throws Exception { // TODO: This isn't an exact port of MRI's pipe behavior, so revisit Ruby runtime = context.getRuntime(); Pipe pipe = Pipe.open(); RubyIO source = new RubyIO(runtime, pipe.source()); RubyIO sink = new RubyIO(runtime, pipe.sink()); sink.openFile.getMainStream().setSync(true); return runtime.newArrayNoCopy(new IRubyObject[] { source, sink }); }