net.spy.memcached.MemcachedNode Java Examples
The following examples show how to use
net.spy.memcached.MemcachedNode.
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: EVCacheClientPool.java From EVCache with Apache License 2.0 | 6 votes |
private void updateQueueStats() { for (ServerGroup serverGroup : memcachedInstancesByServerGroup.keySet()) { List<EVCacheClient> clients = memcachedInstancesByServerGroup.get(serverGroup); for(EVCacheClient client : clients) { getStatsGauge(EVCacheMetricsFactory.POOL_WRITE_Q_SIZE, client).set(Long.valueOf(client.getWriteQueueLength())); getStatsGauge(EVCacheMetricsFactory.POOL_READ_Q_SIZE, client).set(Long.valueOf(client.getReadQueueLength())); if(refreshConnectionOnReadQueueFull.get()) { final Collection<MemcachedNode> allNodes = client.getNodeLocator().getAll(); for (MemcachedNode node : allNodes) { if (node instanceof EVCacheNode) { final EVCacheNode evcNode = ((EVCacheNode) node); if(evcNode.getReadQueueSize() >= refreshConnectionOnReadQueueFullSize.get().intValue()) { EVCacheMetricsFactory.getInstance().getCounter(EVCacheMetricsFactory.POOL_REFRESH_QUEUE_FULL, evcNode.getTags()).increment(); client.getEVCacheMemcachedClient().reconnectNode(evcNode); } } } } } } }
Example #2
Source File: EVCacheClient.java From EVCache with Apache License 2.0 | 6 votes |
public <T> Future<Boolean> appendOrAdd(String key, CachedData value, int timeToLive, EVCacheLatch evcacheLatch) throws Exception { final MemcachedNode node = evcacheMemcachedClient.getEVCacheNode(key); if (!ensureWriteQueueSize(node, key, Call.APPEND_OR_ADD)) { if (log.isInfoEnabled()) log.info("Node : " + node + " is not active. Failing fast and dropping the write event."); final ListenableFuture<Boolean, OperationCompletionListener> defaultFuture = (ListenableFuture<Boolean, OperationCompletionListener>) getDefaultFuture(); if (evcacheLatch != null && evcacheLatch instanceof EVCacheLatchImpl && !isInWriteOnly()) ((EVCacheLatchImpl) evcacheLatch).addFuture(defaultFuture); return defaultFuture; } try { return evcacheMemcachedClient.asyncAppendOrAdd(key, timeToLive, value, evcacheLatch); } catch (Exception e) { log.error(e.getMessage(), e); throw e; } }
Example #3
Source File: ApiInterceptor.java From pinpoint with Apache License 2.0 | 6 votes |
private String getEndPoint(MemcachedNode handlingNode) { // TODO duplicated code : ApiInterceptor, FutureGetInterceptor final SocketAddress socketAddress = handlingNode.getSocketAddress(); if (socketAddress instanceof InetSocketAddress) { final InetSocketAddress inetSocketAddress = (InetSocketAddress) socketAddress; final String hostAddress = getHostAddress(inetSocketAddress); if (hostAddress == null) { // TODO return "Unknown Host"; ? logger.debug("hostAddress is null"); return null; } return HostAndPort.toHostAndPortString(hostAddress, inetSocketAddress.getPort()); } else { if (logger.isDebugEnabled()) { logger.debug("invalid socketAddress:{}", socketAddress); } return null; } }
Example #4
Source File: FutureGetInterceptor.java From pinpoint with Apache License 2.0 | 6 votes |
private String getEndPoint(MemcachedNode handlingNode) { // TODO duplicated code : ApiInterceptor, FutureGetInterceptor final SocketAddress socketAddress = handlingNode.getSocketAddress(); if (socketAddress instanceof InetSocketAddress) { final InetSocketAddress inetSocketAddress = (InetSocketAddress) socketAddress; final String hostAddress = getHostAddress(inetSocketAddress); if (hostAddress == null) { // TODO return "Unknown Host"; logger.debug("hostAddress is null"); return null; } return HostAndPort.toHostAndPortString(hostAddress, inetSocketAddress.getPort()); } else { if (logger.isDebugEnabled()) { logger.debug("invalid socketAddress:{}", socketAddress); } return null; } }
Example #5
Source File: EVCacheNodeLocator.java From EVCache with Apache License 2.0 | 6 votes |
/** * Create a new KetamaNodeLocator using specified nodes and the specifed * hash algorithm and configuration. * * @param nodes * The List of nodes to use in the Ketama consistent hash * continuum * @param alg * The hash algorithm to use when choosing a node in the Ketama * consistent hash continuum * @param conf */ public EVCacheNodeLocator(EVCacheClient client, List<MemcachedNode> nodes, HashAlgorithm alg, KetamaNodeLocatorConfiguration conf) { super(); this.allNodes = nodes; this.hashingAlgorithm = alg; this.config = conf; this.client = client; this.partialStringHash = EVCacheConfig.getInstance().getPropertyRepository().get(client.getAppName() + "." + client.getServerGroupName() + ".hash.on.partial.key", Boolean.class) .orElseGet(client.getAppName()+ ".hash.on.partial.key").orElse(false); this.hashDelimiter = EVCacheConfig.getInstance().getPropertyRepository().get(client.getAppName() + "." + client.getServerGroupName() + ".hash.delimiter", String.class) .orElseGet(client.getAppName() + ".hash.delimiter").orElse(":"); setKetamaNodes(nodes); }
Example #6
Source File: EVCacheNodeLocator.java From EVCache with Apache License 2.0 | 6 votes |
public MemcachedNode getNodeForKey(long _hash) { long start = (log.isDebugEnabled()) ? System.nanoTime() : 0; try { Long hash = Long.valueOf(_hash); hash = ketamaNodes.ceilingKey(hash); if (hash == null) { hash = ketamaNodes.firstKey(); } return ketamaNodes.get(hash); } finally { if (log.isDebugEnabled()) { final long end = System.nanoTime(); log.debug("getNodeForKey : \t" + (end - start) / 1000); } } }
Example #7
Source File: EVCacheKetamaNodeLocatorConfiguration.java From EVCache with Apache License 2.0 | 6 votes |
/** * Returns the socket address of a given MemcachedNode. * * @param node - The MemcachedNode which we're interested in * @return The socket address of the given node format is of the following * For ec2 classic instances - "publicHostname/privateIp:port" (ex - ec2-174-129-159-31.compute-1.amazonaws.com/10.125.47.114:11211) * For ec2 vpc instances - "privateIp/privateIp:port" (ex - 10.125.47.114/10.125.47.114:11211) * privateIp is also known as local ip */ @Override public String getKeyForNode(MemcachedNode node, int repetition) { String result = socketAddresses.get(node); if(result == null) { final SocketAddress socketAddress = node.getSocketAddress(); if(socketAddress instanceof InetSocketAddress) { final InetSocketAddress isa = (InetSocketAddress)socketAddress; result = isa.getHostName() + '/' + isa.getAddress().getHostAddress() + ":11211"; } else { result=String.valueOf(socketAddress); if (result.startsWith("/")) { result = result.substring(1); } } socketAddresses.put(node, result); } return result + "-" + repetition; }
Example #8
Source File: EVCacheClient.java From EVCache with Apache License 2.0 | 5 votes |
public <T> Future<Boolean> touch(String key, int timeToLive, EVCacheLatch latch) throws Exception { if(ignoreTouch.get()) { final ListenableFuture<Boolean, OperationCompletionListener> sf = new SuccessFuture(); if (latch != null && latch instanceof EVCacheLatchImpl && !isInWriteOnly()) ((EVCacheLatchImpl) latch).addFuture(sf); return sf; } final MemcachedNode node = evcacheMemcachedClient.getEVCacheNode(key); if (!ensureWriteQueueSize(node, key, Call.TOUCH)) { final ListenableFuture<Boolean, OperationCompletionListener> defaultFuture = (ListenableFuture<Boolean, OperationCompletionListener>) getDefaultFuture(); if (latch != null && latch instanceof EVCacheLatchImpl && !isInWriteOnly()) ((EVCacheLatchImpl) latch).addFuture(defaultFuture); return defaultFuture; } if (enableChunking.get()) { final ChunkDetails<?> cd = getChunkDetails(key); if (cd.isChunked()) { final List<String> keys = cd.getChunkKeys(); OperationFuture<Boolean>[] futures = new OperationFuture[keys.size() + 1]; futures[0] = evcacheMemcachedClient.touch(key + "_00", timeToLive, latch); for (int i = 0; i < keys.size(); i++) { final String prefix = (i < 10) ? "0" : ""; final String _key = key + "_" + prefix + i; futures[i + 1] = evcacheMemcachedClient.touch(_key, timeToLive, latch); } return new EVCacheFutures(futures, key, appName, serverGroup, latch); } else { return evcacheMemcachedClient.touch(key, timeToLive, latch); } } else if(shouldHashKey()) { final String hKey = getHashedKey(key); return evcacheMemcachedClient.touch(hKey, timeToLive, latch); } else { return evcacheMemcachedClient.touch(key, timeToLive, latch); } }
Example #9
Source File: EVCacheClient.java From EVCache with Apache License 2.0 | 5 votes |
private Future<Boolean> _add(String key, int exp, CachedData value, EVCacheLatch latch) throws Exception { if (enableChunking.get()) throw new EVCacheException("This operation is not supported as chunking is enabled on this EVCacheClient."); final MemcachedNode node = evcacheMemcachedClient.getEVCacheNode(key); if (!ensureWriteQueueSize(node, key, Call.ADD)) return getDefaultFuture(); if(shouldHashKey()) { final String hKey = getHashedKey(key); final CachedData cVal = getEVCacheValue(key, value, exp); return evcacheMemcachedClient.add(hKey, exp, cVal, null, latch); } else { return evcacheMemcachedClient.add(key, exp, value, null, latch); } }
Example #10
Source File: EVCacheClient.java From EVCache with Apache License 2.0 | 5 votes |
private Future<Boolean> _replace(String key, CachedData value, int timeToLive, EVCacheLatch evcacheLatch) throws Exception { final MemcachedNode node = evcacheMemcachedClient.getEVCacheNode(key); if (!ensureWriteQueueSize(node, key, Call.REPLACE)) { if (log.isInfoEnabled()) log.info("Node : " + node + " is not active. Failing fast and dropping the replace event."); final ListenableFuture<Boolean, OperationCompletionListener> defaultFuture = (ListenableFuture<Boolean, OperationCompletionListener>) getDefaultFuture(); if (evcacheLatch != null && evcacheLatch instanceof EVCacheLatchImpl && !isInWriteOnly()) ((EVCacheLatchImpl) evcacheLatch).addFuture(defaultFuture); return defaultFuture; } try { final int dataSize = ((CachedData) value).getData().length; if (enableChunking.get() && dataSize > chunkSize.get()) { final CachedData[] cd = createChunks(value, key); final int len = cd.length; final OperationFuture<Boolean>[] futures = new OperationFuture[len]; for (int i = 0; i < cd.length; i++) { final String prefix = (i < 10) ? "0" : ""; futures[i] = evcacheMemcachedClient.replace(key + "_" + prefix + i, timeToLive, cd[i], null, null); } return new EVCacheFutures(futures, key, appName, serverGroup, evcacheLatch); } else if(shouldHashKey()) { final String hKey = getHashedKey(key); final CachedData cVal = getEVCacheValue(key, value, timeToLive); return evcacheMemcachedClient.replace(hKey, timeToLive, cVal, null, evcacheLatch); } else { return evcacheMemcachedClient.replace(key, timeToLive, value, null, evcacheLatch); } } catch (Exception e) { log.error(e.getMessage(), e); throw e; } }
Example #11
Source File: EVCacheClientPool.java From EVCache with Apache License 2.0 | 5 votes |
public void refreshAsync(MemcachedNode node) { if (log.isInfoEnabled()) log.info("Pool is being refresh as the EVCacheNode is not available. " + node.toString()); if(!_disableAsyncRefresh.get()) { if (node instanceof EVCacheNode) { final EVCacheNode evcNode = ((EVCacheNode) node); EVCacheMetricsFactory.getInstance().getCounter(EVCacheMetricsFactory.POOL_REFRESH_ASYNC, evcNode.getTags()).increment(); } boolean force = (System.currentTimeMillis() - lastReconcileTime) > ( manager.getDefaultRefreshInterval().get() * 1000 ) ? true : false; if(!force) force = !node.isActive(); refreshPool(true, force); } if (duetClientPool != null) duetClientPool.refreshAsync(node); }
Example #12
Source File: EVCacheClient.java From EVCache with Apache License 2.0 | 5 votes |
public <T> Future<Boolean> append(String key, T value) throws Exception { if (enableChunking.get()) throw new EVCacheException( "This operation is not supported as chunking is enabled on this EVCacheClient."); final MemcachedNode node = evcacheMemcachedClient.getEVCacheNode(key); if (!ensureWriteQueueSize(node, key, Call.APPEND)) return getDefaultFuture(); if(shouldHashKey()) { final String hKey = getHashedKey(key); return evcacheMemcachedClient.append(hKey, value); } else { return evcacheMemcachedClient.append(key, value); } }
Example #13
Source File: EVCacheClient.java From EVCache with Apache License 2.0 | 5 votes |
private boolean validateNode(String key, boolean _throwException, EVCache.Call call) throws EVCacheException, EVCacheConnectException { final MemcachedNode node = evcacheMemcachedClient.getEVCacheNode(key); // First check if the node is active if (node instanceof EVCacheNode) { final EVCacheNode evcNode = (EVCacheNode) node; final String hostName; if(evcNode.getSocketAddress() instanceof InetSocketAddress) { hostName = ((InetSocketAddress)evcNode.getSocketAddress()).getHostName(); } else { hostName = evcNode.getSocketAddress().toString(); } if (!evcNode.isAvailable(call)) { incrementFailure(EVCacheMetricsFactory.INACTIVE_NODE, call, hostName); if (log.isDebugEnabled()) log.debug("Node : " + node + " for app : " + appName + "; zone : " + zone + " is not active. Will Fail Fast so that we can fallback to Other Zone if available."); if (_throwException) throw new EVCacheConnectException("Connection for Node : " + node + " for app : " + appName + "; zone : " + zone + " is not active"); return false; } final int size = evcNode.getReadQueueSize(); final boolean canAddToOpQueue = size < maxReadQueueSize.get(); if (log.isDebugEnabled()) log.debug("Current Read Queue Size - " + size + " for app " + appName + " & zone " + zone + " and node : " + evcNode); if (!canAddToOpQueue) { incrementFailure(EVCacheMetricsFactory.READ_QUEUE_FULL, call, hostName); if (log.isDebugEnabled()) log.debug("Read Queue Full for Node : " + node + "; app : " + appName + "; zone : " + zone + "; Current Size : " + size + "; Max Size : " + maxReadQueueSize.get()); if (_throwException) throw new EVCacheReadQueueException("Read Queue Full for Node : " + node + "; app : " + appName + "; zone : " + zone + "; Current Size : " + size + "; Max Size : " + maxReadQueueSize.get()); return false; } } return true; }
Example #14
Source File: EVCacheClient.java From EVCache with Apache License 2.0 | 5 votes |
private boolean ensureWriteQueueSize(MemcachedNode node, String key, EVCache.Call call) throws EVCacheException { if (node instanceof EVCacheNode) { final EVCacheNode evcNode = (EVCacheNode) node; int i = 0; while (true) { final int size = evcNode.getWriteQueueSize(); final boolean canAddToOpQueue = size < maxWriteQueueSize; if (log.isDebugEnabled()) log.debug("App : " + appName + "; zone : " + zone + "; key : " + key + "; WriteQSize : " + size); if (canAddToOpQueue) break; try { Thread.sleep(writeBlock.get()); } catch (InterruptedException e) { throw new EVCacheException("Thread was Interrupted", e); } if(i++ > 3) { final String hostName; if(evcNode.getSocketAddress() instanceof InetSocketAddress) { hostName = ((InetSocketAddress)evcNode.getSocketAddress()).getHostName(); } else { hostName = evcNode.getSocketAddress().toString(); } incrementFailure(EVCacheMetricsFactory.INACTIVE_NODE, call, hostName); if (log.isDebugEnabled()) log.debug("Node : " + evcNode + " for app : " + appName + "; zone : " + zone + " is not active. Will Fail Fast and the write will be dropped for key : " + key); evcNode.shutdown(); return false; } } } return true; }
Example #15
Source File: EVCacheNodeLocator.java From EVCache with Apache License 2.0 | 5 votes |
/** * Setup the KetamaNodeLocator with the list of nodes it should use. * * @param nodes * a List of MemcachedNodes for this KetamaNodeLocator to use in * its continuum */ protected final void setKetamaNodes(List<MemcachedNode> nodes) { TreeMap<Long, MemcachedNode> newNodeMap = new TreeMap<Long, MemcachedNode>(); final int numReps = config.getNodeRepetitions(); for (MemcachedNode node : nodes) { // Ketama does some special work with md5 where it reuses chunks. if (hashingAlgorithm == DefaultHashAlgorithm.KETAMA_HASH) { for (int i = 0; i < numReps / 4; i++) { final String hashString = config.getKeyForNode(node, i); byte[] digest = DefaultHashAlgorithm.computeMd5(hashString); if (log.isDebugEnabled()) log.debug("digest : " + digest); for (int h = 0; h < 4; h++) { long k = ((long) (digest[3 + h * 4] & 0xFF) << 24) | ((long) (digest[2 + h * 4] & 0xFF) << 16) | ((long) (digest[1 + h * 4] & 0xFF) << 8) | (digest[h * 4] & 0xFF); newNodeMap.put(Long.valueOf(k), node); if (log.isDebugEnabled()) log.debug("Key : " + hashString + " ; hash : " + k + "; node " + node ); } } } else { for (int i = 0; i < numReps; i++) { final Long hashL = Long.valueOf(hashingAlgorithm.hash(config.getKeyForNode(node, i))); newNodeMap.put(hashL, node); } } } if (log.isDebugEnabled()) log.debug("NewNodeMapSize : " + newNodeMap.size() + "; MapSize : " + (numReps * nodes.size())); if (log.isTraceEnabled()) { for(Long key : newNodeMap.keySet()) { log.trace("Hash : " + key + "; Node : " + newNodeMap.get(key)); } } ketamaNodes = newNodeMap; }
Example #16
Source File: EVCacheClient.java From EVCache with Apache License 2.0 | 5 votes |
public Future<Boolean> delete(String key, EVCacheLatch latch) throws Exception { final MemcachedNode node = evcacheMemcachedClient.getEVCacheNode(key); if (!ensureWriteQueueSize(node, key, Call.DELETE)) { final ListenableFuture<Boolean, OperationCompletionListener> defaultFuture = (ListenableFuture<Boolean, OperationCompletionListener>) getDefaultFuture(); if (latch != null && latch instanceof EVCacheLatchImpl && !isInWriteOnly()) ((EVCacheLatchImpl) latch).addFuture(defaultFuture); return defaultFuture; } if (enableChunking.get()) { final ChunkDetails<?> cd = getChunkDetails(key); if (cd == null) { // Paranoid delete : cases where get fails and we ensure the first key is deleted just in case return evcacheMemcachedClient.delete(key + "_00", latch); } if (!cd.isChunked()) { return evcacheMemcachedClient.delete(key, latch); } else { final List<String> keys = cd.getChunkKeys(); OperationFuture<Boolean>[] futures = new OperationFuture[keys.size() + 1]; futures[0] = evcacheMemcachedClient.delete(key + "_00"); for (int i = 0; i < keys.size(); i++) { futures[i + 1] = evcacheMemcachedClient.delete(keys.get(i), null); } return new EVCacheFutures(futures, key, appName, serverGroup, latch); } } else if(shouldHashKey()) { final String hKey = getHashedKey(key); return evcacheMemcachedClient.delete(hKey, latch); } else { return evcacheMemcachedClient.delete(key, latch); } }
Example #17
Source File: BaseConnectionFactory.java From EVCache with Apache License 2.0 | 5 votes |
public MemcachedNode createMemcachedNode(SocketAddress sa, SocketChannel c, int bufSize) { boolean doAuth = false; final EVCacheNodeImpl node = new EVCacheNodeImpl(sa, c, bufSize, createReadOperationQueue(), createWriteOperationQueue(), createOperationQueue(), opMaxBlockTime, doAuth, getOperationTimeout(), getAuthWaitTime(), this, client, startTime); node.registerMonitors(); return node; }
Example #18
Source File: EVCacheNodeLocator.java From EVCache with Apache License 2.0 | 5 votes |
public NodeLocator getReadonlyCopy() { final TreeMap<Long, MemcachedNode> ketamaNaodes = new TreeMap<Long, MemcachedNode>(getKetamaNodes()); final Collection<MemcachedNode> aNodes = new ArrayList<MemcachedNode>(allNodes.size()); // Rewrite the values a copy of the map. for (Map.Entry<Long, MemcachedNode> me : ketamaNaodes.entrySet()) { me.setValue(new EVCacheMemcachedNodeROImpl(me.getValue())); } // Copy the allNodes collection. for (MemcachedNode n : allNodes) { aNodes.add(new EVCacheMemcachedNodeROImpl(n)); } return new EVCacheNodeLocator(client, ketamaNaodes, aNodes, hashingAlgorithm, config); }
Example #19
Source File: EVCacheClient.java From EVCache with Apache License 2.0 | 5 votes |
public int getWriteQueueLength() { final Collection<MemcachedNode> allNodes = evcacheMemcachedClient.getNodeLocator().getAll(); int size = 0; for(MemcachedNode node : allNodes) { if(node instanceof EVCacheNode) { size += ((EVCacheNode)node).getWriteQueueSize(); } } return size; }
Example #20
Source File: BaseAsciiConnectionFactory.java From EVCache with Apache License 2.0 | 5 votes |
public MemcachedNode createMemcachedNode(SocketAddress sa, SocketChannel c, int bufSize) { boolean doAuth = false; final EVCacheAsciiNodeImpl node = new EVCacheAsciiNodeImpl(sa, c, bufSize, createReadOperationQueue(), createWriteOperationQueue(), createOperationQueue(), opMaxBlockTime, doAuth, getOperationTimeout(), getAuthWaitTime(), this, client, startTime); node.registerMonitors(); return node; }
Example #21
Source File: EVCacheNodeLocator.java From EVCache with Apache License 2.0 | 5 votes |
private EVCacheNodeLocator(EVCacheClient client, TreeMap<Long, MemcachedNode> smn, Collection<MemcachedNode> an, HashAlgorithm alg, KetamaNodeLocatorConfiguration conf) { super(); this.ketamaNodes = smn; this.allNodes = an; this.hashingAlgorithm = alg; this.config = conf; this.client = client; this.partialStringHash = EVCacheConfig.getInstance().getPropertyRepository().get(client.getAppName() + "." + client.getServerGroupName() + ".hash.on.partial.key", Boolean.class) .orElseGet(client.getAppName()+ ".hash.on.partial.key").orElse(false); this.hashDelimiter = EVCacheConfig.getInstance().getPropertyRepository().get(client.getAppName() + "." + client.getServerGroupName() + ".hash.delimiter", String.class) .orElseGet(client.getAppName() + ".hash.delimiter").orElse(":"); }
Example #22
Source File: FutureGetInterceptor.java From pinpoint with Apache License 2.0 | 5 votes |
@Override protected void doInAfterTrace(SpanEventRecorder recorder, Object target, Object[] args, Object result, Throwable throwable) { recorder.recordApi(methodDescriptor); recorder.recordDestinationId("MEMCACHED"); recorder.recordServiceType(ArcusConstants.MEMCACHED_FUTURE_GET); if (!(target instanceof OperationAccessor)) { logger.info("operation not found"); return; } // find the target node final Operation op = ((OperationAccessor) target)._$PINPOINT$_getOperation(); if (op == null) { logger.info("operation is null"); return; } recorder.recordException(op.getException()); final MemcachedNode handlingNode = op.getHandlingNode(); if (handlingNode != null) { final String endPoint = getEndPoint(handlingNode); if (endPoint != null) { recorder.recordEndPoint(endPoint); } recorder.recordException(op.getException()); } else { logger.info("no handling node"); } if (op instanceof ServiceCodeAccessor) { // determine the service type String serviceCode = ((ServiceCodeAccessor) op)._$PINPOINT$_getServiceCode(); if (serviceCode != null) { recorder.recordDestinationId(serviceCode); recorder.recordServiceType(ArcusConstants.ARCUS_FUTURE_GET); } } }
Example #23
Source File: EVCacheEvent.java From EVCache with Apache License 2.0 | 5 votes |
public Collection<MemcachedNode> getMemcachedNode(EVCacheKey evckey) { final Collection<MemcachedNode> nodeList = new ArrayList<MemcachedNode>(clients.size()); for(EVCacheClient client : clients) { String key = evckey.getDerivedKey(client.isDuetClient()); nodeList.add(client.getNodeLocator().getPrimary(key)); } return nodeList; }
Example #24
Source File: DIEVCacheKetamaNodeLocatorConfiguration.java From EVCache with Apache License 2.0 | 5 votes |
/** * Returns the socket address of a given MemcachedNode. * * @param node - The MemcachedNode which we're interested in * @return The socket address of the given node format is of the following * format "publicHostname/privateIp:port" (ex - ec2-174-129-159-31.compute-1.amazonaws.com/10.125.47.114:11211) */ @Override public String getKeyForNode(MemcachedNode node, int repetition) { String result = socketAddresses.get(node); if(result == null) { final SocketAddress socketAddress = node.getSocketAddress(); if(socketAddress instanceof InetSocketAddress) { final InetSocketAddress isa = (InetSocketAddress)socketAddress; if(eurekaClient != null ) { final Application app = eurekaClient.getApplication(client.getAppName()); if(app != null) { final List<InstanceInfo> instances = app.getInstances(); for(InstanceInfo info : instances) { final String hostName = info.getHostName(); if(hostName.equalsIgnoreCase(isa.getHostName())) { final String ip = info.getIPAddr(); result = hostName + '/' + ip + ":11211"; break; } } } else { result = ((InetSocketAddress)socketAddress).getHostName() + '/' + ((InetSocketAddress)socketAddress).getAddress().getHostAddress() + ":11211"; } } else { result = isa.getHostName() + '/' + isa.getAddress().getHostAddress() + ":11211"; } } else { result=String.valueOf(socketAddress); if (result.startsWith("/")) { result = result.substring(1); } } socketAddresses.put(node, result); } if(log.isDebugEnabled()) log.debug("Returning : " + (result + "-" + repetition)); return result + "-" + repetition; }
Example #25
Source File: EVCacheClient.java From EVCache with Apache License 2.0 | 5 votes |
public int getReadQueueLength() { final Collection<MemcachedNode> allNodes = evcacheMemcachedClient.getNodeLocator().getAll(); int size = 0; for(MemcachedNode node : allNodes) { if(node instanceof EVCacheNode) { size += ((EVCacheNode)node).getReadQueueSize(); } } return size; }
Example #26
Source File: BaseConnectionFactory.java From EVCache with Apache License 2.0 | 4 votes |
public NodeLocator createLocator(List<MemcachedNode> list) { this.locator = new EVCacheNodeLocator(client, list, DefaultHashAlgorithm.KETAMA_HASH, new EVCacheKetamaNodeLocatorConfiguration(client)); return locator; }
Example #27
Source File: DIAsciiConnectionFactory.java From EVCache with Apache License 2.0 | 4 votes |
@Override public NodeLocator createLocator(List<MemcachedNode> list) { this.locator = new EVCacheNodeLocator(client, list, DefaultHashAlgorithm.KETAMA_HASH, new DIEVCacheKetamaNodeLocatorConfiguration(client, eurekaClient)); return locator; }
Example #28
Source File: BaseAsciiConnectionFactory.java From EVCache with Apache License 2.0 | 4 votes |
public NodeLocator createLocator(List<MemcachedNode> list) { this.locator = new EVCacheNodeLocator(client, list, DefaultHashAlgorithm.KETAMA_HASH, new EVCacheKetamaNodeLocatorConfiguration(client)); return locator; }
Example #29
Source File: DIConnectionFactory.java From EVCache with Apache License 2.0 | 4 votes |
@Override public NodeLocator createLocator(List<MemcachedNode> list) { this.locator = new EVCacheNodeLocator(client, list, DefaultHashAlgorithm.KETAMA_HASH, new DIEVCacheKetamaNodeLocatorConfiguration(client, eurekaClient)); return locator; }
Example #30
Source File: MemcachedConnectionFactory.java From kylin-on-parquet-v2 with Apache License 2.0 | 4 votes |
@Override public MemcachedNode createMemcachedNode(SocketAddress sa, SocketChannel c, int bufSize) { return underlying.createMemcachedNode(sa, c, bufSize); }