Package java.nio.channels

Examples of java.nio.channels.Pipe$SourceChannel


    private FileDescriptor[] writable;

    public SelectorImpl(SelectorProvider selectorProvider) {
        super(selectorProvider);
        try {
            Pipe mockSelector = selectorProvider.openPipe();
            sink = mockSelector.sink();
            source = mockSelector.source();
            sourcefd = ((FileDescriptorHandler)source).getFD();
            source.configureBlocking(false);
        } catch (IOException e) {
            // do nothing
        }
View Full Code Here


    private FileDescriptor[] writable;

    public SelectorImpl(SelectorProvider selectorProvider) {
        super(selectorProvider);
        try {
            Pipe mockSelector = selectorProvider.openPipe();
            sink = mockSelector.sink();
            source = mockSelector.source();
            sourcefd = ((FileDescriptorHandler)source).getFD();
            source.configureBlocking(false);
        } catch (IOException e) {
            // do nothing
        }
View Full Code Here

    private FileDescriptor sourcefd;

    public SelectorImpl(SelectorProvider selectorProvider) {
        super(selectorProvider);
        try {
            Pipe mockSelector = selectorProvider.openPipe();
            sink = mockSelector.sink();
            source = mockSelector.source();
            sourcefd = ((FileDescriptorHandler) source).getFD();
            source.configureBlocking(false);

            readableFDs = new FileDescriptor[1];
            writableFDs = new FileDescriptor[0];
View Full Code Here

 
  @Test
  public void testSocketIOWithTimeout() throws Exception {
   
    // first open pipe:
    Pipe pipe = Pipe.open();
    Pipe.SourceChannel source = pipe.source();
    Pipe.SinkChannel sink = pipe.sink();
   
    try {
      final InputStream in = new SocketInputStream(source, TIMEOUT);
      OutputStream out = new SocketOutputStream(sink, TIMEOUT);
     
View Full Code Here

            selector = context.runtime.getSelectorPool().get(channel.provider());
            selectors.add(selector);

            if (!selector.provider().equals(SelectorProvider.provider())) {
                // need to create pipe between alt impl selector and native NIO selector
                Pipe pipe = Pipe.open();
                ENXIOSelector enxioSelector = new ENXIOSelector(selector, pipe);
                if (enxioSelectors.isEmpty()) enxioSelectors = new ArrayList<ENXIOSelector>();
                enxioSelectors.add(enxioSelector);
                pipe.source().configureBlocking(false);
                pipe.source().register(getSelector(context, pipe.source()), SelectionKey.OP_READ, enxioSelector);
            } else if (mainSelector == null) {
                mainSelector = selector;
            }
        }
View Full Code Here

    }

    public Channel[] pipe() {
        clear();
        try {
            Pipe pipe = Pipe.open();
            Channel source = pipe.source(), sink = pipe.sink();

            if (posix.isNative()) {
                // set cloexec if possible
                int read = FilenoUtil.filenoFrom(source);
                int write = FilenoUtil.filenoFrom(sink);
View Full Code Here

  @Test
  public void testWorkerAnnounce() throws IOException {
    final DiscoWorkerListener listener = mock(DiscoWorkerListener.class);
    final InOrder inOrder = inOrder(listener);

    final Pipe pipeFromDisco = Pipe.open();
    final DiscoIOChannel ioChannel = new DiscoIOChannel(pipeFromDisco.source(), new NullByteChannel(),
            new DiscoWorkerDecoder().setListener(listener));

    final String okStr = "OK 4 \"ok\"\n";
    pipeFromDisco.sink().write(ByteBuffer.wrap(okStr.getBytes()));
    ioChannel.write(new WorkerAnnounceEncoder().set("1.0", 555));

    inOrder.verify(listener).ok();
  }
View Full Code Here

    assertEquals(DiscoInputReplicaProtocol.raw, replica.getScheme());
  }

  @Test
  public void testInputFlow() throws IOException {
    final Pipe pipeFromDisco = Pipe.open();

    final DiscoWorker discoWorker = new DiscoWorker(pipeFromDisco.source(), new NullByteChannel());
    final SinkChannel disco = pipeFromDisco.sink();

    // Put messages in the input pipeline (from the disco master)
    final String okStr = "OK 4 \"ok\"\n";
    disco.write(ByteBuffer.wrap(okStr.getBytes()));
    final String taskStr = "TASK 327 {\"taskid\":0,\"master\":\"http://lhoersten-66113:8989\",\"disco_port\":8989,\"put_port\":8990,\"ddfs_data\":\"/srv/disco/ddfs\",\"disco_data\":\"/srv/disco/data\",\"mode\":\"map\",\"jobfile\":\"/srv/disco/data/localhost/5a/lhoersten-FunshineSimulator@524:7310e:1cb44/jobfile\",\"jobname\":\"lhoersten-FunshineSimulator@524:7310e:1cb44\",\"host\":\"localhost\"}\n";
View Full Code Here

    assertEquals("eyJlbnRyeWV4aXRsZXZlbCI6WyJERUMiLDEuNV0sInFyMiI6WyJERUMiLDFdLCJxcjEiOlsiREVD", input);
  }

  @Test
  public void testChannelToString() throws IOException {
    final Pipe pipe = Pipe.open();

    final SinkChannel sink = pipe.sink();
    final String expected = "12345678\n";
    sink.write(ByteBuffer.wrap(expected.getBytes()));

    final String actual = DiscoUtils.channelLineToString(pipe.source());

    assertEquals(expected, actual);
  }
View Full Code Here

        super();
        this.logger = logger;
        try
        {
            Pipe p = Pipe.open();
            SinkChannel sink = p.sink();
            SourceChannel source = p.source();
            writer = Channels.newWriter( sink, Charset.defaultCharset().name() );
            reader = Channels.newReader( source, Charset.defaultCharset().name() );
            parser.setInput( reader );

        }
View Full Code Here

TOP

Related Classes of java.nio.channels.Pipe$SourceChannel

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.