本文整理汇总了Java中net.rubyeye.xmemcached.utils.AddrUtil.getAddresses方法的典型用法代码示例。如果您正苦于以下问题:Java AddrUtil.getAddresses方法的具体用法?Java AddrUtil.getAddresses怎么用?Java AddrUtil.getAddresses使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.rubyeye.xmemcached.utils.AddrUtil
的用法示例。
在下文中一共展示了AddrUtil.getAddresses方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doGet
import net.rubyeye.xmemcached.utils.AddrUtil; //导入方法依赖的package包/类
@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException,
ServletException {
String addr =
System.getenv().containsKey("GAE_MEMCACHE_HOST")
? System.getenv("GAE_MEMCACHE_HOST") : "localhost";
String port =
System.getenv().containsKey("GAE_MEMCACHE_HOST")
? System.getenv("GAE_MEMCACHE_PORT") : "11211";
String key = "count";
MemcachedClientBuilder builder = new XMemcachedClientBuilder(
AddrUtil.getAddresses(addr + ":" + port));
MemcachedClient client = builder.build();
long count = 0L;
try {
count = client.incr(key, 1L, 0L);
} catch (TimeoutException | InterruptedException | MemcachedException e) {
throw new ServletException("Memcache error", e);
}
resp.setContentType("text/plain");
resp.getWriter().print("Value is " + count + "\n");
}
示例2: setUp
import net.rubyeye.xmemcached.utils.AddrUtil; //导入方法依赖的package包/类
protected void setUp() throws Exception {
Config.setSetting("port", "12001");
Config.setSetting("path", "dbtest");
Config.setSetting("logsize", "40");
Config.setSetting("authorization", "key|[email protected]@bbs|pass");
StartNewQueue.newQueueInstance(Integer.parseInt(Config.getSetting("port")));
log.info("running at port " + Config.getSetting("port"));
builder = new XMemcachedClientBuilder(AddrUtil.getAddresses("127.0.0.1:12001"));
builder.setConnectionPoolSize(50); // set connection pool size to five
try {
client = builder.build();
client.setOptimizeGet(false);
builder.setSocketOption(StandardSocketOption.SO_KEEPALIVE, true);
builder.setSocketOption(StandardSocketOption.SO_RCVBUF, 64 * 1024);
builder.setSocketOption(StandardSocketOption.SO_SNDBUF, 64 * 1024);
builder.setSocketOption(StandardSocketOption.SO_REUSEADDR, true);
builder.setSocketOption(StandardSocketOption.TCP_NODELAY, false);
} catch (IOException e) {
throw new RuntimeException(e);
}
client.get("clear|key|abc");
}
示例3: create
import net.rubyeye.xmemcached.utils.AddrUtil; //导入方法依赖的package包/类
/**
* Create a memcached client with params.
*
* @param hosts whitespace separated host or IP addresses and port numbers
* of the form "host:port host2:port hostN:portN"
* @param protocol opcional, BINARY or TEXT
* @param user opcional, user name o null
* @param pass opcional, password o null
* @param authMechanisms opcional, CRAM-MD5 and/or PLAIN
* @return memcached client
*/
public static MemcachedClient create(
String hosts,
CommandFactory protocol,
String user,
String pass,
String[] authMechanisms) {
MemcachedClient client = null;
try {
MemcachedClientBuilder builder = new XMemcachedClientBuilder(AddrUtil.getAddresses(hosts));
builder.setCommandFactory(protocol);
if (isNotNullOrEmpty(user)) {
builder.addAuthInfo(
AddrUtil.getAddresses(hosts).get(0),
new AuthInfo(
new PlainCallbackHandler(user, pass),
authMechanisms));
}
client = builder.build();
} catch (IOException ex) {
log.error("An error occurred when creating the MemcachedClient.", ex);
throw new PippoRuntimeException(ex);
}
return client;
}
示例4: initPool
import net.rubyeye.xmemcached.utils.AddrUtil; //导入方法依赖的package包/类
/**
* 分布策略为一致性哈希
*/
private void initPool(){
StringBuffer memcachedAddr = new StringBuffer();
for(String addr : addresses){
memcachedAddr.append(addr).append(" ");
}
socketAddress = AddrUtil.getAddresses (memcachedAddr.toString().trim());
builder = new XMemcachedClientBuilder(socketAddress);
builder.setConnectionPoolSize(poolConfig.getMaxTotal());
builder.setConnectTimeout(poolConfig.getMaxConnectMillis());
builder.setFailureMode(poolConfig.getFailureMode());
builder.setOpTimeout(poolConfig.getMaxWaitMillis());
builder.setEnableHealSession(poolConfig.getEnableHealSession());
builder.setHealSessionInterval(poolConfig.getHealSessionInterval());
/**
* 分布策略
* 默认分布的策略是按照key的哈希值模以连接数得到的余数
* KetamaMemcachedSessionLocator:一致性哈希(consistent hash)
* ElectionMemcachedSessionLocator:选举散列哈希算法
*/
builder.setSessionLocator(new KetamaMemcachedSessionLocator());
}
示例5: MemcachedService
import net.rubyeye.xmemcached.utils.AddrUtil; //导入方法依赖的package包/类
public MemcachedService() {
MemcachedClientBuilder
builder =
new XMemcachedClientBuilder(
AddrUtil.getAddresses(ConfigUtil.get("memcached.url", "localhost:11211")));
// builder.setConnectionPoolSize(5);
try {
memcachedClient = builder.build();
} catch (IOException e) {
LOGGER.severe("Couldn't initialize memcached client", e);
}
expiry = ConfigUtil.getInt("cache.expiry", 84400);
}
示例6: simpleClient
import net.rubyeye.xmemcached.utils.AddrUtil; //导入方法依赖的package包/类
private static MemcachedClient simpleClient() {
// AuthDescriptor ad = AuthDescriptor.typical("coca", "coca");
MemcachedClient mc = null;
try {
// mc = new MemcachedClient(new
// ConnectionFactoryBuilder().setProtocol(ConnectionFactoryBuilder.Protocol.BINARY).build(),
// AddrUtil.getAddresses("localhost:11211"));
MemcachedClientBuilder builder = new XMemcachedClientBuilder(AddrUtil.getAddresses("localhost:11211"));
mc = builder.build();
} catch (IOException e) {
LOG.error(e.getMessage(), e);
}
return mc;
}
示例7: createJedis
import net.rubyeye.xmemcached.utils.AddrUtil; //导入方法依赖的package包/类
public static MemcachedClient createJedis(String hostport) throws IOException {
MemcachedClientBuilder builder = new XMemcachedClientBuilder(
AddrUtil.getAddresses(hostport));
MemcachedClient memcachedClient = null;
try {
memcachedClient = builder.build();
} catch (IOException e) {
throw e;
}
return memcachedClient;
}
示例8: init
import net.rubyeye.xmemcached.utils.AddrUtil; //导入方法依赖的package包/类
@Override
public synchronized void init(Properties properties) throws IOException {
LOG.debug("init: KestrelClient initializing...");
this.initProperties = properties;
int connectionPoolSize = 1;
try {
connectionPoolSize = Integer.parseInt(properties.getProperty(PROP_KESTREL_CONNECTIONS));
} catch (Exception e) {
LOG.warn(PROP_KESTREL_CONNECTIONS+" undefined, using default of "+connectionPoolSize);
}
final List<InetSocketAddress> memcachedHosts = getMemcachedHosts(properties.getProperty(PROP_KESTREL_HOSTS));
final String hosts = properties.getProperty(PROP_KESTREL_HOSTS);
final MemcachedClientBuilder builder = new XMemcachedClientBuilder(AddrUtil.getAddresses(hosts));
builder.setCommandFactory(new KestrelCommandFactory());
builder.setConnectionPoolSize(connectionPoolSize);
client = builder.build();
client.setPrimitiveAsString(true);
final String reconnectIntervalString = properties.getProperty(PROP_RECONNECT_INTERVAL_IN_MINUTES);
if (reconnectIntervalString != null) {
reconnectIntervalMillis = 60 * 1000 * Long.parseLong(reconnectIntervalString);
}
lastConnect = System.currentTimeMillis();
LOG.info("init: KestrelClient fully initialized with hosts="+memcachedHosts+", reconnecting every "+(reconnectIntervalMillis/1000/60)+" minutes");
}
示例9: initMemcacheClient
import net.rubyeye.xmemcached.utils.AddrUtil; //导入方法依赖的package包/类
/**
* 自己构建memcache客户端
*
* @return
* @throws IOException
*/
private static MemcachedClient initMemcacheClient() throws IOException {
// 构建client端的链接
MemcachedClientBuilder builder = new XMemcachedClientBuilder(
AddrUtil.getAddresses(ParaConstant.memcacheServerURI + ":"
+ ParaConstant.memcacheServerPort));
MemcachedClient memcachedClient = builder.build();
return memcachedClient;
}
示例10: addServer
import net.rubyeye.xmemcached.utils.AddrUtil; //导入方法依赖的package包/类
@Test
public void addServer(){
MemcachedClientBuilder builder = new XMemcachedClientBuilder(
AddrUtil.getAddresses("localhost:11111"));
try {
MemcachedClient memcachedClient = builder.build();
memcachedClient.addServer("localhost:11211");
} catch (Exception e) {
System.err.println("MemcachedClient operation fail");
e.printStackTrace();
}
}
示例11: init
import net.rubyeye.xmemcached.utils.AddrUtil; //导入方法依赖的package包/类
public void init() throws IOException {
if(c!=null) stop();
MemcachedClientBuilder builder = new XMemcachedClientBuilder(
AddrUtil.getAddresses(hostList));
if(binaryConnection) {
builder.setCommandFactory(new BinaryCommandFactory());
}
builder.setConnectionPoolSize(poolSize);
c = builder.build();
}
示例12: testSetAddresses
import net.rubyeye.xmemcached.utils.AddrUtil; //导入方法依赖的package包/类
@Test
public void testSetAddresses() throws Exception {
List<InetSocketAddress> addresses = AddrUtil.getAddresses("a:123 b:321 c:919");
memcacheCacheServiceFactoryReal.setAddresses(addresses);
Assert.assertEquals(memcacheCacheServiceFactoryReal.getAddresses(), addresses);
}
示例13: MemcachedSource
import net.rubyeye.xmemcached.utils.AddrUtil; //导入方法依赖的package包/类
public MemcachedSource(ConfigMap<String, Object> dsCfg) {
String name = dsCfg.getString("name", "default-memcached");
String server = dsCfg.getString("server", "127.0.0.1:11211");
String weight = dsCfg.getString("weight", null);
String username = dsCfg.getString("username", null);
String password = dsCfg.getString("password", null);
int poolSize = dsCfg.getInteger("pool", 5);
boolean failureMode = dsCfg.getBoolean("failure", false);
List<InetSocketAddress> serverAddressList = AddrUtil.getAddresses(server);
if (weight != null) {
String ws[] = weight.split(";");
if (serverAddressList.size() == ws.length) {
int weights[] = new int[ws.length];
for (int i = 0; i < ws.length; i++) {
try {
weights[i] = Integer.parseInt(ws[i]);
} catch (NumberFormatException e) {
weights = null;
break;
}
}
if (weights != null) {
this.builder = new XMemcachedClientBuilder(serverAddressList, weights);
}
}
}
if (this.builder == null) {
this.builder = new XMemcachedClientBuilder(serverAddressList);
}
if (StringUtils.isNotBlank(username) && StringUtils.isNoneBlank(password)) {
for (InetSocketAddress serverAddress : serverAddressList) {
this.builder.addAuthInfo(serverAddress, AuthInfo.typical(username, password));
}
}
this.builder.setName(name);
this.builder.setConnectionPoolSize(poolSize);
this.builder.setFailureMode(failureMode);
}
示例14: init
import net.rubyeye.xmemcached.utils.AddrUtil; //导入方法依赖的package包/类
@Override
public void init() {
if (mcc != null)
return;
log.info("初始化XMemCached,ip:{},readBufSize:{},connectionPoolSize:{}",serverlist,readBufSize,connectionPoolSize);
try {
Configuration.MAX_READ_BUFFER_SIZE = Configuration.MAX_READ_BUFFER_SIZE * 2;
List<InetSocketAddress> socketAddress = AddrUtil
.getAddresses(serverlist);
MemcachedClientBuilder builder = new XMemcachedClientBuilder(
socketAddress);
builder.setConnectionPoolSize(connectionPoolSize);
builder.setSocketOption(StandardSocketOption.TCP_NODELAY,
tcpNoDelay);
builder
.setSocketOption(StandardSocketOption.SO_RCVBUF,
tcpRecvBuff);
builder
.setSocketOption(StandardSocketOption.SO_SNDBUF,
tcpSendBuff);
if (this.transcoder == null) {
this.transcoder = new SerializingTranscoder(10 * 1024 * 1024);// //最大单个数据大小:20M
}
builder.setTranscoder(transcoder);
builder.getConfiguration()
.setSessionIdleTimeout(sessionIdleTimeout);
mcc = builder.build();
mcc.setOpTimeout(this.opTimeout);
//
Field shutdownHookThread = null;
try {
shutdownHookThread = mcc.getClass().getDeclaredField(
"shutdownHookThread");
if (shutdownHookThread != null) {
shutdownHookThread.setAccessible(true);
Thread thread = (Thread) shutdownHookThread.get(mcc);
// shutdownHookThread.set
if (thread != null) {
Runtime.getRuntime().removeShutdownHook(thread);
log.info("删除XMemcached的shutDownHook!");
}
thread = new Thread() {
@Override
public void run() {
System.out.println("修改过的xMemcached shutdown thread,什么也不做....");
// TDOD 关闭的时候清空memecache,后面要改过来
}
};
shutdownHookThread.set(mcc, thread);
Runtime.getRuntime().addShutdownHook(thread);
}
} catch (Exception e) {
e.printStackTrace();
}
log.info("初始化 memcached client 完毕!");
} catch (Exception ex) {
log.debug("初始化 memcached client 出错!");
log.error(ex.getMessage());
}
}
示例15: newMemcachedClient
import net.rubyeye.xmemcached.utils.AddrUtil; //导入方法依赖的package包/类
/**
* Creates a new {@link MemcachedClient}, with specified connection timeout
* and connection pool size.
*
* @param hostsAndPorts
* Memcached' hosts and ports scheme (format
* {@code host1:port1,host2:port2}).
* @param connTimeoutMs
* @param connPoolSize
* @return
* @throws IOException
*/
public static MemcachedClient newMemcachedClient(String hostsAndPorts, long connTimeoutMs,
int connPoolSize) throws IOException {
hostsAndPorts = StringUtils.join(hostsAndPorts.split("[\\s,;]+"), ' ');
MemcachedClientBuilder builder = new XMemcachedClientBuilder(
AddrUtil.getAddresses(hostsAndPorts));
builder.setConnectTimeout(connTimeoutMs);
builder.setConnectionPoolSize(connPoolSize);
return builder.build();
}