io.reactivex.netty.protocol.udp.client.UdpClientBuilder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of rx-netty Show documentation
Show all versions of rx-netty Show documentation
rx-netty developed by Netflix
/*
* Copyright 2014 Netflix, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.reactivex.netty.protocol.udp.client;
import io.netty.bootstrap.Bootstrap;
import io.reactivex.netty.client.AbstractClientBuilder;
import io.reactivex.netty.client.ClientChannelFactoryImpl;
import io.reactivex.netty.client.ClientMetricsEvent;
import io.reactivex.netty.client.ConnectionPoolBuilder;
import io.reactivex.netty.client.RxClient;
import io.reactivex.netty.client.RxClientImpl;
import io.reactivex.netty.metrics.MetricEventsListener;
import io.reactivex.netty.metrics.MetricEventsListenerFactory;
import io.reactivex.netty.pipeline.ssl.SSLEngineFactory;
import java.net.InetSocketAddress;
/**
* A builder to build an instance of {@link RxClientImpl}
*
* @author Nitesh Kant
*/
public class UdpClientBuilder extends AbstractClientBuilder, RxClient> {
public UdpClientBuilder(String host, int port) {
this(host, port, new Bootstrap());
}
public UdpClientBuilder(String host, int port, Bootstrap bootstrap) {
super(bootstrap, host, port, new UdpClientConnectionFactory(new InetSocketAddress(host, port)),
new ClientChannelFactoryImpl(bootstrap));
defaultUdpOptions();
}
@Override
protected RxClient createClient() {
return new UdpClient(getOrCreateName(), serverInfo, bootstrap, pipelineConfigurator, clientConfig,
channelFactory, eventsSubject);
}
@Override
public UdpClientBuilder withSslEngineFactory(SSLEngineFactory sslEngineFactory) {
throw new IllegalArgumentException("SSL protocol is not applicable to UDP ");
}
@Override
protected ConnectionPoolBuilder getPoolBuilder(boolean createNew) {
ConnectionPoolBuilder builder = super.getPoolBuilder(false);
if (null == builder && createNew) {
throw new IllegalStateException("Connection pools are not allowed for UDP clients.");
}
if (null != builder) {
throw new IllegalStateException("Connection pools are not allowed for UDP clients.");
}
return builder;
}
@Override
protected String generatedNamePrefix() {
return "UdpClient-";
}
@Override
protected MetricEventsListener>
newMetricsListener(MetricEventsListenerFactory factory, RxClient client) {
return factory.forUdpClient((UdpClient) client);
}
}