Java Code Examples for com.alibaba.rocketmq.common.MixAll#DEFAULT_CHARSET
The following examples show how to use
com.alibaba.rocketmq.common.MixAll#DEFAULT_CHARSET .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FilterClassManager.java From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 | 5 votes |
private void fetchClassFromRemoteHost() { Iterator<Entry<String, FilterClassInfo>> it = this.filterClassTable.entrySet().iterator(); while (it.hasNext()) { try { Entry<String, FilterClassInfo> next = it.next(); FilterClassInfo filterClassInfo = next.getValue(); String[] topicAndGroup = next.getKey().split("@"); String responseStr = this.filterClassFetchMethod.fetch(topicAndGroup[0], topicAndGroup[1], filterClassInfo.getClassName()); byte[] filterSourceBinary = responseStr.getBytes("UTF-8"); int classCRC = UtilAll.crc32(responseStr.getBytes("UTF-8")); if (classCRC != filterClassInfo.getClassCRC()) { String javaSource = new String(filterSourceBinary, MixAll.DEFAULT_CHARSET); Class<?> newClass = DynaCode.compileAndLoadClass(filterClassInfo.getClassName(), javaSource); Object newInstance = newClass.newInstance(); filterClassInfo.setMessageFilter((MessageFilter) newInstance); filterClassInfo.setClassCRC(classCRC); log.info("fetch Remote class File OK, {} {}", next.getKey(), filterClassInfo.getClassName()); } } catch (Exception e) { log.error("fetchClassFromRemoteHost Exception", e); } } }
Example 2
Source File: AdminBrokerProcessor.java From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 | 5 votes |
private RemotingCommand updateBrokerConfig(ChannelHandlerContext ctx, RemotingCommand request) { final RemotingCommand response = RemotingCommand.createResponseCommand(null); log.info("updateBrokerConfig called by {}", RemotingHelper.parseChannelRemoteAddr(ctx.channel())); byte[] body = request.getBody(); if (body != null) { try { String bodyStr = new String(body, MixAll.DEFAULT_CHARSET); Properties properties = MixAll.string2Properties(bodyStr); if (properties != null) { log.info("updateBrokerConfig, new config: " + properties + " client: " + ctx.channel().remoteAddress()); this.brokerController.updateAllConfig(properties); if (properties.containsKey("brokerPermission")) { this.brokerController.registerBrokerAll(false, false); this.brokerController.getTopicConfigManager().getDataVersion().nextVersion(); } } else { log.error("string2Properties error"); response.setCode(ResponseCode.SYSTEM_ERROR); response.setRemark("string2Properties error"); return response; } } catch (UnsupportedEncodingException e) { log.error("", e); response.setCode(ResponseCode.SYSTEM_ERROR); response.setRemark("UnsupportedEncodingException " + e); return response; } } response.setCode(ResponseCode.SUCCESS); response.setRemark(null); return response; }
Example 3
Source File: FilterClassManager.java From rocketmq with Apache License 2.0 | 5 votes |
private void fetchClassFromRemoteHost() { Iterator<Entry<String, FilterClassInfo>> it = this.filterClassTable.entrySet().iterator(); while (it.hasNext()) { try { Entry<String, FilterClassInfo> next = it.next(); FilterClassInfo filterClassInfo = next.getValue(); String[] topicAndGroup = next.getKey().split("@"); String responseStr = this.filterClassFetchMethod.fetch(topicAndGroup[0], topicAndGroup[1], filterClassInfo.getClassName()); byte[] filterSourceBinary = responseStr.getBytes("UTF-8"); int classCRC = UtilAll.crc32(responseStr.getBytes("UTF-8")); if (classCRC != filterClassInfo.getClassCRC()) { String javaSource = new String(filterSourceBinary, MixAll.DEFAULT_CHARSET); Class<?> newClass = DynaCode.compileAndLoadClass(filterClassInfo.getClassName(), javaSource); Object newInstance = newClass.newInstance(); filterClassInfo.setMessageFilter((MessageFilter) newInstance); filterClassInfo.setClassCRC(classCRC); log.info("fetch Remote class File OK, {} {}", next.getKey(), filterClassInfo.getClassName()); } } catch (Exception e) { log.error("fetchClassFromRemoteHost Exception", e); } } }
Example 4
Source File: AdminBrokerProcessor.java From rocketmq with Apache License 2.0 | 5 votes |
private RemotingCommand updateBrokerConfig(ChannelHandlerContext ctx, RemotingCommand request) { final RemotingCommand response = RemotingCommand.createResponseCommand(null); log.info("updateBrokerConfig called by {}", RemotingHelper.parseChannelRemoteAddr(ctx.channel())); byte[] body = request.getBody(); if (body != null) { try { String bodyStr = new String(body, MixAll.DEFAULT_CHARSET); Properties properties = MixAll.string2Properties(bodyStr); if (properties != null) { log.info("updateBrokerConfig, new config: " + properties + " client: " + ctx.channel().remoteAddress()); this.brokerController.updateAllConfig(properties); if (properties.containsKey("brokerPermission")) { this.brokerController.registerBrokerAll(false, false); this.brokerController.getTopicConfigManager().getDataVersion().nextVersion(); } } else { log.error("string2Properties error"); response.setCode(ResponseCode.SYSTEM_ERROR); response.setRemark("string2Properties error"); return response; } } catch (UnsupportedEncodingException e) { log.error("", e); response.setCode(ResponseCode.SYSTEM_ERROR); response.setRemark("UnsupportedEncodingException " + e); return response; } } response.setCode(ResponseCode.SUCCESS); response.setRemark(null); return response; }
Example 5
Source File: FilterClassManager.java From RocketMQ-Master-analyze with Apache License 2.0 | 5 votes |
private void fetchClassFromRemoteHost() { Iterator<Entry<String, FilterClassInfo>> it = this.filterClassTable.entrySet().iterator(); while (it.hasNext()) { try { Entry<String, FilterClassInfo> next = it.next(); FilterClassInfo filterClassInfo = next.getValue(); String[] topicAndGroup = next.getKey().split("@"); String responseStr = this.filterClassFetchMethod.fetch(topicAndGroup[0], topicAndGroup[1], filterClassInfo.getClassName()); byte[] filterSourceBinary = responseStr.getBytes("UTF-8"); int classCRC = UtilAll.crc32(responseStr.getBytes("UTF-8")); if (classCRC != filterClassInfo.getClassCRC()) { String javaSource = new String(filterSourceBinary, MixAll.DEFAULT_CHARSET); Class<?> newClass = DynaCode.compileAndLoadClass(filterClassInfo.getClassName(), javaSource); Object newInstance = newClass.newInstance(); filterClassInfo.setMessageFilter((MessageFilter) newInstance); filterClassInfo.setClassCRC(classCRC); log.info("fetch Remote class File OK, {} {}", next.getKey(), filterClassInfo.getClassName()); } } catch (Exception e) { log.error("fetchClassFromRemoteHost Exception", e); } } }
Example 6
Source File: AdminBrokerProcessor.java From RocketMQ-Master-analyze with Apache License 2.0 | 5 votes |
private RemotingCommand updateBrokerConfig(ChannelHandlerContext ctx, RemotingCommand request) { final RemotingCommand response = RemotingCommand.createResponseCommand(null); log.info("updateBrokerConfig called by {}", RemotingHelper.parseChannelRemoteAddr(ctx.channel())); byte[] body = request.getBody(); if (body != null) { try { String bodyStr = new String(body, MixAll.DEFAULT_CHARSET); Properties properties = MixAll.string2Properties(bodyStr); if (properties != null) { log.info("updateBrokerConfig, new config: " + properties + " client: " + ctx.channel().remoteAddress()); this.brokerController.updateAllConfig(properties); } else { log.error("string2Properties error"); response.setCode(ResponseCode.SYSTEM_ERROR); response.setRemark("string2Properties error"); return response; } } catch (UnsupportedEncodingException e) { log.error("", e); response.setCode(ResponseCode.SYSTEM_ERROR); response.setRemark("UnsupportedEncodingException " + e); return response; } } response.setCode(ResponseCode.SUCCESS); response.setRemark(null); return response; }
Example 7
Source File: FilterClassManager.java From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 | 4 votes |
public boolean registerFilterClass(final String consumerGroup, final String topic, final String className, final int classCRC, final byte[] filterSourceBinary) { final String key = buildKey(consumerGroup, topic); boolean registerNew = false; FilterClassInfo filterClassInfoPrev = this.filterClassTable.get(key); if (null == filterClassInfoPrev) { registerNew = true; } else { if (this.filtersrvController.getFiltersrvConfig().isClientUploadFilterClassEnable()) { if (filterClassInfoPrev.getClassCRC() != classCRC && classCRC != 0) { registerNew = true; } } } if (registerNew) { synchronized (this.compileLock) { filterClassInfoPrev = this.filterClassTable.get(key); if (null != filterClassInfoPrev && filterClassInfoPrev.getClassCRC() == classCRC) { return true; } try { FilterClassInfo filterClassInfoNew = new FilterClassInfo(); filterClassInfoNew.setClassName(className); filterClassInfoNew.setClassCRC(0); filterClassInfoNew.setMessageFilter(null); if (this.filtersrvController.getFiltersrvConfig().isClientUploadFilterClassEnable()) { String javaSource = new String(filterSourceBinary, MixAll.DEFAULT_CHARSET); Class<?> newClass = DynaCode.compileAndLoadClass(className, javaSource); Object newInstance = newClass.newInstance(); filterClassInfoNew.setMessageFilter((MessageFilter) newInstance); filterClassInfoNew.setClassCRC(classCRC); } this.filterClassTable.put(key, filterClassInfoNew); } catch (Throwable e) { String info = String .format( "FilterServer, registerFilterClass Exception, consumerGroup: %s topic: %s className: %s", consumerGroup, topic, className); log.error(info, e); return false; } } } return true; }
Example 8
Source File: FilterClassManager.java From rocketmq with Apache License 2.0 | 4 votes |
public boolean registerFilterClass(final String consumerGroup, final String topic, final String className, final int classCRC, final byte[] filterSourceBinary) { final String key = buildKey(consumerGroup, topic); boolean registerNew = false; FilterClassInfo filterClassInfoPrev = this.filterClassTable.get(key); if (null == filterClassInfoPrev) { registerNew = true; } else { if (this.filtersrvController.getFiltersrvConfig().isClientUploadFilterClassEnable()) { if (filterClassInfoPrev.getClassCRC() != classCRC && classCRC != 0) { registerNew = true; } } } if (registerNew) { synchronized (this.compileLock) { filterClassInfoPrev = this.filterClassTable.get(key); if (null != filterClassInfoPrev && filterClassInfoPrev.getClassCRC() == classCRC) { return true; } try { FilterClassInfo filterClassInfoNew = new FilterClassInfo(); filterClassInfoNew.setClassName(className); filterClassInfoNew.setClassCRC(0); filterClassInfoNew.setMessageFilter(null); if (this.filtersrvController.getFiltersrvConfig().isClientUploadFilterClassEnable()) { String javaSource = new String(filterSourceBinary, MixAll.DEFAULT_CHARSET); Class<?> newClass = DynaCode.compileAndLoadClass(className, javaSource); Object newInstance = newClass.newInstance(); filterClassInfoNew.setMessageFilter((MessageFilter) newInstance); filterClassInfoNew.setClassCRC(classCRC); } this.filterClassTable.put(key, filterClassInfoNew); } catch (Throwable e) { String info = String .format( "FilterServer, registerFilterClass Exception, consumerGroup: %s topic: %s className: %s", consumerGroup, topic, className); log.error(info, e); return false; } } } return true; }
Example 9
Source File: FilterClassManager.java From RocketMQ-Master-analyze with Apache License 2.0 | 4 votes |
public boolean registerFilterClass(final String consumerGroup, final String topic, final String className, final int classCRC, final byte[] filterSourceBinary) { final String key = buildKey(consumerGroup, topic); // 先检查是否存在,是否CRC相同 boolean registerNew = false; FilterClassInfo filterClassInfoPrev = this.filterClassTable.get(key); if (null == filterClassInfoPrev) { registerNew = true; } else { if (this.filtersrvController.getFiltersrvConfig().isClientUploadFilterClassEnable()) { if (filterClassInfoPrev.getClassCRC() != classCRC && classCRC != 0) { registerNew = true; } } } // 注册新的Class if (registerNew) { synchronized (this.compileLock) { filterClassInfoPrev = this.filterClassTable.get(key); if (null != filterClassInfoPrev && filterClassInfoPrev.getClassCRC() == classCRC) { return true; } try { FilterClassInfo filterClassInfoNew = new FilterClassInfo(); filterClassInfoNew.setClassName(className); filterClassInfoNew.setClassCRC(0); filterClassInfoNew.setMessageFilter(null); if (this.filtersrvController.getFiltersrvConfig().isClientUploadFilterClassEnable()) { String javaSource = new String(filterSourceBinary, MixAll.DEFAULT_CHARSET); Class<?> newClass = DynaCode.compileAndLoadClass(className, javaSource); Object newInstance = newClass.newInstance(); filterClassInfoNew.setMessageFilter((MessageFilter) newInstance); filterClassInfoNew.setClassCRC(classCRC); } this.filterClassTable.put(key, filterClassInfoNew); } catch (Throwable e) { String info = String.format( "FilterServer, registerFilterClass Exception, consumerGroup: %s topic: %s className: %s", consumerGroup, topic, className); log.error(info, e); return false; } } } return true; }