net.spy.memcached.ConnectionFactory Java Examples
The following examples show how to use
net.spy.memcached.ConnectionFactory.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EVCacheNodeImpl.java From EVCache with Apache License 2.0 | 6 votes |
public EVCacheNodeImpl(SocketAddress sa, SocketChannel c, int bufSize, BlockingQueue<Operation> rq, BlockingQueue<Operation> wq, BlockingQueue<Operation> iq, long opQueueMaxBlockTimeMillis, boolean waitForAuth, long dt, long at, ConnectionFactory fa, EVCacheClient client, long stTime) { super(sa, c, bufSize, rq, wq, iq, Long.valueOf(opQueueMaxBlockTimeMillis), waitForAuth, dt, at, fa); this.client = client; final String appName = client.getAppName(); this.readQ = rq; this.inputQueue = iq; this.hostName = ((InetSocketAddress) getSocketAddress()).getHostName(); // final List<Tag> tagsCounter = new ArrayList<Tag>(5); // tagsCounter.add(new BasicTag(EVCacheMetricsFactory.CACHE, client.getAppName())); // tagsCounter.add(new BasicTag(EVCacheMetricsFactory.SERVERGROUP, client.getServerGroupName())); // tagsCounter.add(new BasicTag(EVCacheMetricsFactory.ZONE, client.getZone())); //tagsCounter.add(new BasicTag(EVCacheMetricsFactory.HOST, hostName)); //TODO : enable this and see what is the impact this.operationsCounter = client.getOperationCounter(); setConnectTime(stTime); setupMonitoring(appName); }
Example #2
Source File: MemcachedCache.java From kylin-on-parquet-v2 with Apache License 2.0 | 5 votes |
public static MemcachedCache create(final MemcachedCacheConfig config, String memcachedPrefix, int timeToLive) { try { SerializingTranscoder transcoder = new SerializingTranscoder(config.getMaxObjectSize()); // always no compression inside, we compress/decompress outside transcoder.setCompressionThreshold(Integer.MAX_VALUE); OperationQueueFactory opQueueFactory; int maxQueueSize = config.getMaxOperationQueueSize(); if (maxQueueSize > 0) { opQueueFactory = new ArrayOperationQueueFactory(maxQueueSize); } else { opQueueFactory = new LinkedOperationQueueFactory(); } String hostsStr = config.getHosts(); ConnectionFactory connectionFactory = new MemcachedConnectionFactoryBuilder() .setProtocol(ConnectionFactoryBuilder.Protocol.BINARY) .setHashAlg(DefaultHashAlgorithm.FNV1A_64_HASH) .setLocatorType(ConnectionFactoryBuilder.Locator.CONSISTENT).setDaemon(true) .setFailureMode(FailureMode.Redistribute).setTranscoder(transcoder).setShouldOptimize(true) .setOpQueueMaxBlockTime(config.getTimeout()).setOpTimeout(config.getTimeout()) .setReadBufferSize(config.getReadBufferSize()).setOpQueueFactory(opQueueFactory).build(); return new MemcachedCache(new MemcachedClient(new MemcachedConnectionFactory(connectionFactory), AddrUtil.getAddresses(hostsStr)), config, memcachedPrefix, timeToLive); } catch (IOException e) { logger.error("Unable to create MemcachedCache instance.", e); throw Throwables.propagate(e); } }
Example #3
Source File: MemcachedCache.java From kylin with Apache License 2.0 | 5 votes |
public static MemcachedCache create(final MemcachedCacheConfig config, String memcachedPrefix, int timeToLive) { try { SerializingTranscoder transcoder = new SerializingTranscoder(config.getMaxObjectSize()); // always no compression inside, we compress/decompress outside transcoder.setCompressionThreshold(Integer.MAX_VALUE); OperationQueueFactory opQueueFactory; int maxQueueSize = config.getMaxOperationQueueSize(); if (maxQueueSize > 0) { opQueueFactory = new ArrayOperationQueueFactory(maxQueueSize); } else { opQueueFactory = new LinkedOperationQueueFactory(); } String hostsStr = config.getHosts(); ConnectionFactory connectionFactory = new MemcachedConnectionFactoryBuilder() .setProtocol(ConnectionFactoryBuilder.Protocol.BINARY) .setHashAlg(DefaultHashAlgorithm.FNV1A_64_HASH) .setLocatorType(ConnectionFactoryBuilder.Locator.CONSISTENT).setDaemon(true) .setFailureMode(FailureMode.Redistribute).setTranscoder(transcoder).setShouldOptimize(true) .setOpQueueMaxBlockTime(config.getTimeout()).setOpTimeout(config.getTimeout()) .setReadBufferSize(config.getReadBufferSize()).setOpQueueFactory(opQueueFactory).build(); return new MemcachedCache(new MemcachedClient(new MemcachedConnectionFactory(connectionFactory), getResolvedAddrList(hostsStr)), config, memcachedPrefix, timeToLive); } catch (IOException e) { logger.error("Unable to create MemcachedCache instance.", e); throw Throwables.propagate(e); } }
Example #4
Source File: TCPMemcachedNodeImpl.java From kylin with Apache License 2.0 | 5 votes |
public TCPMemcachedNodeImpl(SocketAddress sa, SocketChannel c, int bufSize, BlockingQueue<Operation> rq, BlockingQueue<Operation> wq, BlockingQueue<Operation> iq, long opQueueMaxBlockTime, boolean waitForAuth, long dt, long authWaitTime, ConnectionFactory fact) { super(); assert sa != null : "No SocketAddress"; assert c != null : "No SocketChannel"; assert bufSize > 0 : "Invalid buffer size: " + bufSize; assert rq != null : "No operation read queue"; assert wq != null : "No operation write queue"; assert iq != null : "No input queue"; socketAddress = sa; connectionFactory = fact; this.authWaitTime = authWaitTime; setChannel(c); // Since these buffers are allocated rarely (only on client creation // or reconfigure), and are passed to Channel.read() and Channel.write(), // use direct buffers to avoid // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6214569 rbuf = ByteBuffer.allocateDirect(bufSize); wbuf = ByteBuffer.allocateDirect(bufSize); getWbuf().clear(); readQ = rq; writeQ = wq; inputQueue = iq; this.opQueueMaxBlockTime = opQueueMaxBlockTime; shouldAuth = waitForAuth; defaultOpTimeout = dt; setupForAuth(); }
Example #5
Source File: MemcacheClientTest.java From ob1k with Apache License 2.0 | 5 votes |
@BeforeClass public static void setupBeforeClass() throws IOException { final ConnectionFactory cf = new ConnectionFactoryBuilder() .setProtocol(ConnectionFactoryBuilder.Protocol.TEXT) .setTranscoder(new WhalinTranscoder()) .setOpTimeout(1000) .build(); spyClient = new MemcachedClient(cf, Collections.singletonList(new InetSocketAddress("localhost", MEMCACHED_PORT))); }
Example #6
Source File: ApiMemcached.java From iaf with Apache License 2.0 | 5 votes |
public ApiMemcached() { AppConstants ac = AppConstants.getInstance(); String address = ac.getProperty("etag.cache.server", "localhost:11211"); String username = ac.getProperty("etag.cache.username", ""); String password = ac.getProperty("etag.cache.password", ""); int timeout = ac.getInt("etag.cache.timeout", 10); List<InetSocketAddress> addresses = AddrUtil.getAddresses(address); ConnectionFactoryBuilder connectionFactoryBuilder = new ConnectionFactoryBuilder() .setProtocol(Protocol.BINARY) .setOpTimeout(timeout) .setInitialObservers(Collections.singleton(obs)); if(addresses.size() > 1) connectionFactoryBuilder.setFailureMode(FailureMode.Redistribute); else connectionFactoryBuilder.setFailureMode(FailureMode.Retry); if(!username.isEmpty()) connectionFactoryBuilder.setAuthDescriptor(AuthDescriptor.typical(username, password)); ConnectionFactory cf = connectionFactoryBuilder.build(); try { client = new MemcachedClient(cf, addresses); //Fetching a none-existing key to test the connection Future<Object> future = client.asyncGet("test-connection"); future.get(timeout, TimeUnit.MILLISECONDS); } catch (Exception e) { ConfigurationWarnings.add(log, "Unable to connect to one or more memcached servers."); } }
Example #7
Source File: ConnectionFactoryBuilder.java From EVCache with Apache License 2.0 | 5 votes |
public ConnectionFactory getConnectionFactory(EVCacheClient client) { final String appName = client.getAppName(); final int maxQueueSize = EVCacheConfig.getInstance().getPropertyRepository().get(appName + ".max.queue.length", Integer.class).orElse(16384).get(); final Property<Integer> operationTimeout = EVCacheConfig.getInstance().getPropertyRepository().get(appName + ".operation.timeout", Integer.class).orElse(2500); final int opQueueMaxBlockTime = EVCacheConfig.getInstance().getPropertyRepository().get(appName + ".operation.QueueMaxBlockTime", Integer.class).orElse(10).get(); final boolean useBinary = EVCacheConfig.getInstance().getPropertyRepository().get("evcache.use.binary.protocol", Boolean.class).orElse(true).get(); if(useBinary) return new BaseConnectionFactory(client, maxQueueSize, operationTimeout, opQueueMaxBlockTime); else return new BaseAsciiConnectionFactory(client, maxQueueSize, operationTimeout, opQueueMaxBlockTime); }
Example #8
Source File: EVCacheAsciiNodeImpl.java From EVCache with Apache License 2.0 | 5 votes |
public EVCacheAsciiNodeImpl(SocketAddress sa, SocketChannel c, int bufSize, BlockingQueue<Operation> rq, BlockingQueue<Operation> wq, BlockingQueue<Operation> iq, long opQueueMaxBlockTimeMillis, boolean waitForAuth, long dt, long at, ConnectionFactory fa, EVCacheClient client, long stTime) { // ASCII never does auth super(sa, c, bufSize, rq, wq, iq, opQueueMaxBlockTimeMillis, false, dt, at, fa); this.client = client; final String appName = client.getAppName(); this.readQ = rq; this.inputQueue = iq; this.hostName = ((InetSocketAddress) getSocketAddress()).getHostName(); this.operationsCounter = client.getOperationCounter(); setConnectTime(stTime); setupMonitoring(appName); }
Example #9
Source File: DIConnectionFactoryBuilderProvider.java From EVCache with Apache License 2.0 | 5 votes |
@Override public ConnectionFactory getConnectionFactory(EVCacheClient client) { final String appName = client.getAppName(); if(useBinaryProtocol()) return new DIConnectionFactory(client, eurekaClient, getMaxQueueLength(appName), getOperationTimeout(appName), getOPQueueMaxBlockTime(appName)); else return new DIAsciiConnectionFactory(client, eurekaClient, getMaxQueueLength(appName), getOperationTimeout(appName), getOPQueueMaxBlockTime(appName)); }
Example #10
Source File: MemcachedConnectionFactory.java From kylin-on-parquet-v2 with Apache License 2.0 | 4 votes |
public MemcachedConnectionFactory(ConnectionFactory underlying) { this.underlying = underlying; }
Example #11
Source File: MemcachedConnectionFactory.java From kylin with Apache License 2.0 | 4 votes |
public MemcachedConnectionFactory(ConnectionFactory underlying) { this.underlying = underlying; }
Example #12
Source File: EVCacheClient.java From EVCache with Apache License 2.0 | 4 votes |
public ConnectionFactory getConnectionFactory() { return connectionFactory; }
Example #13
Source File: EVCacheClient.java From EVCache with Apache License 2.0 | 4 votes |
public ConnectionFactory getEVCacheConnectionFactory() { return this.connectionFactory; }
Example #14
Source File: IConnectionBuilder.java From EVCache with Apache License 2.0 | votes |
ConnectionFactory getConnectionFactory(EVCacheClient client);