Example usage for io.netty.bootstrap Bootstrap clone

List of usage examples for io.netty.bootstrap Bootstrap clone

Introduction

In this page you can find the example usage for io.netty.bootstrap Bootstrap clone.

Prototype

@Override
    @SuppressWarnings("CloneDoesntCallSuperClone")
    public Bootstrap clone() 

Source Link

Usage

From source file:com.basho.riak.client.core.ConnectionPool.java

License:Apache License

/**
 * Sets the Netty {@link Bootstrap} for this pool.
 * {@link Bootstrap#clone()} is called to clone the bootstrap.
 *
 * @param bootstrap/*from   w  ww. j  av a2s. co m*/
 * @throws IllegalArgumentException if it was already set via the builder.
 * @throws IllegalStateException    if the pool has already been started.
 * @see Builder#withBootstrap(io.netty.bootstrap.Bootstrap)
 */
public void setBootstrap(Bootstrap bootstrap) {
    stateCheck(State.CREATED);
    if (this.bootstrap != null) {
        throw new IllegalArgumentException("Bootstrap already set");
    }
    this.bootstrap = bootstrap.clone();
}

From source file:com.basho.riak.client.core.RiakNode.java

License:Apache License

/**
 * Sets the Netty {@link Bootstrap} for this Node's connections.
 * {@link Bootstrap#clone()} is called to clone the bootstrap.
 *
 * @param bootstrap - the Netty Bootstrap to use
 * @return a reference to this RiakNode//w  w w .j  a  v a2  s  .c  o  m
 * @throws IllegalArgumentException if it was already set via the builder.
 * @throws IllegalStateException    if the node has already been started.
 * @see Builder#withBootstrap(io.netty.bootstrap.Bootstrap)
 */
public RiakNode setBootstrap(Bootstrap bootstrap) {
    stateCheck(State.CREATED);
    if (this.bootstrap != null) {
        throw new IllegalArgumentException("Bootstrap already set");
    }

    this.bootstrap = bootstrap.clone();
    return this;
}

From source file:org.restcomm.media.network.netty.NettyNetworkManagerTest.java

License:Open Source License

@Test(expected = IOException.class)
public void testOpenChannelSyncFailure() throws Exception {
    // given/*from w  w w  .  j a v a2  s.  c o  m*/
    this.eventLoopGroup = new NioEventLoopGroup(1);
    final Bootstrap bootstrap = PowerMockito.mock(Bootstrap.class);
    PowerMockito.when(bootstrap.group()).thenReturn(eventLoopGroup);
    final Exception exception = new RuntimeException("Testing purposes!");
    try (final NettyNetworkManager networkManager = new NettyNetworkManager(bootstrap)) {
        // when
        when(bootstrap.clone()).thenReturn(bootstrap);
        when(bootstrap.register()).thenThrow(exception);

        networkManager.openChannel();
    }
}

From source file:org.restcomm.media.network.netty.NettyNetworkManagerTest.java

License:Open Source License

@SuppressWarnings("unchecked")
@Test/*from ww w  .ja v a2s . c  om*/
public void testOpenChannelAsyncFailure() throws Exception {
    // given
    this.eventLoopGroup = new NioEventLoopGroup(1);
    final Bootstrap bootstrap = PowerMockito.mock(Bootstrap.class);
    PowerMockito.when(bootstrap.group()).thenReturn(eventLoopGroup);
    this.eventExecutor = new DefaultEventExecutor();
    final FutureCallback<Channel> callback = mock(FutureCallback.class);
    final Channel channel = mock(Channel.class);
    final ChannelPromise promise = new DefaultChannelProgressivePromise(channel, eventExecutor);
    final Exception exception = new RuntimeException("Testing purposes!");

    try (final NettyNetworkManager networkManager = new NettyNetworkManager(bootstrap)) {
        // when
        when(bootstrap.clone()).thenReturn(bootstrap);
        when(bootstrap.register()).thenReturn(promise);
        promise.setFailure(exception);

        networkManager.openChannel(callback);

        // then
        verify(callback, timeout(100)).onFailure(exception);
    }
}