public SocketAddress getSocketAddress() { return root.getSocketAddress(); }
public boolean isActive() { return root.isActive(); }
public int getBytesRemainingToWrite() { return root.getBytesRemainingToWrite(); }
protected void queueReconnect(MemcachedNode qa) { if (!shutDown) { getLogger().warn("Closing, and reopening %s, attempt %d.", qa, qa.getReconnectCount()); if (qa.getSk() != null) { qa.getSk().cancel(); assert !qa.getSk().isValid() : "Cancelled selection key is valid"; qa.reconnecting(); try { if (qa.getChannel() != null && qa.getChannel().socket() != null) { qa.getChannel().socket().close(); } else { getLogger().info("The channel or socket was null for %s", qa); getLogger().warn("IOException trying to close a socket", e); qa.setChannel(null); qa.getReconnectCount())) * 1000; long reconTime = System.currentTimeMillis() + delay; qa.setupResend(); redistributeOperations(qa.destroyInputQueue()); } else if (failureMode == FailureMode.Cancel) { cancelOperations(qa.destroyInputQueue());
private void connected(MemcachedNode qa) { assert qa.getChannel().isConnected() : "Not connected."; int rt = qa.getReconnectCount(); qa.connected(); for(ConnectionObserver observer : connObservers) { observer.connectionEstablished(qa.getSocketAddress(), rt); } }
private Collection<Operation> shutdownNode(MemcachedNode node) throws IOException{ Collection<Operation> notCompletedOperations = node.destroyInputQueue(); if (node.getChannel() != null) { node.getChannel().close(); node.setSk(null); if (node.getBytesRemainingToWrite() > 0) { getLogger().warn("Shut down with %d bytes remaining to write", node.getBytesRemainingToWrite()); } getLogger().debug("Shut down channel %s", node.getChannel()); } return notCompletedOperations; }
/** * Shut down all of the connections. */ public void shutdown() throws IOException { shutDown=true; Selector s=selector.wakeup(); assert s == selector : "Wakeup returned the wrong selector."; for(MemcachedNode qa : locator.getAll()) { if(qa.getChannel() != null) { qa.getChannel().close(); qa.setSk(null); if(qa.getBytesRemainingToWrite() > 0) { getLogger().warn( "Shut down with %d bytes remaining to write", qa.getBytesRemainingToWrite()); } getLogger().debug("Shut down channel %s", qa.getChannel()); } } selector.close(); getLogger().debug("Shut down selector %s", selector); }
private void handleWrites(SelectionKey sk, MemcachedNode qa) throws IOException { qa.fillWriteBuffer(shouldOptimize); boolean canWriteMore=qa.getBytesRemainingToWrite() > 0; while(canWriteMore) { int wrote=qa.writeSome(); qa.fillWriteBuffer(shouldOptimize); canWriteMore = wrote > 0 && qa.getBytesRemainingToWrite() > 0; } }
/** * Get the addresses of unavailable servers. * * <p> * This is based on a snapshot in time so shouldn't be considered * completely accurate, but is a useful for getting a feel for what's * working and what's not working. * </p> */ public Collection<SocketAddress> getUnavailableServers() { Collection<SocketAddress> rv=new ArrayList<SocketAddress>(); for(MemcachedNode node : conn.getLocator().getAll()) { if(!node.isActive()) { rv.add(node.getSocketAddress()); } } return rv; }
public boolean hasReadOp() { return root.hasReadOp(); }
public void addOperations(final Map<MemcachedNode, Operation> ops) { for (Map.Entry<MemcachedNode, Operation> me : ops.entrySet()) { final MemcachedNode node = me.getKey(); Operation o = me.getValue(); o.setHandlingNode(node); o.initialize(); node.addOp(o); addedQueue.offer(node); } Selector s = selector.wakeup(); assert s == selector : "Wakeup returned the wrong selector."; }
(ArcusReplNodeAddress) oldGroup.getMasterNode().getSocketAddress() : null; ArcusReplNodeAddress oldSlaveAddr = oldGroup.getSlaveNode() != null ? (ArcusReplNodeAddress) oldGroup.getSlaveNode().getSocketAddress() : null; assert (oldMasterAddr != null); } else { for (MemcachedNode node : locator.getAll()) { if (addrs.contains((InetSocketAddress) node.getSocketAddress())) { addrs.remove((InetSocketAddress) node.getSocketAddress()); } else { removeNodes.add(node); cancelOperations(node.destroyWriteQueue(false), cause); cancelOperations(node.destroyInputQueue(), cause); } else if (failureMode == FailureMode.Redistribute || failureMode == FailureMode.Retry) { redistributeOperations(node.destroyWriteQueue(true), cause); redistributeOperations(node.destroyInputQueue(), cause);
public int getSelectionOps() { return root.getSelectionOps(); }
public int getReconnectCount() { return root.getReconnectCount(); }
public void update(Collection<MemcachedNode> toAttach, Collection<MemcachedNode> toDelete) { lock.lock(); try { // Add memcached nodes. for (MemcachedNode node : toAttach) { allNodes.add(node); updateHash(node, false); } // Remove memcached nodes. for (MemcachedNode node : toDelete) { allNodes.remove(node); updateHash(node, true); try { node.getSk().attach(null); node.shutdown(); } catch (IOException e) { getLogger().error( "Failed to shutdown the node : " + node.toString()); node.setSk(null); } } } catch (RuntimeException e) { throw e; } finally { lock.unlock(); } }
ch.configureBlocking(false); MemcachedNode qa = connectionFactory.createMemcachedNode(sa, ch, bufSize); qa.setConnection(this); int ops = 0; ch.socket().setTcpNoDelay(!connectionFactory.useNagleAlgorithm()); qa.setSk(ch.register(selector, ops, qa)); assert ch.isConnected() || qa.getSk().interestOps() == SelectionKey.OP_CONNECT : "Not connected, and not wanting to connect"; } catch (SocketException e) {
MemcachedNode qa = this.connectionFactory.createMemcachedNode(sa, ch, bufSize); qa.setNodeEndPoint(endPoint); int ops = 0; ch.socket().setTcpNoDelay(!connectionFactory.useNagleAlgorithm()); qa.setSk(ch.register(selector, ops, qa)); assert ch.isConnected() || qa.getSk().interestOps() == SelectionKey.OP_CONNECT : "Not connected, and not wanting to connect"; } catch (SocketException e) {
private void queueReconnect(MemcachedNode qa) { if(!shutDown) { getLogger().warn("Closing, and reopening %s, attempt %d.", qa, qa.getReconnectCount()); if(qa.getSk() != null) { qa.getSk().cancel(); assert !qa.getSk().isValid() : "Cancelled selection key is valid"; qa.reconnecting(); try { if(qa.getChannel() != null && qa.getChannel().socket() != null) { qa.getChannel().socket().close(); } else { getLogger().info("The channel or socket was null for %s", getLogger().warn("IOException trying to close a socket", e); qa.setChannel(null); Math.pow(2, qa.getReconnectCount())) * 1000; long reconTime = System.currentTimeMillis() + delay; qa.setupResend(); redistributeOperations(qa.destroyInputQueue()); } else if(failureMode == FailureMode.Cancel) { cancelOperations(qa.destroyInputQueue());
private void connected(MemcachedNode qa) { assert qa.getChannel().isConnected() : "Not connected."; int rt = qa.getReconnectCount(); qa.connected(); for (ConnectionObserver observer : connObservers) { observer.connectionEstablished(qa.getSocketAddress(), rt); } }