List of usage examples for io.netty.channel Channel localAddress
SocketAddress localAddress();
From source file:club.jmint.crossing.client.call.CrossingCall.java
License:Apache License
public String syncCall(String inf, String params, boolean isEncrypt) throws CrossException { //Starting client call Channel channel = cfuture.channel(); CrossingReqProto.CrossingReq.Builder builder = CrossingReqProto.CrossingReq.newBuilder(); InetSocketAddress isa = (InetSocketAddress) channel.localAddress(); String ip = isa.getAddress().getHostAddress(); builder.setSeqId(Utils.getSeqId(ip)); builder.setInterfaceName(inf);// w w w .jav a 2 s .c om builder.setParams(params); builder.setIsEncrypt(isEncrypt); //sending a call CrossingReqProto.CrossingReq callmsg = builder.build(); CrossLog.logger.debug("Sending a request:\n" + callmsg); long stime = Utils.getTimeInMillis(); channel.writeAndFlush(callmsg); //wait the result CrossingRespProto.CrossingResp res = null; String msgKey = String.valueOf(callmsg.getSeqId()); try { do { cfuture.await(); res = handler.getRespMsg(msgKey); } while (res == null); } catch (InterruptedException e) { CrossLog.printStackTrace(e); } long etime = Utils.getTimeInMillis(); long delay = etime - stime; CrossLog.logger.debug(String.format("Received a response(in %dms):\n", delay) + res); //output the calling result //String rs = res.getServiceName(); //String ri = res.getInterfaceName(); String rparams = res.getParams(); //remove the respMsg after getting return. handler.removeRespMsg(msgKey); return rparams; }
From source file:com.barchart.http.server.PooledServerRequest.java
License:BSD License
void init(final Channel channel_, final FullHttpRequest nettyRequest_, final String relativeUri_) { local = (InetSocketAddress) channel_.localAddress(); remote = (InetSocketAddress) channel_.remoteAddress(); nettyRequest = nettyRequest_;/*from w w w . j a va 2s .c o m*/ nettyRequest.retain(); baseUri = relativeUri_; final int q = baseUri.indexOf('?'); if (q == -1) { pathInfo = baseUri; queryString = null; } else { pathInfo = baseUri.substring(0, q); queryString = baseUri.substring(q + 1); } // Reset previous state queryStringDecoded = null; cookies = null; attributes = null; remoteUser = null; }
From source file:com.dinstone.jrpc.transport.netty4.NettyConnector.java
License:Apache License
public Channel createSession() { Channel channel = clientBoot.connect().awaitUninterruptibly().channel(); LOG.debug("session connect {} to {}", channel.localAddress(), channel.remoteAddress()); return channel; }
From source file:com.eucalyptus.util.async.AsyncRequestHandler.java
License:Open Source License
private void logAcquired(final Channel channel, final long before) { final long acquireTime = System.currentTimeMillis() - before; final Level level; if (acquireTime > 45_000L) { level = Level.WARN;/*from w w w. ja v a 2s . c o m*/ } else if (acquireTime > 30_000L) { level = Level.INFO; } else if (acquireTime > 10_000L) { level = Level.DEBUG; } else { level = Level.TRACE; } if (LOG.isEnabledFor(level)) { LOG.log(level, "Acquire took " + acquireTime + "ms for " + channel.remoteAddress()); } Logs.extreme().debug("Acquired as: " + channel.localAddress()); }
From source file:com.farsunset.cim.sdk.android.filter.CIMLoggingHandler.java
License:Apache License
private String getSessionInfo(Channel session) { StringBuilder builder = new StringBuilder(); if (session == null) { return ""; }//from ww w . ja va 2 s. c om builder.append(" ["); builder.append("id:").append(session.id().asShortText()); if (session.localAddress() != null) { builder.append(" L:").append(session.localAddress().toString()); } if (session.remoteAddress() != null) { builder.append(" R:").append(session.remoteAddress().toString()); } builder.append("]"); return builder.toString(); }
From source file:com.flowpowered.examples.networking.Server.java
License:MIT License
@Override public Session newSession(Channel c) { System.out.println("Server session created!"); return session = new DynamicSession(c, pr.getProtocol(c.localAddress())); }
From source file:com.gis09.srpc.remoting.RemotingException.java
License:Apache License
public RemotingException(Channel channel, String msg) { this(channel == null ? null : (InetSocketAddress) channel.localAddress(), channel == null ? null : (InetSocketAddress) channel.remoteAddress(), msg); }
From source file:com.gis09.srpc.remoting.RemotingException.java
License:Apache License
public RemotingException(Channel channel, Throwable cause) { this(channel == null ? null : (InetSocketAddress) channel.localAddress(), channel == null ? null : (InetSocketAddress) channel.remoteAddress(), cause); }
From source file:com.gis09.srpc.remoting.RemotingException.java
License:Apache License
public RemotingException(Channel channel, String message, Throwable cause) { this(channel == null ? null : (InetSocketAddress) channel.localAddress(), channel == null ? null : (InetSocketAddress) channel.remoteAddress(), message, cause); }
From source file:com.googlecode.protobuf.pro.duplex.client.DuplexTcpClientPipelineFactory.java
License:Apache License
/** * Creates a new client with the provided channel attributes to the remoteAddress. * @param remoteAddress/*from w w w. ja va 2 s.com*/ * @param bootstrap * @param attributes * @return * @throws IOException */ public RpcClient peerWith(InetSocketAddress remoteAddress, Bootstrap bootstrap, Map<String, Object> attributes) throws IOException { if (remoteAddress == null) { throw new NullPointerException("remotedAddress"); } InetSocketAddress localAddress = null; if (clientInfo.getHostName() != null) { localAddress = new InetSocketAddress(clientInfo.getHostName(), clientInfo.getPort()); } ChannelFuture connectFuture = bootstrap.connect(remoteAddress, localAddress).awaitUninterruptibly(); if (!connectFuture.isSuccess()) { throw new IOException("Failed to connect to " + remoteAddress, connectFuture.cause()); } Channel channel = connectFuture.channel(); InetSocketAddress connectedAddress = (InetSocketAddress) channel.localAddress(); PeerInfo effectiveClientInfo = new PeerInfo( clientInfo.getHostName() == null ? connectedAddress.getHostName() : clientInfo.getHostName(), connectedAddress.getPort(), clientInfo.getPid()); ConnectRequest connectRequest = ConnectRequest.newBuilder() .setClientHostName(effectiveClientInfo.getHostName()).setClientPort(effectiveClientInfo.getPort()) .setClientPID(effectiveClientInfo.getPid()).setCorrelationId(correlationId.incrementAndGet()) .setCompress(isCompression()).build(); WirePayload payload = WirePayload.newBuilder().setConnectRequest(connectRequest).build(); if (log.isDebugEnabled()) { log.debug("Sending [" + connectRequest.getCorrelationId() + "]ConnectRequest."); } channel.writeAndFlush(payload); ClientConnectResponseHandler connectResponseHandler = (ClientConnectResponseHandler) channel.pipeline() .get(Handler.CLIENT_CONNECT); if (connectResponseHandler == null) { throw new IllegalStateException("No connectReponse handler in channel pipeline."); } ConnectResponse connectResponse = connectResponseHandler.getConnectResponse(connectResponseTimeoutMillis); if (connectResponse == null) { connectFuture.channel().close().awaitUninterruptibly(); throw new IOException( "No Channel response received before " + connectResponseTimeoutMillis + " millis timeout."); } if (connectResponse.hasErrorCode()) { connectFuture.channel().close().awaitUninterruptibly(); throw new IOException( "DuplexTcpServer CONNECT_RESPONSE indicated error " + connectResponse.getErrorCode()); } if (!connectResponse.hasCorrelationId()) { connectFuture.channel().close().awaitUninterruptibly(); throw new IOException("DuplexTcpServer CONNECT_RESPONSE missing correlationId."); } if (connectResponse.getCorrelationId() != connectRequest.getCorrelationId()) { connectFuture.channel().close().awaitUninterruptibly(); throw new IOException("DuplexTcpServer CONNECT_RESPONSE correlationId mismatch. TcpClient sent " + connectRequest.getCorrelationId() + " received " + connectResponse.getCorrelationId() + " from TcpServer."); } PeerInfo serverInfo = null; if (connectResponse.hasServerPID()) { serverInfo = new PeerInfo(remoteAddress.getHostName(), remoteAddress.getPort(), connectResponse.getServerPID()); } else { serverInfo = new PeerInfo(remoteAddress.getHostName(), remoteAddress.getPort()); } RpcClient rpcClient = new RpcClient(channel, effectiveClientInfo, serverInfo, connectResponse.getCompress(), getRpcLogger(), getExtensionRegistry()); if (attributes != null) { // transfer the input attributes to the channel before we state it's opened. for (Entry<String, Object> attr : attributes.entrySet()) { rpcClient.setAttribute(attr.getKey(), attr.getValue()); } } RpcClientHandler rpcClientHandler = completePipeline(rpcClient); rpcClientHandler.notifyOpened(); // register the rpcClient in the RpcClientRegistry if (!getRpcClientRegistry().registerRpcClient(rpcClient)) { log.warn("Client RpcClient already registered. Bug??"); } // channels remove themselves when closed. return rpcClient; }