Skip to content

Instantly share code, notes, and snippets.

@ttfcfc
ttfcfc / FileToJvm.java
Created January 12, 2017 03:47 — forked from yangl/FileToJvm.java
将远程配置中心配置通过Dubbo RPC远程调用保存至本地客户端JVM,这是之前做服务治理时的部分代码;
package com.jd.market.servicemanagement.token.collect;
import java.io.File;
import java.util.Calendar;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.base.Strings;
import com.google.common.io.Files;
@ttfcfc
ttfcfc / NearestLoadBalance.java
Created January 12, 2017 03:45 — forked from yangl/NearestLoadBalance.java
最近路径负载均衡,多线程任务ping各个注册中心,获取速度
package com.jd.registry.failover;
import java.net.InetAddress;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.concurrent.*;
import com.jd.registry.Registry;
@ttfcfc
ttfcfc / NamedThreadFactory.java
Created January 12, 2017 03:45 — forked from yangl/NamedThreadFactory.java
带前缀命名的线程工厂,来自dubbo。
package com.alibaba.rocketmq.common;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicInteger;
/**
* 带前缀命名的线程工厂
*
* @author YAGNLiiN<[email protected]>
* @since 2013-05-23
@ttfcfc
ttfcfc / Java monitor
Created January 12, 2017 03:45 — forked from yangl/Java monitor
Java性能监控开源方案
<!-- 1.将如下内容加入pom.xml -->
<javasimon.version>3.5.0</javasimon.version>
<sirona.version>0.2-incubating</sirona.version>
<!-- Monitor begin -->
<!-- javasimon -->
<!-- Core JAR is absolutely necessary to use Simons (Stopwatch, etc.) -->
1.cd $NGINX_HOME,执行./sbin/nginx -V 查看安装参数;
2.得到安装参数后,添加nginx-sticky-module模块重新编译nginx,
./configure "之前的参数" --add-module=/nginx-sticky-module下载所在目录/nginx-sticky-module
make && make install
3.在upsteam中添加如下:
sticky name=srv_id expires=1h domain=uxin.com path=/;
@ttfcfc
ttfcfc / nginx手机端跳转配置.conf
Created January 12, 2017 03:42 — forked from yangl/nginx手机端跳转配置.conf
nginx根据user-agent手机端跳转,nginx rewrite详见:http://seanlook.com/2015/05/17/nginx-location-rewrite/
location = / {
if ($http_user_agent ~* "(Android|iPhone|iPod|Symbian|BlackBerry|Windows Phone|Mobile|J2ME)") {
rewrite ^ http://m.uxin.com permanent;
}
#htpasswd密码生成可用在线工具http://tool.oschina.net/htpasswd,加密方式选Crypt
auth_basic_user_file /data/soft/nginx/conf/htpasswd;
auth_basic "please input passwd, or contact YANGL";
@ttfcfc
ttfcfc / GuavaCache及@Value使用例子.java
Created January 12, 2017 03:41 — forked from yangl/GuavaCache及@Value使用例子.java
guava cache使用例子。。。注意在查询数据库时没有记录的情况,暂时获取CacheLoader.InvalidCacheLoadException异常,或者存放默认数据并标示NoDATA!@value注入static属性时注意要加到其非静态setter方法上即可!
package com.uxin.starclock.manage.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.uxin.starclock.common.Constant;
import com.uxin.starclock.common.exception.BaseException;
import com.uxin.starclock.dto.IncallringDto;
@ttfcfc
ttfcfc / RandomStringUtils.txt
Created January 12, 2017 03:40 — forked from yangl/RandomStringUtils.txt
用16位数字字母随机生成字符串,直接使用org.apache.commons.lang3.RandomStringUtils即可
RandomStringUtils.random(16, "1234567890qwertyuioplkjhgfdsazxcvbnm")
@ttfcfc
ttfcfc / Phones2.java
Created January 12, 2017 03:39 — forked from yangl/Phones2.java
根据ipip.net提供的手机号码归属地生成客户端本地数据文件,供通讯录快速匹配数据,原来数据14.2M压缩后436k
package com.uxin.feerate.util;
import com.google.common.base.Charsets;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.google.common.io.Files;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
@ttfcfc
ttfcfc / MultiTokenFilter.java
Created January 12, 2017 03:15 — forked from yangl/MultiTokenFilter.java
Dubbo多token拦截器实现, 为每个调用方配置一个token,方便统计每个调用方的调用次等数据及服务降级处理;
package com.jd.market.servicemanagement.token;
import java.lang.reflect.Method;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.alibaba.dubbo.common.extension.Activate;
import com.alibaba.dubbo.rpc.*;