Esempio n. 1
0
  /**
   * @param args
   * @throws IOException
   * @throws URISyntaxException
   */
  public static void main(String[] args) throws IOException, URISyntaxException {
    // ApplicationContext ctx = new GenericXmlApplicationContext("applicationContext.xml");
    ApplicationContext ctx = new AnnotationConfigApplicationContext(SpringConfig.class);
    MemcachedClient memcachedClient = ctx.getBean(MemcachedClient.class);

    memcachedClient.add("testSpring", 0, "testDataSpring");
    System.out.println(memcachedClient.get("testSpring"));
    memcachedClient.shutdown();
  }
 @AfterMethod
 public void release() {
   try {
     memcachedServer.stop();
     TestingUtil.killCacheManagers(cacheManager);
     memcachedClient.shutdown();
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
Esempio n. 3
0
 public void finish() {
   try {
     if (memcache != null) {
       log.info("Shutting down memcache {}", memcache);
       memcache.shutdown(1, TimeUnit.SECONDS);
     }
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
Esempio n. 4
0
 public StatefulStreamMapper() {
   if (System.getProperty("memcache.address") != null) {
     try {
       memcache =
           new MemcachedClient(AddrUtil.getAddresses(System.getProperty("memcache.address")));
     } catch (Exception e) {
       e.printStackTrace();
       if (memcache != null) {
         log.info("Shutting down memcache connection...");
         memcache.shutdown();
         memcache = null;
       }
     }
   } else memcache = null;
 }
  public static void main(String[] args) throws Exception {
    final MemcachedClient db = new MemcachedClient(AddrUtil.getAddresses(args[0]));
    final Transcoder<Object> transcoder =
        new Transcoder<Object>() {
          public CachedData encode(Object data) {
            return new CachedData(0, (byte[]) data, getMaxSize());
          }

          public Object decode(CachedData cachedData) {
            return cachedData.getData();
          }

          public boolean asyncDecode(CachedData arg0) {
            return false;
          }

          public int getMaxSize() {
            return CachedData.MAX_SIZE;
          }
        };
    final String key = "key";
    final byte[] value = new byte[128];
    value[0] = 1;
    value[1] = 2;
    value[2] = 3;
    db.set(key, 0, value).get();
    Runnable task =
        new Runnable() {
          public void run() {
            try {
              assertArrayEquals(value, (byte[]) db.asyncGet(key, transcoder).get());
            } catch (Exception e) {
              e.printStackTrace();
            }
          }
        };
    for (int c : new int[] {1, 10, 100, 200, 300}) {
      System.out.println(c + ":" + (new Benchmark(c, 10000).run(task)) + "ms");
    }
    db.shutdown();
  }
Esempio n. 6
0
  public static void main(String[] args) throws IOException {
    // TODO Auto-generated method stub
    String configEndpoint = "localhost";
    Integer clusterPort = 11211;

    MemcachedClient client =
        new MemcachedClient(new InetSocketAddress(configEndpoint, clusterPort));
    // DefaultConnectionFactory cf=new DefaultConnectionFactory();
    // The client will connect to the other cache nodes automatically

    // Store a data item for an hour.  The client will decide which cache host will store this item.
    // Store a value (async) for one hour
    UserProfile set = new UserProfile();
    set.setEmail("myemail");
    System.out.println(client.set("someKey", 3600, set));
    // Retrieve a value (synchronously).
    // Object myObject=client.get("someKey");
    // client.set("Key1111", 10, "This is the data value");
    // System.out.println("Value is "+client.get("*****@*****.**").toString());
    Object obj = client.get("someKey");
    UserProfile up = (UserProfile) obj;
    System.out.println("Value is " + up.getEmail());
    client.shutdown();
  }
Esempio n. 7
0
 @Override
 public void shutdown() {
   readClient.shutdown();
   writeClient.shutdown();
 }
 @PreDestroy
 public void shutdown() {
   logger.info("shutdown memcached cache client");
   memcachedClient.shutdown();
 }
 @Override
 public void close() {
   memcached.shutdown();
 }