/** * Bind desired port and start network service. Before starting network service, {@link NettyRestServer} * will initialize its configuration. * */ @Override public void start() { if (handler == null) { throw new IllegalStateException("ChannelHandler is null."); } super.init(new NettyRestChannelInitializer(handler), workerCount); super.start(); }
private synchronized static int getUnusedPort() throws IOException { while (true) { int port = nextPortNum.getAndIncrement(); if (port >= endPortRange) { synchronized (lockObject) { nextPortNum.set(startPortRange); port = nextPortNum.getAndIncrement(); } } if (available(port)) { return port; } } }
public void shutdown() { shutdown(false); }
public AsyncRpcServer(final Class<?> protocol, final Object instance, final InetSocketAddress bindAddress, final int threads) throws Exception { super(protocol.getSimpleName(), bindAddress); String serviceClassName = protocol.getName() + "$" + protocol.getSimpleName() + "Service"; Class<?> serviceClass = Class.forName(serviceClassName); Class<?> interfaceClass = Class.forName(serviceClassName + "$Interface"); Method method = serviceClass.getMethod("newReflectiveService", interfaceClass); this.service = (Service) method.invoke(null, instance); this.initializer = new ProtoServerChannelInitializer(new ServerHandler(), RpcRequest.getDefaultInstance()); super.init(this.initializer, threads); }
public void start() { if (serviceName == null) { this.serviceName = getNextDefaultServiceName(); } if (initIsa.getPort() == 0) { try { int port = getUnusedPort(); serverAddr = new InetSocketAddress(initIsa.getHostName(), port); } catch (IOException e) { LOG.error(e, e); } } else { serverAddr = initIsa; } this.channelFuture = bootstrap.clone().bind(serverAddr).syncUninterruptibly(); this.bindAddress = (InetSocketAddress) channelFuture.channel().localAddress(); LOG.info("Rpc (" + serviceName + ") listens on " + this.bindAddress); }
public AsyncRpcServer(final Class<?> protocol, final Object instance, final InetSocketAddress bindAddress, final int threads) throws Exception { super(protocol.getSimpleName(), bindAddress); String serviceClassName = protocol.getName() + "$" + protocol.getSimpleName() + "Service"; Class<?> serviceClass = Class.forName(serviceClassName); Class<?> interfaceClass = Class.forName(serviceClassName + "$Interface"); Method method = serviceClass.getMethod("newReflectiveService", interfaceClass); this.service = (Service) method.invoke(null, instance); this.initializer = new ProtoServerChannelInitializer(new ServerHandler(), RpcRequest.getDefaultInstance()); super.init(this.initializer, threads); }
public void start() { for (RpcEventListener listener: listeners) { listener.onBeforeStart(this); } if (serviceName == null) { this.serviceName = getNextDefaultServiceName(); } if (initIsa.getPort() == 0) { try { int port = getUnusedPort(); serverAddr = new InetSocketAddress(initIsa.getHostName(), port); } catch (IOException e) { LOG.error(e, e); } } else { serverAddr = initIsa; } this.channelFuture = bootstrap.clone().bind(serverAddr).syncUninterruptibly(); this.bindAddress = (InetSocketAddress) channelFuture.channel().localAddress(); for (RpcEventListener listener: listeners) { listener.onAfterStart(this); } LOG.info("Rpc (" + serviceName + ") listens on " + this.bindAddress); }
public AsyncRpcServer(final Class<?> protocol, final Object instance, final InetSocketAddress bindAddress, final int workerNum) throws Exception { super(protocol.getSimpleName(), bindAddress); String serviceClassName = protocol.getName() + "$" + protocol.getSimpleName() + "Service"; Class<?> serviceClass = Class.forName(serviceClassName); Class<?> interfaceClass = Class.forName(serviceClassName + "$Interface"); Method method = serviceClass.getMethod("newReflectiveService", interfaceClass); this.service = (Service) method.invoke(null, instance); this.initializer = new ProtoChannelInitializer(new ServerHandler(), RpcRequest.getDefaultInstance()); super.init(this.initializer, workerNum); }
/** * Bind desired port and start network service. Before starting network service, {@link NettyRestServer} * will initialize its configuration. * */ @Override public void start() { if (handler == null) { throw new IllegalStateException("ChannelHandler is null."); } super.init(new NettyRestChannelInitializer(handler), workerCount); super.start(); }
public void shutdown() { shutdown(false); }
private synchronized static int getUnusedPort() throws IOException { while (true) { int port = nextPortNum.getAndIncrement(); if (port >= endPortRange) { synchronized (lockObject) { nextPortNum.set(startPortRange); port = nextPortNum.getAndIncrement(); } } if (available(port)) { return port; } } }
public BlockingRpcServer(final Class<?> protocol, final Object instance, final InetSocketAddress bindAddress, final int threads) throws Exception { super(protocol.getSimpleName(), bindAddress); String serviceClassName = protocol.getName() + "$" + protocol.getSimpleName() + "Service"; Class<?> serviceClass = Class.forName(serviceClassName); Class<?> interfaceClass = Class.forName(serviceClassName + "$BlockingInterface"); Method method = serviceClass.getMethod( "newReflectiveBlockingService", interfaceClass); this.service = (BlockingService) method.invoke(null, instance); this.initializer = new ProtoServerChannelInitializer(new ServerHandler(), RpcRequest.getDefaultInstance()); super.init(this.initializer, threads); }
public BlockingRpcServer(final Class<?> protocol, final Object instance, final InetSocketAddress bindAddress, final int threads) throws Exception { super(protocol.getSimpleName(), bindAddress); String serviceClassName = protocol.getName() + "$" + protocol.getSimpleName() + "Service"; Class<?> serviceClass = Class.forName(serviceClassName); Class<?> interfaceClass = Class.forName(serviceClassName + "$BlockingInterface"); Method method = serviceClass.getMethod( "newReflectiveBlockingService", interfaceClass); this.service = (BlockingService) method.invoke(null, instance); this.initializer = new ProtoServerChannelInitializer(new ServerHandler(), RpcRequest.getDefaultInstance()); super.init(this.initializer, threads); }
public BlockingRpcServer(final Class<?> protocol, final Object instance, final InetSocketAddress bindAddress, final int workerNum) throws Exception { super(protocol.getSimpleName(), bindAddress); String serviceClassName = protocol.getName() + "$" + protocol.getSimpleName() + "Service"; Class<?> serviceClass = Class.forName(serviceClassName); Class<?> interfaceClass = Class.forName(serviceClassName + "$BlockingInterface"); Method method = serviceClass.getMethod( "newReflectiveBlockingService", interfaceClass); this.service = (BlockingService) method.invoke(null, instance); this.initializer = new ProtoChannelInitializer(new ServerHandler(), RpcRequest.getDefaultInstance()); super.init(this.initializer, workerNum); }