Package net.spy.memcached

Examples of net.spy.memcached.MemcachedClient


     * machine as your application, for example.
     * @param address where the <i>memcached</i> daemon is running
     * @throws IOException
     */
    public MemcachedHttpCacheStorage(InetSocketAddress address) throws IOException {
        this(new MemcachedClient(address));
    }
View Full Code Here


     * machine as your application, for example.
     * @param address where the <i>memcached</i> daemon is running
     * @throws IOException
     */
    public MemcachedHttpCacheStorage(InetSocketAddress address) throws IOException {
        this(new MemcachedClient(address));
    }
View Full Code Here

    }

    public void initClient() throws IOException {
        System.setProperty("net.spy.log.LoggerImpl", "net.spy.memcached.compat.log.Log4JLogger");
        if (Play.configuration.containsKey("memcached.host")) {
            client = new MemcachedClient(AddrUtil.getAddresses(Play.configuration.getProperty("memcached.host")));
        } else if (Play.configuration.containsKey("memcached.1.host")) {
            int nb = 1;
            String addresses = "";
            while (Play.configuration.containsKey("memcached." + nb + ".host")) {
                addresses += Play.configuration.get("memcached." + nb + ".host") + " ";
                nb++;
            }
            client = new MemcachedClient(AddrUtil.getAddresses(addresses));
        } else {
            throw new ConfigurationException(("Bad configuration for memcached"));
        }
    }
View Full Code Here

      CompatibilityCacheFactory.killCacheFactories(cacheFactory);
   }

   public void testLoadingAndStoringEventsMemcached() throws InterruptedException, ExecutionException, TimeoutException {
      Cache<String, String> embedded = cacheFactory.getEmbeddedCache();
      MemcachedClient remote = cacheFactory.getMemcachedClient();

      TestCacheListener l = new TestCacheListener();
      embedded.addListener(l);

      assertTrue(l.created.isEmpty());
      assertTrue(l.removed.isEmpty());
      assertTrue(l.modified.isEmpty());
      assertTrue(l.visited.isEmpty());

      Future<Boolean> future1 = remote.add("k", 0, "v");
      assertTrue(future1.get(60, TimeUnit.SECONDS));

      assertEquals(1, l.createdCounter);
      assertEquals("v", l.created.get("k"));
      assertTrue(l.removed.isEmpty());
      assertEquals(1, l.modifiedCounter);
      assertEquals("v", l.modified.get("k"));
      assertTrue(l.visited.isEmpty());

      Future<Boolean> future2 = remote.set("key", 0, "value");
      assertTrue(future2.get(60, TimeUnit.SECONDS));

      assertEquals(2, l.createdCounter);
      assertTrue(l.removed.isEmpty());
      assertEquals(2, l.modifiedCounter);
      assertTrue(l.visited.isEmpty());

      Future<Boolean> future3 = remote.set("key", 0, "modifiedValue");
      assertTrue(future3.get(60, TimeUnit.SECONDS));

      assertEquals(2, l.createdCounter);
      assertTrue(l.removed.isEmpty());
      assertEquals(3, l.modifiedCounter);
      assertEquals("modifiedValue", l.modified.get("key"));
      assertTrue(l.visited.isEmpty());

      Future<Boolean> future4 = remote.replace("k", 0, "replacedValue");
      assertTrue(future4.get(60, TimeUnit.SECONDS));

      assertEquals(2, l.createdCounter);
      assertTrue(l.removed.isEmpty());
      assertEquals(4, l.modifiedCounter);
      assertEquals("replacedValue", l.modified.get("k"));
      assertTrue(l.visited.isEmpty());

      //resetting so don't have to type "== 2" etc. all over again
      l.reset();

      Future<Boolean> future5 = remote.delete("key");
      assertTrue(future5.get(60, TimeUnit.SECONDS));

      assertTrue(l.created.isEmpty());
      assertEquals(1, l.removedCounter);
      assertEquals("modifiedValue", l.removed.get("key"));
      assertTrue(l.modified.isEmpty());

      l.reset();

      String value = (String) remote.get("k");
      assertTrue(l.created.isEmpty());
      assertTrue(l.removed.isEmpty());
      assertTrue(l.modified.isEmpty());
      assertEquals(1, l.visitedCounter);
      assertEquals("replacedValue", l.visited.get("k"));
View Full Code Here

            final String[] hostPort = hostname.split(":");
            addresses.add(new InetSocketAddress(hostPort[0], Integer.parseInt(hostPort[1])));
        }

        try {
            this.client = new MemcachedClient(addresses);
        } catch (final IOException e) {
            throw new IllegalStateException(e);
        }
    }
View Full Code Here

            ConnectionFactory cf = new ConnectionFactoryBuilder()
                                        .setProtocol(ConnectionFactoryBuilder.Protocol.BINARY)
                                        .setAuthDescriptor(ad)
                                        .build();
           
            client = new MemcachedClient(cf, addrs);
      
        } else {
            client = new MemcachedClient(addrs);
        }

       
    }
View Full Code Here

            ObjectParameter op = params.getObjectParam(CONNECTION_FACTORY_CREATOR);
            if (op == null || op.getObject() == null)
            {
               LOG.debug("No connection factory creator has been defined, "
                  + "so we will use the BinaryConnectionFactory by default");
               return new MemcachedClient(new BinaryConnectionFactory(), isaLocations);
            }
            else if (!(op.getObject() instanceof ConnectionFactoryCreator))
            {
               throw new IllegalArgumentException("The parameter '" + CONNECTION_FACTORY_CREATOR
                  + "' must refer to a ConnectionFactoryCreator.");
            }
            else
            {
               return new MemcachedClient(((ConnectionFactoryCreator)op.getObject()).create(), isaLocations);
            }
         }
      });

      ValueParam vp = params.getValueParam(DEFAULT_EXPIRATION_TIMEOUT);
View Full Code Here

      }

      cfb.setOpTimeout(operationTimeout);

      try {
        MemcachedClient spyClient = new MemcachedClient(cfb.build(), AddrUtil.getAddresses(memcachedNodes));
        clientPool.add(new SpyTokyotyrantClient(spyClient));
      } catch (IOException e) {
        logger.error("MemcachedClient initilization error: ", e);
        throw e;
      }
View Full Code Here

    }

    cfb.setOpTimeout(operationTimeout);

    try {
      memcachedClient = new MemcachedClient(cfb.build(), AddrUtil.getAddresses(memcachedNodes));
    } catch (IOException e) {
      logger.error("MemcachedClient initilization error: ", e);
      throw e;
    }
  }
View Full Code Here

      boolean namespaceVersioning) throws IOException {
    super(name);
    if (Cutils.isBlank(name)) {
      throw new IllegalArgumentException("SpyRequestCache name must not be blank");
    }
    this.client = new MemcachedClient(connectionFactory, addrs);
    this.clientCreated = true;
    this.operationTimeout = connectionFactory.getOperationTimeout();
    this.namespaceVersioning = namespaceVersioning;
  }
View Full Code Here

TOP

Related Classes of net.spy.memcached.MemcachedClient

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.