/** */ public void scanNotActiveChannel() { Iterator<Entry<Channel, FilterServerInfo>> it = this.filterServerTable.entrySet().iterator(); while (it.hasNext()) { Entry<Channel, FilterServerInfo> next = it.next(); long timestamp = next.getValue().getLastUpdateTimestamp(); Channel channel = next.getKey(); if ((System.currentTimeMillis() - timestamp) > FilterServerMaxIdleTimeMills) { log.info("The Filter Server<{}> expired, remove it", next.getKey()); it.remove(); RemotingUtil.closeChannel(channel); } } }
private boolean connectMaster() throws ClosedChannelException { if (null == socketChannel) { String addr = this.masterAddress.get(); if (addr != null) { SocketAddress socketAddress = RemotingUtil.string2SocketAddress(addr); if (socketAddress != null) { this.socketChannel = RemotingUtil.connect(socketAddress); if (this.socketChannel != null) { this.socketChannel.register(this.selector, SelectionKey.OP_READ); } } } this.currentReportedOffset = HAService.this.defaultMessageStore.getMaxPhyOffset(); this.lastWriteTimestamp = System.currentTimeMillis(); } return this.socketChannel != null; }
public static Selector openSelector() throws IOException { Selector result = null; if (isLinuxPlatform()) { try { final Class<?> providerClazz = Class.forName("sun.nio.ch.EPollSelectorProvider"); if (providerClazz != null) { try { final Method method = providerClazz.getMethod("provider"); if (method != null) { final SelectorProvider selectorProvider = (SelectorProvider) method.invoke(null); if (selectorProvider != null) { result = selectorProvider.openSelector(); } } } catch (final Exception e) { log.warn("Open ePoll Selector for linux platform exception", e); } } } catch (final Exception e) { // ignore } } if (result == null) { result = Selector.open(); } return result; }
if (!address.isLoopbackAddress()) { if (address instanceof Inet6Address) { ipv6Result.add(normalizeHostAddress(address)); } else { ipv4Result.add(normalizeHostAddress(address)); if (ip.startsWith("127.0") || isInnerIP(ip) ) { continue; return normalizeHostAddress(localHost); } catch (SocketException e) { log.error("getLocalAddress() error ." , e);
if (addrArray != null) { for (String addr : addrArray) { RemotingUtil.string2SocketAddress(addr);
public static SocketChannel connect(SocketAddress remote) { return connect(remote, 1000 * 5); }
@Override public ConsumeMessageDirectlyResult consumeMessageDirectly(String consumerGroup, String clientId, String msgId) throws RemotingException, MQClientException, InterruptedException, MQBrokerException { MessageExt msg = this.viewMessage(msgId); return this.mqClientInstance.getMQClientAPIImpl().consumeMessageDirectly(RemotingUtil.socketAddress2String(msg.getStoreHost()), consumerGroup, clientId, msgId, timeoutMillis * 3); }
if (!address.isLoopbackAddress()) { if (address instanceof Inet6Address) { ipv6Result.add(normalizeHostAddress(address)); } else { ipv4Result.add(normalizeHostAddress(address)); return normalizeHostAddress(localHost); } catch (SocketException e) { e.printStackTrace();
public static boolean isInnerIP(String ip){ long n = getIpNum(ip); return (n >= b1 && n <= b2) || (n >= c1 && n <= c2) || (n >= a1 && n <= a2); }
if (addrArray != null) { for (String addr : addrArray) { RemotingUtil.string2SocketAddress(addr);
public static SocketChannel connect(SocketAddress remote) { return connect(remote, 1000 * 5); }
public boolean consumed(final MessageExt msg, final String group) throws RemotingException, MQClientException, InterruptedException, MQBrokerException { ConsumeStats cstats = this.examineConsumeStats(group); ClusterInfo ci = this.examineBrokerClusterInfo(); Iterator<Entry<MessageQueue, OffsetWrapper>> it = cstats.getOffsetTable().entrySet().iterator(); while (it.hasNext()) { Entry<MessageQueue, OffsetWrapper> next = it.next(); MessageQueue mq = next.getKey(); if (mq.getTopic().equals(msg.getTopic()) && mq.getQueueId() == msg.getQueueId()) { BrokerData brokerData = ci.getBrokerAddrTable().get(mq.getBrokerName()); if (brokerData != null) { String addr = brokerData.getBrokerAddrs().get(MixAll.MASTER_ID); if (addr.equals(RemotingUtil.socketAddress2String(msg.getStoreHost()))) { if (next.getValue().getConsumerOffset() > msg.getQueueOffset()) { return true; } } } } } return false; }
if (!address.isLoopbackAddress()) { if (address instanceof Inet6Address) { ipv6Result.add(normalizeHostAddress(address)); } else { ipv4Result.add(normalizeHostAddress(address)); return normalizeHostAddress(localHost); } catch (SocketException e) { e.printStackTrace();
/** * Filter Server 10s向Broker注册一次,Broker如果发现30s没有注册,则删除它 */ public void scanNotActiveChannel() { // 单位毫秒 Iterator<Entry<Channel, FilterServerInfo>> it = this.filterServerTable.entrySet().iterator(); while (it.hasNext()) { Entry<Channel, FilterServerInfo> next = it.next(); long timestamp = next.getValue().getLastUpdateTimestamp(); Channel channel = next.getKey(); if ((System.currentTimeMillis() - timestamp) > FilterServerMaxIdleTimeMills) { log.info("The Filter Server<{}> expired, remove it", next.getKey()); it.remove(); RemotingUtil.closeChannel(channel); } } }
RemotingSendRequestException, RemotingTimeoutException { long beginTime = System.currentTimeMillis(); SocketAddress socketAddress = RemotingUtil.string2SocketAddress(addr); SocketChannel socketChannel = RemotingUtil.connect(socketAddress); if (socketChannel != null) { boolean sendRequestOK = false;
private void generateOffsetMovedEvent(final OffsetMovedEvent event) { try { MessageExtBrokerInner msgInner = new MessageExtBrokerInner(); msgInner.setTopic(MixAll.OFFSET_MOVED_EVENT); msgInner.setTags(event.getConsumerGroup()); msgInner.setDelayTimeLevel(0); msgInner.setKeys(event.getConsumerGroup()); msgInner.setBody(event.encode()); msgInner.setFlag(0); msgInner.setPropertiesString(MessageDecoder.messageProperties2String(msgInner.getProperties())); msgInner.setTagsCode(MessageExtBrokerInner.tagsString2tagsCode(TopicFilterType.SINGLE_TAG, msgInner.getTags())); msgInner.setQueueId(0); msgInner.setSysFlag(0); msgInner.setBornTimestamp(System.currentTimeMillis()); msgInner.setBornHost(RemotingUtil.string2SocketAddress(this.brokerController.getBrokerAddr())); msgInner.setStoreHost(msgInner.getBornHost()); msgInner.setReconsumeTimes(0); PutMessageResult putMessageResult = this.brokerController.getMessageStore().putMessage(msgInner); } catch (Exception e) { log.warn(String.format("generateOffsetMovedEvent Exception, %s", event.toString()), e); } }
public static SocketChannel connect(SocketAddress remote) { return connect(remote, 1000 * 5); }
public static Selector openSelector() throws IOException { Selector result = null; if (isLinuxPlatform()) { try { final Class<?> providerClazz = Class.forName("sun.nio.ch.EPollSelectorProvider"); if (providerClazz != null) { try { final Method method = providerClazz.getMethod("provider"); if (method != null) { final SelectorProvider selectorProvider = (SelectorProvider) method.invoke(null); if (selectorProvider != null) { result = selectorProvider.openSelector(); } } } catch (final Exception e) { log.warn("Open ePoll Selector for linux platform exception", e); } } } catch (final Exception e) { // ignore } } if (result == null) { result = Selector.open(); } return result; }
@Override public ConsumeMessageDirectlyResult consumeMessageDirectly(final String consumerGroup, final String clientId, final String topic, final String msgId) throws RemotingException, MQClientException, InterruptedException, MQBrokerException { MessageExt msg = this.viewMessage(topic, msgId); if (msg.getProperty(MessageConst.PROPERTY_UNIQ_CLIENT_MESSAGE_ID_KEYIDX) == null) { return this.mqClientInstance.getMQClientAPIImpl().consumeMessageDirectly(RemotingUtil.socketAddress2String(msg.getStoreHost()), consumerGroup, clientId, msgId, timeoutMillis * 3); } else { MessageClientExt msgClient = (MessageClientExt) msg; return this.mqClientInstance.getMQClientAPIImpl().consumeMessageDirectly(RemotingUtil.socketAddress2String(msg.getStoreHost()), consumerGroup, clientId, msgClient.getOffsetMsgId(), timeoutMillis * 3); } }
@Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { final String remoteAddress = RemotingHelper.parseChannelRemoteAddr(ctx.channel()); log.warn("NETTY SERVER PIPELINE: exceptionCaught {}", remoteAddress); log.warn("NETTY SERVER PIPELINE: exceptionCaught exception.", cause); if (NettyRemotingServer.this.channelEventListener != null) { NettyRemotingServer.this.putNettyEvent(new NettyEvent(NettyEventType.EXCEPTION, remoteAddress.toString(), ctx.channel())); } RemotingUtil.closeChannel(ctx.channel()); } }