當前位置: 首頁>>代碼示例>>Java>>正文


Java Channel.remoteAddress方法代碼示例

本文整理匯總了Java中io.netty.channel.Channel.remoteAddress方法的典型用法代碼示例。如果您正苦於以下問題:Java Channel.remoteAddress方法的具體用法?Java Channel.remoteAddress怎麽用?Java Channel.remoteAddress使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在io.netty.channel.Channel的用法示例。


在下文中一共展示了Channel.remoteAddress方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: parseChannelRemoteAddr

import io.netty.channel.Channel; //導入方法依賴的package包/類
public static String parseChannelRemoteAddr(final Channel channel) {
    if (null == channel) {
        return "";
    }
    final SocketAddress remote = channel.remoteAddress();
    final String addr = remote != null ? remote.toString() : "";

    if (addr.length() > 0) {
        int index = addr.lastIndexOf("/");
        if (index >= 0) {
            return addr.substring(index + 1);
        }

        return addr;
    }

    return "";
}
 
開發者ID:jiumao-org,項目名稱:wechat-mall,代碼行數:19,代碼來源:RemotingHelper.java

示例2: getKey

import io.netty.channel.Channel; //導入方法依賴的package包/類
/**
 * Get key.
 *
 * @param channel the channel
 * @return the string
 */
public static String getKey(Channel channel){
    InetSocketAddress local = (InetSocketAddress)channel.localAddress();
    InetSocketAddress address = (InetSocketAddress)channel.remoteAddress();
    StringBuilder sb = new StringBuilder();
    sb.append(NetUtils.toIpString(address));
    sb.append(":");
    sb.append(address.getPort());
    sb.append(" --> ");
    sb.append(NetUtils.toIpString(local));
    sb.append(":");
    sb.append(local.getPort());

    String key = sb.toString();
    return key;
}
 
開發者ID:tiglabs,項目名稱:jsf-sdk,代碼行數:22,代碼來源:BaseServerHandler.java

示例3: parseChannelRemoteAddr

import io.netty.channel.Channel; //導入方法依賴的package包/類
/**
 * 獲取Channel的遠程IP地址
 * @param channel
 * @return
 */
public static String parseChannelRemoteAddr(final Channel channel) {
    if (null == channel) {
        return "";
    }
    SocketAddress remote = channel.remoteAddress();
    final String addr = remote != null ? remote.toString() : "";

    if (addr.length() > 0) {
        int index = addr.lastIndexOf("/");
        if (index >= 0) {
            return addr.substring(index + 1);
        }

        return addr;
    }

    return "";
}
 
開發者ID:ChinaLHR,項目名稱:JavaQuarkBBS,代碼行數:24,代碼來源:NettyUtil.java

示例4: parseChannelRemoteAddr

import io.netty.channel.Channel; //導入方法依賴的package包/類
public static String parseChannelRemoteAddr(final Channel channel) {
    if (null == channel) {
        return "";
    }
    SocketAddress remote = channel.remoteAddress();
    final String addr = remote != null ? remote.toString() : "";

    if (addr.length() > 0) {
        int index = addr.lastIndexOf("/");
        if (index >= 0) {
            return addr.substring(index + 1);
        }

        return addr;
    }

    return "";
}
 
開發者ID:lirenzuo,項目名稱:rocketmq-rocketmq-all-4.1.0-incubating,代碼行數:19,代碼來源:RemotingHelper.java

示例5: parseRemoteAddr

import io.netty.channel.Channel; //導入方法依賴的package包/類
/**
 * 獲取Channel的遠程IP地址
 * @param channel
 * @return
 */
public static String parseRemoteAddr(final Channel channel) {
    if (null == channel) {
        return "";
    }
    SocketAddress remote = channel.remoteAddress();
    final String addr = remote != null ? remote.toString() : "";

    if (addr.length() > 0) {
        int index = addr.lastIndexOf("/");
        if (index >= 0) {
            return addr.substring(index + 1);
        }

        return addr;
    }

    return "";
}
 
開發者ID:beyondfengyu,項目名稱:DistributedID-SDK,代碼行數:24,代碼來源:NettyUtil.java

示例6: getRemoteAddress

import io.netty.channel.Channel; //導入方法依賴的package包/類
/** Returns the remote address on the channel or "<unknown remote>" if none exists. */
public static String getRemoteAddress(Channel channel) {
  if (channel != null && channel.remoteAddress() != null) {
    return channel.remoteAddress().toString();
  }
  return "<unknown remote>";
}
 
