protected MemcachedConnector newConnector(BufferAllocator bufferAllocator, Configuration configuration, MemcachedSessionLocator memcachedSessionLocator, CommandFactory commandFactory, int poolSize, int maxQueuedNoReplyOperations) { // make sure dispatch message thread count is zero configuration.setDispatchMessageThreadCount(0); return new MemcachedConnector(configuration, memcachedSessionLocator, bufferAllocator, commandFactory, poolSize, maxQueuedNoReplyOperations); }
public synchronized void addSession(Session session) { MemcachedSession tcpSession = (MemcachedSession) session; InetSocketAddressWrapper addrWrapper = tcpSession.getInetSocketAddressWrapper(); // Remember the first time address resolved and use it in all // application lifecycle. if (addrWrapper.getRemoteAddressStr() == null) { addrWrapper.setRemoteAddressStr(String.valueOf(session.getRemoteSocketAddress())); } InetSocketAddress mainNodeAddress = addrWrapper.getMainNodeAddress(); if (mainNodeAddress != null) { // It is a standby session this.addStandbySession(session, mainNodeAddress, addrWrapper.getResolvedMainNodeSocketAddress(), addrWrapper); } else { // It is a main session this.addMainSession(session, addrWrapper.getResolvedSocketAddress(), addrWrapper); // Update main sessions this.updateSessions(); } }
public Future<Boolean> connect(InetSocketAddressWrapper addressWrapper) { if (addressWrapper == null) { throw new NullPointerException("Null Address"); } // Remove addr from removed set this.removedAddrSet.remove(addressWrapper.getInetSocketAddress()); SocketChannel socketChannel = null; ConnectFuture future = new ConnectFuture(addressWrapper); try { socketChannel = SocketChannel.open(); this.configureSocketChannel(socketChannel); if (!socketChannel.connect(addressWrapper.getInetSocketAddress())) { this.selectorManager.registerChannel(socketChannel, SelectionKey.OP_CONNECT, future); } else { this.addSession(this.createSession(socketChannel, addressWrapper)); future.setResult(true); } } catch (Exception e) { if (socketChannel != null) { try { socketChannel.close(); } catch (IOException e1) { //propagate original exception } } future.failure(e); } return future; }
@Override protected NioSession buildSession(SocketChannel sc) { Queue<WriteMessage> queue = this.buildQueue(); final NioSessionConfig sessionCofig = this.buildSessionConfig(sc, queue); MemcachedTCPSession session = new MemcachedTCPSession(sessionCofig, this.configuration.getSessionReadBufferSize(), this.optimiezer, this.getReadThreadCount(), this.commandFactory); session.setBufferAllocator(this.bufferAllocator); return session; }
public MemcachedConnector(Configuration configuration, MemcachedSessionLocator locator, BufferAllocator allocator, CommandFactory commandFactory, int poolSize, int maxQueuedNoReplyOperations) { super(configuration, null); this.sessionLocator = locator; this.protocol = commandFactory.getProtocol(); this.addStateListener(new InnerControllerStateListener()); this.updateSessions(); this.bufferAllocator = allocator; this.optimiezer = new Optimizer(this.protocol); this.optimiezer.setBufferAllocator(this.bufferAllocator); this.connectionPoolSize = poolSize; this.soLingerOn = true; this.commandFactory = commandFactory; this.flowControl = new FlowControl(maxQueuedNoReplyOperations); this.setSelectorPoolSize(configuration.getSelectorPoolSize()); // setDispatchMessageThreadPoolSize(Runtime.getRuntime(). // availableProcessors()); }
ConnectFuture future = (ConnectFuture) key.attachment(); if (future == null || future.isCancelled()) { this.cancelKey(key); return; this.cancelKey(key); future .failure(new IOException("Connect to " } else { key.attach(null); this.addSession(this.createSession((SocketChannel) key.channel(), future.getInetSocketAddressWrapper())); future.setResult(Boolean.TRUE); this.cancelKey(key); throw new IOException("Connect to " + SystemUtils.getRawAddress(future.getInetSocketAddressWrapper().getInetSocketAddress())
Throwable throwable = null; try { future = this.connector.connect(inetSocketAddressWrapper); this.connector.addSession(new ClosedMemcachedTCPSession(inetSocketAddressWrapper)); this.connector.addToWatingQueue( new ReconnectRequest(inetSocketAddressWrapper, 0, this.getHealSessionInterval())); log.error("Connect to " + SystemUtils.getRawAddress(inetSocketAddress) + ":"
public void addStateListener(MemcachedClientStateListener listener) { MemcachedClientStateListenerAdapter adapter = new MemcachedClientStateListenerAdapter(listener, this); this.stateListenerAdapters.add(adapter); this.connector.addStateListener(adapter); }
protected MemcachedTCPSession createSession(SocketChannel socketChannel, InetSocketAddressWrapper wrapper) { MemcachedTCPSession session = (MemcachedTCPSession) this.buildSession(socketChannel); session.setInetSocketAddressWrapper(wrapper); this.selectorManager.registerSession(session, EventType.ENABLE_READ); session.start(); session.onEvent(EventType.CONNECTED, null); return session; }
@Override protected NioSession buildSession(SocketChannel sc) { Queue<WriteMessage> queue = this.buildQueue(); final NioSessionConfig sessionCofig = this.buildSessionConfig(sc, queue); MemcachedTCPSession session = new MemcachedTCPSession(sessionCofig, this.configuration.getSessionReadBufferSize(), this.optimiezer, this.getReadThreadCount(), this.commandFactory); session.setBufferAllocator(this.bufferAllocator); return session; }
public MemcachedConnector(Configuration configuration, MemcachedSessionLocator locator, BufferAllocator allocator, CommandFactory commandFactory, int poolSize, int maxQueuedNoReplyOperations) { super(configuration, null); this.sessionLocator = locator; this.protocol = commandFactory.getProtocol(); this.addStateListener(new InnerControllerStateListener()); this.updateSessions(); this.bufferAllocator = allocator; this.optimiezer = new Optimizer(this.protocol); this.optimiezer.setBufferAllocator(this.bufferAllocator); this.connectionPoolSize = poolSize; this.soLingerOn = true; this.commandFactory = commandFactory; this.flowControl = new FlowControl(maxQueuedNoReplyOperations); this.setSelectorPoolSize(configuration.getSelectorPoolSize()); // setDispatchMessageThreadPoolSize(Runtime.getRuntime(). // availableProcessors()); }
ConnectFuture future = (ConnectFuture) key.attachment(); if (future == null || future.isCancelled()) { this.cancelKey(key); return; this.cancelKey(key); future .failure(new IOException("Connect to " } else { key.attach(null); this.addSession(this.createSession((SocketChannel) key.channel(), future.getInetSocketAddressWrapper())); future.setResult(Boolean.TRUE); this.cancelKey(key); throw new IOException("Connect to " + SystemUtils.getRawAddress(future.getInetSocketAddressWrapper().getInetSocketAddress())
Throwable throwable = null; try { future = this.connector.connect(inetSocketAddressWrapper); this.connector.addSession(new ClosedMemcachedTCPSession(inetSocketAddressWrapper)); this.connector.addToWatingQueue( new ReconnectRequest(inetSocketAddressWrapper, 0, this.getHealSessionInterval())); log.error("Connect to " + SystemUtils.getRawAddress(inetSocketAddress) + ":"
public void addStateListener(MemcachedClientStateListener listener) { MemcachedClientStateListenerAdapter adapter = new MemcachedClientStateListenerAdapter(listener, this); this.stateListenerAdapters.add(adapter); this.connector.addStateListener(adapter); }
protected MemcachedTCPSession createSession(SocketChannel socketChannel, InetSocketAddressWrapper wrapper) { MemcachedTCPSession session = (MemcachedTCPSession) this.buildSession(socketChannel); session.setInetSocketAddressWrapper(wrapper); this.selectorManager.registerSession(session, EventType.ENABLE_READ); session.start(); session.onEvent(EventType.CONNECTED, null); return session; }
public synchronized void addSession(Session session) { MemcachedSession tcpSession = (MemcachedSession) session; InetSocketAddressWrapper addrWrapper = tcpSession.getInetSocketAddressWrapper(); // Remember the first time address resolved and use it in all // application lifecycle. if (addrWrapper.getRemoteAddressStr() == null) { addrWrapper.setRemoteAddressStr(String.valueOf(session.getRemoteSocketAddress())); } InetSocketAddress mainNodeAddress = addrWrapper.getMainNodeAddress(); if (mainNodeAddress != null) { // It is a standby session this.addStandbySession(session, mainNodeAddress, addrWrapper.getResolvedMainNodeSocketAddress(), addrWrapper); } else { // It is a main session this.addMainSession(session, addrWrapper.getResolvedSocketAddress(), addrWrapper); // Update main sessions this.updateSessions(); } }
public Future<Boolean> connect(InetSocketAddressWrapper addressWrapper) { if (addressWrapper == null) { throw new NullPointerException("Null Address"); } // Remove addr from removed set this.removedAddrSet.remove(addressWrapper.getInetSocketAddress()); SocketChannel socketChannel = null; ConnectFuture future = new ConnectFuture(addressWrapper); try { socketChannel = SocketChannel.open(); this.configureSocketChannel(socketChannel); if (!socketChannel.connect(addressWrapper.getInetSocketAddress())) { this.selectorManager.registerChannel(socketChannel, SelectionKey.OP_CONNECT, future); } else { this.addSession(this.createSession(socketChannel, addressWrapper)); future.setResult(true); } } catch (Exception e) { if (socketChannel != null) { try { socketChannel.close(); } catch (IOException e1) { //propagate original exception } } future.failure(e); } return future; }
protected MemcachedConnector newConnector(BufferAllocator bufferAllocator, Configuration configuration, MemcachedSessionLocator memcachedSessionLocator, CommandFactory commandFactory, int poolSize, int maxQueuedNoReplyOperations) { // make sure dispatch message thread count is zero configuration.setDispatchMessageThreadCount(0); return new MemcachedConnector(configuration, memcachedSessionLocator, bufferAllocator, commandFactory, poolSize, maxQueuedNoReplyOperations); }