本文整理汇总了Java中net.spy.memcached.AddrUtil类的典型用法代码示例。如果您正苦于以下问题:Java AddrUtil类的具体用法?Java AddrUtil怎么用?Java AddrUtil使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AddrUtil类属于net.spy.memcached包,在下文中一共展示了AddrUtil类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initMemcached
import net.spy.memcached.AddrUtil; //导入依赖的package包/类
public void initMemcached(String addresses) // addresses: space sep. like 'localhost:11211 10.10.10.10:1234'
{
if (memcachedClient.get() != null)
throw new IllegalStateException("memcached already initialized");
try
{
final MemcachedClient _memcachedClient = new MemcachedClient(
new BinaryConnectionFactory(),
AddrUtil.getAddresses(addresses));
_memcachedClient.addObserver(this);
memcachedClient.set(_memcachedClient);
}
catch (IOException e)
{
e.printStackTrace();
}
}
示例2: MemCacheTicketRegistry
import net.spy.memcached.AddrUtil; //导入依赖的package包/类
/**
* Creates a new instance that stores tickets in the given memcached hosts.
*
* @param hostnames Array of memcached hosts where each element is of the form host:port.
* @param ticketGrantingTicketTimeOut TGT timeout in seconds.
* @param serviceTicketTimeOut ST timeout in seconds.
*/
@Autowired
public MemCacheTicketRegistry(@Value("${memcached.servers:}")
final String[] hostnames,
@Value("${tgt.maxTimeToLiveInSeconds:28800}")
final int ticketGrantingTicketTimeOut,
@Value("${st.timeToKillInSeconds:10}")
final int serviceTicketTimeOut) {
try {
final List<String> hostNamesArray = Arrays.asList(hostnames);
if (hostNamesArray.isEmpty()) {
logger.debug("No memcached hosts are define. Client shall not be configured");
} else {
logger.info("Setting up Memcached Ticket Registry...");
this.tgtTimeout = ticketGrantingTicketTimeOut;
this.stTimeout = serviceTicketTimeOut;
this.client = new MemcachedClient(AddrUtil.getAddresses(hostNamesArray));
}
} catch (final IOException e) {
throw new IllegalArgumentException("Invalid memcached host specification.", e);
}
}
示例3: MemcachedDistributedGroup
import net.spy.memcached.AddrUtil; //导入依赖的package包/类
/**
* 构造memcached组
*
* @param groupServerUrl
* -- 组中Memcached服务器连接字符串
*/
MemcachedDistributedGroup(String groupServerUrl) {
this.groupServerUrl = groupServerUrl;
String items = groupServerUrl.replaceAll(";", " ");
try {
mcc = new MemcachedClient(new DefaultConnectionFactory() {
@Override
public long getOperationTimeout() {
return connectTimeout;
}
}, AddrUtil.getAddresses(items));
initMemCachedHealthMBean(groupServerUrl);
} catch (Exception ex) {
throw new FwRuntimeException("初始化MemcachedClient对象失败", ex);
}
}
示例4: ExceptionSwallowingMemcachedClient
import net.spy.memcached.AddrUtil; //导入依赖的package包/类
@Autowired
public ExceptionSwallowingMemcachedClient(GlobalConfigHandler globalConfigHandler, ZkCuratorHandler zkCuratorHandler) throws Exception {
logger.info("Initializing...");
Stat stat = zkCuratorHandler.getCurator().checkExists().forPath(ZK_CONFIG_KEY_MEMCACHED_SERVERS_FPATH);
if (stat != null)
{
ObjectMapper mapper = new ObjectMapper();
byte[] bytes = zkCuratorHandler.getCurator().getData().forPath(ZK_CONFIG_KEY_MEMCACHED_SERVERS_FPATH);
MemcacheConfig config = mapper.readValue(bytes,MemcacheConfig.class);
logger.info(config.toString());
memcachedClient = new MemcachedClient(new ConnectionFactoryBuilder(new DefaultConnectionFactory()).setOpTimeout(MEMCACHE_OP_TIMEOUT).build(),
AddrUtil.getAddresses(config.servers));
logger.info(String.format("MemcachedClient initialized using %s[%s]", ZK_CONFIG_KEY_MEMCACHED_SERVERS, config.servers));
MemCachePeer.initialise(config.servers,config.numClients);
}
if (memcachedClient == null) {
throw new Exception("*Warning* Memcached NOT initialized!");
}
globalConfigHandler.addSubscriber(ZK_CONFIG_KEY_MEMCACHED_SERVERS, this);
}
示例5: SASLConnectReconnect
import net.spy.memcached.AddrUtil; //导入依赖的package包/类
SASLConnectReconnect(String username, String password, String host) {
AuthDescriptor ad = new AuthDescriptor(new String[] { "PLAIN" },
new PlainCallbackHandler(username, password));
try {
List<InetSocketAddress> addresses = AddrUtil.getAddresses(host);
mc = new MemcachedClient(
new ConnectionFactoryBuilder().setProtocol(Protocol.BINARY)
.setAuthDescriptor(ad).build(), addresses);
} catch (IOException ex) {
System.err
.println("Couldn't create a connection, bailing out: \nIOException "
+ ex.getMessage());
if (mc != null) {
mc.shutdown();
}
}
}
示例6: MemCacheTicketRegistry
import net.spy.memcached.AddrUtil; //导入依赖的package包/类
/**
* Creates a new instance that stores tickets in the given memcached hosts.
*
* @param hostnames Array of memcached hosts where each element is of the form host:port.
* @param ticketGrantingTicketTimeOut TGT timeout in seconds.
* @param serviceTicketTimeOut ST timeout in seconds.
*/
public MemCacheTicketRegistry(final String[] hostnames, final int ticketGrantingTicketTimeOut,
final int serviceTicketTimeOut) {
try {
this.client = new MemcachedClient(AddrUtil.getAddresses(Arrays.asList(hostnames)));
} catch (final IOException e) {
throw new IllegalArgumentException("Invalid memcached host specification.", e);
}
this.tgtTimeout = ticketGrantingTicketTimeOut;
this.stTimeout = serviceTicketTimeOut;
}
示例7: MemCacheTicketRegistry
import net.spy.memcached.AddrUtil; //导入依赖的package包/类
/**
* Creates a new instance that stores tickets in the given memcached hosts.
*
* @param hostnames Array of memcached hosts where each element is of the form host:port.
* @param ticketGrantingTicketTimeOut TGT timeout in seconds.
* @param serviceTicketTimeOut ST timeout in seconds.
*/
public MemCacheTicketRegistry(final String[] hostnames, final int ticketGrantingTicketTimeOut,
final int serviceTicketTimeOut) {
try {
this.client = new MemcachedClient(AddrUtil.getAddresses(Arrays.asList(hostnames)));
} catch (final IOException e) {
throw new IllegalArgumentException("Invalid memcached host specification.", e);
}
this.tgtTimeout = ticketGrantingTicketTimeOut;
this.stTimeout = serviceTicketTimeOut;
}
示例8: setServers
import net.spy.memcached.AddrUtil; //导入依赖的package包/类
/**
* Populate server list from comma-separated list of hostname:port strings.
*
* @param value Comma-separated list
*/
public void setServers(String value) {
if (StringUtils.isEmpty(value)) {
throw new IllegalArgumentException("Server list is empty");
}
this.servers = AddrUtil.getAddresses(Arrays.asList(value.split(",")));
}
示例9: activateService
import net.spy.memcached.AddrUtil; //导入依赖的package包/类
@Override
public void activateService()
throws Exception
{
MemcacheConfiguration config = configuration.get();
expiration = ( config.expiration().get() == null )
? 3600
: config.expiration().get();
String addresses = ( config.addresses().get() == null )
? "localhost:11211"
: config.addresses().get();
Protocol protocol = ( config.protocol().get() == null )
? Protocol.TEXT
: Protocol.valueOf( config.protocol().get().toUpperCase() );
String username = config.username().get();
String password = config.password().get();
String authMech = config.authMechanism().get() == null
? "PLAIN"
: config.authMechanism().get();
ConnectionFactoryBuilder builder = new ConnectionFactoryBuilder();
builder.setProtocol( protocol );
if( username != null && !username.isEmpty() )
{
String[] authType = { authMech };
AuthDescriptor to = new AuthDescriptor( authType, new PlainCallbackHandler( username, password ) );
builder.setAuthDescriptor( to );
}
client = new MemcachedClient( builder.build(), AddrUtil.getAddresses( addresses ) );
}
示例10: setup
import net.spy.memcached.AddrUtil; //导入依赖的package包/类
@Before
public void setup()
{
MemcacheStore operatorStore = new MemcacheStore();
operatorStore.setServerAddresses( AddrUtil.getAddresses("localhost:11211") );
MemcacheStore testStore = new MemcacheStore();
testStore.setServerAddresses( AddrUtil.getAddresses("localhost:11211") );
testFramework = new KeyValueStoreOperatorTest<MemcacheStore>( operatorStore, testStore );
}
示例11: MemcacheConnect
import net.spy.memcached.AddrUtil; //导入依赖的package包/类
public MemcacheConnect(String ip, int port) {
super(ip, port);
try {
client = new MemcachedClient(new ConnectionFactoryBuilder().setDaemon(true).setFailureMode(FailureMode.Retry).build(),AddrUtil.getAddresses(ip + ":" + port));
} catch (IOException ex) {
Logger.getLogger(MemcacheConnect.class.getName()).log(Level.SEVERE, null, ex);
}
}
示例12: create
import net.spy.memcached.AddrUtil; //导入依赖的package包/类
public static MemcachedCache create(final MemcachedCacheConfig config) {
if (INSTANCE == null) {
try {
LZ4Transcoder transcoder = new LZ4Transcoder(config.getMaxObjectSize());
// always use compression
transcoder.setCompressionThreshold(0);
OperationQueueFactory opQueueFactory;
long maxQueueBytes = config.getMaxOperationQueueSize();
if (maxQueueBytes > 0) {
opQueueFactory = new MemcachedOperationQueueFactory(maxQueueBytes);
} else {
opQueueFactory = new LinkedOperationQueueFactory();
}
String hosts2Str = config.getHosts().toString();
String hostsList = hosts2Str.substring(1, hosts2Str.length() - 1);
synchronized (MemcachedCache.class) {
if (INSTANCE == null) {
INSTANCE = new MemcachedCache(new MemcachedClient(new ConnectionFactoryBuilder().setProtocol(ConnectionFactoryBuilder.Protocol.BINARY).setHashAlg(DefaultHashAlgorithm.FNV1A_64_HASH).setLocatorType(ConnectionFactoryBuilder.Locator.CONSISTENT).setDaemon(true).setFailureMode(FailureMode.Cancel).setTranscoder(transcoder).setShouldOptimize(true).setOpQueueMaxBlockTime(config.getTimeout()).setOpTimeout(config.getTimeout()).setReadBufferSize(config.getReadBufferSize())
.setOpQueueFactory(opQueueFactory).build(), AddrUtil.getAddresses(hostsList)), config);
}
}
} catch (IOException e) {
logger.error("Unable to create MemcachedCache instance: " + e.getMessage());
throw Throwables.propagate(e);
}
}
return INSTANCE;
}
示例13: MemcachedClientPool
import net.spy.memcached.AddrUtil; //导入依赖的package包/类
public MemcachedClientPool(int poolSize, String server) throws IOException {
this.index = 0;
this.clients = new ArrayList<>();
for (int i = 0; i < poolSize; i++) {
this.clients.add(new MemcachedClient(new BinaryConnectionFactory(),
AddrUtil.getAddresses(server.trim())));
}
}
示例14: setUp
import net.spy.memcached.AddrUtil; //导入依赖的package包/类
@Before
public void setUp() throws IOException {
client = new MemcachedClient(AddrUtil.getAddresses("localhost:11211"));
Properties properties = new Properties();
PropertiesHelper props = new PropertiesHelper(properties);
Config config = new Config(props);
cache = new MemcachedCache("MemcachedCacheTest", new SpyMemcache(client), config);
}
示例15: ServerAddress
import net.spy.memcached.AddrUtil; //导入依赖的package包/类
public static MongoClient newClient(String server, String user, String pass, String db) throws UnknownHostException{
MongoClientOptions options = MongoClientOptions
.builder()
.readPreference( ReadPreference.secondaryPreferred() )
.build();
List<InetSocketAddress> serverList = AddrUtil.getAddresses(server);
List<ServerAddress> addrs = new ArrayList<ServerAddress>();
Iterator<InetSocketAddress> it = serverList.iterator();
while ( it.hasNext() ){
InetSocketAddress isa = it.next();
addrs.add( new ServerAddress( isa.getAddress(), isa.getPort() ) );
}
if ( user != null ) {
MongoCredential cred = MongoCredential.createCredential( user, db, pass.toCharArray() );
List<MongoCredential> creds = new ArrayList<MongoCredential>();
creds.add( cred );
return new MongoClient( addrs, creds, options );
} else {
return new MongoClient( addrs, options );
}
}