開發者ID:Tencent,項目名稱:angel,代碼行數:8,代碼來源:NettyUtils.java

示例7: parseChannelRemoteName

import io.netty.channel.Channel; //導入方法依賴的package包/類
public static String parseChannelRemoteName(final Channel channel) {
    if (null == channel) {
        return "";
    }
    final InetSocketAddress remote = (InetSocketAddress) channel.remoteAddress();
    if (remote != null) {
        return remote.getAddress().getHostName();
    }
    return "";
}
 
開發者ID:jiumao-org,項目名稱:wechat-mall,代碼行數:11,代碼來源:RemotingHelper.java

示例8: invokeSyncImpl

import io.netty.channel.Channel; //導入方法依賴的package包/類
public RemotingCommand invokeSyncImpl(final Channel channel, final RemotingCommand request, final long timeoutMillis)
    throws InterruptedException, RemotingSendRequestException, RemotingTimeoutException {
    final int opaque = request.getOpaque();

    try {
        final ResponseFuture responseFuture = new ResponseFuture(opaque, timeoutMillis, null, null);
        this.responseTable.put(opaque, responseFuture);
        final SocketAddress addr = channel.remoteAddress();
        channel.writeAndFlush(request).addListener(new ChannelFutureListener() {
            @Override
            public void operationComplete(ChannelFuture f) throws Exception {
                if (f.isSuccess()) {
                    responseFuture.setSendRequestOK(true);
                    return;
                } else {
                    responseFuture.setSendRequestOK(false);
                }

                responseTable.remove(opaque);
                responseFuture.setCause(f.cause());
                responseFuture.putResponse(null);
                PLOG.warn("send a request command to channel <" + addr + "> failed.");
            }
        });

        RemotingCommand responseCommand = responseFuture.waitResponse(timeoutMillis);
        if (null == responseCommand) {
            if (responseFuture.isSendRequestOK()) {
                throw new RemotingTimeoutException(RemotingHelper.parseSocketAddressAddr(addr), timeoutMillis,
                    responseFuture.getCause());
            } else {
                throw new RemotingSendRequestException(RemotingHelper.parseSocketAddressAddr(addr), responseFuture.getCause());
            }
        }

        return responseCommand;
    } finally {
        this.responseTable.remove(opaque);
    }
}
 
開發者ID:lirenzuo,項目名稱:rocketmq-rocketmq-all-4.1.0-incubating,代碼行數:41,代碼來源:NettyRemotingAbstract.java

示例9: getRemoteIp

import io.netty.channel.Channel; //導入方法依賴的package包/類
public static String getRemoteIp(Channel channel) {
    InetSocketAddress inetSocketAddress = (InetSocketAddress) channel.remoteAddress();
    if (inetSocketAddress == null) {
        return "";
    }
    final InetAddress inetAddr = inetSocketAddress.getAddress();
    return inetAddr != null ? inetAddr.getHostAddress() : inetSocketAddress.getHostName();
}
 
開發者ID:lirenzuo,項目名稱:rocketmq-rocketmq-all-4.1.0-incubating,代碼行數:9,代碼來源:ChannelUtil.java

示例10: setChannel

import io.netty.channel.Channel; //導入方法依賴的package包/類
public void setChannel(Channel channel){
    this.channel = channel;
    super.remoteAddress = channel.remoteAddress();
    super.localAddress = channel.localAddress();
}
 
開發者ID:tiglabs,項目名稱:jsf-sdk,代碼行數:6,代碼來源:JSFClientTransport.java

示例11: invokeSyncImpl

