本文整理汇总了Java中net.spy.memcached.MemcachedClient.shutdown方法的典型用法代码示例。如果您正苦于以下问题:Java MemcachedClient.shutdown方法的具体用法?Java MemcachedClient.shutdown怎么用?Java MemcachedClient.shutdown使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.spy.memcached.MemcachedClient
的用法示例。
在下文中一共展示了MemcachedClient.shutdown方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import net.spy.memcached.MemcachedClient; //导入方法依赖的package包/类
public static void main(String[] args) {
try{
// 连接本地的 Memcached 服务
MemcachedClient mcc = new MemcachedClient(new InetSocketAddress("172.18.3.34", 9101));
System.out.println("Connection to server sucessful.");
// 添加数据
Future fo = mcc.set("runoob", 900, "Free Education");
// 输出执行 set 方法后的状态
System.out.println("set status:" + fo.get());
// 使用 get 方法获取数据
System.out.println("runoob value in cache - " + mcc.get("runoob"));
// 关闭连接
mcc.shutdown();
}catch(Exception ex) {
System.out.println(ex.getMessage());
}
}
示例2: test
import net.spy.memcached.MemcachedClient; //导入方法依赖的package包/类
public void test() throws Exception {
MeasurementReport measurementReport = getMeasurementReport(component);
ResourceDescriptor resourceDescriptor = getResourceDescriptor("Memcached");
log.info("measurements " + measurementReport.getNumericData());
log.info("measurements " + measurementReport.getTraitData());
measurementReport = getMeasurementReport(component);
// ratio not set yet
// assertAll(measurementReport, resourceDescriptor);
MemcachedClient c = new MemcachedClient(component.getAddress());
String key = "foo";
c.set(key, 0, "value").get();
c.get(key);
c.get(key);
c.get(key + "_not");
measurementReport = getMeasurementReport(component);
assertAll(measurementReport, resourceDescriptor);
Double d = (Double) map(measurementReport).get(
MemcachedComponent.GET_RATIO);
assertEquals(.66, d.doubleValue(), .1);
measurementReport = getMeasurementReport(component);
c.shutdown();
}
示例3: SASLConnectReconnect
import net.spy.memcached.MemcachedClient; //导入方法依赖的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();
}
}
}
示例4: setValue
import net.spy.memcached.MemcachedClient; //导入方法依赖的package包/类
public static void setValue() {
try {
/* 建立MemcachedClient 实例,并指定memcached服务的IP地址和端口号 */
MemcachedClient mc = new MemcachedClient(new InetSocketAddress(hostname, port));
Future<Boolean> b = null;
/* 将key值,过期时间(秒)和要缓存的对象set到memcached中 */
b = mc.set("neead", 900, "someObject");
if (b.get()) {
mc.shutdown();
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
示例5: getValue
import net.spy.memcached.MemcachedClient; //导入方法依赖的package包/类
public static void getValue() {
try {
/* 建立MemcachedClient 实例,并指定memcached服务的IP地址和端口号 */
MemcachedClient mc = new MemcachedClient(new InetSocketAddress(hostname, port));
/* 按照key值从memcached中查找缓存,不存在则返回null */
Object b = mc.get("neead");
System.out.println(b);
mc.shutdown();
} catch (Exception ex) {
ex.printStackTrace();
}
}
示例6: closeMemcachedClient
import net.spy.memcached.MemcachedClient; //导入方法依赖的package包/类
public void closeMemcachedClient(String key, MemcachedClient memcachedClient) {
try {
LOG.debug("Closing client connection to {}", key);
memcachedClient.shutdown();
memcachedClientCache.remove(key);
} catch (Exception e) {
LOG.warn("Failed to close client connection to " + key, e);
}
}
示例7: closeSilently
import net.spy.memcached.MemcachedClient; //导入方法依赖的package包/类
/**
* 关闭Spy MemcachedClient资源对象 备注: 如果资源对象不为null, 关闭资源,不抛出任何异常
*
* @param rsc
* -- 资源对象
*/
public static void closeSilently(MemcachedClient rsc) {
if (null != rsc) {
try {
rsc.shutdown();
// rsc.destroy();
} catch (Throwable ex) {
/* 消除异常 */
}
rsc = null;
}
}
示例8: testCreate_PippoSettings
import net.spy.memcached.MemcachedClient; //导入方法依赖的package包/类
/**
* Test of create method, of class SpymemcachedUtil.
*/
@Test
public void testCreate_PippoSettings() {
System.out.println("create");
MemcachedClient result = SpymemcachedFactory.create(application.getPippoSettings());
assertNotNull(result);
result.shutdown();
}
示例9: testCreate_5args
import net.spy.memcached.MemcachedClient; //导入方法依赖的package包/类
/**
* Test of create method, of class SpymemcachedUtil.
*/
@Test
public void testCreate_5args() {
System.out.println("create");
ConnectionFactoryBuilder.Protocol protocol = ConnectionFactoryBuilder.Protocol.BINARY;
String user = "";
String pass = "";
String[] authMechanisms = new String[]{"PLAIN"};
MemcachedClient result = SpymemcachedFactory.create(HOST, protocol, user, pass, authMechanisms);
assertNotNull(result);
result.shutdown();
}
示例10: main
import net.spy.memcached.MemcachedClient; //导入方法依赖的package包/类
/**
* @param args Command line arguments.
* @throws Exception In case of error.
*/
public static void main(String[] args) throws Exception {
MemcachedClient client = null;
try (Ignite ignite = Ignition.start(MemcacheRestExampleNodeStartup.configuration())) {
System.out.println();
System.out.println(">>> Memcache REST example started.");
IgniteCache<String, Object> cache = ignite.cache("default");
client = startMemcachedClient(host, port);
// Put string value to cache using Memcache binary protocol.
if (client.add("strKey", 0, "strVal").get())
System.out.println(">>> Successfully put string value using Memcache client.");
// Check that string value is actually in cache using traditional
// Ignite API and Memcache binary protocol.
System.out.println(">>> Getting value for 'strKey' using Ignite cache API: " + cache.get("strKey"));
System.out.println(">>> Getting value for 'strKey' using Memcache client: " + client.get("strKey"));
// Remove string value from cache using Memcache binary protocol.
if (client.delete("strKey").get())
System.out.println(">>> Successfully removed string value using Memcache client.");
// Check that cache is empty.
System.out.println(">>> Current cache size: " + cache.size() + " (expected: 0).");
// Put integer value to cache using Memcache binary protocol.
if (client.add("intKey", 0, 100).get())
System.out.println(">>> Successfully put integer value using Memcache client.");
// Check that integer value is actually in cache using traditional
// Ignite API and Memcache binary protocol.
System.out.println(">>> Getting value for 'intKey' using Ignite cache API: " + cache.get("intKey"));
System.out.println(">>> Getting value for 'intKey' using Memcache client: " + client.get("intKey"));
// Remove string value from cache using Memcache binary protocol.
if (client.delete("intKey").get())
System.out.println(">>> Successfully removed integer value using Memcache client.");
// Check that cache is empty.
System.out.println(">>> Current cache size: " + cache.size() + " (expected: 0).");
// Create atomic long and close it after test is done.
try (IgniteAtomicLong l = ignite.atomicLong("atomicLong", 10, true)) {
// Increment atomic long by 5 using Memcache client.
if (client.incr("atomicLong", 5, 0) == 15)
System.out.println(">>> Successfully incremented atomic long by 5.");
// Increment atomic long using Ignite API and check that value is correct.
System.out.println(">>> New atomic long value: " + l.incrementAndGet() + " (expected: 16).");
// Decrement atomic long by 3 using Memcache client.
if (client.decr("atomicLong", 3, 0) == 13)
System.out.println(">>> Successfully decremented atomic long by 3.");
// Decrement atomic long using Ignite API and check that value is correct.
System.out.println(">>> New atomic long value: " + l.decrementAndGet() + " (expected: 12).");
}
}
finally {
if (client != null)
client.shutdown();
}
}
示例11: shutdown
import net.spy.memcached.MemcachedClient; //导入方法依赖的package包/类
public void shutdown() {
for (MemcachedClient client : clients) {
client.shutdown();
}
}
示例12: main
import net.spy.memcached.MemcachedClient; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
final MemcachedClient client = createClients();
final ExecutorService executorService = Executors.newFixedThreadPool(1000, daemonThreadFactory());
int count = 10000;
final long start = System.currentTimeMillis();
for (int i = 0; i < count; i++) {
final int key = i;
executorService.execute(new Runnable() {
@Override
public void run() {
// MemcachedClient client = clients.get(random);
Object toPut = testGrant();
// Object toPut = UUID.randomUUID().toString();
OperationFuture<Boolean> set = null;
for (int j = 0; j < 3; j++) {
set = client.set(Integer.toString(key), 60, toPut);
}
OperationStatus status = set.getStatus(); // block
System.out.println(
" key: " + key + ", time: " + (new Date().getTime() - start) + "ms, set: " + status);
executorService.execute(new Runnable() {
@Override
public void run() {
int random = random();
if (random % 3 == 0) {
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
Object get = client.get(Integer.toString(key));
System.out.println("GET key: " + key + " result: " + get);
}
});
}
});
}
sleep(40);
// System.out.println(client.get("myKey"));
//
// client.set("myKey", 30, testState());
//
// sleep(12);
// System.out.println(client.get("myKey"));
//
// sleep(12);
// System.out.println(client.get("myKey"));
client.shutdown();
}
示例13: destroyConnectionClient
import net.spy.memcached.MemcachedClient; //导入方法依赖的package包/类
@Override
protected void destroyConnectionClient(MemcachedClient connectionClient) {
connectionClient.shutdown(10, TimeUnit.SECONDS);
}