protected void updateLastAccessed() { if(server.connExpireTime() > 0) last_access=getTimestamp(); }
client_sock.setSoTimeout(server.peerAddressReadTimeout()); throw new SocketException(String.format("%s: BaseServer.TcpConnection.readPeerAddress(): cookie sent by " + "%s:%d does not match own cookie; terminating connection", server.localAddress(), client_sock.getInetAddress(), client_sock.getPort()));
public void run() { Throwable t=null; while(canRun()) { try { int len=in.readInt(); // needed to read messages from TCP_NIO2 server.receive(peer_addr, in, len); updateLastAccessed(); } catch(OutOfMemoryError mem_ex) { t=mem_ex; break; // continue; } catch(IOException io_ex) { t=io_ex; break; } catch(Throwable e) { } } server.notifyConnectionClosed(TcpConnection.this, String.format("%s: %s", getClass().getSimpleName(), t != null? t.toString() : "n/a")); } }
@Override public void stop() { if(running.compareAndSet(true, false)) { Util.close(conn); super.stop(); } }
@Override public void start() throws Exception { if(running.compareAndSet(false, true)) { acceptor.start(); super.start(); } }
public void connect(Address dest) throws Exception { connect(dest, server.usePeerConnections()); }
/** Creates a connection stub and binds it, use {@link #connect(Address)} to connect */ public TcpConnection(Address peer_addr, TcpBaseServer server) throws Exception { this.server=server; if(peer_addr == null) throw new IllegalArgumentException("Invalid parameter peer_addr="+ peer_addr); this.peer_addr=peer_addr; this.sock=server.socketFactory().createSocket("jgroups.tcp.sock"); setSocketParameters(sock); last_access=getTimestamp(); // last time a message was sent or received (ns) }
protected long getTimestamp() { return server.timeService() != null? server.timeService().timestamp() : System.nanoTime(); }
protected void connect(Address dest, boolean send_local_addr) throws Exception { SocketAddress destAddr=new InetSocketAddress(((IpAddress)dest).getIpAddress(), ((IpAddress)dest).getPort()); try { if(!server.defer_client_binding) this.sock.bind(new InetSocketAddress(server.client_bind_addr, server.client_bind_port)); Util.connect(this.sock, destAddr, server.sock_conn_timeout); if(this.sock.getLocalSocketAddress() != null && this.sock.getLocalSocketAddress().equals(destAddr)) throw new IllegalStateException("socket's bind and connect address are the same: " + destAddr); this.out=new DataOutputStream(createBufferedOutputStream(sock.getOutputStream())); this.in=new DataInputStream(createBufferedInputStream(sock.getInputStream())); connected=sock.isConnected(); if(send_local_addr) sendLocalAddress(server.localAddress()); } catch(Exception t) { Util.close(this.sock); connected=false; throw t; } }
@Override public void stop() { if(running.compareAndSet(true, false)) { Util.close(srv_sock); Util.interruptAndWaitToDie(acceptor); super.stop(); } }
@Override public void start() throws Exception { if(running.compareAndSet(false, true)) { super.start(); conn=createConnection(remote_addr); addConnectionListener(this); conn.connect(remote_addr, false); local_addr=conn.localAddress(); if(use_peer_connections) conn.sendLocalAddress(local_addr); conn.start(); // starts the receiver thread } }
public void start() throws Exception { server=new TcpServer(getThreadFactory(), getSocketFactory(), bind_addr, bind_port, bind_port+port_range, external_addr, external_port); server.receiver(this) .timeService(time_service) .receiveBufferSize(recv_buf_size) .sendBufferSize(send_buf_size) .socketConnectionTimeout(sock_conn_timeout) .tcpNodelay(tcp_nodelay).linger(linger) .clientBindAddress(client_bind_addr).clientBindPort(client_bind_port).deferClientBinding(defer_client_bind_addr) .log(this.log); server.setBufferedInputStreamSize(buffered_input_stream_size).setBufferedOutputStreamSize(buffered_output_stream_size) .peerAddressReadTimeout(peer_addr_read_timeout) .usePeerConnections(true) .socketFactory(getSocketFactory()); if(reaper_interval > 0 || conn_expire_time > 0) { if(reaper_interval == 0) { reaper_interval=5000; log.warn("reaper_interval was 0, set it to %d", reaper_interval); } if(conn_expire_time == 0) { conn_expire_time=(long) 1000 * 60 * 5; log.warn("conn_expire_time was 0, set it to %d", conn_expire_time); } server.connExpireTimeout(conn_expire_time).reaperInterval(reaper_interval); } // we first start threads in TP (http://jira.jboss.com/jira/browse/JGRP-626) super.start(); }
/** Creates a connection stub and binds it, use {@link #connect(Address)} to connect */ public TcpConnection(Address peer_addr, TcpBaseServer server) throws Exception { this.server=server; if(peer_addr == null) throw new IllegalArgumentException("Invalid parameter peer_addr="+ peer_addr); this.peer_addr=peer_addr; this.sock=server.socketFactory().createSocket("jgroups.tcp.sock"); setSocketParameters(sock); last_access=getTimestamp(); // last time a message was sent or received (ns) }
protected long getTimestamp() { return server.timeService() != null? server.timeService().timestamp() : System.nanoTime(); }
protected void connect(Address dest, boolean send_local_addr) throws Exception { SocketAddress destAddr=new InetSocketAddress(((IpAddress)dest).getIpAddress(), ((IpAddress)dest).getPort()); try { if(!server.defer_client_binding) this.sock.bind(new InetSocketAddress(server.client_bind_addr, server.client_bind_port)); Util.connect(this.sock, destAddr, server.sock_conn_timeout); if(this.sock.getLocalSocketAddress() != null && this.sock.getLocalSocketAddress().equals(destAddr)) throw new IllegalStateException("socket's bind and connect address are the same: " + destAddr); this.out=new DataOutputStream(createBufferedOutputStream(sock.getOutputStream())); this.in=new DataInputStream(createBufferedInputStream(sock.getInputStream())); connected=sock.isConnected(); if(send_local_addr) sendLocalAddress(server.localAddress()); } catch(Exception t) { Util.close(this.sock); connected=false; throw t; } }
public void run() { Throwable t=null; while(canRun()) { try { int len=in.readInt(); // needed to read messages from TCP_NIO2 server.receive(peer_addr, in, len); updateLastAccessed(); } catch(OutOfMemoryError mem_ex) { t=mem_ex; break; // continue; } catch(IOException io_ex) { t=io_ex; break; } catch(Throwable e) { } } server.notifyConnectionClosed(TcpConnection.this, String.format("%s: %s", getClass().getSimpleName(), t != null? t.toString() : "n/a")); } }
client_sock.setSoTimeout(server.peerAddressReadTimeout()); throw new SocketException(String.format("%s: BaseServer.TcpConnection.readPeerAddress(): cookie sent by " + "%s:%d does not match own cookie; terminating connection", server.localAddress(), client_sock.getInetAddress(), client_sock.getPort()));
@Override public void stop() { if(running.compareAndSet(true, false)) { Util.close(conn); super.stop(); } }
@Override public void start() throws Exception { if(running.compareAndSet(false, true)) { acceptor.start(); super.start(); } }
public void connect(Address dest) throws Exception { connect(dest, server.usePeerConnections()); }