import io.netty.channel.Channel; //導入方法依賴的package包/類
public RemotingCommand invokeSyncImpl(final Channel channel, final RemotingCommand request, final long timeoutMillis)
		throws InterruptedException,RemotingTimeoutException,RemotingSendRequestException{
	final int unique = request.getUnique();
	try{
		final SocketAddress addr = channel.remoteAddress();
		final ResponseFuture responseFuture = new ResponseFuture(unique, timeoutMillis);
		this.responseTable.put(unique, responseFuture);
		channel.writeAndFlush(request).addListener(new ChannelFutureListener() {
			@Override
			public void operationComplete(ChannelFuture future) throws Exception {
				if(future.isSuccess()){
					responseFuture.setSendRequestOK(true);
                       return;
				}
				responseFuture.setSendRequestOK(false);
				responseTable.remove(unique);
                   responseFuture.setCause(future.cause());
                   responseFuture.putResponse(null);
                   log.warn("send a request command to channel <" + addr + "> failed.");
			}
		});
		RemotingCommand respose = responseFuture.waitRespose(timeoutMillis);
		if(null == respose){
			if(responseFuture.isSendRequestOK()){
				throw new RemotingTimeoutException(RemotingHelper.parseSocketAddressAddr(addr), timeoutMillis, responseFuture.getCause());
			}else {
				throw new RemotingSendRequestException(RemotingHelper.parseSocketAddressAddr(addr), responseFuture.getCause());
			}
		}
		return respose;
	}finally{
		responseTable.remove(unique);
	}
}
 
開發者ID:yanghuijava,項目名稱:elephant,代碼行數:35,代碼來源:NettyRemotingAbstract.java

示例12: getRemoteAddress

import io.netty.channel.Channel; //導入方法依賴的package包/類
private String getRemoteAddress(Channel channel){
    InetSocketAddress addr = (InetSocketAddress) channel.remoteAddress();
    return addr.getAddress().getHostAddress();
}
 
開發者ID:ctripcorp,項目名稱:cornerstone,代碼行數:5,代碼來源:VINettyHandler.java

示例13: onHandshake

import io.netty.channel.Channel; //導入方法依賴的package包/類
@EventHandler
public void onHandshake(HandshakeEvent event) {
    Channel channel = event.getChannel();
    PacketHandshake packet = event.getPacket();

    String header = "auth";
    String version = Cloud.getInstance().getVersion();
    InetSocketAddress remoteAddress = (InetSocketAddress) channel.remoteAddress();

    // checks if address is allowed by the whitelist
    if(!Cloud.getInstance().getServer().getWhitelist().allowed(remoteAddress)) {
        packet.respond(new PacketRespond(header, version, ResponseStatus.FORBIDDEN));
        channel.disconnect();
    }

    // checks if the instance name is valid
    if(!Validation.INSTANCE_NAME.matches(packet.identifier)) {
        packet.respond(new PacketRespond(header, version, ResponseStatus.BAD_REQUEST));
        channel.disconnect();
        return;
    }

    // checks if already a daemon from this host connected to the server
    if(packet.type == ClientType.DAEMON && Cloud.getInstance().getClientManager().contains(remoteAddress)) {
        packet.respond(new PacketRespond(header, version, ResponseStatus.FORBIDDEN));
        channel.disconnect();
        return;
    }

    //.
    packet.respond(new PacketRespond(header, version, ResponseStatus.OK));

    // Add client
    MooClient client = new MooClient(packet.identifier,
            remoteAddress.getAddress().getHostAddress(),
            remoteAddress.getPort(), packet.subPort, packet.type, channel);
    client.setId(Cloud.getInstance().getClientManager().add(client));

    // fire event of client connection
    EventExecutor.getInstance().execute(new MooClientConnectedEvent(client));

    Cloud.getInstance().getLogger().debug(ConsoleColor.GREEN.toString()
            + client.getType() + " client connected @(" + remoteAddress.getAddress().getHostAddress() + ")");
}
 
開發者ID:Superioz,項目名稱:MooProject,代碼行數:45,代碼來源:HandshakeListener.java

示例14: invokeSyncImpl

import io.netty.channel.Channel; //導入方法依賴的package包/類
/**
 * 發送消息,同步等待響應
 * @param channel
 * @param request
 * @param timeoutMillis
 * @return
 * @throws InterruptedException
 * @throws RemotingSendRequestException
 * @throws RemotingTimeoutException
 */
