本文整理汇总了Java中net.rubyeye.xmemcached.utils.AddrUtil类的典型用法代码示例。如果您正苦于以下问题:Java AddrUtil类的具体用法?Java AddrUtil怎么用?Java AddrUtil使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AddrUtil类属于net.rubyeye.xmemcached.utils包,在下文中一共展示了AddrUtil类的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: getAuth
import net.rubyeye.xmemcached.utils.AddrUtil; //导入依赖的package包/类
public Map<InetSocketAddress, AuthInfo> getAuth() {
Map<InetSocketAddress, AuthInfo> authMap = new HashMap<InetSocketAddress, AuthInfo>();
if (auth != null && auth.size() > 0) {
for (Entry<String, String> authEntry : auth.entrySet()) {
String authInfo[] = authEntry.getValue().split("\\|");
if (authInfo != null && authInfo.length == 2) {
InetSocketAddress host = AddrUtil.getOneAddress(authEntry.getKey());
if (authType.equals("md5")) {
authMap.put(host, AuthInfo.cramMD5(authInfo[0], authInfo[1]));
} else if (authType.equals("typecal")) {
authMap.put(host, AuthInfo.typical(authInfo[0], authInfo[1]));
} else {
authMap.put(host, AuthInfo.plain(authInfo[0], authInfo[1]));
}
}
}
}
return authMap;
}
示例4: 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;
}
示例5: 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());
}
示例6: 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);
}
示例7: 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;
}
示例8: 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;
}
示例9: 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");
}
示例10: 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;
}
示例11: 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();
}
}
示例12: 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();
}
示例13: setUp
import net.rubyeye.xmemcached.utils.AddrUtil; //导入依赖的package包/类
@BeforeMethod
public void setUp() throws Exception {
newClientMock = mock(MemcachedClient.class);
memcacheCacheServiceFactoryMock = spy(new MemcacheCacheServiceFactory());
Random random = new Random();
String randomHost = "prefix" + random.nextLong() + ":" + (1 + random.nextInt(30000));
memcacheCacheServiceFactoryMock.setAddresses(AddrUtil.getAddresses(randomHost));
doReturn(newClientMock).when(memcacheCacheServiceFactoryMock).createNew();
memcacheCacheServiceFactoryReal = new MemcacheCacheServiceFactory();
}
示例14: testGetDifferentHost
import net.rubyeye.xmemcached.utils.AddrUtil; //导入依赖的package包/类
@Test
public void testGetDifferentHost() throws Exception {
CacheService client = memcacheCacheServiceFactoryMock.get();
Assert.assertNotNull(client);
memcacheCacheServiceFactoryMock.getAddresses().add(AddrUtil.getOneAddress("foo.host:12312"));
CacheService client2 = memcacheCacheServiceFactoryMock.get();
Assert.assertNotNull(client2);
verify(memcacheCacheServiceFactoryMock, times(2)).get();
verify(memcacheCacheServiceFactoryMock, times(2)).createNew();
}
示例15: testGetAddresses
import net.rubyeye.xmemcached.utils.AddrUtil; //导入依赖的package包/类
@Test
public void testGetAddresses() throws Exception {
List<InetSocketAddress> addresses = memcacheCacheServiceFactoryReal.getAddresses();
Assert.assertEquals(addresses.size(), 1); // default host
Assert.assertEquals(addresses.get(0), AddrUtil.getOneAddress("127.0.0.1:11211"));
}