public RemotingCommand invokeSyncImpl(final Channel channel, final RemotingCommand request, final long timeoutMillis)
        throws InterruptedException, RemotingSendRequestException, RemotingTimeoutException {
    final int opaque = request.getOpaque();

    try {
        final ResponseFuture responseFuture = new ResponseFuture(opaque, timeoutMillis, null, null);
        this.responseTable.put(opaque, responseFuture);
        final SocketAddress addr = channel.remoteAddress();
        channel.writeAndFlush(request).addListener(new ChannelFutureListener() {
            @Override
            public void operationComplete(ChannelFuture f) throws Exception {
                if (f.isSuccess()) {
                    responseFuture.setSendRequestOK(true);
                    return;
                } else {
                    responseFuture.setSendRequestOK(false);
                }

                responseTable.remove(opaque);
                responseFuture.setCause(f.cause());
                responseFuture.putResponse(null);
                plog.warn("send a request command to channel <" + addr + "> failed.");
            }
        });
        // 阻塞等待響應,直到responseFuture.putResponse方法,或者超時
        RemotingCommand responseCommand = responseFuture.waitResponse(timeoutMillis);
        if (null == responseCommand) {
            if (responseFuture.isSendRequestOK()) {
                throw new RemotingTimeoutException(RemotingHelper.parseSocketAddressAddr(addr), timeoutMillis,
                        responseFuture.getCause());
            } else {
                throw new RemotingSendRequestException(RemotingHelper.parseSocketAddressAddr(addr), responseFuture.getCause());
            }
        }

        return responseCommand;
    } finally {
        this.responseTable.remove(opaque);
    }
}
 
開發者ID:beyondfengyu,項目名稱:ConfigCenter,代碼行數:51,代碼來源:NettyRemotingAbstract.java

示例15: invokeSyncImpl

import io.netty.channel.Channel; //導入方法依賴的package包/類
public RemotingCommand invokeSyncImpl(final Channel channel, final RemotingCommand request, final long timeoutMillis)
    throws InterruptedException, RemotingSendRequestException, RemotingTimeoutException {
    //獲取請求標識,該標識在RemotingCommand 創建時,便經過 int opaque = requestId.getAndIncrement()生成。
    //而RemotingCommand.requestId = new AtomicInteger(0) ,該屬性是屬於RemotingCommand的類屬性,並且getAndIncrement是線程安全的,
    //所以,在RemotingCommand 創建實例變量時,便可以生成一個唯一的opaque標識了。
    final int opaque = request.getOpaque();

    try {
        //rmq使用CountDownLatch實現了同步調用的Future模式
        final ResponseFuture responseFuture = new ResponseFuture(opaque, timeoutMillis, null, null);

        //step 1->responseTable.put
        //放入響應緩存裏,key為opaque,可以以responseFuture一一對應
        this.responseTable.put(opaque, responseFuture);
        final SocketAddress addr = channel.remoteAddress();

        //step 2->channel.writeAndFlush(request),正真發起網絡請求
        //這裏使用了netty 的ChannelFutureListener為了監聽發送結果,這裏使用了閉包的方式實現
        channel.writeAndFlush(request).addListener(new ChannelFutureListener() {
            //step 3-> 注冊發送消息結果,ChannelFuture返回true,則說明發送消息成功了。
            //但任然需要等待響應。注冊該監聽器,是為了避免發送失敗,但客戶端任然在等待,
            //直到超時的情況,否則,如果短時間內被調用方不可用,就會導致大量線程在閑置等待響應結果。
            @Override
            public void operationComplete(ChannelFuture f) throws Exception {
                if (f.isSuccess()) {
                    responseFuture.setSendRequestOK(true);
                    return;
                } else {
                    responseFuture.setSendRequestOK(false);
                }

                responseTable.remove(opaque);
                responseFuture.setCause(f.cause());

                responseFuture.putResponse(null);
                PLOG.warn("send a request command to channel <" + addr + "> failed.");
            }
        });

        //step 4->responseFuture.waitResponse,這裏同步等待遠程調用的響應結果
        RemotingCommand responseCommand = responseFuture.waitResponse(timeoutMillis);
        if (null == responseCommand) {
            if (responseFuture.isSendRequestOK()) {
                throw new RemotingTimeoutException(RemotingHelper.parseSocketAddressAddr(addr), timeoutMillis,
                    responseFuture.getCause());
            } else {
                throw new RemotingSendRequestException(RemotingHelper.parseSocketAddressAddr(addr), responseFuture.getCause());
            }
        }
        return responseCommand;
    } finally {
        //這裏是為了處理等待超時,我們任然需要移除該次請求。
        this.responseTable.remove(opaque);
    }
}
 
開發者ID:lyy4j,項目名稱:rmq4note,代碼行數:56,代碼來源:NettyRemotingAbstract.java


注:本文中的io.netty.channel.Channel.remoteAddress方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。